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();
}
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");
}
}
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;
}
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);
}
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");
}
}
Aggregations