Search in sources :

Example 1 with NicVO

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

the class NetworkOrchestratorTest method testDontRemoveDhcpServiceFromDomainRouter.

@Test
public void testDontRemoveDhcpServiceFromDomainRouter() {
    // make local mocks
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    NicVO nic = mock(NicVO.class);
    NetworkVO network = mock(NetworkVO.class);
    // make sure that release dhcp won't be called
    when(vm.getType()).thenReturn(Type.DomainRouter);
    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, never()).getElementImplementingProvider(dhcpProvider);
    verify(testOrchastrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
    verify(testOrchastrator._networksDao, times(1)).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 2 with NicVO

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

the class NetworkOrchestratorTest method testDontRemoveDhcpServiceWhenNotProvided.

@Test
public void testDontRemoveDhcpServiceWhenNotProvided() {
    // make local mocks
    VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
    NicVO nic = mock(NicVO.class);
    NetworkVO network = mock(NetworkVO.class);
    // make sure that release dhcp will *not* be called
    when(vm.getType()).thenReturn(Type.User);
    when(testOrchastrator._networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp)).thenReturn(false);
    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, never()).getElementImplementingProvider(dhcpProvider);
    verify(testOrchastrator._ntwkSrvcDao, never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
    verify(testOrchastrator._networksDao, times(1)).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 3 with NicVO

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

the class SspElement method deleteNicEnv.

@Override
public boolean deleteNicEnv(Network network, NicProfile nic, ReservationContext context) {
    if (context == null) {
        s_logger.error("ReservationContext was null for " + nic + " " + network);
        return false;
    }
    String reservationId = context.getReservationId();
    SspUuidVO deleteTarget = null;
    SspUuidVO remainingTarget = null;
    List<SspUuidVO> tenantPortUuidVos = _sspUuidDao.listUUidVoByNicProfile(nic);
    for (SspUuidVO tenantPortUuidVo : tenantPortUuidVos) {
        if (reservationId.equals(tenantPortUuidVo.getReservationId())) {
            deleteTarget = tenantPortUuidVo;
        } else {
            remainingTarget = tenantPortUuidVo;
        }
    }
    if (deleteTarget != null) {
        // delete the target ssp uuid (tenant-port)
        String tenantPortUuid = deleteTarget.getUuid();
        boolean processed = false;
        for (SspClient client : fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
            SspClient.TenantPort sspPort = client.updateTenantVifBinding(tenantPortUuid, null);
            if (sspPort != null) {
                processed = true;
                break;
            }
        }
        if (!processed) {
            s_logger.warn("Ssp api nic detach failed " + nic.toString());
        }
        processed = false;
        for (SspClient client : fetchSspClients(network.getPhysicalNetworkId(), network.getDataCenterId(), true)) {
            if (client.deleteTenantPort(tenantPortUuid)) {
                _sspUuidDao.removeUuid(tenantPortUuid);
                processed = true;
                break;
            }
        }
        if (!processed) {
            s_logger.warn("Ssp api tenant port deletion failed " + nic.toString());
        }
        _sspUuidDao.removeUuid(tenantPortUuid);
    }
    if (remainingTarget != null) {
        NicVO nicVo = _nicDao.findById(nic.getId());
        nicVo.setReservationId(remainingTarget.getReservationId());
        // persist the new reservationId
        _nicDao.persist(nicVo);
    }
    return true;
}
Also used : SspUuidVO(org.apache.cloudstack.network.dao.SspUuidVO) NicVO(com.cloud.vm.NicVO)

Example 4 with NicVO

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

the class NetworkOrchestrator method prepareNicForMigration.

@Override
public void prepareNicForMigration(final VirtualMachineProfile vm, final DeployDestination dest) {
    if (vm.getType().equals(VirtualMachine.Type.DomainRouter) && (vm.getHypervisorType().equals(HypervisorType.KVM) || vm.getHypervisorType().equals(HypervisorType.VMware))) {
        //Include nics hot plugged and not stored in DB
        prepareAllNicsForMigration(vm, dest);
        return;
    }
    final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
    final ReservationContext context = new ReservationContextImpl(UUID.randomUUID().toString(), null, null);
    for (final NicVO 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));
        if (guru instanceof NetworkMigrationResponder) {
            if (!((NetworkMigrationResponder) guru).prepareMigration(profile, network, vm, dest, context)) {
                // XXX: Transaction error
                s_logger.error("NetworkGuru " + guru + " prepareForMigration failed.");
            }
        }
        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 (element instanceof NetworkMigrationResponder) {
                    if (!((NetworkMigrationResponder) element).prepareMigration(profile, network, vm, dest, context)) {
                        // XXX: Transaction error
                        s_logger.error("NetworkElement " + element + " prepareForMigration failed.");
                    }
                }
            }
        }
        guru.updateNicProfile(profile, network);
        vm.addNic(profile);
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkMigrationResponder(com.cloud.network.NetworkMigrationResponder) NetworkGuru(com.cloud.network.guru.NetworkGuru) NicProfile(com.cloud.vm.NicProfile) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) 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) NetworkElement(com.cloud.network.element.NetworkElement) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NicVO(com.cloud.vm.NicVO)

Example 5 with NicVO

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

the class NetworkOrchestrator method savePlaceholderNic.

@Override
public NicVO savePlaceholderNic(final Network network, final String ip4Address, final String ip6Address, final Type vmType) {
    final NicVO nic = new NicVO(null, null, network.getId(), null);
    nic.setIPv4Address(ip4Address);
    nic.setIPv6Address(ip6Address);
    nic.setReservationStrategy(ReservationStrategy.PlaceHolder);
    nic.setState(Nic.State.Reserved);
    nic.setVmType(vmType);
    return _nicDao.persist(nic);
}
Also used : NicVO(com.cloud.vm.NicVO)

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