Search in sources :

Example 46 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class GloboDnsElementTest method testReleaseMethodCallResource.

@Test
public void testReleaseMethodCallResource() throws Exception {
    Network network = mock(Network.class);
    when(network.getDataCenterId()).thenReturn(zoneId);
    when(network.getId()).thenReturn(1l);
    NicProfile nic = new NicProfile();
    nic.setIPv4Address("10.11.12.13");
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    when(vm.getHostName()).thenReturn("vm-name");
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    DataCenterVO dataCenterVO = mock(DataCenterVO.class);
    when(dataCenterVO.getId()).thenReturn(zoneId);
    when(_datacenterDao.findById(zoneId)).thenReturn(dataCenterVO);
    ReservationContext context = new ReservationContextImpl(null, null, user);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(globoDnsHostId);
    when(_hostDao.findByTypeNameAndZoneId(eq(zoneId), eq(Provider.GloboDns.getName()), eq(Type.L2Networking))).thenReturn(hostVO);
    when(_agentMgr.easySend(eq(globoDnsHostId), isA(RemoveRecordCommand.class))).then(new org.mockito.stubbing.Answer<Answer>() {

        @Override
        public Answer answer(InvocationOnMock invocation) throws Throwable {
            Command cmd = (Command) invocation.getArguments()[1];
            return new Answer(cmd);
        }
    });
    _globodnsElement.release(network, nic, vm, context);
    verify(_agentMgr, times(1)).easySend(eq(globoDnsHostId), isA(RemoveRecordCommand.class));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Answer(com.cloud.agent.api.Answer) RemoveRecordCommand(com.globo.globodns.cloudstack.commands.RemoveRecordCommand) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Command(com.cloud.agent.api.Command) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Network(com.cloud.network.Network) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) Test(org.junit.Test)

Example 47 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method finalizeVirtualMachineProfile.

@Override
public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) {
    //Internal LB vm starts up with 2 Nics
    //Nic #1 - Guest Nic with IP address that would act as the LB entry point
    //Nic #2 - Control/Management Nic
    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;
    Network guestNetwork = null;
    for (final NicProfile nic : profile.getNics()) {
        final int deviceId = nic.getDeviceId();
        buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address());
        buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask());
        if (nic.isDefaultNic()) {
            buf.append(" gateway=").append(nic.getIPv4Gateway());
            buf.append(" dns1=").append(nic.getIPv4Gateway());
        }
        if (nic.getTrafficType() == TrafficType.Guest) {
            guestNetwork = _ntwkModel.getNetwork(nic.getNetworkId());
        } else if (nic.getTrafficType() == TrafficType.Management) {
            buf.append(" localgw=").append(dest.getPod().getGateway());
        } else if (nic.getTrafficType() == TrafficType.Control) {
            controlNic = nic;
            // Internal LB control command is sent over management server in VMware
            if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Check if we need to add management server explicit route to Internal LB. pod cidr: " + dest.getPod().getCidrAddress() + "/" + dest.getPod().getCidrSize() + ", pod gateway: " + dest.getPod().getGateway() + ", management host: " + _mgmtHost);
                }
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Add management server explicit route to Internal LB.");
                }
                buf.append(" mgmtcidr=").append(_mgmtCidr);
                buf.append(" localgw=").append(dest.getPod().getGateway());
            }
        }
    }
    if (controlNic == null) {
        throw new CloudRuntimeException("Didn't start a control port");
    }
    if (guestNetwork != null) {
        final String domain = guestNetwork.getNetworkDomain();
        if (domain != null) {
            buf.append(" domain=" + domain);
        }
    }
    final String type = "ilbvm";
    buf.append(" type=" + type);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
    }
    return true;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile)

Example 48 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method createApplyLoadBalancingRulesCommands.

private void createApplyLoadBalancingRulesCommands(final List<LoadBalancingRule> rules, final VirtualRouter internalLbVm, final Commands cmds, final long guestNetworkId) {
    final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
    int i = 0;
    final boolean inline = false;
    for (final LoadBalancingRule rule : rules) {
        final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke);
        final String protocol = rule.getProtocol();
        final String algorithm = rule.getAlgorithm();
        final String uuid = rule.getUuid();
        final String srcIp = rule.getSourceIp().addr();
        final int srcPort = rule.getSourcePortStart();
        final List<LbDestination> destinations = rule.getDestinations();
        final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
        final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies);
        lbs[i++] = lb;
    }
    final Network guestNetwork = _ntwkModel.getNetwork(guestNetworkId);
    final Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId());
    final NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(), _ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()), _ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _ntwkModel.getNetworkTag(internalLbVm.getHypervisorType(), guestNetwork));
    final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
    String maxconn = null;
    if (offering.getConcurrentConnections() == null) {
        maxconn = _configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
    } else {
        maxconn = offering.getConcurrentConnections().toString();
    }
    final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, guestNic.getIPv4Address(), guestNic.getIPv4Address(), internalLbVm.getPrivateIpAddress(), _itMgr.toNicTO(guestNicProfile, internalLbVm.getHypervisorType()), internalLbVm.getVpcId(), maxconn, offering.isKeepAliveEnabled());
    cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
    cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
    cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
    cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, getInternalLbControlIp(internalLbVm.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, guestNic.getIPv4Address());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, internalLbVm.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(internalLbVm.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) NetworkOffering(com.cloud.offering.NetworkOffering) Nic(com.cloud.vm.Nic) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) NicProfile(com.cloud.vm.NicProfile) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) Network(com.cloud.network.Network) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 49 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method createInternalLbVmNetworks.

protected LinkedHashMap<Network, List<? extends NicProfile>> createInternalLbVmNetworks(final Network guestNetwork, final DeploymentPlan plan, final Ip guestIp) throws ConcurrentOperationException, InsufficientAddressCapacityException {
    //Form networks
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
    //1) Guest network - default
    if (guestNetwork != null) {
        s_logger.debug("Adding nic for Internal LB in Guest network " + guestNetwork);
        final NicProfile guestNic = new NicProfile();
        if (guestIp != null) {
            guestNic.setIPv4Address(guestIp.addr());
        } else {
            guestNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null));
        }
        guestNic.setIPv4Gateway(guestNetwork.getGateway());
        guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
        guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
        guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
        guestNic.setMode(guestNetwork.getMode());
        final String gatewayCidr = guestNetwork.getCidr();
        guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr));
        guestNic.setDefaultNic(true);
        networks.put(guestNetwork, new ArrayList<NicProfile>(Arrays.asList(guestNic)));
    }
    //2) Control network
    s_logger.debug("Adding nic for Internal LB vm in Control network ");
    final List<? extends NetworkOffering> offerings = _ntwkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
    final NetworkOffering controlOffering = offerings.get(0);
    final Network controlConfig = _ntwkMgr.setupNetwork(_accountMgr.getSystemAccount(), controlOffering, plan, null, null, false).get(0);
    networks.put(controlConfig, new ArrayList<NicProfile>());
    return networks;
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 50 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method findOrDeployInternalLbVm.

@DB
protected List<DomainRouterVO> findOrDeployInternalLbVm(final Network guestNetwork, final Ip requestedGuestIp, final DeployDestination dest, final Account owner, final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    List<DomainRouterVO> internalLbVms = new ArrayList<DomainRouterVO>();
    final Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), NetworkOrchestrationService.NetworkLockTimeout.value());
    if (lock == null) {
        throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId());
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Lock is acquired for network id " + lock.getId() + " as a part of internal lb startup in " + dest);
    }
    final long internalLbProviderId = getInternalLbProviderId(guestNetwork);
    try {
        assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
        assert guestNetwork.getTrafficType() == TrafficType.Guest;
        //deploy internal lb vm
        final Pair<DeploymentPlan, List<DomainRouterVO>> planAndInternalLbVms = getDeploymentPlanAndInternalLbVms(dest, guestNetwork.getId(), requestedGuestIp);
        internalLbVms = planAndInternalLbVms.second();
        final DeploymentPlan plan = planAndInternalLbVms.first();
        if (internalLbVms.size() > 0) {
            s_logger.debug("Found " + internalLbVms.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr());
            return internalLbVms;
        }
        final LinkedHashMap<Network, List<? extends NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
        long internalLbVmOfferingId = _internalLbVmOfferingId;
        if (internalLbVmOfferingId == 0L) {
            ServiceOfferingVO serviceOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.internalLbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
            internalLbVmOfferingId = serviceOffering.getId();
        }
        //Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
        final DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
        if (internalLbVm != null) {
            _internalLbVmDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
            internalLbVms.add(internalLbVm);
        }
    } finally {
        if (lock != null) {
            _networkDao.releaseFromLockTable(lock.getId());
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Lock is released for network id " + lock.getId() + " as a part of internal lb vm startup in " + dest);
            }
        }
    }
    return internalLbVms;
}
Also used : Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DeploymentPlan(com.cloud.deploy.DeploymentPlan) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) DB(com.cloud.utils.db.DB)

Aggregations

NicProfile (com.cloud.vm.NicProfile)84 Network (com.cloud.network.Network)31 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 NetworkVO (com.cloud.network.dao.NetworkVO)27 ArrayList (java.util.ArrayList)23 DataCenterVO (com.cloud.dc.DataCenterVO)19 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 DomainRouterVO (com.cloud.vm.DomainRouterVO)16 NicVO (com.cloud.vm.NicVO)14 List (java.util.List)14 DataCenter (com.cloud.dc.DataCenter)13 NetworkOffering (com.cloud.offering.NetworkOffering)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 NetworkGuru (com.cloud.network.guru.NetworkGuru)11 LinkedHashMap (java.util.LinkedHashMap)11 Provider (com.cloud.network.Network.Provider)10 Nic (com.cloud.vm.Nic)10 ReservationContext (com.cloud.vm.ReservationContext)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9