Search in sources :

Example 1 with DeleteLogicalSwitchAnswer

use of com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer in project cosmic by MissionCriticalCloud.

the class NiciraNvpGuestNetworkGuru method shutdown.

@Override
public void shutdown(final NetworkProfile profile, final NetworkOffering offering) {
    final NetworkVO networkObject = networkDao.findById(profile.getId());
    if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Lswitch || networkObject.getBroadcastUri() == null) {
        s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText());
        return;
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + networkObject.getPhysicalNetworkId());
        return;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    final DeleteLogicalSwitchCommand cmd = new DeleteLogicalSwitchCommand(BroadcastDomainType.getValue(networkObject.getBroadcastUri()));
    final DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("DeleteLogicalSwitchCommand failed");
    }
    super.shutdown(profile, offering);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteLogicalSwitchCommand(com.cloud.legacymodel.communication.command.DeleteLogicalSwitchCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) DeleteLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer) HostVO(com.cloud.host.HostVO)

Example 2 with DeleteLogicalSwitchAnswer

use of com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testDeleteLogicalSwitchApiException.

@Test
public void testDeleteLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalSwitch((String) any());
    final DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
    final DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
    assertFalse(dlsa.getResult());
}
Also used : DeleteLogicalSwitchCommand(com.cloud.legacymodel.communication.command.DeleteLogicalSwitchCommand) DeleteLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Example 3 with DeleteLogicalSwitchAnswer

use of com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer in project cosmic by MissionCriticalCloud.

the class NiciraNvpDeleteLogicalSwitchCommandWrapper method execute.

@Override
public Answer execute(final DeleteLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) {
    try {
        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
        niciraNvpApi.deleteLogicalSwitch(command.getLogicalSwitchUuid());
        return new DeleteLogicalSwitchAnswer(command, true, "Logicalswitch " + command.getLogicalSwitchUuid() + " deleted");
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, DeleteLogicalSwitchAnswer.class, e);
    }
}
Also used : NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) DeleteLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 4 with DeleteLogicalSwitchAnswer

use of com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer in project cosmic by MissionCriticalCloud.

the class NiciraNvpGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT", "VXLAN" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(Network.State.Implementing);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(netdao.findById(NETWORK_ID)).thenReturn(network);
    final DeployDestination dest = mock(DeployDestination.class);
    final Zone zone = mock(Zone.class);
    when(dest.getZone()).thenReturn(zone);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(NETWORK_ID);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("lswitch:aaaa"));
    when(offering.getSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.legacymodel.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) Zone(com.cloud.db.model.Zone) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) NetworkProfile(com.cloud.network.NetworkProfile) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer) Domain(com.cloud.legacymodel.domain.Domain) Test(org.junit.Test)

Example 5 with DeleteLogicalSwitchAnswer

use of com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testDeleteLogicalSwitch.

@Test
public void testDeleteLogicalSwitch() throws ConfigurationException {
    resource.configure("NiciraNvpResource", parameters);
    final DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
    final DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
    assertTrue(dlsa.getResult());
}
Also used : DeleteLogicalSwitchCommand(com.cloud.legacymodel.communication.command.DeleteLogicalSwitchCommand) DeleteLogicalSwitchAnswer(com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer) Test(org.junit.Test)

Aggregations

DeleteLogicalSwitchAnswer (com.cloud.legacymodel.communication.answer.DeleteLogicalSwitchAnswer)5 DeleteLogicalSwitchCommand (com.cloud.legacymodel.communication.command.DeleteLogicalSwitchCommand)3 Test (org.junit.Test)3 HostVO (com.cloud.host.HostVO)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)2 Zone (com.cloud.db.model.Zone)1 DeployDestination (com.cloud.deploy.DeployDestination)1 Domain (com.cloud.legacymodel.domain.Domain)1 Account (com.cloud.legacymodel.user.Account)1 NetworkProfile (com.cloud.network.NetworkProfile)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)1 NetworkOffering (com.cloud.offering.NetworkOffering)1 ReservationContext (com.cloud.vm.ReservationContext)1 URI (java.net.URI)1