@Override public VpcResponse createVpcResponse(ResponseView view, Vpc vpc) { VpcResponse response = new VpcResponse(); response.setId(vpc.getUuid()); response.setName(vpc.getName()); response.setDisplayText(vpc.getDisplayText()); response.setState(vpc.getState().name()); VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId()); if (voff != null) { response.setVpcOfferingId(voff.getUuid()); response.setCidr(vpc.getCidr()); response.setRestartRequired(vpc.isRestartRequired()); response.setNetworkDomain(vpc.getNetworkDomain()); response.setForDisplay(vpc.isDisplay()); response.setUsesDistributedRouter(vpc.usesDistributedRouter()); response.setRedundantRouter(vpc.isRedundant()); response.setRegionLevelVpc(vpc.isRegionLevelVpc()); Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId()); List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>(); for (Map.Entry<Service,Set<Provider>>entry : serviceProviderMap.entrySet()) { List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId()); for (Network network : networks) { NetworkResponse ntwkRsp = createNetworkResponse(view, network); DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId()); if (zone != null) { response.setZoneId(zone.getUuid());
@Override public StaticRouteVO doInTransaction(final TransactionStatus status) throws NetworkRuleConflictException { StaticRouteVO newRoute = new StaticRouteVO(gateway.getId(), cidr, vpc.getId(), vpc.getAccountId(), vpc.getDomainId()); s_logger.debug("Adding static route " + newRoute); newRoute = _staticRouteDao.persist(newRoute); detectRoutesConflict(newRoute); if (!_staticRouteDao.setStateToAdd(newRoute)) { throw new CloudRuntimeException("Unable to update the state to add for " + newRoute); } CallContext.current().setEventDetails("Static route Id: " + newRoute.getId()); return newRoute; } });
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { _vpcDao.update(vpc.getId(), vpcVO); // decrement resource count _resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc); } });
@Override public void startVpc(Vpc vpc) { if (vpc.getState() != Vpc.State.Enabled) { try { _vpcService.startVpc(vpc.getId(), true); } catch (ResourceUnavailableException | InsufficientCapacityException e) { s_logger.error("Vpc can not be started. Aborting migration process"); throw new CloudRuntimeException("Vpc can not be started.", e); } } }
@Override public PublicIp assignSourceNatIpAddressToVpc(final Account owner, final Vpc vpc) throws InsufficientAddressCapacityException, ConcurrentOperationException { final long dcId = vpc.getZoneId(); final IPAddressVO sourceNatIp = getExistingSourceNatInVpc(owner.getId(), vpc.getId()); PublicIp ipToReturn = null; if (sourceNatIp != null) { ipToReturn = PublicIp.createFromAddrAndVlan(sourceNatIp, _vlanDao.findById(sourceNatIp.getVlanId())); } else { ipToReturn = _ipAddrMgr.assignDedicateIpAddress(owner, null, vpc.getId(), dcId, true); } return ipToReturn; }
@Override public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { if (vpc.getState().equals(Vpc.State.Inactive)) { List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId()); if (CollectionUtils.isEmpty(routers)) { routers = _routerDao.listIncludingRemovedByVpcId(vpc.getId()); Domain vpcDomain = _domainDao.findById(vpc.getDomainId()); VpcDetailVO domainTemplateNameDetail = _vpcDetailsDao.findDetail(vpc.getId(), NuageVspManager.nuageDomainTemplateDetailName); if (domainTemplateNameDetail != null) { preConfiguredDomainTemplateName = domainTemplateNameDetail.getValue(); Map<String, String> vpcDetails = _vpcDetailsDao.listDetailsKeyPairs(vpc.getId(), false); cleanUpVpcCaching(vpc.getId()); List<? extends ResourceTag> vpcResourceDetails = _resourceTagDao.listByResourceUuid(vpc.getUuid()); if (vpcResourceDetails != null) { vpcResourceDetails.stream() ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand(vpcDomain.getUuid(), vpc.getUuid(), preConfiguredDomainTemplateName, domainRouterUuids, vpcDetails); send(cmd, vpc);
@Override public void create() throws ResourceAllocationException { Vpc vpc = _vpcService.createVpc(getZoneId(), getVpcOffering(), getEntityOwnerId(), getVpcName(), getDisplayText(), getCidr(), getNetworkDomain(), getDisplayVpc()); if (vpc != null) { setEntityId(vpc.getId()); setEntityUuid(vpc.getUuid()); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a VPC"); } }
if (shutdownVpc(vpc.getId())) { return startVpc(vpc.getId(), false); _ntwkMgr.destroyExpendableRouters(_routerDao.listByVpcId(vpc.getId()), context); final DeployDestination dest = new DeployDestination(_dcDao.findById(vpc.getZoneId()), null, null, null); final List<DomainRouterVO> oldRouters = _routerDao.listByVpcId(vpc.getId()); vpc.setRollingRestart(true); vpc.setRollingRestart(false); if (vpc.isRedundant() || (oldRouters.size() == 1 && oldRouters.get(0).getIsRedundantRouter())) { try { Thread.sleep(NetworkOrchestrationService.RVRHandoverTime); return _ntwkMgr.areRoutersRunning(_routerDao.listByVpcId(vpc.getId()));
private void reassignPublicIpsToNewVpc(long srcVpcId, Vpc dstVpc) { List<? extends IPAddressVO> publicIps = _ipAddressDao.listByAssociatedVpc(srcVpcId, _vpcManager.isSrcNatIpRequired(dstVpc.getVpcOfferingId()) ? null : false); for(IPAddressVO publicIp : publicIps) { publicIp.setVpcId(dstVpc.getId()); _ipAddressDao.persist(publicIp); } }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { final Vpc locked = _vpcDao.acquireInLockTable(vpc.getId()); if (locked == null) { throw new CloudRuntimeException("Unable to acquire lock on " + vpc); if (_ntwkDao.countVpcNetworks(vpc.getId()) >= _maxNetworks) { throw new CloudRuntimeException("Number of networks per VPC can't extend " + _maxNetworks + "; increase it using global config " + Config.VpcMaxNetworks); if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) { throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr"); final List<? extends Network> ntwks = _ntwkDao.listByVpc(vpc.getId()); for (final Network ntwk : ntwks) { assert cidr != null : "Why the network cidr is null when it belongs to vpc?"; if (vpc.getAccountId() != networkOwner.getId()) { throw new InvalidParameterValueException("Vpc " + vpc + " owner is different from the network owner " + networkOwner); if (!networkDomain.equalsIgnoreCase(vpc.getNetworkDomain())) { throw new InvalidParameterValueException("Network domain of the new network should match network" + " domain of vpc " + vpc); _vpcDao.releaseFromLockTable(locked.getId());
private void send(Command cmd, Vpc vpc) throws ResourceUnavailableException { send(cmd, getPhysicalNetworkId(vpc.getZoneId()), Vpc.class, vpc); }
@Override public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { List<VpcOfferingServiceMapVO> vpcOfferingServices = _vpcOfferingSrvcDao.listByVpcOffId(vpc.getVpcOfferingId()); Multimap<Service, Provider> supportedVpcServices = NuageVspManagerImpl.SUPPORTED_NUAGE_VSP_VPC_SERVICE_MAP; for (VpcOfferingServiceMapVO vpcOfferingService : vpcOfferingServices) { Network.Service service = Network.Service.getService(vpcOfferingService.getService()); if (!supportedVpcServices.containsKey(service)) { s_logger.warn(String.format("NuageVsp doesn't support service %s for VPCs", service.getName())); return false; } Network.Provider provider = Network.Provider.getProvider(vpcOfferingService.getProvider()); if (!supportedVpcServices.containsEntry(service, provider)) { s_logger.warn(String.format("NuageVsp doesn't support provider %s for service %s for VPCs", provider.getName(), service.getName())); return false; } } String globalDomainTemplate = _nuageVspManager.NuageVspVpcDomainTemplateName.value(); if (StringUtils.isNotBlank(globalDomainTemplate) && !_nuageVspManager.checkIfDomainTemplateExist(vpc.getDomainId(),globalDomainTemplate,vpc.getZoneId(),null)) { s_logger.warn("The global pre configured domain template does not exist on the VSD."); throw new CloudRuntimeException("The global pre configured domain template does not exist on the VSD."); } return true; }
@Override public long getEntityOwnerId() { Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); return vpc.getAccountId(); }
final String networkName = "vpc-" + vpc.getName() + "-privateNetwork"; privateNtwk = _ntwkSvc.createPrivateNetwork(networkName, networkName, physicalNetworkIdFinal, broadcastUri, ipAddress, null, gateway, netmask, gatewayOwnerId, vpcId, isSourceNat, networkOfferingId); gateway, netmask, vpc.getAccountId(), vpc.getDomainId(), isSourceNat, networkAclId); _vpcGatewayDao.persist(gatewayVO);
@DB @Override public Network createVpcGuestNetwork(final long ntwkOffId, final String name, final String displayText, final String gateway, final String cidr, final String vlanId, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk, final long zoneId, final ACLType aclType, final Boolean subdomainAccess, final long vpcId, final Long aclId, final Account caller, final Boolean isDisplayNetworkEnabled, String externalId) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException { final Vpc vpc = getActiveVpc(vpcId); if (vpc == null) { final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC "); ex.addProxyObject(String.valueOf(vpcId), "VPC"); throw ex; } _accountMgr.checkAccess(caller, null, false, vpc); if (networkDomain == null) { networkDomain = vpc.getNetworkDomain(); } if (!vpc.isRegionLevelVpc() && vpc.getZoneId() != zoneId) { throw new InvalidParameterValueException("New network doesn't belong to vpc zone"); } // 1) Validate if network can be created for VPC validateNtwkOffForNtwkInVpc(null, ntwkOffId, cidr, networkDomain, vpc, gateway, owner, aclId); // 2) Create network final Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, false, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, null, null, isDisplayNetworkEnabled, null, externalId); if (guestNetwork != null) { guestNetwork.setNetworkACLId(aclId); _ntwkDao.update(guestNetwork.getId(), (NetworkVO) guestNetwork); } return guestNetwork; }
final DataCenter dc = _entityMgr.findById(DataCenter.class, vpc.getZoneId()); final ReservationContext context = new ReservationContextImpl(null, null, callerUser, _accountMgr.getAccount(vpc.getAccountId()));