Search in sources :

Example 16 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)

Example 17 with Vpc

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

the class CommandSetupHelper method configureRemoteAccessVpn.

private void configureRemoteAccessVpn(final VirtualRouter router, final RemoteAccessVpn remoteAccessVpnToExclude, final NetworkOverviewTO.VPNTO vpnTO) {
    final RemoteAccessVpnVO vpn = _remoteAccessVpnDao.findByAccountAndVpc(router.getAccountId(), router.getVpcId());
    if (vpn != null && !vpn.equals(remoteAccessVpnToExclude)) {
        final NetworkOverviewTO.VPNTO.RemoteAccessTO remoteAccessTO = new NetworkOverviewTO.VPNTO.RemoteAccessTO();
        final IpAddress serverIp = _networkModel.getIp(vpn.getServerAddressId());
        remoteAccessTO.setVpnServerIp(serverIp.getAddress().addr());
        remoteAccessTO.setPreSharedKey(vpn.getIpsecPresharedKey());
        remoteAccessTO.setIpRange(vpn.getIpRange());
        remoteAccessTO.setLocalIp(vpn.getLocalIp());
        final Vpc vpc = _vpcDao.findById(vpn.getVpcId());
        remoteAccessTO.setLocalCidr(vpc.getCidr());
        remoteAccessTO.setVpnUsers(_vpnUsersDao.listByAccount(vpn.getAccountId()).stream().filter(vpnUser -> VpnUser.State.Add.equals(vpnUser.getState()) || VpnUser.State.Active.equals(vpnUser.getState())).map(vpnUser -> new NetworkOverviewTO.VPNTO.RemoteAccessTO.VPNUserTO(vpnUser.getUsername(), vpnUser.getPassword())).toArray(NetworkOverviewTO.VPNTO.RemoteAccessTO.VPNUserTO[]::new));
        vpnTO.setRemoteAccess(remoteAccessTO);
    }
}
Also used : LbStickinessPolicy(com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy) NetworkModel(com.cloud.network.NetworkModel) VpnUser(com.cloud.legacymodel.network.VpnUser) Nic(com.cloud.legacymodel.network.Nic) StaticRouteProfile(com.cloud.legacymodel.network.vpc.StaticRouteProfile) NetworkACLTO(com.cloud.legacymodel.to.NetworkACLTO) ServiceOfferingDao(com.cloud.service.dao.ServiceOfferingDao) VlanDao(com.cloud.dc.dao.VlanDao) Map(java.util.Map) ZoneRepository(com.cloud.db.repository.ZoneRepository) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) FirewallRule(com.cloud.legacymodel.network.FirewallRule) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) NicTO(com.cloud.legacymodel.to.NicTO) LoadBalancingRule(com.cloud.legacymodel.network.LoadBalancingRule) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) StaticNatRule(com.cloud.legacymodel.network.StaticNatRule) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) SetPublicIpACLCommand(com.cloud.legacymodel.communication.command.SetPublicIpACLCommand) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) SetStaticNatRulesCommand(com.cloud.legacymodel.communication.command.SetStaticNatRulesCommand) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) VpnUserDao(com.cloud.network.dao.VpnUserDao) NumbersUtil(com.cloud.utils.NumbersUtil) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine) Ip(com.cloud.legacymodel.network.Ip) Zone(com.cloud.db.model.Zone) UpdateVmOverviewCommand(com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand) NicProfile(com.cloud.vm.NicProfile) ArrayList(java.util.ArrayList) Purpose(com.cloud.legacymodel.network.FirewallRule.Purpose) VlanVO(com.cloud.dc.VlanVO) ConfigurationDao(com.cloud.framework.config.dao.ConfigurationDao) DomainRouterVO(com.cloud.vm.DomainRouterVO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) Site2SiteVpnConnection(com.cloud.network.Site2SiteVpnConnection) PortForwardingRule(com.cloud.legacymodel.network.PortForwardingRule) DomainRouterDao(com.cloud.vm.dao.DomainRouterDao) SavePasswordCommand(com.cloud.legacymodel.communication.command.SavePasswordCommand) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) PublicIpACLTO(com.cloud.legacymodel.to.PublicIpACLTO) Site2SiteVpnConnectionDao(com.cloud.network.dao.Site2SiteVpnConnectionDao) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) UserVmDao(com.cloud.vm.dao.UserVmDao) NetworkElementCommand(com.cloud.legacymodel.communication.command.NetworkElementCommand) NicDao(com.cloud.vm.dao.NicDao) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) Site2SiteCustomerGatewayDao(com.cloud.network.dao.Site2SiteCustomerGatewayDao) StaticRouteDao(com.cloud.network.vpc.dao.StaticRouteDao) SetPortForwardingRulesVpcCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesVpcCommand) FirewallRuleTO(com.cloud.legacymodel.to.FirewallRuleTO) PortForwardingRuleTO(com.cloud.legacymodel.to.PortForwardingRuleTO) SetPortForwardingRulesCommand(com.cloud.legacymodel.communication.command.SetPortForwardingRulesCommand) Site2SiteVpnGatewayDao(com.cloud.network.dao.Site2SiteVpnGatewayDao) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) StaticNatRuleTO(com.cloud.legacymodel.to.StaticNatRuleTO) URI(java.net.URI) Config(com.cloud.configuration.Config) SetFirewallRulesCommand(com.cloud.legacymodel.communication.command.SetFirewallRulesCommand) StringUtils(com.cloud.utils.StringUtils) SetNetworkACLCommand(com.cloud.legacymodel.communication.command.SetNetworkACLCommand) TrafficType(com.cloud.model.enumeration.TrafficType) LBStickinessPolicyDao(com.cloud.network.dao.LBStickinessPolicyDao) Commands(com.cloud.agent.manager.Commands) IpAddress(com.cloud.network.IpAddress) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) NicVO(com.cloud.vm.NicVO) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Collectors(java.util.stream.Collectors) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) List(java.util.List) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) NetworkACLItem(com.cloud.legacymodel.network.vpc.NetworkACLItem) RemoteAccessVpnDao(com.cloud.network.dao.RemoteAccessVpnDao) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) Optional(java.util.Optional) NetUtils(com.cloud.utils.net.NetUtils) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StaticNat(com.cloud.network.rules.StaticNat) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) HashMap(java.util.HashMap) NetworkDao(com.cloud.network.dao.NetworkDao) Inject(javax.inject.Inject) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkVO(com.cloud.network.dao.NetworkVO) Qualifier(org.springframework.beans.factory.annotation.Qualifier) IPAddressDao(com.cloud.network.dao.IPAddressDao) VMOverviewTO(com.cloud.legacymodel.to.VMOverviewTO) GuestType(com.cloud.model.enumeration.GuestType) FirewallRulesDao(com.cloud.network.dao.FirewallRulesDao) Network(com.cloud.legacymodel.network.Network) NetworkACLItemDao(com.cloud.network.vpc.NetworkACLItemDao) SetupVRCommand(com.cloud.legacymodel.communication.command.SetupVRCommand) PublicIpAddress(com.cloud.network.PublicIpAddress) NetworkOffering(com.cloud.offering.NetworkOffering) UserVmVO(com.cloud.vm.UserVmVO) VpcDao(com.cloud.network.vpc.dao.VpcDao) NetworkOfferingDao(com.cloud.offerings.dao.NetworkOfferingDao) LoadBalancer(com.cloud.legacymodel.network.LoadBalancer) Vpc(com.cloud.legacymodel.network.vpc.Vpc) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) Vpc(com.cloud.legacymodel.network.vpc.Vpc) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress)

Example 18 with Vpc

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

the class CommandSetupHelper method configureSyslog.

private void configureSyslog(final VirtualRouter router, final NetworkOverviewTO networkOverviewTO) {
    final Vpc vpc = _vpcDao.findById(router.getVpcId());
    if (StringUtils.isNotBlank(vpc.getSyslogServerList())) {
        final NetworkOverviewTO.SyslogTO syslogTO = new NetworkOverviewTO.SyslogTO();
        syslogTO.setServers(vpc.getSyslogServerList().split(","));
        networkOverviewTO.setSyslog(syslogTO);
    }
}
Also used : Vpc(com.cloud.legacymodel.network.vpc.Vpc) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO)

Example 19 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 20 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)

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