Search in sources :

Example 86 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class UpdateNetworkCmd method getEventDescription.

@Override
public String getEventDescription() {
    final StringBuilder eventMsg = new StringBuilder("Updating network: " + getId());
    if (getNetworkOfferingId() != null) {
        final Network network = _networkService.getNetwork(getId());
        if (network == null) {
            throw new InvalidParameterValueException("Networkd ID=" + id + " doesn't exist");
        }
        if (network.getNetworkOfferingId() != getNetworkOfferingId()) {
            final NetworkOffering oldOff = _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());
            final NetworkOffering newOff = _entityMgr.findById(NetworkOffering.class, getNetworkOfferingId());
            if (newOff == null) {
                throw new InvalidParameterValueException("Networkd offering ID supplied is invalid");
            }
            eventMsg.append(". Original network offering ID: " + oldOff.getUuid() + ", new network offering ID: " + newOff.getUuid());
        }
    }
    return eventMsg.toString();
}
Also used : InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.legacymodel.network.Network)

Example 87 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class CreateNetworkCmd method execute.

@Override
public // an exception thrown by createNetwork() will be caught by the dispatcher.
void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
    final Network result = _networkService.createGuestNetwork(this);
    if (result != null) {
        final NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Restricted, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) Network(com.cloud.legacymodel.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse)

Example 88 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class DeployVMCmd method getIpToNetworkMap.

private Map<Long, IpAddresses> getIpToNetworkMap() {
    if ((networkIds != null || ipAddress != null || getIp6Address() != null) && ipToNetworkList != null) {
        throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter");
    }
    LinkedHashMap<Long, IpAddresses> ipToNetworkMap = null;
    if (ipToNetworkList != null && !ipToNetworkList.isEmpty()) {
        ipToNetworkMap = new LinkedHashMap<>();
        final Collection ipsCollection = ipToNetworkList.values();
        final Iterator iter = ipsCollection.iterator();
        while (iter.hasNext()) {
            final HashMap<String, String> ips = (HashMap<String, String>) iter.next();
            final Long networkId;
            final Network network = _networkService.getNetwork(ips.get("networkid"));
            if (network != null) {
                networkId = network.getId();
            } else {
                try {
                    networkId = Long.parseLong(ips.get("networkid"));
                } catch (final NumberFormatException e) {
                    throw new InvalidParameterValueException("Unable to translate and find entity with networkId: " + ips.get("networkid"));
                }
            }
            final String requestedIp = ips.get("ip");
            String requestedIpv6 = ips.get("ipv6");
            String requestedMac = ips.get("mac");
            if (requestedIpv6 != null) {
                requestedIpv6 = NetUtils.standardizeIp6Address(requestedIpv6);
            }
            if (requestedMac != null) {
                if (!NetUtils.isValidMac(requestedMac)) {
                    throw new InvalidParameterValueException("MAC-Address is not valid: " + requestedMac);
                } else if (!NetUtils.isUnicastMac(requestedMac)) {
                    throw new InvalidParameterValueException("MAC-Address is not unicast: " + requestedMac);
                }
                requestedMac = NetUtils.standardizeMacAddress(requestedMac);
            }
            final IpAddresses addrs = new IpAddresses(requestedIp, requestedIpv6, requestedMac);
            ipToNetworkMap.put(networkId, addrs);
        }
    }
    return ipToNetworkMap;
}
Also used : IpAddresses(com.cloud.legacymodel.network.Network.IpAddresses) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Network(com.cloud.legacymodel.network.Network) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 89 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class ListSupportedNetworkServicesCmd method execute.

@Override
public void execute() {
    final List<? extends Network.Service> services;
    if (getServiceName() != null) {
        Network.Service service = null;
        if (serviceName != null) {
            service = Network.Service.getService(serviceName);
            if (service == null) {
                throw new InvalidParameterValueException("Invalid Network Service=" + serviceName);
            }
        }
        final List<Network.Service> serviceList = new ArrayList<>();
        serviceList.add(service);
        services = serviceList;
    } else {
        services = _networkService.listNetworkServices(getProviderName());
    }
    final ListResponse<ServiceResponse> response = new ListResponse<>();
    final List<ServiceResponse> servicesResponses = new ArrayList<>();
    for (final Network.Service service : services) {
        // skip gateway service
        if (service == Service.Gateway) {
            continue;
        }
        final ServiceResponse serviceResponse = _responseGenerator.createNetworkServiceResponse(service);
        servicesResponses.add(serviceResponse);
    }
    response.setResponses(servicesResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ServiceResponse(com.cloud.api.response.ServiceResponse) ListResponse(com.cloud.api.response.ListResponse) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Network(com.cloud.legacymodel.network.Network) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) Service(com.cloud.legacymodel.network.Network.Service)

Example 90 with Network

use of com.cloud.legacymodel.network.Network in project cosmic by MissionCriticalCloud.

the class CreateNetworkCmdByAdmin method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public // an exception thrown by createNetwork() will be caught by the dispatcher.
void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException {
    final Network result = _networkService.createGuestNetwork(this);
    if (result != null) {
        final NetworkResponse response = _responseGenerator.createNetworkResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create network");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) Network(com.cloud.legacymodel.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse)

Aggregations

Network (com.cloud.legacymodel.network.Network)160 ArrayList (java.util.ArrayList)57 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)56 Account (com.cloud.legacymodel.user.Account)46 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)42 NetworkOffering (com.cloud.offering.NetworkOffering)36 PhysicalNetwork (com.cloud.network.PhysicalNetwork)34 IPAddressVO (com.cloud.network.dao.IPAddressVO)32 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)30 NetworkVO (com.cloud.network.dao.NetworkVO)28 List (java.util.List)28 Zone (com.cloud.db.model.Zone)27 DB (com.cloud.utils.db.DB)27 NicProfile (com.cloud.vm.NicProfile)26 Nic (com.cloud.legacymodel.network.Nic)21 DataCenter (com.cloud.legacymodel.dc.DataCenter)20 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)20 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)19 DomainRouterVO (com.cloud.vm.DomainRouterVO)18 ActionEvent (com.cloud.event.ActionEvent)17