Search in sources :

Example 1 with NetworkType

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

the class NetworkServiceImpl method createPhysicalNetwork.

@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_PHYSICAL_NETWORK_CREATE, eventDescription = "Creating Physical Network", create = true)
public PhysicalNetwork createPhysicalNetwork(final Long zoneId, final String vnetRange, final String networkSpeed, final List<String> isolationMethods, final String broadcastDomainRangeStr, final Long domainId, final List<String> tags, final String name) {
    // Check if zone exists
    if (zoneId == null) {
        throw new InvalidParameterValueException("Please specify a valid zone.");
    }
    final Zone zone = zoneRepository.findOne(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Please specify a valid zone.");
    }
    if (AllocationState.Enabled == zone.getAllocationState()) {
        // TBD: Send uuid instead of zoneId; may have to hardcode tablename in call to addProxyObject().
        throw new PermissionDeniedException("Cannot create PhysicalNetwork since the Zone is currently enabled, zone Id: " + zoneId);
    }
    final NetworkType zoneType = zone.getNetworkType();
    if (zoneType == NetworkType.Basic) {
        if (!_physicalNetworkDao.listByZone(zoneId).isEmpty()) {
            // TBD: Send uuid instead of zoneId; may have to hardcode tablename in call to addProxyObject().
            throw new CloudRuntimeException("Cannot add the physical network to basic zone id: " + zoneId + ", there is a physical network already existing in this basic " + "Zone");
        }
    }
    if (tags != null && tags.size() > 1) {
        throw new InvalidParameterException("Only one tag can be specified for a physical network at this time");
    }
    if (isolationMethods != null && isolationMethods.size() > 1) {
        throw new InvalidParameterException("Only one isolationMethod can be specified for a physical network at this time");
    }
    if (vnetRange != null) {
        // Verify zone type
        if (zoneType == NetworkType.Basic) {
            throw new InvalidParameterValueException("Can't add vnet range to the physical network in the zone that supports " + zoneType + " network");
        }
    }
    BroadcastDomainRange broadcastDomainRange = null;
    if (broadcastDomainRangeStr != null && !broadcastDomainRangeStr.isEmpty()) {
        try {
            broadcastDomainRange = PhysicalNetwork.BroadcastDomainRange.valueOf(broadcastDomainRangeStr.toUpperCase());
        } catch (final IllegalArgumentException ex) {
            throw new InvalidParameterValueException("Unable to resolve broadcastDomainRange '" + broadcastDomainRangeStr + "' to a supported value {Pod or Zone}");
        }
        // in Acton release you can specify only Zone broadcastdomain type in Advance zone, and Pod in Basic
        if (zoneType == NetworkType.Basic && broadcastDomainRange != null && broadcastDomainRange != BroadcastDomainRange.POD) {
            throw new InvalidParameterValueException("Basic zone can have broadcast domain type of value " + BroadcastDomainRange.POD + " only");
        } else if (zoneType == NetworkType.Advanced && broadcastDomainRange != null && broadcastDomainRange != BroadcastDomainRange.ZONE) {
            throw new InvalidParameterValueException("Advance zone can have broadcast domain type of value " + BroadcastDomainRange.ZONE + " only");
        }
    }
    if (broadcastDomainRange == null) {
        if (zoneType == NetworkType.Basic) {
            broadcastDomainRange = PhysicalNetwork.BroadcastDomainRange.POD;
        } else {
            broadcastDomainRange = PhysicalNetwork.BroadcastDomainRange.ZONE;
        }
    }
    try {
        final BroadcastDomainRange broadcastDomainRangeFinal = broadcastDomainRange;
        return Transaction.execute(new TransactionCallback<PhysicalNetworkVO>() {

            @Override
            public PhysicalNetworkVO doInTransaction(final TransactionStatus status) {
                // Create the new physical network in the database
                final long id = _physicalNetworkDao.getNextInSequence(Long.class, "id");
                PhysicalNetworkVO pNetwork = new PhysicalNetworkVO(id, zoneId, vnetRange, networkSpeed, domainId, broadcastDomainRangeFinal, name);
                pNetwork.setTags(tags);
                pNetwork.setIsolationMethods(isolationMethods);
                pNetwork = _physicalNetworkDao.persist(pNetwork);
                // Add vnet entries for the new zone if zone type is Advanced
                if (vnetRange != null) {
                    addOrRemoveVnets(vnetRange.split(","), pNetwork);
                }
                // add VirtualRouter as the default network service provider
                addDefaultVirtualRouterToPhysicalNetwork(pNetwork.getId());
                // add VPCVirtualRouter as the default network service provider
                addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
                return pNetwork;
            }
        });
    } catch (final Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new CloudRuntimeException("Fail to create a physical network");
    }
}
Also used : Zone(com.cloud.db.model.Zone) BroadcastDomainRange(com.cloud.network.PhysicalNetwork.BroadcastDomainRange) TransactionStatus(com.cloud.utils.db.TransactionStatus) InvalidParameterException(java.security.InvalidParameterException) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) UnknownHostException(java.net.UnknownHostException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) InvalidParameterException(java.security.InvalidParameterException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkType(com.cloud.model.enumeration.NetworkType) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ActionEvent(com.cloud.event.ActionEvent) DB(com.cloud.utils.db.DB)

Example 2 with NetworkType

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

the class ConfigurationManagerImpl method createZone.

@Override
@ActionEvent(eventType = EventTypes.EVENT_ZONE_CREATE, eventDescription = "creating zone", async = false)
public DataCenter createZone(final CreateZoneCmd cmd) {
    // grab parameters from the command
    final Long userId = CallContext.current().getCallingUserId();
    final String zoneName = cmd.getZoneName();
    final String dns1 = cmd.getDns1();
    final String dns2 = cmd.getDns2();
    final String ip6Dns1 = cmd.getIp6Dns1();
    final String ip6Dns2 = cmd.getIp6Dns2();
    final String internalDns1 = cmd.getInternalDns1();
    final String internalDns2 = cmd.getInternalDns2();
    final String guestCidr = cmd.getGuestCidrAddress();
    final Long domainId = cmd.getDomainId();
    final String type = cmd.getNetworkType();
    Boolean isBasic = false;
    String allocationState = cmd.getAllocationState();
    final String networkDomain = cmd.getDomain();
    final boolean isLocalStorageEnabled = cmd.getLocalStorageEnabled();
    if (allocationState == null) {
        allocationState = AllocationState.Disabled.toString();
    }
    if (!type.equalsIgnoreCase(NetworkType.Basic.toString()) && !type.equalsIgnoreCase(NetworkType.Advanced.toString())) {
        throw new InvalidParameterValueException("Invalid zone type; only Advanced and Basic values are supported");
    } else if (type.equalsIgnoreCase(NetworkType.Basic.toString())) {
        isBasic = true;
    }
    final NetworkType zoneType = isBasic ? NetworkType.Basic : NetworkType.Advanced;
    // error out when the parameter specified for Basic zone
    if (zoneType == NetworkType.Basic && guestCidr != null) {
        throw new InvalidParameterValueException("guestCidrAddress parameter is not supported for Basic zone");
    }
    DomainVO domainVO = null;
    if (domainId != null) {
        domainVO = _domainDao.findById(domainId);
    }
    return createZone(userId, zoneName, dns1, dns2, internalDns1, internalDns2, guestCidr, domainVO != null ? domainVO.getName() : null, domainId, zoneType, allocationState, networkDomain, isLocalStorageEnabled, ip6Dns1, ip6Dns2);
}
Also used : DomainVO(com.cloud.domain.DomainVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkType(com.cloud.model.enumeration.NetworkType) ActionEvent(com.cloud.event.ActionEvent)

Aggregations

ActionEvent (com.cloud.event.ActionEvent)2 NetworkType (com.cloud.model.enumeration.NetworkType)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 Zone (com.cloud.db.model.Zone)1 DomainVO (com.cloud.domain.DomainVO)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)1 BroadcastDomainRange (com.cloud.network.PhysicalNetwork.BroadcastDomainRange)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 DB (com.cloud.utils.db.DB)1 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 UnknownHostException (java.net.UnknownHostException)1 InvalidParameterException (java.security.InvalidParameterException)1