use of com.cloud.network.Network.Service in project cloudstack by apache.
the class NetworkServiceImpl method addProviderToPhysicalNetwork.
@Override
@DB
@ActionEvent(eventType = EventTypes.EVENT_SERVICE_PROVIDER_CREATE, eventDescription = "Creating Physical Network ServiceProvider", create = true)
public PhysicalNetworkServiceProvider addProviderToPhysicalNetwork(Long physicalNetworkId, String providerName, Long destinationPhysicalNetworkId, List<String> enabledServices) {
// verify input parameters
PhysicalNetworkVO network = _physicalNetworkDao.findById(physicalNetworkId);
if (network == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Physical Network with specified id doesn't exist in the system");
ex.addProxyObject(physicalNetworkId.toString(), "physicalNetworkId");
throw ex;
}
// verify input parameters
if (destinationPhysicalNetworkId != null) {
PhysicalNetworkVO destNetwork = _physicalNetworkDao.findById(destinationPhysicalNetworkId);
if (destNetwork == null) {
InvalidParameterValueException ex = new InvalidParameterValueException("Destination Physical Network with specified id doesn't exist in the system");
ex.addProxyObject(destinationPhysicalNetworkId.toString(), "destinationPhysicalNetworkId");
throw ex;
}
}
if (providerName != null) {
Provider provider = Network.Provider.getProvider(providerName);
if (provider == null) {
throw new InvalidParameterValueException("Invalid Network Service Provider=" + providerName);
}
}
if (_pNSPDao.findByServiceProvider(physicalNetworkId, providerName) != null) {
// TBD: send uuid instead of physicalNetworkId.
throw new CloudRuntimeException("The '" + providerName + "' provider already exists on physical network : " + physicalNetworkId);
}
// check if services can be turned off
NetworkElement element = _networkModel.getElementImplementingProvider(providerName);
if (element == null) {
throw new InvalidParameterValueException("Unable to find the Network Element implementing the Service Provider '" + providerName + "'");
}
List<Service> services = new ArrayList<Service>();
if (enabledServices != null) {
if (!element.canEnableIndividualServices()) {
if (enabledServices.size() != element.getCapabilities().keySet().size()) {
throw new InvalidParameterValueException("Cannot enable subset of Services, Please specify the complete list of Services for this Service Provider '" + providerName + "'");
}
}
// validate Services
boolean addGatewayService = false;
for (String serviceName : enabledServices) {
Network.Service service = Network.Service.getService(serviceName);
if (service == null || service == Service.Gateway) {
throw new InvalidParameterValueException("Invalid Network Service specified=" + serviceName);
} else if (service == Service.SourceNat) {
addGatewayService = true;
}
// check if the service is provided by this Provider
if (!element.getCapabilities().containsKey(service)) {
throw new InvalidParameterValueException(providerName + " Provider cannot provide this Service specified=" + serviceName);
}
services.add(service);
}
if (addGatewayService) {
services.add(Service.Gateway);
}
} else {
// enable all the default services supported by this element.
services = new ArrayList<Service>(element.getCapabilities().keySet());
}
try {
// Create the new physical network in the database
PhysicalNetworkServiceProviderVO nsp = new PhysicalNetworkServiceProviderVO(physicalNetworkId, providerName);
// set enabled services
nsp.setEnabledServices(services);
if (destinationPhysicalNetworkId != null) {
nsp.setDestinationPhysicalNetworkId(destinationPhysicalNetworkId);
}
nsp = _pNSPDao.persist(nsp);
return nsp;
} catch (Exception ex) {
s_logger.warn("Exception: ", ex);
throw new CloudRuntimeException("Fail to add a provider to physical network");
}
}
use of com.cloud.network.Network.Service in project cloudstack by apache.
the class NetworkServiceImpl method canIpsUseOffering.
private boolean canIpsUseOffering(List<PublicIp> publicIps, long offeringId) {
Map<PublicIp, Set<Service>> ipToServices = getIpToServices(publicIps, false, true);
Map<Service, Set<Provider>> serviceToProviders = _networkModel.getNetworkOfferingServiceProvidersMap(offeringId);
NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId);
//For inline mode checking, using firewall provider for LB instead, because public ip would apply on firewall provider
if (offering.isInline()) {
Provider firewallProvider = null;
if (serviceToProviders.containsKey(Service.Firewall)) {
firewallProvider = (Provider) serviceToProviders.get(Service.Firewall).toArray()[0];
}
Set<Provider> p = new HashSet<Provider>();
p.add(firewallProvider);
serviceToProviders.remove(Service.Lb);
serviceToProviders.put(Service.Lb, p);
}
for (PublicIp ip : ipToServices.keySet()) {
Set<Service> services = ipToServices.get(ip);
Provider provider = null;
for (Service service : services) {
Set<Provider> curProviders = serviceToProviders.get(service);
if (curProviders == null || curProviders.isEmpty()) {
continue;
}
Provider curProvider = (Provider) curProviders.toArray()[0];
if (provider == null) {
provider = curProvider;
continue;
}
// We don't support multiple providers for one service now
if (!provider.equals(curProvider)) {
throw new InvalidParameterException("There would be multiple providers for IP " + ip.getAddress() + " with the new network offering!");
}
}
}
return true;
}
use of com.cloud.network.Network.Service in project cloudstack by apache.
the class VirtualRouterElement method applyIps.
@Override
public boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Service> services) throws ResourceUnavailableException {
boolean canHandle = true;
for (final Service service : services) {
if (!canHandle(network, service)) {
canHandle = false;
break;
}
}
boolean result = true;
if (canHandle) {
final List<DomainRouterVO> routers = getRouters(network);
if (routers == null || routers.isEmpty()) {
s_logger.debug("Virtual router elemnt doesn't need to associate ip addresses on the backend; virtual " + "router doesn't exist in the network " + network.getId());
return true;
}
final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
for (final DomainRouterVO domainRouterVO : routers) {
result = result && networkTopology.associatePublicIP(network, ipAddress, domainRouterVO);
}
}
return result;
}
use of com.cloud.network.Network.Service in project CloudStack-archive by CloudStack-extras.
the class ListSupportedNetworkServicesCmd method execute.
@Override
public void execute() {
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);
}
}
List<Network.Service> serviceList = new ArrayList<Network.Service>();
serviceList.add(service);
services = serviceList;
} else {
services = _networkService.listNetworkServices(getProviderName());
}
ListResponse<ServiceResponse> response = new ListResponse<ServiceResponse>();
List<ServiceResponse> servicesResponses = new ArrayList<ServiceResponse>();
for (Network.Service service : services) {
//skip gateway service
if (service == Service.Gateway) {
continue;
}
ServiceResponse serviceResponse = _responseGenerator.createNetworkServiceResponse(service);
servicesResponses.add(serviceResponse);
}
response.setResponses(servicesResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
use of com.cloud.network.Network.Service in project cloudstack by apache.
the class LoadBalancingRulesManagerImpl method getLBCapability.
// Will return a string. For LB Stickiness this will be a json, for
// autoscale this will be "," separated values
@Override
public String getLBCapability(long networkid, String capabilityName) {
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = _networkModel.getNetworkCapabilities(networkid);
if (serviceCapabilitiesMap != null) {
for (Service service : serviceCapabilitiesMap.keySet()) {
ServiceResponse serviceResponse = new ServiceResponse();
serviceResponse.setName(service.getName());
if ("Lb".equalsIgnoreCase(service.getName())) {
Map<Capability, String> serviceCapabilities = serviceCapabilitiesMap.get(service);
if (serviceCapabilities != null) {
for (Capability capability : serviceCapabilities.keySet()) {
if (capabilityName.equals(capability.getName())) {
return serviceCapabilities.get(capability);
}
}
}
}
}
}
return null;
}
Aggregations