Search in sources :

Example 31 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method listNiciraNvpDevices.

@Override
public List<NiciraNvpDeviceVO> listNiciraNvpDevices(final ListNiciraNvpDevicesCmd cmd) {
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final Long niciraNvpDeviceId = cmd.getNiciraNvpDeviceId();
    List<NiciraNvpDeviceVO> responseList = new ArrayList<>();
    if (physicalNetworkId == null && niciraNvpDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or nicira device Id must be specified");
    }
    if (niciraNvpDeviceId != null) {
        final NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao.findById(niciraNvpDeviceId);
        if (niciraNvpDevice == null) {
            throw new InvalidParameterValueException("Could not find Nicira Nvp device with id: " + niciraNvpDevice);
        }
        responseList.add(niciraNvpDevice);
    } else {
        final PhysicalNetworkVO physicalNetwork = physicalNetworkDao.findById(physicalNetworkId);
        if (physicalNetwork == null) {
            throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
        }
        responseList = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
    }
    return responseList;
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 32 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO 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 33 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class NiciraNvpGuestNetworkGuru method design.

@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
    // Check if the isolation type of the related physical network is supported
    PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (physnet == null) {
        final List<PhysicalNetworkVO> physicalNetworks = physicalNetworkDao.listByZoneAndTrafficTypeAndIsolationMethod(dc.getId(), offering.getTrafficType(), IsolationMethod.STT);
        if (!physicalNetworks.isEmpty()) {
            physnet = physicalNetworks.get(0);
            plan.setPhysicalNetworkId(physnet.getId());
        }
    }
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        s_logger.debug(this.getClass().getSimpleName() + ": Refusing to design this network");
        return null;
    }
    final List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physnet.getId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + physnet.getName());
        return null;
    }
    final NiciraNvpDeviceVO niciraNvpDeviceVO = devices.get(0);
    s_logger.debug("Nicira Nvp " + niciraNvpDeviceVO.getUuid() + " found on physical network " + physnet.getId());
    checkThatLogicalSwitchExists(userSpecified, niciraNvpDeviceVO);
    s_logger.debug("Physical isolation type is supported, asking GuestNetworkGuru to design this network");
    final NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner);
    if (networkObject == null) {
        return null;
    }
    networkObject.setBroadcastDomainType(BroadcastDomainType.Lswitch);
    return networkObject;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 34 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cosmic by MissionCriticalCloud.

the class AddNiciraNvpDeviceCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        final NiciraNvpDeviceVO niciraNvpDeviceVO = niciraNvpElementService.addNiciraNvpDevice(this);
        if (niciraNvpDeviceVO != null) {
            final NiciraNvpDeviceResponse response = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO);
            response.setObjectName("niciranvpdevice");
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error.");
        }
    } catch (final InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (final CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) NiciraNvpDeviceResponse(com.cloud.api.response.NiciraNvpDeviceResponse)

Example 35 with NiciraNvpDeviceVO

use of com.cloud.network.NiciraNvpDeviceVO in project cloudstack by apache.

the class NiciraNvpElementTest method implementSharedNetworkUuidVlanIdTest.

@Test
public void implementSharedNetworkUuidVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    // SHARED NETWORKS CASE 1: LOGICAL ROUTER'S UUID AS VLAN ID
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getGuestType()).thenReturn(GuestType.Shared);
    when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
    when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
    HostVO niciraNvpHost = mock(HostVO.class);
    when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
    when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    final DeployDestination dest = mock(DeployDestination.class);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    // SHARED NETWORKS CASE 1
    when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(true);
    when(network.getCidr()).thenReturn(NETWORK_CIDR);
    when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
    NiciraNvpRouterMappingVO mapping = mock(NiciraNvpRouterMappingVO.class);
    when(mapping.getLogicalRouterUuid()).thenReturn("xxxx-xxxx-xxxx");
    when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(mapping);
    final ConfigureSharedNetworkUuidAnswer answer = mock(ConfigureSharedNetworkUuidAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command) any())).thenReturn(answer);
    assertTrue(element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) ConfigureSharedNetworkUuidAnswer(com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) Domain(com.cloud.domain.Domain) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Aggregations

NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)50 HostVO (com.cloud.host.HostVO)34 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)26 NetworkVO (com.cloud.network.dao.NetworkVO)18 NetworkOffering (com.cloud.offering.NetworkOffering)18 Account (com.cloud.user.Account)18 Test (org.junit.Test)18 Network (com.cloud.network.Network)16 ArrayList (java.util.ArrayList)14 NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)13 DeployDestination (com.cloud.deploy.DeployDestination)12 Domain (com.cloud.domain.Domain)12 ReservationContext (com.cloud.vm.ReservationContext)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)8 PublicIpAddress (com.cloud.network.PublicIpAddress)8 URI (java.net.URI)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)6 DataCenter (com.cloud.dc.DataCenter)5