Search in sources :

Example 1 with DeleteLogicalSwitchPortCommand

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());
}
Also used : Answer(com.cloud.agent.api.Answer) DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Example 2 with DeleteLogicalSwitchPortCommand

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;
}
Also used : NiciraNvpNicMappingVO(com.cloud.network.NiciraNvpNicMappingVO) DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) DeleteLogicalSwitchPortAnswer(com.cloud.agent.api.DeleteLogicalSwitchPortAnswer) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO)

Example 3 with DeleteLogicalSwitchPortCommand

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());
}
Also used : Answer(com.cloud.agent.api.Answer) DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Example 4 with DeleteLogicalSwitchPortCommand

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());
}
Also used : DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) DeleteLogicalSwitchPortAnswer(com.cloud.agent.api.DeleteLogicalSwitchPortAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Example 5 with DeleteLogicalSwitchPortCommand

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;
}
Also used : NiciraNvpNicMappingVO(com.cloud.network.NiciraNvpNicMappingVO) DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) DeleteLogicalSwitchPortAnswer(com.cloud.agent.api.DeleteLogicalSwitchPortAnswer) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO)

Aggregations

DeleteLogicalSwitchPortCommand (com.cloud.agent.api.DeleteLogicalSwitchPortCommand)6 DeleteLogicalSwitchPortAnswer (com.cloud.agent.api.DeleteLogicalSwitchPortAnswer)4 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)4 Test (org.junit.Test)4 Answer (com.cloud.agent.api.Answer)2 HostVO (com.cloud.host.HostVO)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2 NiciraNvpNicMappingVO (com.cloud.network.NiciraNvpNicMappingVO)2 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)2 NicVO (com.cloud.vm.NicVO)2