Search in sources :

Example 81 with NicVO

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

the class NetworkOrchestrator method getNicProfileForVm.

protected NicProfile getNicProfileForVm(final Network network, final NicProfile requested, final VirtualMachine vm) {
    NicProfile nic = null;
    if (requested != null && requested.getBroadCastUri() != null) {
        final String broadcastUri = requested.getBroadCastUri().toString();
        final String ipAddress = requested.getIPv4Address();
        final NicVO nicVO = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri);
        if (nicVO != null) {
            if (ipAddress == null || nicVO.getIPv4Address().equals(ipAddress)) {
                nic = _networkModel.getNicProfile(vm, network.getId(), broadcastUri);
            }
        }
    } else {
        final NicVO nicVO = _nicDao.findByNtwkIdAndInstanceId(network.getId(), vm.getId());
        if (nicVO != null) {
            nic = _networkModel.getNicProfile(vm, network.getId(), null);
        }
    }
    return nic;
}
Also used : NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO)

Example 82 with NicVO

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

the class NetworkOrchestrator method getNicProfiles.

@Override
public List<NicProfile> getNicProfiles(final VirtualMachine vm) {
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final List<NicProfile> profiles = new ArrayList<NicProfile>();
    if (nics != null) {
        for (final Nic nic : nics) {
            final NetworkVO network = _networksDao.findById(nic.getNetworkId());
            final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
            final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
            final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
            guru.updateNicProfile(profile, network);
            profiles.add(profile);
        }
    }
    return profiles;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkGuru(com.cloud.network.guru.NetworkGuru) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO)

Example 83 with NicVO

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

the class NetworkOrchestratorTest method testRemoveDhcpServiceWithNic.

@Test
public void testRemoveDhcpServiceWithNic() {
    // make local mocks
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    NicVO nic = mock(NicVO.class);
    NetworkVO network = mock(NetworkVO.class);
    // make sure that release dhcp will be called
    when(vm.getType()).thenReturn(Type.User);
    when(testOrchastrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(true);
    when(network.getTrafficType()).thenReturn(TrafficType.Guest);
    when(network.getGuestType()).thenReturn(GuestType.Shared);
    when(testOrchastrator._nicDao.listByNetworkIdTypeAndGatewayAndBroadcastUri(nic.getNetworkId(), VirtualMachine.Type.User, nic.getIPv4Gateway(), nic.getBroadcastUri())).thenReturn(new ArrayList<NicVO>());
    when(network.getGuruName()).thenReturn(guruName);
    when(testOrchastrator._networksDao.findById(nic.getNetworkId())).thenReturn(network);
    testOrchastrator.removeNic(vm, nic);
    verify(nic, times(1)).setState(Nic.State.Deallocating);
    verify(testOrchastrator._networkModel, times(2)).getElementImplementingProvider(dhcpProvider);
    verify(testOrchastrator._ntwkSrvcDao, times(2)).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
    verify(testOrchastrator._networksDao, times(2)).findById(nic.getNetworkId());
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) Test(org.junit.Test)

Example 84 with NicVO

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

the class NetworkOrchestrator method prepare.

@Override
public void prepare(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
    // we have to implement default nics first - to ensure that default network elements start up first in multiple
    //nics case
    // (need for setting DNS on Dhcp to domR's Ip4 address)
    Collections.sort(nics, new Comparator<NicVO>() {

        @Override
        public int compare(final NicVO nic1, final NicVO nic2) {
            final boolean isDefault1 = nic1.isDefaultNic();
            final boolean isDefault2 = nic2.isDefaultNic();
            return isDefault1 ^ isDefault2 ? isDefault1 ^ true ? 1 : -1 : 0;
        }
    });
    for (final NicVO nic : nics) {
        final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter);
        if (implemented == null || implemented.first() == null) {
            s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId());
            throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId());
        }
        final NetworkVO network = implemented.second();
        final NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network);
        vmProfile.addNic(profile);
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO)

Example 85 with NicVO

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

the class NetworkOrchestrator method prepareNic.

@Override
public NicProfile prepareNic(final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context, final long nicId, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vmProfile.getId());
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    final NicVO nic = _nicDao.findById(nicId);
    NicProfile profile = null;
    if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
        nic.setState(Nic.State.Reserving);
        nic.setReservationId(context.getReservationId());
        _nicDao.update(nic.getId(), nic);
        URI broadcastUri = nic.getBroadcastUri();
        if (broadcastUri == null) {
            broadcastUri = network.getBroadcastUri();
        }
        final URI isolationUri = nic.getIsolationUri();
        profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.reserve(profile, network, vmProfile, dest, context);
        nic.setIPv4Address(profile.getIPv4Address());
        nic.setAddressFormat(profile.getFormat());
        nic.setIPv6Address(profile.getIPv6Address());
        nic.setIPv6Cidr(profile.getIPv6Cidr());
        nic.setIPv6Gateway(profile.getIPv6Gateway());
        nic.setMacAddress(profile.getMacAddress());
        nic.setIsolationUri(profile.getIsolationUri());
        nic.setBroadcastUri(profile.getBroadCastUri());
        nic.setReserver(guru.getName());
        nic.setState(Nic.State.Reserved);
        nic.setIPv4Netmask(profile.getIPv4Netmask());
        nic.setIPv4Gateway(profile.getIPv4Gateway());
        if (profile.getReservationStrategy() != null) {
            nic.setReservationStrategy(profile.getReservationStrategy());
        }
        updateNic(nic, network.getId(), 1);
    } else {
        profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getHypervisorType(), network));
        guru.updateNicProfile(profile, network);
        nic.setState(Nic.State.Reserved);
        updateNic(nic, network.getId(), 1);
    }
    final List<Provider> providersToImplement = getNetworkProviders(network.getId());
    for (final NetworkElement element : networkElements) {
        if (providersToImplement.contains(element.getProvider())) {
            if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network), element.getProvider().getName())) {
                throw new CloudRuntimeException("Service provider " + element.getProvider().getName() + " either doesn't exist or is not enabled in physical network id: " + network.getPhysicalNetworkId());
            }
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
            }
            if (!prepareElement(element, network, profile, vmProfile, dest, context)) {
                throw new InsufficientAddressCapacityException("unable to configure the dhcp service, due to insufficiant address capacity", Network.class, network.getId());
            }
        }
    }
    profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
    guru.updateNicProfile(profile, network);
    return profile;
}
Also used : NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkGuru(com.cloud.network.guru.NetworkGuru) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) URI(java.net.URI) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider)

Aggregations

NicVO (com.cloud.vm.NicVO)86 NetworkVO (com.cloud.network.dao.NetworkVO)33 ArrayList (java.util.ArrayList)21 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 NicProfile (com.cloud.vm.NicProfile)15 VMInstanceVO (com.cloud.vm.VMInstanceVO)13 DataCenterVO (com.cloud.dc.DataCenterVO)12 Commands (com.cloud.agent.manager.Commands)11 Network (com.cloud.network.Network)11 HostVO (com.cloud.host.HostVO)10 UserVmVO (com.cloud.vm.UserVmVO)10 Answer (com.cloud.agent.api.Answer)9 NetworkGuru (com.cloud.network.guru.NetworkGuru)9 Nic (com.cloud.vm.Nic)9 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)9 Test (org.junit.Test)9 DataCenter (com.cloud.dc.DataCenter)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 VirtualRouter (com.cloud.network.router.VirtualRouter)7