Search in sources :

Example 6 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class ContrailManagerImpl method initializeDefaultVirtualNetworkModels.

private void initializeDefaultVirtualNetworkModels() {
    List<TrafficType> types = new ArrayList<TrafficType>();
    types.add(TrafficType.Management);
    types.add(TrafficType.Storage);
    types.add(TrafficType.Control);
    List<NetworkVO> dbNets = findManagedNetworks(types);
    for (NetworkVO net : dbNets) {
        VirtualNetworkModel vnModel = getDatabase().lookupVirtualNetwork(null, getCanonicalName(net), net.getTrafficType());
        if (vnModel == null) {
            vnModel = new VirtualNetworkModel(net, null, getCanonicalName(net), net.getTrafficType());
            vnModel.build(getModelController(), net);
            try {
                if (!vnModel.verify(getModelController())) {
                    vnModel.update(getModelController());
                }
            } catch (Exception ex) {
                s_logger.warn("virtual-network update: ", ex);
            }
            getDatabase().getVirtualNetworks().add(vnModel);
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) ConfigurationException(javax.naming.ConfigurationException) IOException(java.io.IOException) TrafficType(com.cloud.network.Networks.TrafficType) VirtualNetworkModel(org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)

Example 7 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class NetworkModelImpl method getNetworkTag.

@Override
public String getNetworkTag(HypervisorType hType, Network network) {
    // no network tag for control traffic type
    TrafficType effectiveTrafficType = network.getTrafficType();
    if (hType == HypervisorType.VMware && effectiveTrafficType == TrafficType.Control)
        effectiveTrafficType = TrafficType.Management;
    if (effectiveTrafficType == TrafficType.Control) {
        return null;
    }
    Long physicalNetworkId = null;
    if (effectiveTrafficType != TrafficType.Guest) {
        physicalNetworkId = getNonGuestNetworkPhysicalNetworkId(network, effectiveTrafficType);
    } else {
        NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
        physicalNetworkId = network.getPhysicalNetworkId();
        if (physicalNetworkId == null) {
            physicalNetworkId = findPhysicalNetworkId(network.getDataCenterId(), offering.getTags(), offering.getTrafficType());
        }
    }
    if (physicalNetworkId == null) {
        assert (false) : "Can't get the physical network";
        s_logger.warn("Can't get the physical network");
        return null;
    }
    return _pNTrafficTypeDao.getNetworkTag(physicalNetworkId, effectiveTrafficType, hType);
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) TrafficType(com.cloud.network.Networks.TrafficType)

Example 8 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class ListTrafficTypeImplementorsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    List<Pair<TrafficType, String>> results = _networkService.listTrafficTypeImplementor(this);
    ListResponse<TrafficTypeImplementorResponse> response = new ListResponse<TrafficTypeImplementorResponse>();
    List<TrafficTypeImplementorResponse> responses = new ArrayList<TrafficTypeImplementorResponse>();
    for (Pair<TrafficType, String> r : results) {
        TrafficTypeImplementorResponse p = new TrafficTypeImplementorResponse();
        p.setTrafficType(r.first().toString());
        p.setImplementor(r.second());
        p.setObjectName("traffictypeimplementorresponse");
        responses.add(p);
    }
    response.setResponses(responses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(org.apache.cloudstack.api.response.ListResponse) TrafficTypeImplementorResponse(org.apache.cloudstack.api.response.TrafficTypeImplementorResponse) ArrayList(java.util.ArrayList) Pair(com.cloud.utils.Pair) TrafficType(com.cloud.network.Networks.TrafficType)

Example 9 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class ConsoleProxyManagerImpl method getDefaultNetworkForAdvancedZone.

/**
     * Get default network for a console proxy VM starting up in an advanced zone. If the zone
     * is security group-enabled, the first network found that supports SG services is returned.
     * If the zone is not SG-enabled, the Public network is returned.
     * @param dc - The zone.
     * @return The selected default network.
     * @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found.
     */
protected NetworkVO getDefaultNetworkForAdvancedZone(DataCenter dc) {
    if (dc.getNetworkType() != NetworkType.Advanced) {
        throw new CloudRuntimeException("Zone " + dc + " is not advanced.");
    }
    if (dc.isSecurityGroupEnabled()) {
        List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dc.getId());
        if (CollectionUtils.isEmpty(networks)) {
            throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
        }
        return networks.get(0);
    } else {
        TrafficType defaultTrafficType = TrafficType.Public;
        List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType);
        // api should never allow this situation to happen
        if (defaultNetworks.size() != 1) {
            throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
        }
        return defaultNetworks.get(0);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficType(com.cloud.network.Networks.TrafficType)

Example 10 with TrafficType

use of com.cloud.network.Networks.TrafficType in project cloudstack by apache.

the class ConsoleProxyManagerImpl method getDefaultNetworkForBasicZone.

/**
     * Get default network for console proxy VM for starting up in a basic zone. Basic zones select
     * the Guest network whether or not the zone is SG-enabled.
     * @param dc - The zone.
     * @return The default network according to the zone's network selection rules.
     * @throws CloudRuntimeException - If the zone is not a valid choice or a network couldn't be found.
     */
protected NetworkVO getDefaultNetworkForBasicZone(DataCenter dc) {
    if (dc.getNetworkType() != NetworkType.Basic) {
        throw new CloudRuntimeException("Zone " + dc + "is not basic.");
    }
    TrafficType defaultTrafficType = TrafficType.Guest;
    List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dc.getId(), defaultTrafficType);
    // api should never allow this situation to happen
    if (defaultNetworks.size() != 1) {
        throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
    }
    return defaultNetworks.get(0);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TrafficType(com.cloud.network.Networks.TrafficType)

Aggregations

TrafficType (com.cloud.network.Networks.TrafficType)26 NetworkVO (com.cloud.network.dao.NetworkVO)13 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Pair (com.cloud.utils.Pair)3 ConfigurationException (javax.naming.ConfigurationException)3 Test (org.junit.Test)3 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 DB (com.cloud.utils.db.DB)2 IOException (java.io.IOException)2 Map (java.util.Map)2 NicResponse (org.apache.cloudstack.api.response.NicResponse)2 ListResponse (com.cloud.api.response.ListResponse)1 TrafficTypeImplementorResponse (com.cloud.api.response.TrafficTypeImplementorResponse)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 CloudException (com.cloud.exception.CloudException)1