Search in sources :

Example 11 with BroadcastDomainType

use of com.cloud.model.enumeration.BroadcastDomainType in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method implement.

@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
    if (!canHandle(network, Network.Service.Connectivity)) {
        return false;
    }
    if (network.getBroadcastUri() == null) {
        s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
        return false;
    }
    final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId());
    this.hostDao.loadDetails(niciraNvpHost);
    final Account owner = context.getAccount();
    // Implement SourceNat immediately as we have al the info already
    if (this.networkModel.isProviderSupportServiceInNetwork(network.getId(), Network.Service.SourceNat, Network.Provider.NiciraNvp)) {
        s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
        final PublicIp sourceNatIp = this.ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
        final String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
        final String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
        // assuming a vlan:
        String vtag = sourceNatIp.getVlanTag();
        BroadcastDomainType tiep = null;
        try {
            tiep = BroadcastDomainType.getTypeOf(vtag);
        } catch (final URISyntaxException use) {
            throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
        }
        if (tiep == BroadcastDomainType.Vlan) {
            vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
        } else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
            throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
        }
        final long vlanid = Vlan.UNTAGGED.equals(vtag) ? 0 : Long.parseLong(vtag);
        final CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
        final CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd);
        if (answer.getResult() == false) {
            s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
            return false;
        }
        // Store the uuid so we can easily find it during cleanup
        final NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
        this.niciraNvpRouterMappingDao.persist(routermapping);
    }
    return true;
}
Also used : Account(com.cloud.legacymodel.user.Account) CreateLogicalRouterCommand(com.cloud.legacymodel.communication.command.CreateLogicalRouterCommand) PublicIp(com.cloud.network.addr.PublicIp) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URISyntaxException(java.net.URISyntaxException) CreateLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.CreateLogicalRouterAnswer) HostVO(com.cloud.host.HostVO) BroadcastDomainType(com.cloud.model.enumeration.BroadcastDomainType) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Aggregations

BroadcastDomainType (com.cloud.model.enumeration.BroadcastDomainType)11 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)5 Test (org.junit.Test)5 DataCenterVO (com.cloud.dc.DataCenterVO)3 Account (com.cloud.legacymodel.user.Account)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)3 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 URI (java.net.URI)2 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)1 HostVO (com.cloud.host.HostVO)1 CreateLogicalRouterAnswer (com.cloud.legacymodel.communication.answer.CreateLogicalRouterAnswer)1 CreateLogicalRouterCommand (com.cloud.legacymodel.communication.command.CreateLogicalRouterCommand)1 DataCenter (com.cloud.legacymodel.dc.DataCenter)1 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)1 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)1 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)1 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)1 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)1