Search in sources :

Example 1 with UpdateLogicalSwitchPortCommand

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

the class NiciraNvpRequestWrapperTest method testUpdateLogicalSwitchPortCommand.

@Test
public void testUpdateLogicalSwitchPortCommand() {
    final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
    final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
    final VifAttachment vifAttachment = Mockito.mock(VifAttachment.class);
    final String logicalSwitchPortUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String logicalSwitchUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String attachmentUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
    final String ownerName = "admin";
    final String nicName = "eth0";
    final UpdateLogicalSwitchPortCommand command = new UpdateLogicalSwitchPortCommand(logicalSwitchPortUuid, logicalSwitchUuid, attachmentUuid, ownerName, nicName);
    when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
    when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
    try {
        when(niciraNvpUtilities.createVifAttachment(attachmentUuid)).thenReturn(vifAttachment);
        doNothing().when(niciraNvpApi).updateLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, vifAttachment);
    } 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) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) UpdateLogicalSwitchPortCommand(com.cloud.agent.api.UpdateLogicalSwitchPortCommand) VifAttachment(com.cloud.network.nicira.VifAttachment) Test(org.junit.Test)

Example 2 with UpdateLogicalSwitchPortCommand

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

the class NiciraNvpResourceTest method testUpdateLogicalSwitchPortException.

@Test
public void testUpdateLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    doThrow(new NiciraNvpApiException()).when(nvpApi).updateLogicalSwitchPortAttachment((String) any(), (String) any(), (Attachment) any());
    final UpdateLogicalSwitchPortAnswer dlspa = (UpdateLogicalSwitchPortAnswer) resource.executeRequest(new UpdateLogicalSwitchPortCommand("aaaa", "bbbb", "cccc", "owner", "nicname"));
    assertFalse(dlspa.getResult());
}
Also used : UpdateLogicalSwitchPortAnswer(com.cloud.agent.api.UpdateLogicalSwitchPortAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) UpdateLogicalSwitchPortCommand(com.cloud.agent.api.UpdateLogicalSwitchPortCommand) Test(org.junit.Test)

Example 3 with UpdateLogicalSwitchPortCommand

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

the class NiciraNvpElement method prepare.

@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    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 existingNicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
    if (existingNicMap != null) {
        FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchUuid(), existingNicMap.getLogicalSwitchPortUuid());
        FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), findCmd);
        if (answer.getResult()) {
            s_logger.warn("Existing Logical Switchport found for nic " + nic.getName() + " with uuid " + existingNicMap.getLogicalSwitchPortUuid());
            UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(existingNicMap.getLogicalSwitchPortUuid(), BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
            agentMgr.easySend(niciraNvpHost.getId(), cmd);
            return true;
        } else {
            s_logger.error("Stale entry found for nic " + nic.getName() + " with logical switchport uuid " + existingNicMap.getLogicalSwitchPortUuid());
            niciraNvpNicMappingDao.remove(existingNicMap.getId());
        }
    }
    CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(BroadcastDomainType.getValue(network.getBroadcastUri()), nicVO.getUuid(), context.getDomain().getName() + "-" + context.getAccount().getAccountName(), nic.getName());
    CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("CreateLogicalSwitchPortCommand failed");
        return false;
    }
    NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()), answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
    niciraNvpNicMappingDao.persist(nicMap);
    return true;
}
Also used : NiciraNvpNicMappingVO(com.cloud.network.NiciraNvpNicMappingVO) FindLogicalSwitchPortAnswer(com.cloud.agent.api.FindLogicalSwitchPortAnswer) FindLogicalSwitchPortCommand(com.cloud.agent.api.FindLogicalSwitchPortCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) CreateLogicalSwitchPortAnswer(com.cloud.agent.api.CreateLogicalSwitchPortAnswer) NicVO(com.cloud.vm.NicVO) CreateLogicalSwitchPortCommand(com.cloud.agent.api.CreateLogicalSwitchPortCommand) HostVO(com.cloud.host.HostVO) UpdateLogicalSwitchPortCommand(com.cloud.agent.api.UpdateLogicalSwitchPortCommand)

Aggregations

UpdateLogicalSwitchPortCommand (com.cloud.agent.api.UpdateLogicalSwitchPortCommand)3 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)2 Test (org.junit.Test)2 Answer (com.cloud.agent.api.Answer)1 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)1 CreateLogicalSwitchPortCommand (com.cloud.agent.api.CreateLogicalSwitchPortCommand)1 FindLogicalSwitchPortAnswer (com.cloud.agent.api.FindLogicalSwitchPortAnswer)1 FindLogicalSwitchPortCommand (com.cloud.agent.api.FindLogicalSwitchPortCommand)1 UpdateLogicalSwitchPortAnswer (com.cloud.agent.api.UpdateLogicalSwitchPortAnswer)1 HostVO (com.cloud.host.HostVO)1 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)1 NiciraNvpNicMappingVO (com.cloud.network.NiciraNvpNicMappingVO)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 VifAttachment (com.cloud.network.nicira.VifAttachment)1 NicVO (com.cloud.vm.NicVO)1