Search in sources :

Example 41 with NiciraNvpDeviceVO

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

the class NiciraNvpElement method release.

@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
    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 nicMap = niciraNvpNicMappingDao.findByNicUuid(nicVO.getUuid());
    if (nicMap == null) {
        s_logger.error("No mapping for nic " + nic.getName());
        return false;
    }
    DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchPortUuid());
    DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    if (answer == null || !answer.getResult()) {
        s_logger.error("DeleteLogicalSwitchPortCommand failed");
        return false;
    }
    niciraNvpNicMappingDao.remove(nicMap.getId());
    return true;
}
Also used : NiciraNvpNicMappingVO(com.cloud.network.NiciraNvpNicMappingVO) DeleteLogicalSwitchPortCommand(com.cloud.agent.api.DeleteLogicalSwitchPortCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) DeleteLogicalSwitchPortAnswer(com.cloud.agent.api.DeleteLogicalSwitchPortAnswer) NicVO(com.cloud.vm.NicVO) HostVO(com.cloud.host.HostVO)

Example 42 with NiciraNvpDeviceVO

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

Example 43 with NiciraNvpDeviceVO

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

the class NiciraNvpGuestNetworkGuru method design.

@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
    // Check of the isolation type of the related physical network is supported
    final PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        s_logger.debug("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;
    }
    s_logger.debug("Nicira Nvp " + devices.get(0).getUuid() + " found on physical network " + physnet.getId());
    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);
    if (offering.getGuestType().equals(GuestType.Shared)) {
        networkObject.setState(State.Allocated);
    }
    return networkObject;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Example 44 with NiciraNvpDeviceVO

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

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

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