Search in sources :

Example 1 with DeleteLogicalSwitchAnswer

use of com.cloud.agent.api.DeleteLogicalSwitchAnswer in project cloudstack by apache.

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.agent.api.DeleteLogicalSwitchAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 2 with DeleteLogicalSwitchAnswer

use of com.cloud.agent.api.DeleteLogicalSwitchAnswer in project cloudstack by apache.

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.agent.api.DeleteLogicalSwitchCommand) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) Test(org.junit.Test)

Example 3 with DeleteLogicalSwitchAnswer

use of com.cloud.agent.api.DeleteLogicalSwitchAnswer in project cloudstack by apache.

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.agent.api.DeleteLogicalSwitchCommand) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Example 4 with DeleteLogicalSwitchAnswer

use of com.cloud.agent.api.DeleteLogicalSwitchAnswer in project cloudstack by apache.

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(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 DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    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.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 5 with DeleteLogicalSwitchAnswer

use of com.cloud.agent.api.DeleteLogicalSwitchAnswer in project cloudstack by apache.

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());
    String logicalSwitchUuid = BroadcastDomainType.getValue(networkObject.getBroadcastUri());
    if (offering.getGuestType().equals(GuestType.Shared)) {
        sharedNetworksCleanup(networkObject, logicalSwitchUuid, niciraNvpHost);
    }
    final DeleteLogicalSwitchCommand cmd = new DeleteLogicalSwitchCommand(logicalSwitchUuid);
    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 : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DeleteLogicalSwitchCommand(com.cloud.agent.api.DeleteLogicalSwitchCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) HostVO(com.cloud.host.HostVO)

Aggregations

DeleteLogicalSwitchAnswer (com.cloud.agent.api.DeleteLogicalSwitchAnswer)5 DeleteLogicalSwitchCommand (com.cloud.agent.api.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 DataCenter (com.cloud.dc.DataCenter)1 DeployDestination (com.cloud.deploy.DeployDestination)1 Domain (com.cloud.domain.Domain)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 Account (com.cloud.user.Account)1 ReservationContext (com.cloud.vm.ReservationContext)1 URI (java.net.URI)1