Search in sources :

Example 6 with PhysicalNetworkTrafficType

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

the class UpdateTrafficTypeCmd method execute.

@Override
public void execute() {
    PhysicalNetworkTrafficType result = _networkService.updatePhysicalNetworkTrafficType(getId(), getXenLabel(), getKvmLabel(), getVmwareLabel(), getHypervLabel(), getOvm3Label());
    if (result != null) {
        TrafficTypeResponse response = _responseGenerator.createTrafficTypeResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update traffic type");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) TrafficTypeResponse(org.apache.cloudstack.api.response.TrafficTypeResponse) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 7 with PhysicalNetworkTrafficType

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

the class AddTrafficTypeCmd method create.

@Override
public void create() throws ResourceAllocationException {
    PhysicalNetworkTrafficType result = _networkService.addTrafficTypeToPhysicalNetwork(getPhysicalNetworkId(), getTrafficType(), getIsolationMethod(), getXenLabel(), getKvmLabel(), getVmwareLabel(), getSimulatorLabel(), getVlan(), getHypervLabel(), getOvm3Label());
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add traffic type to physical network");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 8 with PhysicalNetworkTrafficType

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

the class OvsTunnelManagerImpl method getGreEndpointIP.

private String getGreEndpointIP(Host host, Network nw) throws AgentUnavailableException, OperationTimedoutException {
    String endpointIp = null;
    // Fetch fefault name for network label from configuration
    String physNetLabel = _configDao.getValue(Config.OvsTunnelNetworkDefaultLabel.key());
    Long physNetId = nw.getPhysicalNetworkId();
    PhysicalNetworkTrafficType physNetTT = _physNetTTDao.findBy(physNetId, TrafficType.Guest);
    HypervisorType hvType = host.getHypervisorType();
    String label = null;
    switch(hvType) {
        case XenServer:
            label = physNetTT.getXenNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        case KVM:
            label = physNetTT.getKvmNetworkLabel();
            if ((label != null) && (!label.equals(""))) {
                physNetLabel = label;
            }
            break;
        default:
            throw new CloudRuntimeException("Hypervisor " + hvType.toString() + " unsupported by OVS Tunnel Manager");
    }
    // Try to fetch GRE endpoint IP address for cloud db
    // If not found, then find it on the hypervisor
    OvsTunnelInterfaceVO tunnelIface = _tunnelInterfaceDao.getByHostAndLabel(host.getId(), physNetLabel);
    if (tunnelIface == null) {
        //Now find and fetch configuration for physical interface
        //for network with label on target host
        Commands fetchIfaceCmds = new Commands(new OvsFetchInterfaceCommand(physNetLabel));
        s_logger.debug("Ask host " + host.getId() + " to retrieve interface for phy net with label:" + physNetLabel);
        Answer[] fetchIfaceAnswers = _agentMgr.send(host.getId(), fetchIfaceCmds);
        //And finally save it for future use
        endpointIp = handleFetchInterfaceAnswer(fetchIfaceAnswers, host.getId());
    } else {
        endpointIp = tunnelIface.getIp();
    }
    return endpointIp;
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) OvsFetchInterfaceCommand(com.cloud.agent.api.OvsFetchInterfaceCommand) OvsTunnelInterfaceVO(com.cloud.network.ovs.dao.OvsTunnelInterfaceVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Commands(com.cloud.agent.manager.Commands) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Example 9 with PhysicalNetworkTrafficType

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

the class ManagementServerMock method locatePhysicalNetwork.

private void locatePhysicalNetwork() {
    // mandatory: name, zone-id
    try {
        long id = _networkService.findPhysicalNetworkId(_zone.getId(), "znet", TrafficType.Guest);
        _znet = _networkService.getPhysicalNetwork(id);
        List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
        if (nets == null || nets.isEmpty()) {
            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), "vlan", null, null, null, null, null, null, null);
        }
    } catch (InvalidParameterValueException e) {
        List<String> isolationMethods = new ArrayList<String>();
        isolationMethods.add("L3VPN");
        _znet = _networkService.createPhysicalNetwork(_zone.getId(), null, null, isolationMethods, BroadcastDomainRange.ZONE.toString(), _zone.getDomainId(), null, "znet");
        List<PhysicalNetworkVO> nets = _physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
        if (nets == null || nets.isEmpty()) {
            _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Public.toString(), "vlan", null, null, null, null, null, null, null);
        }
    }
    if (_znet.getState() != PhysicalNetwork.State.Enabled) {
        _znet = _networkService.updatePhysicalNetwork(_znet.getId(), null, null, null, PhysicalNetwork.State.Enabled.toString());
    }
    // Ensure that the physical network supports Guest traffic.
    Pair<List<? extends PhysicalNetworkTrafficType>, Integer> trafficTypes = _networkService.listTrafficTypes(_znet.getId());
    boolean found = false;
    for (PhysicalNetworkTrafficType ttype : trafficTypes.first()) {
        if (ttype.getTrafficType() == TrafficType.Guest) {
            found = true;
        }
    }
    if (!found) {
        _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(), TrafficType.Guest.toString(), "vlan", null, null, null, null, null, null, null);
    }
    Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> providers = _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null, null);
    if (providers.second() == 0) {
        s_logger.debug("Add " + Provider.JuniperContrailRouter.getName() + " to network " + _znet.getName());
        PhysicalNetworkServiceProvider provider = _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrailRouter.getName(), null, null);
        _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
    } else {
        PhysicalNetworkServiceProvider provider = providers.first().get(0);
        if (provider.getState() != PhysicalNetworkServiceProvider.State.Enabled) {
            _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
        }
    }
    providers = _networkService.listNetworkServiceProviders(_znet.getId(), null, PhysicalNetworkServiceProvider.State.Enabled.toString(), null, null);
    s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled providers");
    for (PhysicalNetworkServiceProvider provider : providers.first()) {
        if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName())) {
            continue;
        }
        s_logger.debug("Disabling " + provider.getProviderName());
        _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Disabled.toString(), null);
    }
}
Also used : PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) List(java.util.List) ArrayList(java.util.ArrayList) PhysicalNetworkTrafficType(com.cloud.network.PhysicalNetworkTrafficType)

Aggregations

PhysicalNetworkTrafficType (com.cloud.network.PhysicalNetworkTrafficType)9 TrafficTypeResponse (com.cloud.api.response.TrafficTypeResponse)3 ArrayList (java.util.ArrayList)3 ServerApiException (org.apache.cloudstack.api.ServerApiException)3 TrafficTypeResponse (org.apache.cloudstack.api.response.TrafficTypeResponse)3 ServerApiException (com.cloud.api.ServerApiException)2 List (java.util.List)2 Answer (com.cloud.agent.api.Answer)1 OvsCreateTunnelAnswer (com.cloud.agent.api.OvsCreateTunnelAnswer)1 OvsFetchInterfaceAnswer (com.cloud.agent.api.OvsFetchInterfaceAnswer)1 OvsFetchInterfaceCommand (com.cloud.agent.api.OvsFetchInterfaceCommand)1 Commands (com.cloud.agent.manager.Commands)1 ListResponse (com.cloud.api.response.ListResponse)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)1 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)1 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)1 OvsTunnelInterfaceVO (com.cloud.network.ovs.dao.OvsTunnelInterfaceVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1