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());
}
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());
}
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;
}
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);
}
}
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);
}
Aggregations