use of com.cloud.agent.api.DeleteLogicalSwitchPortCommand in project cloudstack by apache.
the class NiciraNvpRequestWrapperTest method testDeleteLogicalSwitchPortCommand.
@Test
public void testDeleteLogicalSwitchPortCommand() {
final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
final String logicalSwitchUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final String logicalSwitchPortUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final DeleteLogicalSwitchPortCommand command = new DeleteLogicalSwitchPortCommand(logicalSwitchUuid, logicalSwitchPortUuid);
when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
try {
doNothing().when(niciraNvpApi).deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), command.getLogicalSwitchPortUuid());
} catch (final NiciraNvpApiException e) {
fail(e.getMessage());
}
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.DeleteLogicalSwitchPortCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpElement method release.
@Override
public boolean release(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
if (!canHandle(network, Network.Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
final NicVO nicVO = nicDao.findById(nic.getId());
final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
final NiciraNvpNicMappingVO nicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
if (nicMap == null) {
s_logger.error("No mapping for nic " + nic.getName());
return false;
}
// When the lswitch is used in another network in the zone, simply return without deleting the lswitch
if (networkDao.countByZoneAndUri(network.getDataCenterId(), network.getBroadcastUri().toString()) > 1) {
s_logger.error("There are other networks using this lswitch, so not deleting lswitch!");
return true;
}
final DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
final DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DeleteLogicalSwitchPortCommand failed");
return false;
}
niciraNvpNicMappingDao.remove(nicMap.getId());
return true;
}
use of com.cloud.agent.api.DeleteLogicalSwitchPortCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpRequestWrapperTest method testDeleteLogicalSwitchPortCommand.
@Test
public void testDeleteLogicalSwitchPortCommand() {
final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
final String logicalSwitchUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final String logicalSwitchPortUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final DeleteLogicalSwitchPortCommand command = new DeleteLogicalSwitchPortCommand(logicalSwitchUuid, logicalSwitchPortUuid);
when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
try {
doNothing().when(niciraNvpApi).deleteLogicalSwitchPort(command.getLogicalSwitchUuid(), command.getLogicalSwitchPortUuid());
} catch (final NiciraNvpApiException e) {
fail(e.getMessage());
}
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
use of com.cloud.agent.api.DeleteLogicalSwitchPortCommand in project cosmic by MissionCriticalCloud.
the class NiciraNvpResourceTest method testDeleteLogicalSwitchPortException.
@Test
public void testDeleteLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalSwitchPort((String) any(), (String) any());
final DeleteLogicalSwitchPortAnswer dlspa = (DeleteLogicalSwitchPortAnswer) resource.executeRequest(new DeleteLogicalSwitchPortCommand("aaaa", "bbbb"));
assertFalse(dlspa.getResult());
}
use of com.cloud.agent.api.DeleteLogicalSwitchPortCommand in project cloudstack by apache.
the class NiciraNvpElement method release.
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
NicVO nicVO = nicDao.findById(nic.getId());
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpNicMappingVO nicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
if (nicMap == null) {
s_logger.error("No mapping for nic " + nic.getName());
return false;
}
DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DeleteLogicalSwitchPortCommand failed");
return false;
}
niciraNvpNicMappingDao.remove(nicMap.getId());
return true;
}
Aggregations