public static VpcVO findVpcById(long vpcId) { return s_vpcDao.findById(vpcId); }
boolean isVpcEnabledForDistributedRouter(long vpcId) { VpcVO vpc = _vpcDao.findById(vpcId); return vpc.usesDistributedRouter(); } }
boolean isVpcEnabledForDistributedRouter(long vpcId) { VpcVO vpc = _vpcDao.findById(vpcId); return vpc.usesDistributedRouter(); }
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 deleteCopyOfVpc(long vpcCopyId, long originalVpcId) { VpcVO copyOfvpc = _vpcDao.findById(vpcCopyId); VpcVO originalVpc = _vpcDao.findById(originalVpcId); //Be sure that when we delete the vpc, it has the uuid with what it was created. swapUuids(copyOfvpc, originalVpc); try { if(!_vpcService.deleteVpc(vpcCopyId)) { throw new CloudRuntimeException("Deletion of VPC failed. Clean up was not successful."); } } catch (ResourceUnavailableException e) { throw new CloudRuntimeException(e.getMessage()); } finally { swapUuids(originalVpc, copyOfvpc); } _resourceTagDao.removeByResourceIdAndKey(originalVpcId, ResourceTag.ResourceObjectType.Vpc, MIGRATION); }
@Override public PublicIp doInTransaction(TransactionStatus status) throws InsufficientAddressCapacityException { Account owner = _accountDao.acquireInLockTable(ownerId); if (owner == null) { // this ownerId comes from owner or type Account. See the class "AccountVO" and the annotations in that class // to get the table name and field name that is queried to fill this ownerid. ConcurrentOperationException ex = new ConcurrentOperationException("Unable to lock account"); throw ex; } if (s_logger.isDebugEnabled()) { s_logger.debug("lock account " + ownerId + " is acquired"); } boolean displayIp = true; if (guestNtwkId != null) { Network ntwk = _networksDao.findById(guestNtwkId); displayIp = ntwk.getDisplayNetwork(); } else if (vpcId != null) { VpcVO vpc = _vpcDao.findById(vpcId); displayIp = vpc.isDisplay(); } return fetchNewPublicIp(dcId, null, null, owner, VlanType.VirtualNetwork, guestNtwkId, isSourceNat, true, null, false, vpcId, displayIp, false); } });
@Override public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException { _router = router; VpcDao vpcDao = visitor.getVirtualNetworkApplianceFactory().getVpcDao(); Vpc vpc = vpcDao.findById(_remoteAccessVpn.getVpcId()); if (_router.getState() != State.Running) { s_logger.warn("Failed to add/remove Remote Access VPN users: router not in running state"); throw new ResourceUnavailableException("Failed to add/remove Remote Access VPN users: router not in running state: " + router.getState(), DataCenter.class, vpc.getZoneId()); } return visitor.visit(this); } }
List<OvsVpcRoutingPolicyConfigCommand.Tier> tiers = new ArrayList<>(); VpcVO vpc = _vpcDao.findById(vpcId); List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId); assert (vpc != null && (vpcNetworks != null && !vpcNetworks.isEmpty())): "invalid vpc id";
@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; }
/** Build VspDhcpVMOption to put on the subnet */ public VspDhcpDomainOption buildNetworkDhcpOption(Network network, NetworkOffering offering) { List<String> dnsProvider = _ntwkOfferingSrvcDao.listProvidersForServiceForNetworkOffering(offering.getId(), Network.Service.Dns); boolean isVrDnsProvider = dnsProvider.contains("VirtualRouter") || dnsProvider.contains("VpcVirtualRouter"); VspDhcpDomainOption.Builder vspDhcpDomainBuilder = new VspDhcpDomainOption.Builder() .dnsServers(_nuageVspManager.getDnsDetails(network.getDataCenterId())) .vrIsDnsProvider(isVrDnsProvider); if (isVrDnsProvider) { vspDhcpDomainBuilder.networkDomain(network.getVpcId() != null ? _vpcDao.findById(network.getVpcId()).getNetworkDomain() : network.getNetworkDomain()); } return vspDhcpDomainBuilder.build(); }
private void handleVmStateChange(VMInstanceVO vm) { // get the VPC's impacted with the VM start List<Long> vpcIds = _ovsNetworkToplogyGuru.getVpcIdsVmIsPartOf(vm.getId()); if (vpcIds == null || vpcIds.isEmpty()) { return; } for (Long vpcId: vpcIds) { VpcVO vpc = _vpcDao.findById(vpcId); // nothing to do if the VPC is not setup for distributed routing if (vpc == null || !vpc.usesDistributedRouter()) { return; } // get the list of hosts on which VPC spans (i.e hosts that need to be aware of VPC topology change update) List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId); String bridgeName=generateBridgeNameForVpc(vpcId); OvsVpcPhysicalTopologyConfigCommand topologyConfigCommand = prepareVpcTopologyUpdate(vpcId); topologyConfigCommand.setSequenceNumber(getNextTopologyUpdateSequenceNumber(vpcId)); // send topology change update to VPC spanned hosts for (Long id: vpcSpannedHostIds) { if (!sendVpcTopologyChangeUpdate(topologyConfigCommand, id, bridgeName)) { s_logger.debug("Failed to send VPC topology change update to host : " + id + ". Moving on " + "with rest of the host update."); } } } }
private void verifyAlreadyMigratedTiers(long migratedVpcId, long vpcOfferingId, Map<String, String> networkToOffering) { Vpc migratedVpc = _vpcDao.findById(migratedVpcId); if (migratedVpc.getVpcOfferingId() != vpcOfferingId) { s_logger.error("The vpc is already partially migrated in a previous run. The provided vpc offering is not the same as the one used during the first migration process."); throw new InvalidParameterValueException("Failed to resume migrating VPC as VPC offering does not match previously specified VPC offering (" + migratedVpc.getVpcOfferingId() + ")"); } List<NetworkVO> migratedTiers = _networksDao.listByVpc(migratedVpcId); for (Network tier : migratedTiers) { String tierNetworkOfferingUuid = networkToOffering.get(tier.getUuid()); if (!StringUtils.isNotBlank(tierNetworkOfferingUuid)) { throwInvalidIdException("Failed to resume migrating VPC as the specified tierNetworkOfferings is not complete", String.valueOf(tier.getUuid()), "networkUuid"); } NetworkOfferingVO newNetworkOffering = _networkOfferingDao.findByUuid(tierNetworkOfferingUuid); if (newNetworkOffering == null) { throw new InvalidParameterValueException("Failed to migrate VPC as at least one tier offering in tierNetworkOfferings does not exist."); } if (newNetworkOffering.getId() != tier.getNetworkOfferingId()) { NetworkOfferingVO tierNetworkOffering = _networkOfferingDao.findById(tier.getNetworkOfferingId()); throw new InvalidParameterValueException( "Failed to resume migrating VPC as at least one network offering in tierNetworkOfferings does not match previously specified network offering (network uuid=" + tier.getUuid() + " was previously specified with offering uuid=" + tierNetworkOffering.getUuid() + ")"); } } }
@Override public Long makeCopyOfVpc(long vpcId, long vpcOfferingId) { VpcVO vpc = _vpcDao.findById(vpcId); if (s_logger.isDebugEnabled()) { s_logger.debug("Making a copy of vpc with uuid " + vpc.getUuid() + " and id " + vpc.getId() + " for migration."); VpcVO copyVpcVO = _vpcDao.findById(copyOfVpcId); vpc.setDisplay(false); swapUuids(vpc, copyVpcVO);
final Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid VPC id provided");
@Override @ActionEvent(eventType = EventTypes.EVENT_VPC_DELETE, eventDescription = "deleting VPC") public boolean deleteVpc(final long vpcId) throws ConcurrentOperationException, ResourceUnavailableException { CallContext.current().setEventDetails(" Id: " + vpcId); final CallContext ctx = CallContext.current(); // Verify vpc id final Vpc vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("unable to find VPC id=" + vpcId); } // verify permissions _accountMgr.checkAccess(ctx.getCallingAccount(), null, false, vpc); _resourceTagDao.removeByIdAndType(vpcId, ResourceObjectType.Vpc); return destroyVpc(vpc, ctx.getCallingAccount(), ctx.getCallingUserId()); }
@Override @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", async = true) public Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd) { Account caller = CallContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); //Verify that caller can perform actions in behalf of vpc owner _accountMgr.checkAccess(caller, null, false, owner); Long vpcId = cmd.getVpcId(); VpcVO vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid VPC " + vpcId + " for site to site vpn gateway creation!"); } Site2SiteVpnGatewayVO gws = _vpnGatewayDao.findByVpcId(vpcId); if (gws != null) { throw new InvalidParameterValueException("The VPN gateway of VPC " + vpcId + " already existed!"); } //Use source NAT ip for VPC List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, true); if (ips.size() != 1) { throw new CloudRuntimeException("Cannot found source nat ip of vpc " + vpcId); } Site2SiteVpnGatewayVO gw = new Site2SiteVpnGatewayVO(owner.getAccountId(), owner.getDomainId(), ips.get(0).getId(), vpcId); if (cmd.getDisplay() != null) { gw.setDisplay(cmd.getDisplay()); } _vpnGatewayDao.persist(gw); return gw; }
@Override public void associateNuageVspDomainTemplate(AssociateNuageVspDomainTemplateCmd cmd){ VpcVO vpc = _vpcDao.findById(cmd.getVpcId()); Long physicalNetworkId; if (cmd.getPhysicalNetworkId() != null) { physicalNetworkId = cmd.getPhysicalNetworkId(); } else if (cmd.getZoneId() != null) { physicalNetworkId = getPhysicalNetworkBasedOnZone(cmd.getZoneId()); } else { throw new InvalidParameterValueException("No zoneid or physicalnetworkid specified."); } EntityExistsCommand entityCmd = new EntityExistsCommand(VpcVO.class, vpc.getUuid()); boolean exists = entityExist(entityCmd, physicalNetworkId); if (exists) { throw new CloudRuntimeException("Failed to associate domain template, VPC is already pushed to the Nuage VSP device."); } if (!checkIfDomainTemplateExist(vpc.getDomainId(), cmd.getDomainTemplate(), cmd.getZoneId(), cmd.getPhysicalNetworkId())) { throw new InvalidParameterValueException("Could not find a Domain Template with name: " + cmd.getDomainTemplate()); } setPreConfiguredDomainTemplateName(cmd.getVpcId(), cmd.getDomainTemplate()); }
public void createApplyVpnCommands(final boolean isCreate, final RemoteAccessVpn vpn, final VirtualRouter router, final Commands cmds) { final List<VpnUserVO> vpnUsers = _vpnUsersDao.listByAccount(vpn.getAccountId()); createApplyVpnUsersCommand(vpnUsers, router, cmds); final IpAddress ip = _networkModel.getIp(vpn.getServerAddressId()); // This block is needed due to the line 206 of the // RemoteAccessVpnManagenerImpl: // TODO: assumes one virtual network / domr per account per zone final String cidr; final Network network = _networkDao.findById(vpn.getNetworkId()); if (network == null) { final Vpc vpc = _vpcDao.findById(vpn.getVpcId()); cidr = vpc.getCidr(); } else { cidr = network.getCidr(); } final RemoteAccessVpnCfgCommand startVpnCmd = new RemoteAccessVpnCfgCommand(isCreate, ip.getAddress().addr(), vpn.getLocalIp(), vpn.getIpRange(), vpn.getIpsecPresharedKey(), vpn.getVpcId() != null); startVpnCmd.setLocalCidr(cidr); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); startVpnCmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); startVpnCmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("startVpn", startVpnCmd); }
public void createSite2SiteVpnCfgCommands(final Site2SiteVpnConnection conn, final boolean isCreate, final VirtualRouter router, final Commands cmds) { final Site2SiteCustomerGatewayVO gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId()); final Site2SiteVpnGatewayVO vpnGw = _s2sVpnGatewayDao.findById(conn.getVpnGatewayId()); final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId()); final Vpc vpc = _vpcDao.findById(ip.getVpcId()); final String localPublicIp = ip.getAddress().toString(); final String localGuestCidr = vpc.getCidr(); final String localPublicGateway = _vlanDao.findById(ip.getVlanId()).getVlanGateway(); final String peerGatewayIp = gw.getGatewayIp(); final String peerGuestCidrList = gw.getGuestCidrList(); final String ipsecPsk = gw.getIpsecPsk(); final String ikePolicy = gw.getIkePolicy(); final String espPolicy = gw.getEspPolicy(); final Long ikeLifetime = gw.getIkeLifetime(); final Long espLifetime = gw.getEspLifetime(); final Boolean dpd = gw.getDpd(); final Boolean encap = gw.getEncap(); final Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(isCreate, localPublicIp, localPublicGateway, localGuestCidr, peerGatewayIp, peerGuestCidrList, ikePolicy, espPolicy, ipsecPsk, ikeLifetime, espLifetime, dpd, conn.isPassive(), encap); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("applyS2SVpn", cmd); }