server, api, ui: filtering network offerings for a domain while create network

Signed-off-by: Abhishek Kumar <abhishek.kumar@shapeblue.com>
This commit is contained in:
Abhishek Kumar 2019-07-01 15:17:31 +05:30
parent 5766ddb4d1
commit 18439ca84b
3 changed files with 40 additions and 8 deletions

View File

@ -23,6 +23,7 @@ import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
@ -62,6 +63,13 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
@Parameter(name = ApiConstants.AVAILABILITY, type = CommandType.STRING, description = "the availability of network offering. Default value is required")
private String availability;
@Parameter(name = ApiConstants.DOMAIN_ID,
type = CommandType.UUID,
entityType = DomainResponse.class,
description = "list network offerings available for network creation in specific domain",
since = "4.13")
private Long domainId;
@Parameter(name = ApiConstants.ZONE_ID,
type = CommandType.UUID,
entityType = ZoneResponse.class,
@ -137,6 +145,10 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
return availability;
}
public Long getDomainId() {
return domainId;
}
public Long getZoneId() {
return zoneId;
}

View File

@ -5298,6 +5298,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
final Object specifyVlan = cmd.getSpecifyVlan();
final Object availability = cmd.getAvailability();
final Object state = cmd.getState();
final Long domainId = cmd.getDomainId();
final Long zoneId = cmd.getZoneId();
DataCenter zone = null;
final Long networkId = cmd.getNetworkId();
@ -5308,6 +5309,16 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
final Boolean isTagged = cmd.isTagged();
final Boolean forVpc = cmd.getForVpc();
if (domainId != null) {
Domain domain = _entityMgr.findById(Domain.class, domainId);
if (domain == null) {
throw new InvalidParameterValueException("Unable to find the domain by id=" + domainId);
}
if (!_domainDao.isChildDomain(caller.getDomainId(), domainId)) {
throw new InvalidParameterValueException(String.format("Unable to list network offerings for domain: %s as caller does not have access for it", domain.getUuid()));
}
}
if (zoneId != null) {
zone = _entityMgr.findById(DataCenter.class, zoneId);
if (zone == null) {
@ -5426,19 +5437,23 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
}
final List<NetworkOfferingJoinVO> offerings = networkOfferingJoinDao.search(sc, searchFilter);
// Remove offerings that are not associated with caller's domain
// TODO: Better approach
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && CollectionUtils.isNotEmpty(offerings)) {
// Remove offerings that are not associated with caller's domain or domainId passed
if ((caller.getType() != Account.ACCOUNT_TYPE_ADMIN || domainId != null) && CollectionUtils.isNotEmpty(offerings)) {
ListIterator<NetworkOfferingJoinVO> it = offerings.listIterator();
while (it.hasNext()) {
NetworkOfferingJoinVO offering = it.next();
if(!Strings.isNullOrEmpty(offering.getDomainId())) {
boolean toRemove = true;
if (!Strings.isNullOrEmpty(offering.getDomainId())) {
boolean toRemove = false;
String[] domainIdsArray = offering.getDomainId().split(",");
for (String domainIdString : domainIdsArray) {
Long dId = Long.valueOf(domainIdString.trim());
if (_domainDao.isChildDomain(caller.getDomainId(), dId)) {
toRemove = false;
if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN &&
!_domainDao.isChildDomain(caller.getDomainId(), dId)) {
toRemove = true;
break;
}
if (domainId != null && !_domainDao.isChildDomain(dId, domainId)) {
toRemove = true;
break;
}
}

View File

@ -534,7 +534,7 @@ var addGuestNetworkDialog = {
networkOfferingId: {
label: 'label.network.offering',
docID: 'helpGuestNetworkZoneNetworkOffering',
dependsOn: ['zoneId', 'physicalNetworkId', 'scope'],
dependsOn: ['zoneId', 'physicalNetworkId', 'scope', 'domainId'],
select: function(args) {
if(args.$form.find('.form-item[rel=zoneId]').find('select').val() == null || args.$form.find('.form-item[rel=zoneId]').find('select').val().length == 0) {
args.response.success({
@ -570,6 +570,11 @@ var addGuestNetworkDialog = {
$.extend(data, {
guestiptype: 'Shared'
});
if (args.scope == "domain-specific") {
$.extend(data, {
domainid: args.domainId
});
}
}
var items = [];