@Override public boolean shutdown(final Network network, final ReservationContext context, final boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { final List<DomainRouterVO> routers = getRouters(network); if (routers == null || routers.isEmpty()) { return true; } boolean stopResult = true; boolean destroyResult = true; for (final DomainRouterVO router : routers) { stopResult = stopResult && _routerMgr.stop(router, false, context.getCaller(), context.getAccount()) != null; if (!stopResult) { s_logger.warn("Failed to stop virtual router element " + router + ", but would try to process clean up anyway."); } if (cleanup) { destroyResult = destroyResult && _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null; if (!destroyResult) { s_logger.warn("Failed to clean up virtual router element " + router); } } } return stopResult & destroyResult; }
@Override public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { List<? extends VirtualRouter> internalLbVms = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM); if (internalLbVms == null || internalLbVms.isEmpty()) { return true; } boolean result = true; for (VirtualRouter internalLbVm : internalLbVms) { result = result && (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId())); } return result; }
@Override public boolean shutdownVpc(final Vpc vpc, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { final List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId()); if (routers == null || routers.isEmpty()) { return true; } boolean result = true; for (final DomainRouterVO router : routers) { result = result && _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null; } return result; }
@Override public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { List<? extends VirtualRouter> internalLbVms = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM); if (internalLbVms == null || internalLbVms.isEmpty()) { return true; } boolean result = true; for (VirtualRouter internalLbVm : internalLbVms) { result = result && _internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId()); if (cleanup) { if (!result) { s_logger.warn("Failed to stop internal lb element " + internalLbVm + ", but would try to process clean up anyway."); } result = (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId())); if (!result) { s_logger.warn("Failed to clean up internal lb element " + internalLbVm); } } } return result; }
@Override public void destroyExpendableRouters(final List<? extends VirtualRouter> routers, final ReservationContext context) throws ResourceUnavailableException { final List<VirtualRouter> remainingRouters = new ArrayList<>(); for (final VirtualRouter router : routers) { if (router.getState() == VirtualMachine.State.Stopped || router.getState() == VirtualMachine.State.Error || router.getState() == VirtualMachine.State.Shutdowned || router.getState() == VirtualMachine.State.Unknown) { s_logger.debug("Destroying old router " + router); _routerService.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()); } else { remainingRouters.add(router); } } if (remainingRouters.size() < 2) { return; } VirtualRouter backupRouter = null; for (final VirtualRouter router : remainingRouters) { if (router.getRedundantState() == VirtualRouter.RedundantState.BACKUP) { backupRouter = router; } } if (backupRouter == null) { backupRouter = routers.get(routers.size() - 1); } if (backupRouter != null) { _routerService.destroyRouter(backupRouter.getId(), context.getAccount(), context.getCaller().getId()); } }
cleanupResult = shutdownNetworkResources(network.getId(), context.getAccount(), context.getCaller().getId());
@Override public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException { assert (network.getState() == State.Implementing) : "Why are we implementing " + network; Network implemented = super.implement(network, offering, dest, context); int vlanTag = Integer.parseInt(BroadcastDomainType.getValue(implemented.getBroadcastUri())); //get physical network id Long physicalNetworkId = network.getPhysicalNetworkId(); List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { s_logger.error("No Brocade VCS Switch on physical network " + physicalNetworkId); return null; } for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) { HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId()); // create createNetworkCmd instance and agentMgr execute it. CreateNetworkCommand cmd = new CreateNetworkCommand(vlanTag, network.getId(), context.getDomain().getName() + "-" + context.getAccount().getAccountName()); CreateNetworkAnswer answer = (CreateNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("CreateNetworkCommand failed"); s_logger.error("Unable to create network " + network.getId()); return null; } } // Persist the network-vlan mapping from db BrocadeVcsNetworkVlanMappingVO brocadeVcsNetworkVlanMapping = new BrocadeVcsNetworkVlanMappingVO(network.getId(), vlanTag); _brocadeVcsNetworkVlanDao.persist(brocadeVcsNetworkVlanMapping); return implemented; }
@Override public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), Type.InternalLbVm); if (element == null) { return true; } long elementId = element.getId(); List<DomainRouterVO> internalLbVms = _routerDao.listByElementId(elementId); boolean result = true; for (DomainRouterVO internalLbVm : internalLbVms) { result = result && (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId())); } _vrProviderDao.remove(elementId); return result; }
@Override @DB public boolean destroyNetwork(final long networkId, final ReservationContext context, final boolean forced) { final Account callerAccount = context.getAccount();
@Override public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { super.reserve(nic, network, vm, dest, context); //get physical network id Long physicalNetworkId = network.getPhysicalNetworkId(); List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId); if (devices.isEmpty()) { s_logger.error("No Controller on physical network " + physicalNetworkId); throw new InsufficientVirtualNetworkCapacityException("No OpenDaylight Controller configured for this network", dest.getPod().getId()); } OpenDaylightControllerVO controller = devices.get(0); AddHypervisorCommand addCmd = new AddHypervisorCommand(dest.getHost().getUuid(), dest.getHost().getPrivateIpAddress()); AddHypervisorAnswer addAnswer = (AddHypervisorAnswer)agentManager.easySend(controller.getHostId(), addCmd); if (addAnswer == null || !addAnswer.getResult()) { s_logger.error("Failed to add " + dest.getHost().getName() + " as a node to the controller"); throw new InsufficientVirtualNetworkCapacityException("Failed to add destination hypervisor to the OpenDaylight Controller", dest.getPod().getId()); } ConfigurePortCommand cmd = new ConfigurePortCommand(UUID.fromString(nic.getUuid()), UUID.fromString(BroadcastDomainType.getValue(network.getBroadcastUri())), context .getAccount().getAccountName(), nic.getMacAddress()); ConfigurePortAnswer answer = (ConfigurePortAnswer)agentManager.easySend(controller.getHostId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("ConfigureNetworkCommand failed"); throw new InsufficientVirtualNetworkCapacityException("Failed to configure the port on the OpenDaylight Controller", dest.getPod().getId()); } }
@Override public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException { super.reserve(nic, network, vm, dest, context); DataCenter dc = _dcDao.findById(network.getDataCenterId()); String interfaceMac = nic.getMacAddress(); List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId()); if (devices.isEmpty()) { s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId()); return; } for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) { HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId()); // create AssociateMacToNetworkCmd instance and agentMgr execute it. AssociateMacToNetworkCommand cmd = new AssociateMacToNetworkCommand(network.getId(), interfaceMac, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer)_agentMgr.easySend(brocadeVcsHost.getId(), cmd); if (answer == null || !answer.getResult()) { s_logger.error("AssociateMacToNetworkCommand failed"); throw new InsufficientVirtualNetworkCapacityException("Unable to associate mac " + interfaceMac + " to network " + network.getId(), DataCenter.class, dc.getId()); } } }
_routerService.destroyRouter(oldRouter.getId(), context.getAccount(), context.getCaller().getId());
@Override public boolean shutdownProviderInstances(final PhysicalNetworkServiceProvider provider, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { final VirtualRouterProviderVO element = _vrProviderDao.findByNspIdAndType(provider.getId(), getVirtualRouterProvider()); if (element == null) { return true; } // Find domain routers final long elementId = element.getId(); final List<DomainRouterVO> routers = _routerDao.listByElementId(elementId); boolean result = true; for (final DomainRouterVO router : routers) { result = result && _routerMgr.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId()) != null; } _vrProviderDao.remove(elementId); return result; }
+ context.getAccount().getAccountName()); final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
_routerService.destroyRouter(oldRouter.getId(), context.getAccount(), context.getCaller().getId());
ConfigureNetworkCommand cmd = new ConfigureNetworkCommand(name, context.getAccount().getAccountName()); ConfigureNetworkAnswer answer = (ConfigureNetworkAnswer)agentManager.easySend(controller.getHostId(), cmd);
hostDao.loadDetails(niciraNvpHost); Account owner = context.getAccount(); String ownerName = context.getDomain().getName() + "-" + context.getAccount().getAccountName(); return sharedNetworkSupport(network, lSwitchUuid, ownerName, niciraNvpHost); new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName()); CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd); if (answer.getResult() == false) {
UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName()); agentMgr.easySend(niciraNvpHost.getId(), cmd); return true; context.getAccount().getAccountName(), nic.getName()); CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId(); s_logger.info("Implemented OK, network " + implemented.getUuid() + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri()); } finally {