Skip to content

Commit 598503f

Browse files
author
Murali Reddy
committed
bug 9129:can't create vm if an instance limit is set at root domain
pushing 2.2.4 fixes
1 parent a748ddf commit 598503f

4 files changed

Lines changed: 44 additions & 28 deletions

File tree

server/src/com/cloud/configuration/Config.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,14 @@ public enum Config {
226226

227227
DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null),
228228

229-
TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds");
229+
TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds"),
230230

231+
// Account Default Limits
232+
DefaultMaxAccountUserVms("Account Defaults", ManagementServer.class, Long.class, "max.account.user.vms", "20", "The default maximum number of user VMs that can be deployed for an account", null),
233+
DefaultMaxAccountPublicIPs("Account Defaults", ManagementServer.class, Long.class, "max.account.public.ips", "20", "The default maximum number of public IPs that can be consumed by an account", null),
234+
DefaultMaxAccountTemplates("Account Defaults", ManagementServer.class, Long.class, "max.account.templates", "20", "The default maximum number of templates that can be deployed for an account", null),
235+
DefaultMaxAccountSnapshots("Account Defaults", ManagementServer.class, Long.class, "max.account.snapshots", "20", "The default maximum number of snapshots that can be created for an account", null),
236+
DefaultMaxAccountVolumes("Account Defaults", ManagementServer.class, Long.class, "max.account.volumes", "20", "The default maximum number of volumes that can be created for an account", null);
231237

232238
private final String _category;
233239
private final Class<?> _componentClass;
@@ -250,6 +256,7 @@ public enum Config {
250256
_configs.put("Premium", new ArrayList<Config>());
251257
_configs.put("Developer", new ArrayList<Config>());
252258
_configs.put("Hidden", new ArrayList<Config>());
259+
_configs.put("Account Defaults", new ArrayList<Config>());
253260

254261
// Add values into HashMap
255262
for (Config c : Config.values()) {

server/src/com/cloud/test/DatabaseConfig.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ public class DatabaseConfig {
189189
s_configurationDescriptions.put("storage.capacity.threshold", "percentage (as a value between 0 and 1) of storage utilization above which alerts will be sent about low storage available");
190190
s_configurationDescriptions.put("public.ip.capacity.threshold", "percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent");
191191
s_configurationDescriptions.put("private.ip.capacity.threshold", "percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent");
192-
s_configurationDescriptions.put("max.account.user.vms", "the maximum number of user VMs that can be deployed for an account");
193-
s_configurationDescriptions.put("max.account.public.ips", "the maximum number of public IPs that can be reserved for an account");
194192
s_configurationDescriptions.put("expunge.interval", "the interval to wait before running the expunge thread");
195193
s_configurationDescriptions.put("network.throttling.rate", "default data transfer rate in megabits per second allowed per user");
196194
s_configurationDescriptions.put("multicast.throttling.rate", "default multicast rate in megabits per second allowed");
@@ -234,8 +232,6 @@ public class DatabaseConfig {
234232
s_configurationComponents.put("public.ip.capacity.threshold", "management-server");
235233
s_configurationComponents.put("private.ip.capacity.threshold", "management-server");
236234
s_configurationComponents.put("capacity.check.period", "management-server");
237-
s_configurationComponents.put("max.account.user.vms", "management-server");
238-
s_configurationComponents.put("max.account.public.ips", "management-server");
239235
s_configurationComponents.put("network.throttling.rate", "management-server");
240236
s_configurationComponents.put("multicast.throttling.rate", "management-server");
241237
s_configurationComponents.put("account.cleanup.interval", "management-server");
@@ -313,8 +309,6 @@ public class DatabaseConfig {
313309
s_defaultConfigurationValues.put("snapshot.test.months.per.year", "12");
314310
s_defaultConfigurationValues.put("alert.wait", "1800");
315311
s_defaultConfigurationValues.put("update.wait", "600");
316-
s_defaultConfigurationValues.put("max.account.user.vms", "20");
317-
s_defaultConfigurationValues.put("max.account.public.ips", "20");
318312
s_defaultConfigurationValues.put("expunge.interval", "86400");
319313
s_defaultConfigurationValues.put("extract.url.cleanup.interval", "120");
320314
s_defaultConfigurationValues.put("instance.name", "VM");

server/src/com/cloud/user/AccountManagerImpl.java

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
119119

120120
private String _name;
121121
@Inject private AccountDao _accountDao;
122+
@Inject ConfigurationDao _configDao;
122123
@Inject private DomainDao _domainDao;
123124
@Inject private ResourceLimitDao _resourceLimitDao;
124125
@Inject private ResourceCountDao _resourceCountDao;
@@ -250,22 +251,33 @@ public void decrementResourceCount(long accountId, ResourceType type, Long...del
250251
public long findCorrectResourceLimit(AccountVO account, ResourceType type) {
251252
long max = -1;
252253

253-
// Check account
254254
ResourceLimitVO limit = _resourceLimitDao.findByAccountIdAndType(account.getId(), type);
255-
255+
256+
// Check if limit is configured for account
256257
if (limit != null) {
257258
max = limit.getMax().longValue();
258259
} else {
259-
// If the account has an infinite limit, check the ROOT domain
260-
Long domainId = account.getDomainId();
261-
while ((domainId != null) && (limit == null)) {
262-
limit = _resourceLimitDao.findByDomainIdAndType(domainId, type);
263-
DomainVO domain = _domainDao.findById(domainId);
264-
domainId = domain.getParent();
265-
}
266-
267-
if (limit != null) {
268-
max = limit.getMax().longValue();
260+
// If the account has an no limit set, then return global default account limits
261+
try {
262+
switch (type) {
263+
case public_ip:
264+
max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key()));
265+
break;
266+
case snapshot:
267+
max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key()));
268+
break;
269+
case template:
270+
max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountTemplates.key()));
271+
break;
272+
case user_vm:
273+
max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountUserVms.key()));
274+
break;
275+
case volume:
276+
max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVolumes.key()));
277+
break;
278+
}
279+
} catch (NumberFormatException nfe) {
280+
s_logger.error("Invalid value is set for the default account limit.");
269281
}
270282
}
271283

@@ -310,14 +322,12 @@ public boolean resourceLimitExceeded(Account account, ResourceType type, long...
310322

311323
if (m_resourceCountLock.lock(120)) { // 2 minutes
312324
try {
313-
// Check account
314-
ResourceLimitVO limit = _resourceLimitDao.findByAccountIdAndType(account.getId(), type);
315-
316-
if (limit != null) {
317-
long potentialCount = _resourceCountDao.getAccountCount(account.getId(), type) + numResources;
318-
if (potentialCount > limit.getMax().longValue()) {
319-
return true;
320-
}
325+
// Check account limits
326+
AccountVO accountVo = _accountDao.findById(account.getAccountId());
327+
long accountLimit = findCorrectResourceLimit(accountVo, type);
328+
long potentialCount = _resourceCountDao.getAccountCount(account.getId(), type) + numResources;
329+
if (potentialCount > accountLimit) {
330+
return true;
321331
}
322332

323333
// check all domains in the account's domain hierarchy

setup/db/db/schema-222to224.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES
114114
('Advanced','DEFAULT','management-server','vmware.private.vswitch',NULL,'Specify the vSwitch on host for private network'),
115115
('Advanced','DEFAULT','management-server','vmware.public.vswitch',NULL,'Specify the vSwitch on host for public network'),
116116
('Advanced','DEFAULT','management-server','vmware.service.console','Service Console','Specify the service console network name (ESX host only)'),
117-
('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return');
117+
('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return'),
118+
('Account Defaults','DEFAULT','management-server','max.account.user.vms','20','The default maximum number of user VMs that can be deployed for an account'),
119+
('Account Defaults','DEFAULT','management-server','max.account.public.ips','20','The default maximum number of public IPs that can be consumed by an account'),
120+
('Account Defaults','DEFAULT','management-server','max.account.templates','20','The default maximum number of templates that can be deployed for an account'),
121+
('Account Defaults','DEFAULT','management-server','max.account.snapshots','20','The default maximum number of snapshots that can be created for an account'),
122+
('Account Defaults','DEFAULT','management-server','max.account.volumes','20','The default maximum number of volumes that can be created for an account');
118123

119124
ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL;
120125
ALTER TABLE `cloud`.`op_dc_ip_address_alloc` ADD CONSTRAINT `fk_op_dc_ip_address_alloc__data_center_id` FOREIGN KEY (`data_center_id`) REFERENCES `data_center`(`id`) ON DELETE CASCADE;

0 commit comments

Comments
 (0)