@Override protected void planDeploymentRouters() { routers = routerDao.listByVpcId(vpc.getId()); }
@Override public Long getSyncObjId() { Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid id is specified for the vpc"); } return vpc.getId(); }
@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); } } }
protected boolean startVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { // deploy provider boolean success = true; final List<Provider> providersToImplement = getVpcProviders(vpc.getId()); for (final VpcProvider element : getVpcElements()) { if (providersToImplement.contains(element.getProvider())) { if (element.implementVpc(vpc, dest, context)) { s_logger.debug("Vpc " + vpc + " has started successfully"); } else { s_logger.warn("Vpc " + vpc + " failed to start"); success = false; } } } return success; }
protected boolean applyStaticRoutes(final List<StaticRouteProfile> routes) throws ResourceUnavailableException { if (routes.isEmpty()) { s_logger.debug("No static routes to apply"); return true; } final Vpc vpc = _vpcDao.findById(routes.get(0).getVpcId()); s_logger.debug("Applying static routes for vpc " + vpc); final String staticNatProvider = _vpcSrvcDao.getProviderForServiceInVpc(vpc.getId(), Service.StaticNat); for (final VpcProvider provider : getVpcElements()) { if (!(provider instanceof StaticNatServiceProvider && provider.getName().equalsIgnoreCase(staticNatProvider))) { continue; } if (provider.applyStaticRoutes(vpc, routes)) { s_logger.debug("Applied static routes for vpc " + vpc); } else { s_logger.warn("Failed to apply static routes for vpc " + vpc); return false; } } return true; }
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { _vpcDao.update(vpc.getId(), vpcVO); // decrement resource count _resourceLimitMgr.decrementResourceCount(vpc.getAccountId(), ResourceType.vpc); } });
@Override public boolean applyStaticRoutes(final Vpc vpc, final List<StaticRouteProfile> routes) throws ResourceUnavailableException { final List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId()); if (routers == null || routers.isEmpty()) { s_logger.debug("Virtual router elemnt doesn't need to static routes on the backend; virtual " + "router doesn't exist in the vpc " + vpc); return true; } final DataCenterVO dcVO = _dcDao.findById(vpc.getZoneId()); final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO); if (!networkTopology.applyStaticRoutes(routes, routers)) { throw new CloudRuntimeException("Failed to apply static routes in vpc " + vpc); } else { s_logger.debug("Applied static routes on vpc " + vpc); return true; } }
@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; }
public String getPublicIpByVpc(Vpc vpc){ List<IPAddressVO> allocatedIps = _ipAddressDao.listByAssociatedVpc(vpc.getId(), true); for (IPAddressVO ip: allocatedIps){ if(ip.isSourceNat()){ return ip.getAddress().addr(); } } return null; }
@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 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()); 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());
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 boolean shutdownVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { final CallContext ctx = CallContext.current(); final Account caller = ctx.getCallingAccount(); // check if vpc exists final Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Unable to find vpc by id " + vpcId); } // permission check _accountMgr.checkAccess(caller, null, false, vpc); // shutdown provider s_logger.debug("Shutting down vpc " + vpc); // TODO - shutdown all vpc resources here (ACLs, gateways, etc) boolean success = true; final List<Provider> providersToImplement = getVpcProviders(vpc.getId()); final ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(ctx.getCallingUserId()), caller); for (final VpcProvider element : getVpcElements()) { if (providersToImplement.contains(element.getProvider())) { if (element.shutdownVpc(vpc, context)) { s_logger.debug("Vpc " + vpc + " has been shutdown succesfully"); } else { s_logger.warn("Vpc " + vpc + " failed to shutdown"); success = false; } } } return success; }
@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; } });
copyOfVpc = _vpcService.createVpc(vpc.getZoneId(), vpcOfferingId, vpc.getAccountId(), vpc.getName(), vpc.getDisplayText(), vpc.getCidr(), vpc.getNetworkDomain(), vpc.isDisplay()); copyOfVpcId = copyOfVpc.getId(); copyVpcResourceTagsToNewVpc(vpcId, copyOfVpcId); if (s_logger.isDebugEnabled()) { s_logger.debug("Succesfully created a copy of network " + vpc.getName() + "(" + vpc.getUuid() + ") id is " + vpc.getId() + " for migration. The network copy has uuid " + copyVpcVO.getUuid() + " and id " + copyOfVpc.getId());
@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"); } }
private void updateBcfRouter(Network network) throws IllegalArgumentException{ bcfUtilsInit(); Vpc vpc = null; if(network.getVpcId()!=null){ vpc = _vpcDao.acquireInLockTable(network.getVpcId()); } String tenantId; if (vpc != null) { tenantId = vpc.getUuid(); _vpcDao.releaseFromLockTable(vpc.getId()); } else { tenantId = network.getUuid(); } UpdateBcfRouterCommand cmd = new UpdateBcfRouterCommand(tenantId); List<AclData> aclList = _bcfUtils.listACLbyNetwork(network); for(AclData acl: aclList){ cmd.addAcl(acl); } if(vpc != null){ cmd.setPublicIp(_bcfUtils.getPublicIpByVpc(vpc)); } else { cmd.setPublicIp(_bcfUtils.getPublicIpByNetwork(network)); } BcfAnswer answer = _bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network); if(answer != null && !answer.getResult()){ throw new IllegalArgumentException("Illegal router update arguments"); } }
if (vpc != null) { tenantId = vpc.getUuid(); _vpcDao.releaseFromLockTable(vpc.getId()); } else {
tenantId = vpc.getUuid(); tenantName = vpc.getName(); _vpcDao.releaseFromLockTable(vpc.getId()); } else {