mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-4259 Dedicated Resources: createAffinityGroup API should not allow admin to create the group of this type through API
Changes: - Block API from creating this type of group
This commit is contained in:
parent
25cc9eb869
commit
96ca70e2da
|
|
@ -79,4 +79,7 @@ public interface AffinityGroupService {
|
|||
|
||||
boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId);
|
||||
|
||||
AffinityGroup createAffinityGroupInternal(String account, Long domainId, String affinityGroupName,
|
||||
String affinityGroupType, String description);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -609,7 +609,7 @@ public class DedicatedResourceManagerImpl implements DedicatedService {
|
|||
}
|
||||
|
||||
|
||||
group = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
|
||||
group = _affinityGroupService.createAffinityGroupInternal(accountName, domainId, affinityGroupName,
|
||||
"ExplicitDedication", "dedicated resources group");
|
||||
|
||||
return group;
|
||||
|
|
|
|||
|
|
@ -1852,7 +1852,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
|
|||
}
|
||||
}
|
||||
|
||||
group = _affinityGroupService.createAffinityGroup(accountName, domainId, affinityGroupName,
|
||||
group = _affinityGroupService.createAffinityGroupInternal(accountName, domainId, affinityGroupName,
|
||||
"ExplicitDedication", "dedicated resources group");
|
||||
|
||||
return group;
|
||||
|
|
|
|||
|
|
@ -134,6 +134,34 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
|
|||
|
||||
AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
|
||||
|
||||
if (processor.isAdminControlledGroup()) {
|
||||
throw new PermissionDeniedException("Cannot create the affinity group");
|
||||
}
|
||||
|
||||
return createAffinityGroupInternal(account, domainId, affinityGroupName, affinityGroupType, description);
|
||||
}
|
||||
|
||||
@DB
|
||||
@Override
|
||||
public AffinityGroup createAffinityGroupInternal(String account, Long domainId, String affinityGroupName,
|
||||
String affinityGroupType, String description) {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
|
||||
// validate the affinityGroupType
|
||||
Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
|
||||
if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
|
||||
if (!typeProcessorMap.containsKey(affinityGroupType)) {
|
||||
throw new InvalidParameterValueException("Unable to create affinity group, invalid affinity group type"
|
||||
+ affinityGroupType);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidParameterValueException(
|
||||
"Unable to create affinity group, no Affinity Group Types configured");
|
||||
}
|
||||
|
||||
AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
|
||||
|
||||
if (processor.isAdminControlledGroup() && !_accountMgr.isRootAdmin(caller.getType())) {
|
||||
throw new PermissionDeniedException("Cannot create the affinity group");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue