use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method prepareElement.
protected boolean prepareElement(final NetworkElement element, final Network network, final NicProfile profile, final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
try {
element.prepare(network, profile, vmProfile, dest, context);
} catch (final IllegalVirtualMachineException e) {
s_logger.warn(e.getMessage());
}
if (vmProfile.getType() == VirtualMachineType.User && element.getProvider() != null) {
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) {
final DhcpServiceProvider sp = (DhcpServiceProvider) element;
final Map<Capability, String> dhcpCapabilities = element.getCapabilities().get(Service.Dhcp);
final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets) && profile.getIPv6Address() == null) {
if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
return false;
}
}
if (!sp.addDhcpEntry(network, profile, vmProfile, dest, context)) {
return false;
}
}
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && element instanceof UserDataServiceProvider) {
final UserDataServiceProvider sp = (UserDataServiceProvider) element;
if (!sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context)) {
return false;
}
}
}
return true;
}
use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method validateSourceNatServiceCapablities.
void validateSourceNatServiceCapablities(final Map<Capability, String> sourceNatServiceCapabilityMap) {
if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
if (sourceNatServiceCapabilityMap.keySet().size() > 2) {
throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + " and " + Capability.RedundantRouter + " capabilities can be sepcified for source nat service");
}
for (final Map.Entry<Capability, String> srcNatPair : sourceNatServiceCapabilityMap.entrySet()) {
final Capability capability = srcNatPair.getKey();
final String value = srcNatPair.getValue();
if (capability == Capability.SupportedSourceNatTypes) {
final boolean perAccount = value.contains("peraccount");
final boolean perZone = value.contains("perzone");
if (perAccount && perZone || !perAccount && !perZone) {
throw new InvalidParameterValueException("Either peraccount or perzone source NAT type can be specified for " + Capability.SupportedSourceNatTypes.getName());
}
} else if (capability == Capability.RedundantRouter) {
final boolean enabled = value.contains("true");
final boolean disabled = value.contains("false");
if (!enabled && !disabled) {
throw new InvalidParameterValueException("Unknown specified value for " + Capability.RedundantRouter.getName());
}
} else {
throw new InvalidParameterValueException("Only " + Capability.SupportedSourceNatTypes.getName() + " and " + Capability.RedundantRouter + " capabilities can be sepcified for source nat service");
}
}
}
}
use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.
the class ConfigurationManagerImpl method createNetworkOffering.
@Override
@DB
public NetworkOfferingVO createNetworkOffering(final String name, final String displayText, final TrafficType trafficType, String tags, final boolean specifyVlan, final Availability availability, final Integer networkRate, final Map<Service, Set<Provider>> serviceProviderMap, final boolean isDefault, final GuestType type, final boolean systemOnly, final Long serviceOfferingId, final Long secondaryServiceOfferingId, final boolean conserveMode, final Map<Service, Map<Capability, String>> serviceCapabilityMap, final boolean specifyIpRanges, final boolean isPersistent, final Map<NetworkOffering.Detail, String> details, final boolean egressDefaultPolicy, final Integer maxconn, final boolean enableKeepAlive) {
final String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
final int multicastRate = multicastRateStr == null ? 10 : Integer.parseInt(multicastRateStr);
tags = StringUtils.cleanupTags(tags);
// specifyVlan should always be true for Shared network offerings
if (!specifyVlan && type == GuestType.Shared) {
throw new InvalidParameterValueException("SpecifyVlan should be true if network offering's type is " + type);
}
// Nat service
if (specifyIpRanges) {
if (type == GuestType.Isolated) {
if (serviceProviderMap.containsKey(Service.SourceNat)) {
throw new InvalidParameterValueException("SpecifyIpRanges can only be true for Shared network offerings and Isolated with no SourceNat service");
}
}
} else {
if (type == GuestType.Shared) {
throw new InvalidParameterValueException("SpecifyIpRanges should always be true for Shared network offerings");
}
}
// isPersistent should always be false for Shared network Offerings
if (isPersistent && type == GuestType.Shared) {
throw new InvalidParameterValueException("isPersistent should be false if network offering's type is " + type);
}
// validate availability value
if (availability == NetworkOffering.Availability.Required) {
final boolean canOffBeRequired = type == GuestType.Isolated && serviceProviderMap.containsKey(Service.SourceNat);
if (!canOffBeRequired) {
throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
}
// only one network offering in the system can be Required
final List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
if (!offerings.isEmpty()) {
throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
}
}
boolean dedicatedLb = false;
boolean elasticLb = false;
boolean sharedSourceNat = false;
boolean redundantRouter = false;
boolean elasticIp = false;
boolean associatePublicIp = false;
boolean inline = false;
boolean publicLb = false;
boolean strechedL2Subnet = false;
if (serviceCapabilityMap != null && !serviceCapabilityMap.isEmpty()) {
final Map<Capability, String> lbServiceCapabilityMap = serviceCapabilityMap.get(Service.Lb);
if (lbServiceCapabilityMap != null && !lbServiceCapabilityMap.isEmpty()) {
final String isolationCapability = lbServiceCapabilityMap.get(Capability.SupportedLBIsolation);
if (isolationCapability != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.SupportedLBIsolation, isolationCapability);
dedicatedLb = isolationCapability.contains("dedicated");
} else {
dedicatedLb = true;
}
final String param = lbServiceCapabilityMap.get(Capability.ElasticLb);
if (param != null) {
elasticLb = param.contains("true");
}
final String inlineMode = lbServiceCapabilityMap.get(Capability.InlineMode);
if (inlineMode != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.InlineMode, inlineMode);
inline = inlineMode.contains("true");
} else {
inline = false;
}
final String publicLbStr = lbServiceCapabilityMap.get(Capability.LbSchemes);
if (serviceProviderMap.containsKey(Service.Lb)) {
if (publicLbStr != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.Lb), Service.Lb, Capability.LbSchemes, publicLbStr);
publicLb = publicLbStr.contains("public");
}
}
}
final Map<Capability, String> sourceNatServiceCapabilityMap = serviceCapabilityMap.get(Service.SourceNat);
if (sourceNatServiceCapabilityMap != null && !sourceNatServiceCapabilityMap.isEmpty()) {
final String sourceNatType = sourceNatServiceCapabilityMap.get(Capability.SupportedSourceNatTypes);
if (sourceNatType != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.SupportedSourceNatTypes, sourceNatType);
sharedSourceNat = sourceNatType.contains("perzone");
}
final String param = sourceNatServiceCapabilityMap.get(Capability.RedundantRouter);
if (param != null) {
_networkModel.checkCapabilityForProvider(serviceProviderMap.get(Service.SourceNat), Service.SourceNat, Capability.RedundantRouter, param);
redundantRouter = param.contains("true");
}
}
final Map<Capability, String> staticNatServiceCapabilityMap = serviceCapabilityMap.get(Service.StaticNat);
if (staticNatServiceCapabilityMap != null && !staticNatServiceCapabilityMap.isEmpty()) {
final String param = staticNatServiceCapabilityMap.get(Capability.ElasticIp);
if (param != null) {
elasticIp = param.contains("true");
final String associatePublicIP = staticNatServiceCapabilityMap.get(Capability.AssociatePublicIP);
if (associatePublicIP != null) {
associatePublicIp = associatePublicIP.contains("true");
}
}
}
final Map<Capability, String> connectivityServiceCapabilityMap = serviceCapabilityMap.get(Service.Connectivity);
if (connectivityServiceCapabilityMap != null && !connectivityServiceCapabilityMap.isEmpty()) {
final String value = connectivityServiceCapabilityMap.get(Capability.StretchedL2Subnet);
if ("true".equalsIgnoreCase(value)) {
strechedL2Subnet = true;
}
}
}
if (serviceProviderMap != null && serviceProviderMap.containsKey(Service.Lb) && !publicLb) {
// if not specified, default public lb to true
publicLb = true;
}
final NetworkOfferingVO offeringFinal = new NetworkOfferingVO(name, displayText, trafficType, systemOnly, specifyVlan, networkRate, multicastRate, isDefault, availability, tags, type, conserveMode, dedicatedLb, sharedSourceNat, redundantRouter, elasticIp, elasticLb, specifyIpRanges, inline, isPersistent, associatePublicIp, publicLb, egressDefaultPolicy, strechedL2Subnet);
if (serviceOfferingId != null) {
offeringFinal.setServiceOfferingId(serviceOfferingId);
}
if (secondaryServiceOfferingId != null) {
offeringFinal.setSecondaryServiceOfferingId(secondaryServiceOfferingId);
}
// validate the details
if (details != null) {
validateNtwkOffDetails(details, serviceProviderMap);
}
return Transaction.execute(new TransactionCallback<NetworkOfferingVO>() {
@Override
public NetworkOfferingVO doInTransaction(final TransactionStatus status) {
NetworkOfferingVO offering = offeringFinal;
// 1) create network offering object
s_logger.debug("Adding network offering " + offering);
offering.setConcurrentConnections(maxconn);
offering.setKeepAliveEnabled(enableKeepAlive);
offering = _networkOfferingDao.persist(offering, details);
// 2) populate services and providers
if (serviceProviderMap != null) {
for (final Network.Service service : serviceProviderMap.keySet()) {
final Set<Provider> providers = serviceProviderMap.get(service);
if (providers != null && !providers.isEmpty()) {
boolean vpcOff = false;
for (final Network.Provider provider : providers) {
if (provider == Provider.VPCVirtualRouter) {
vpcOff = true;
}
final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, provider);
_ntwkOffServiceMapDao.persist(offService);
s_logger.trace("Added service for the network offering: " + offService + " with provider " + provider.getName());
}
if (vpcOff) {
final List<Service> supportedSvcs = new ArrayList<>();
supportedSvcs.addAll(serviceProviderMap.keySet());
_vpcMgr.validateNtwkOffForVpc(offering, supportedSvcs);
}
} else {
final NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(), service, null);
_ntwkOffServiceMapDao.persist(offService);
s_logger.trace("Added service for the network offering: " + offService + " with null provider");
}
}
}
return offering;
}
});
}
use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.
the class CreateNetworkOfferingCmd method getServiceCapabilities.
public Map<Capability, String> getServiceCapabilities(final Service service) {
Map<Capability, String> capabilityMap = null;
if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) {
capabilityMap = new HashMap<>();
final Collection serviceCapabilityCollection = serviceCapabilitystList.values();
final Iterator iter = serviceCapabilityCollection.iterator();
while (iter.hasNext()) {
final HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
Capability capability = null;
final String svc = svcCapabilityMap.get("service");
final String capabilityName = svcCapabilityMap.get("capabilitytype");
final String capabilityValue = svcCapabilityMap.get("capabilityvalue");
if (capabilityName != null) {
capability = Capability.getCapability(capabilityName);
}
if ((capability == null) || (capabilityName == null) || (capabilityValue == null)) {
throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue);
}
if (svc.equalsIgnoreCase(service.getName())) {
capabilityMap.put(capability, capabilityValue);
} else {
// throw new InvalidParameterValueException("Service is not equal ")
}
}
}
return capabilityMap;
}
use of com.cloud.legacymodel.network.Network.Capability in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createNetworkResponse.
@Override
public NetworkResponse createNetworkResponse(final ResponseView view, final Network network) {
// need to get network profile in order to retrieve dns information from
// there
final NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
final NetworkResponse response = new NetworkResponse();
response.setId(network.getUuid());
response.setName(network.getName());
response.setDisplaytext(network.getDisplayText());
if (network.getBroadcastDomainType() != null) {
response.setBroadcastDomainType(network.getBroadcastDomainType().toString());
}
if (network.getTrafficType() != null) {
response.setTrafficType(network.getTrafficType().name());
}
if (network.getGuestType() != null) {
response.setType(network.getGuestType().toString());
}
response.setGateway(network.getGateway());
// FIXME - either set netmask or cidr
response.setCidr(network.getCidr());
response.setNetworkCidr(network.getNetworkCidr());
// network cidr
if (network.getNetworkCidr() != null) {
response.setNetmask(NetUtils.cidr2Netmask(network.getNetworkCidr()));
}
if (network.getCidr() != null && network.getNetworkCidr() == null) {
response.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
}
response.setIpExclusionList(((NetworkVO) network).getIpExclusionList());
response.setIp6Gateway(network.getIp6Gateway());
response.setIp6Cidr(network.getIp6Cidr());
// create response for reserved IP ranges that can be used for
// non-cloudstack purposes
String reservation = null;
if (network.getCidr() != null && NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr())) {
final String[] guestVmCidrPair = network.getCidr().split("\\/");
final String[] guestCidrPair = network.getNetworkCidr().split("\\/");
final Long guestVmCidrSize = Long.valueOf(guestVmCidrPair[1]);
final Long guestCidrSize = Long.valueOf(guestCidrPair[1]);
final String[] guestVmIpRange = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], guestVmCidrSize);
final String[] guestIpRange = NetUtils.getIpRangeFromCidr(guestCidrPair[0], guestCidrSize);
final long startGuestIp = NetUtils.ip2Long(guestIpRange[0]);
final long endGuestIp = NetUtils.ip2Long(guestIpRange[1]);
final long startVmIp = NetUtils.ip2Long(guestVmIpRange[0]);
final long endVmIp = NetUtils.ip2Long(guestVmIpRange[1]);
if (startVmIp == startGuestIp && endVmIp < endGuestIp - 1) {
reservation = NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp);
}
if (endVmIp == endGuestIp && startVmIp > startGuestIp + 1) {
reservation = NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1);
}
if (startVmIp > startGuestIp + 1 && endVmIp < endGuestIp - 1) {
reservation = NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1) + " , " + NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp);
}
}
response.setReservedIpRange(reservation);
if (network.getBroadcastUri() != null) {
final String broadcastUri = network.getBroadcastUri().toString();
response.setBroadcastUri(broadcastUri);
String vlan = "N/A";
switch(BroadcastDomainType.getSchemeValue(network.getBroadcastUri())) {
case Vlan:
case Vxlan:
vlan = BroadcastDomainType.getValue(network.getBroadcastUri());
break;
}
response.setVlan(vlan);
}
final DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
if (zone != null) {
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
}
if (network.getPhysicalNetworkId() != null) {
final PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(network.getPhysicalNetworkId());
response.setPhysicalNetworkId(pnet.getUuid());
}
// populate network offering information
final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
if (networkOffering != null) {
response.setNetworkOfferingId(networkOffering.getUuid());
response.setNetworkOfferingName(networkOffering.getName());
response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
response.setNetworkOfferingConserveMode(networkOffering.isConserveMode());
response.setIsSystem(networkOffering.isSystemOnly());
response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
response.setIsPersistent(networkOffering.getIsPersistent());
}
if (network.getAclType() != null) {
response.setAclType(network.getAclType().toString());
}
response.setDisplayNetwork(network.getDisplayNetwork());
response.setState(network.getState().toString());
response.setRestartRequired(network.isRestartRequired());
final NetworkVO nw = ApiDBUtils.findNetworkById(network.getRelated());
if (nw != null) {
response.setRelated(nw.getUuid());
}
response.setNetworkDomain(network.getNetworkDomain());
response.setDns1(profile.getDns1());
response.setDns2(profile.getDns2());
response.setDhcpTftpServer(profile.getDhcpTftpServer());
response.setDhcpBootfileName(profile.getDhcpBootfileName());
// populate capability
final Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
final List<ServiceResponse> serviceResponses = new ArrayList<>();
if (serviceCapabilitiesMap != null) {
for (final Map.Entry<Service, Map<Capability, String>> entry : serviceCapabilitiesMap.entrySet()) {
final Service service = entry.getKey();
final ServiceResponse serviceResponse = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
serviceResponse.setName(service.getName());
// set list of capabilities for the service
final List<CapabilityResponse> capabilityResponses = new ArrayList<>();
final Map<Capability, String> serviceCapabilities = entry.getValue();
if (serviceCapabilities != null) {
for (final Map.Entry<Capability, String> ser_cap_entries : serviceCapabilities.entrySet()) {
final Capability capability = ser_cap_entries.getKey();
final CapabilityResponse capabilityResponse = new CapabilityResponse();
final String capabilityValue = ser_cap_entries.getValue();
capabilityResponse.setName(capability.getName());
capabilityResponse.setValue(capabilityValue);
capabilityResponse.setObjectName("capability");
capabilityResponses.add(capabilityResponse);
}
serviceResponse.setCapabilities(capabilityResponses);
}
serviceResponse.setObjectName("service");
serviceResponses.add(serviceResponse);
}
}
response.setServices(serviceResponses);
if (network.getAclType() == null || network.getAclType() == ACLType.Account) {
populateOwner(response, network);
} else {
// get domain from network_domain table
final Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
if (domainNetworkDetails.first() != null) {
final Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
if (domain != null) {
response.setDomainId(domain.getUuid());
}
}
response.setSubdomainAccess(domainNetworkDetails.second());
}
final Long dedicatedDomainId = ApiDBUtils.getDedicatedNetworkDomain(network.getId());
if (dedicatedDomainId != null) {
final Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId);
if (domain != null) {
response.setDomainId(domain.getUuid());
response.setDomainName(domain.getName());
}
}
response.setSpecifyIpRanges(network.getSpecifyIpRanges());
if (network.getVpcId() != null) {
final Vpc vpc = ApiDBUtils.findVpcById(network.getVpcId());
if (vpc != null) {
response.setVpcId(vpc.getUuid());
response.setVpcName(vpc.getName());
}
}
response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Network, network.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
if (tagResponse != null) {
tagResponses.add(tagResponse);
}
}
response.setTags(tagResponses);
if (network.getNetworkACLId() != null) {
final NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
if (acl != null) {
response.setAclId(acl.getUuid());
response.setAclName(acl.getName());
}
}
response.setStrechedL2Subnet(network.isStrechedL2Network());
if (network.isStrechedL2Network()) {
final Set<String> networkSpannedZones = new HashSet<>();
final List<VMInstanceVO> vmInstances = new ArrayList<>();
vmInstances.addAll(ApiDBUtils.listUserVMsByNetworkId(network.getId()));
vmInstances.addAll(ApiDBUtils.listDomainRoutersByNetworkId(network.getId()));
for (final VirtualMachine vm : vmInstances) {
final DataCenter vmZone = ApiDBUtils.findZoneById(vm.getDataCenterId());
networkSpannedZones.add(vmZone.getUuid());
}
response.setNetworkSpannedZones(networkSpannedZones);
}
response.setObjectName("network");
return response;
}
Aggregations