Search in sources :

Example 21 with NicProfile

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

the class InternalLoadBalancerVMManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    final DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId());
    final NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control);
    if (controlNic == null) {
        s_logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm);
        return false;
    }
    finalizeSshAndVersionOnStart(cmds, profile, internalLbVm, controlNic);
    // restart network if restartNetwork = false is not specified in profile parameters
    boolean reprogramGuestNtwk = true;
    if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
        reprogramGuestNtwk = false;
    }
    final VirtualRouterProvider lbProvider = _vrProviderDao.findById(internalLbVm.getElementId());
    if (lbProvider == null) {
        throw new CloudRuntimeException("Cannot find related element " + Type.InternalLbVm + " of vm: " + internalLbVm.getHostName());
    }
    final Provider provider = Network.Provider.getProvider(lbProvider.getType().toString());
    if (provider == null) {
        throw new CloudRuntimeException("Cannot find related provider of provider: " + lbProvider.getType().toString());
    }
    if (reprogramGuestNtwk) {
        final NicProfile guestNic = getNicProfileByTrafficType(profile, TrafficType.Guest);
        finalizeLbRulesForIp(cmds, internalLbVm, provider, new Ip(guestNic.getIPv4Address()), guestNic.getNetworkId());
    }
    return true;
}
Also used : VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ip(com.cloud.utils.net.Ip) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) Provider(com.cloud.network.Network.Provider)

Example 22 with NicProfile

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

the class NetworkModelImpl method getNicProfile.

@Override
public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) {
    NicVO nic = null;
    if (broadcastUri != null) {
        nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(networkId, vm.getId(), broadcastUri);
    } else {
        nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vm.getId());
    }
    if (nic == null) {
        return null;
    }
    NetworkVO network = _networksDao.findById(networkId);
    Integer networkRate = getNetworkRate(network.getId(), vm.getId());
    //        NetworkGuru guru = _networkGurus.get(network.getGuruName());
    NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
    //        guru.updateNicProfile(profile, network);
    return profile;
}
Also used : BigInteger(java.math.BigInteger) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO)

Example 23 with NicProfile

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

the class HypervGuru method implement.

@Override
public final VirtualMachineTO implement(VirtualMachineProfile vm) {
    VirtualMachineTO to = toVirtualMachineTO(vm);
    List<NicProfile> nicProfiles = vm.getNics();
    if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
        NicProfile publicNicProfile = null;
        NicProfile controlNicProfile = null;
        NicProfile profile = null;
        for (NicProfile nicProfile : nicProfiles) {
            if (nicProfile.getTrafficType() == TrafficType.Public) {
                publicNicProfile = nicProfile;
                break;
            } else if (nicProfile.getTrafficType() == TrafficType.Control) {
                controlNicProfile = nicProfile;
            }
        }
        if (publicNicProfile != null || controlNicProfile != null) {
            NicTO[] nics = to.getNics();
            // reserve extra NICs
            NicTO[] expandedNics = new NicTO[MaxNicSupported];
            int i = 0;
            int deviceId = -1;
            for (i = 0; i < nics.length; i++) {
                expandedNics[i] = nics[i];
                if (nics[i].getDeviceId() > deviceId)
                    deviceId = nics[i].getDeviceId();
            }
            deviceId++;
            long networkId = 0;
            if (publicNicProfile != null) {
                networkId = publicNicProfile.getNetworkId();
                profile = publicNicProfile;
            } else {
                networkId = controlNicProfile.getNetworkId();
                profile = controlNicProfile;
            }
            NetworkVO network = _networkDao.findById(networkId);
            // creating the VR with extra nics (actual nics(3) + extra nics) will be 8
            for (; i < MaxNicSupported; i++) {
                NicTO nicTo = new NicTO();
                nicTo.setDeviceId(deviceId++);
                nicTo.setBroadcastType(BroadcastDomainType.Vlan);
                nicTo.setType(TrafficType.Public);
                nicTo.setIp("0.0.0.0");
                nicTo.setNetmask("255.255.255.255");
                nicTo.setName(profile.getName());
                try {
                    String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId);
                    nicTo.setMac(mac);
                } catch (InsufficientAddressCapacityException e) {
                    throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
                }
                nicTo.setDns1(profile.getIPv4Dns1());
                nicTo.setDns2(profile.getIPv4Dns2());
                if (publicNicProfile != null && publicNicProfile.getIPv4Gateway() != null) {
                    nicTo.setGateway(publicNicProfile.getIPv4Gateway());
                } else {
                    nicTo.setGateway(network.getGateway());
                }
                nicTo.setDefaultNic(false);
                nicTo.setBroadcastUri(profile.getBroadCastUri());
                nicTo.setIsolationuri(profile.getIsolationUri());
                Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
                nicTo.setNetworkRateMbps(networkRate);
                expandedNics[i] = nicTo;
            }
            to.setNics(expandedNics);
        }
        StringBuffer sbMacSequence = new StringBuffer();
        for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
            sbMacSequence.append(nicTo.getMac()).append("|");
        }
        if (!sbMacSequence.toString().isEmpty()) {
            sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
            String bootArgs = to.getBootArgs();
            to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
        }
    }
    // Determine the VM's OS description
    GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
    to.setOs(guestOS.getDisplayName());
    return to;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) GuestOSVO(com.cloud.storage.GuestOSVO) NicProfile(com.cloud.vm.NicProfile) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicTO(com.cloud.agent.api.to.NicTO)

Example 24 with NicProfile

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

the class GloboDnsElementTest method testPrepareMethodCallGloboDnsToRegisterHostName.

@Test
public void testPrepareMethodCallGloboDnsToRegisterHostName() 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);
    DeployDestination dest = new DeployDestination();
    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(CreateOrUpdateRecordAndReverseCommand.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.prepare(network, nic, vm, dest, context);
    verify(_agentMgr, times(1)).easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) 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) DeployDestination(com.cloud.deploy.DeployDestination) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Network(com.cloud.network.Network) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 25 with NicProfile

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

the class GloboDnsElementTest method testUpperCaseCharactersAreNotAllowed.

@Test(expected = InvalidParameterValueException.class)
public void testUpperCaseCharactersAreNotAllowed() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    Network network = mock(Network.class);
    when(network.getDataCenterId()).thenReturn(zoneId);
    when(network.getId()).thenReturn(1l);
    NicProfile nic = new NicProfile();
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    when(vm.getHostName()).thenReturn("UPPERCASENAME");
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(_datacenterDao.findById(zoneId)).thenReturn(mock(DataCenterVO.class));
    DeployDestination dest = new DeployDestination();
    ReservationContext context = new ReservationContextImpl(null, null, user);
    _globodnsElement.prepare(network, nic, vm, dest, context);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

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