Search in sources :

Example 6 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testCreateLogicalSwitch.

@Test
public void testCreateLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
    assertTrue("cccc".equals(clsa.getLogicalSwitchUuid()));
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 7 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpGuestNetworkGuru method implement.

@Override
public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert network.getState() == Network.State.Implementing : "Why are we implementing " + network;
    final long zoneId = dest.getZone().getId();
    Long physicalNetworkId = network.getPhysicalNetworkId();
    // physical network id can be null in Guest Network in Basic zone, so locate the physical network
    if (physicalNetworkId == null) {
        physicalNetworkId = networkModel.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
    }
    final NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), Network.State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = network.getUuid();
    }
    if (name.length() > MAX_NAME_LENGTH) {
        name = name.substring(0, MAX_NAME_LENGTH - 1);
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
        return null;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
    final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
    final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-" + context.getAccount().getAccountName(), network.getId());
    final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("CreateLogicalSwitchCommand failed");
        return null;
    }
    try {
        implemented.setBroadcastUri(new URI("lswitch", answer.getLogicalSwitchUuid(), null));
        implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch);
        s_logger.info("Implemented OK, network linked to  = " + implemented.getBroadcastUri().toString());
    } catch (final URISyntaxException e) {
        s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
        return null;
    }
    return implemented;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) URI(java.net.URI) HostVO(com.cloud.host.HostVO)

Example 8 with CreateLogicalSwitchCommand

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

the class NiciraNvpGuestNetworkGuru method implement.

@Override
public Network implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert network.getState() == State.Implementing : "Why are we implementing " + network;
    final long dcId = dest.getDataCenter().getId();
    Long physicalNetworkId = network.getPhysicalNetworkId();
    // physical network id can be null in Guest Network in Basic zone, so locate the physical network
    if (physicalNetworkId == null) {
        physicalNetworkId = networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
    }
    final NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.isRedundantRouter());
    if (network.getGateway() != null) {
        implemented.setGateway(network.getGateway());
    }
    if (network.getCidr() != null) {
        implemented.setCidr(network.getCidr());
    }
    // Name is either the given name or the uuid
    String name = network.getName();
    if (name == null || name.isEmpty()) {
        name = ((NetworkVO) network).getUuid();
    }
    if (name.length() > MAX_NAME_LENGTH) {
        name = name.substring(0, MAX_NAME_LENGTH - 1);
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
        return null;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    hostDao.loadDetails(niciraNvpHost);
    final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
    final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
    if (offering.getGuestType().equals(GuestType.Shared)) {
        try {
            checkL2GatewayServiceSharedNetwork(niciraNvpHost);
        } catch (Exception e) {
            s_logger.error("L2 Gateway Service Issue: " + e.getMessage());
            return null;
        }
    }
    final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
    final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("CreateLogicalSwitchCommand failed");
        return null;
    }
    try {
        implemented.setBroadcastUri(new URI("lswitch", answer.getLogicalSwitchUuid(), null));
        implemented.setBroadcastDomainType(BroadcastDomainType.Lswitch);
        s_logger.info("Implemented OK, network linked to  = " + implemented.getBroadcastUri().toString());
    } catch (final URISyntaxException e) {
        s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
        return null;
    }
    return implemented;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) URI(java.net.URI) HostVO(com.cloud.host.HostVO) URISyntaxException(java.net.URISyntaxException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException)

Example 9 with CreateLogicalSwitchCommand

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

the class NiciraNvpResourceTest method testRetries.

@Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner");
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 10 with CreateLogicalSwitchCommand

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

the class NiciraNvpResourceTest method testCreateLogicalSwitch.

@Test
public void testCreateLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner");
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
    assertTrue("cccc".equals(clsa.getLogicalSwitchUuid()));
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Aggregations

CreateLogicalSwitchCommand (com.cloud.agent.api.CreateLogicalSwitchCommand)10 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)8 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)8 Test (org.junit.Test)8 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)6 Answer (com.cloud.agent.api.Answer)2 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 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1