Search in sources :

Example 26 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createPrivateGatewayResponse.

@Override
public PrivateGatewayResponse createPrivateGatewayResponse(final PrivateGateway result) {
    final PrivateGatewayResponse response = new PrivateGatewayResponse();
    response.setId(result.getUuid());
    if (result.getVpcId() != null) {
        final Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
        response.setVpcId(vpc.getUuid());
    }
    final DataCenter zone = ApiDBUtils.findZoneById(result.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setAddress(result.getIp4Address());
    final Network network = ApiDBUtils.findNetworkById(result.getNetworkId());
    response.setNetworkId(network.getUuid());
    response.setNetworkName(network.getName());
    response.setCidr(network.getCidr());
    populateAccount(response, result.getAccountId());
    populateDomain(response, result.getDomainId());
    response.setState(result.getState().toString());
    response.setSourceNat(result.getSourceNat());
    final NetworkACL acl = ApiDBUtils.findByNetworkACLId(result.getNetworkACLId());
    if (acl != null) {
        response.setAclId(acl.getUuid());
    }
    response.setObjectName("privategateway");
    return response;
}
Also used : PrivateGatewayResponse(com.cloud.api.response.PrivateGatewayResponse) DataCenter(com.cloud.legacymodel.dc.DataCenter) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) Vpc(com.cloud.legacymodel.network.vpc.Vpc) NetworkACL(com.cloud.legacymodel.network.vpc.NetworkACL)

Example 27 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createStaticRouteResponse.

@Override
public StaticRouteResponse createStaticRouteResponse(final StaticRoute result) {
    final StaticRouteResponse response = new StaticRouteResponse();
    response.setId(result.getUuid());
    if (result.getVpcId() != null) {
        final Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
        }
    }
    response.setCidr(result.getCidr());
    response.setGwIpAddress(result.getGwIpAddress());
    StaticRoute.State state = result.getState();
    if (state.equals(StaticRoute.State.Revoke)) {
        state = StaticRoute.State.Deleting;
    }
    response.setState(state.toString());
    populateAccount(response, result.getAccountId());
    populateDomain(response, result.getDomainId());
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        if (tagResponse != null) {
            tagResponses.add(tagResponse);
        }
    }
    response.setTags(tagResponses);
    response.setObjectName("staticroute");
    return response;
}
Also used : StaticRouteResponse(com.cloud.api.response.StaticRouteResponse) StaticRoute(com.cloud.legacymodel.network.vpc.StaticRoute) ResourceTag(com.cloud.server.ResourceTag) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList)

Example 28 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method deployRouter.

@Override
public DomainRouterVO deployRouter(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean startRouter) throws InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException, StorageUnavailableException, ResourceUnavailableException {
    final List<DomainRouterVO> routers;
    final boolean isRedundant;
    if (routerDeploymentDefinition.isVpcRouter()) {
        final Vpc vpc = routerDeploymentDefinition.getVpc();
        routers = _routerDao.listByVpcId(vpc.getId());
        isRedundant = vpc.isRedundant();
    } else {
        final Network guestnetwork = routerDeploymentDefinition.getGuestNetwork();
        routers = _routerDao.listByNetworkAndRole(guestnetwork.getId(), Role.VIRTUAL_ROUTER);
        isRedundant = guestnetwork.isRedundant();
    }
    ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId());
    if (isRedundant && routers != null && routers.size() == 1 && routers.get(0).getServiceOfferingId() == routerDeploymentDefinition.getServiceOfferingId()) {
        routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getSecondaryServiceOfferingId());
    }
    Long routerUnicastId = 1L;
    if (isRedundant && routers != null && routers.size() == 1 && routers.get(0).getRouterUnicastId() != null && routers.get(0).getRouterUnicastId() == 1L) {
        routerUnicastId = 2L;
    }
    _serviceOfferingDao.loadDetails(routerOffering);
    final String serviceofferingHypervisor = routerOffering.getDetail("hypervisor");
    if (serviceofferingHypervisor != null && !serviceofferingHypervisor.isEmpty()) {
        logger.debug(String.format("Found hypervisor '%s' in details of serviceoffering with id %s. Going to check if that hypervisor is available.", serviceofferingHypervisor, routerDeploymentDefinition.getServiceOfferingId()));
    }
    final Account owner = routerDeploymentDefinition.getOwner();
    // Router is the network element, we don't know the hypervisor type yet.
    // Try to allocate the domR twice using diff hypervisors, and when
    // failed both times, throw the exception up
    final List<HypervisorType> hypervisors = getHypervisors(routerDeploymentDefinition);
    int allocateRetry = 0;
    int startRetry = 0;
    DomainRouterVO router = null;
    for (final Iterator<HypervisorType> iter = hypervisors.iterator(); iter.hasNext(); ) {
        final HypervisorType hType = iter.next();
        try {
            final long id = _routerDao.getNextInSequence(Long.class, "id");
            if (serviceofferingHypervisor != null && !serviceofferingHypervisor.isEmpty() && !hType.toString().equalsIgnoreCase(serviceofferingHypervisor)) {
                logger.debug(String.format("Skipping hypervisor type '%s' as the service offering details request hypervisor '%s'", hType, serviceofferingHypervisor));
                continue;
            }
            logger.debug(String.format("Allocating the VR with id=%s in datacenter %s with the hypervisor type %s", id, routerDeploymentDefinition.getDest().getZone(), hType));
            final String templateName = retrieveTemplateName(hType, routerDeploymentDefinition.getDest().getZone().getId());
            final VMTemplateVO template = _templateDao.findRoutingTemplate(hType, templateName, routerDeploymentDefinition.getDest().getZone().getId());
            if (template == null) {
                logger.debug(hType + " won't support system vm, skip it");
                continue;
            }
            final boolean offerHA = routerOffering.getOfferHA();
            // routerDeploymentDefinition.getVpc().getId() ==> do not use
            // VPC because it is not a VPC offering.
            final Long vpcId = routerDeploymentDefinition.getVpc() != null ? routerDeploymentDefinition.getVpc().getId() : null;
            long userId = CallContext.current().getCallingUserId();
            if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
                final List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
                if (!userVOs.isEmpty()) {
                    userId = userVOs.get(0).getId();
                }
            }
            router = new DomainRouterVO(id, routerOffering.getId(), routerDeploymentDefinition.getVirtualProvider().getId(), VirtualMachineName.getRouterName(id, s_vmInstanceName), template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, routerDeploymentDefinition.isRedundant(), RedundantState.UNKNOWN, offerHA, false, vpcId, template.getOptimiseFor(), template.getManufacturerString(), template.getCpuFlags(), template.getMacLearning(), false, template.getMaintenancePolicy(), routerUnicastId);
            router.setDynamicallyScalable(template.isDynamicallyScalable());
            router.setRole(Role.VIRTUAL_ROUTER);
            router = _routerDao.persist(router);
            reallocateRouterNetworks(routerDeploymentDefinition, router, template, null);
            router = _routerDao.findById(router.getId());
        } catch (final InsufficientCapacityException ex) {
            if (allocateRetry < 2 && iter.hasNext()) {
                logger.debug("Failed to allocate the VR with hypervisor type " + hType + ", retrying one more time");
                continue;
            } else {
                throw ex;
            }
        } finally {
            allocateRetry++;
        }
        if (startRouter) {
            try {
                final Account caller = CallContext.current().getCallingAccount();
                final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
                router = startVirtualRouter(router, callerUser, caller, routerDeploymentDefinition.getParams());
                break;
            } catch (final InsufficientCapacityException ex) {
                if (startRetry < 2 && iter.hasNext()) {
                    logger.debug("Failed to start the VR  " + router + " with hypervisor type " + hType + ", " + "destroying it and recreating one more time");
                    // destroy the router
                    destroyRouter(router.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM);
                    continue;
                } else {
                    throw ex;
                }
            } finally {
                startRetry++;
            }
        } else {
            // return stopped router
            return router;
        }
    }
    return router;
}
Also used : Account(com.cloud.legacymodel.user.Account) User(com.cloud.legacymodel.user.User) Vpc(com.cloud.legacymodel.network.vpc.Vpc) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HypervisorType(com.cloud.model.enumeration.HypervisorType) UserVO(com.cloud.user.UserVO) Network(com.cloud.legacymodel.network.Network) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 29 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class NicProfileHelperImpl method createPrivateNicProfileForGateway.

@Override
@DB
public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) {
    final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
    final Long vpcId = privateGateway.getVpcId();
    final Vpc activeVpc = _vpcMgr.getActiveVpc(vpcId);
    PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), vpcId, privateGateway.getIp4Address());
    if (activeVpc.isRedundant() && ipVO == null) {
        ipVO = _privateIpDao.findByIpAndVpcId(vpcId, privateGateway.getIp4Address());
    }
    Nic privateNic = null;
    if (ipVO != null) {
        privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
    }
    NicProfile privateNicProfile = new NicProfile();
    if (privateNic != null) {
        privateNicProfile = new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(privateNetwork.getId(), router.getId()), _networkModel.getNetworkTag(router.getHypervisorType(), privateNetwork));
        if (router.getIsRedundantRouter()) {
            final String newMacAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
            privateNicProfile.setMacAddress(newMacAddress);
        }
    } else {
        final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask, NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
        final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
        privateNicProfile.setIPv4Address(ip.getIpAddress());
        privateNicProfile.setIPv4Gateway(ip.getGateway());
        privateNicProfile.setIPv4Netmask(ip.getNetmask());
        privateNicProfile.setIsolationUri(netUri);
        privateNicProfile.setBroadcastUri(netUri);
        // can we solve this in setBroadcastUri()???
        // or more plugable construct is desirable
        privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri));
        privateNicProfile.setFormat(IpAddressFormat.Ip4);
        privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri()));
        privateNicProfile.setMacAddress(ip.getMacAddress());
    }
    return privateNicProfile;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) Network(com.cloud.legacymodel.network.Network) Vpc(com.cloud.legacymodel.network.vpc.Vpc) Nic(com.cloud.legacymodel.network.Nic) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) DB(com.cloud.utils.db.DB)

Example 30 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeVirtualMachineProfile.

@Override
public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) {
    boolean dnsProvided = true;
    boolean dhcpProvided = true;
    boolean publicNetwork = false;
    final DataCenterVO dc = _dcDao.findById(dest.getZone().getId());
    _dcDao.loadDetails(dc);
    // 1) Set router details
    final DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId());
    final Vpc vpc = _vpcDao.findById(router.getVpcId());
    final List<DomainRouterVO> routerList = _routerDao.listByVpcId(router.getVpcId());
    final Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(router.getId());
    router.setDetails(details);
    // 2) Prepare boot loader elements related with Control network
    final StringBuilder buf = profile.getBootArgsBuilder();
    buf.append(" template=domP");
    buf.append(" name=").append(profile.getHostName());
    if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
        buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
    }
    NicProfile controlNic = null;
    String defaultDns1 = null;
    String defaultDns2 = null;
    String defaultIp6Dns1 = null;
    String defaultIp6Dns2 = null;
    for (final NicProfile nic : profile.getNics()) {
        final Network network = _networkDao.findById(nic.getNetworkId());
        final String deviceMac = nic.getMacAddress();
        if (nic.isDefaultNic()) {
            buf.append(" gateway=").append(nic.getIPv4Gateway());
            defaultDns1 = nic.getIPv4Dns1();
            defaultDns2 = nic.getIPv4Dns2();
            defaultIp6Dns1 = nic.getIPv6Dns1();
            defaultIp6Dns2 = nic.getIPv6Dns2();
        }
        if (nic.getTrafficType() == TrafficType.Management) {
            buf.append(" localgw=").append(dest.getPod().getGateway());
        } else if (nic.getTrafficType() == TrafficType.Control) {
            controlNic = nic;
            buf.append(" controlmac=").append(deviceMac);
            buf.append(" controlmask=").append(nic.getIPv4Netmask());
            buf.append(" controlip=").append(nic.getIPv4Address());
            buf.append(createRedundantRouterArgs(controlNic, router));
        } else if (TrafficType.Guest.equals(nic.getTrafficType()) && !GuestType.Sync.equals(network.getGuestType())) {
            dnsProvided = _networkModel.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter);
            dhcpProvided = _networkModel.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter);
            // build bootloader parameter for the guest
            buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router));
        } else if (TrafficType.Guest.equals(nic.getTrafficType()) && GuestType.Sync.equals(network.getGuestType())) {
            buf.append(" syncmac=").append(deviceMac);
        } else if (nic.getTrafficType() == TrafficType.Public) {
            publicNetwork = true;
        }
    }
    if (controlNic == null) {
        throw new CloudRuntimeException("Didn't start a control port");
    }
    final String rpValue = _configDao.getValue(Config.NetworkRouterRpFilter.key());
    _disableRpFilter = rpValue != null && rpValue.equalsIgnoreCase("true");
    String rpFilter = " ";
    final String type;
    if (router.getVpcId() != null) {
        type = "vpcrouter";
        if (_disableRpFilter) {
            rpFilter = " disable_rp_filter=true";
        }
    } else if (!publicNetwork) {
        type = "dhcpsrvr";
    } else {
        type = "router";
        if (_disableRpFilter) {
            rpFilter = " disable_rp_filter=true";
        }
    }
    if (_disableRpFilter) {
        rpFilter = " disable_rp_filter=true";
    }
    buf.append(" type=").append(type).append(rpFilter);
    final String domain_suffix = dc.getDetail(ZoneConfig.DnsSearchOrder.getName());
    if (domain_suffix != null) {
        buf.append(" dnssearchorder=").append(domain_suffix);
    }
    /*
         * If virtual router didn't provide DNS service but provide DHCP
         * service, we need to override the DHCP response to return DNS server
         * rather than virtual router itself.
         */
    if (dnsProvided || dhcpProvided) {
        if (defaultDns1 != null) {
            buf.append(" dns1=").append(defaultDns1);
        }
        if (defaultDns2 != null) {
            buf.append(" dns2=").append(defaultDns2);
        }
        if (defaultIp6Dns1 != null) {
            buf.append(" ip6dns1=").append(defaultIp6Dns1);
        }
        if (defaultIp6Dns2 != null) {
            buf.append(" ip6dns2=").append(defaultIp6Dns2);
        }
        boolean useExtDns = !dnsProvided;
        /* For backward compatibility */
        useExtDns = useExtDns || UseExternalDnsServers.valueIn(dc.getId());
        if (useExtDns) {
            buf.append(" useextdns=true");
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) Network(com.cloud.legacymodel.network.Network) Vpc(com.cloud.legacymodel.network.vpc.Vpc) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Vpc (com.cloud.legacymodel.network.vpc.Vpc)60 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)24 Account (com.cloud.legacymodel.user.Account)24 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)17 DomainRouterVO (com.cloud.vm.DomainRouterVO)17 Network (com.cloud.legacymodel.network.Network)15 ArrayList (java.util.ArrayList)14 NetworkACL (com.cloud.legacymodel.network.vpc.NetworkACL)11 ActionEvent (com.cloud.event.ActionEvent)9 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)9 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)8 NetworkVO (com.cloud.network.dao.NetworkVO)8 List (java.util.List)8 ServerApiException (com.cloud.api.ServerApiException)7 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 DB (com.cloud.utils.db.DB)7 VpcResponse (com.cloud.api.response.VpcResponse)6 CallContext (com.cloud.context.CallContext)6 DataCenter (com.cloud.legacymodel.dc.DataCenter)6