mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	bug 9129:can't create vm if an instance limit is set at root domain
pushing 2.2.4 fixes
This commit is contained in:
		
							parent
							
								
									a748ddf35d
								
							
						
					
					
						commit
						598503f094
					
				@ -226,8 +226,14 @@ public enum Config {
 | 
			
		||||
	
 | 
			
		||||
	DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null),
 | 
			
		||||
	
 | 
			
		||||
	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");
 | 
			
		||||
	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"),
 | 
			
		||||
	
 | 
			
		||||
	// Account Default Limits
 | 
			
		||||
	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),
 | 
			
		||||
	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),
 | 
			
		||||
	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),
 | 
			
		||||
	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),
 | 
			
		||||
	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);
 | 
			
		||||
	
 | 
			
		||||
	private final String _category;
 | 
			
		||||
	private final Class<?> _componentClass;
 | 
			
		||||
@ -250,6 +256,7 @@ public enum Config {
 | 
			
		||||
    	_configs.put("Premium", new ArrayList<Config>());
 | 
			
		||||
    	_configs.put("Developer", new ArrayList<Config>());
 | 
			
		||||
    	_configs.put("Hidden", new ArrayList<Config>());
 | 
			
		||||
    	_configs.put("Account Defaults", new ArrayList<Config>());
 | 
			
		||||
    	
 | 
			
		||||
    	// Add values into HashMap
 | 
			
		||||
        for (Config c : Config.values()) {
 | 
			
		||||
 | 
			
		||||
@ -189,8 +189,6 @@ public class DatabaseConfig {
 | 
			
		||||
        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");
 | 
			
		||||
        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");
 | 
			
		||||
        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");
 | 
			
		||||
        s_configurationDescriptions.put("max.account.user.vms", "the maximum number of user VMs that can be deployed for an account");
 | 
			
		||||
        s_configurationDescriptions.put("max.account.public.ips", "the maximum number of public IPs that can be reserved for an account");
 | 
			
		||||
        s_configurationDescriptions.put("expunge.interval", "the interval to wait before running the expunge thread");
 | 
			
		||||
        s_configurationDescriptions.put("network.throttling.rate", "default data transfer rate in megabits per second allowed per user");
 | 
			
		||||
        s_configurationDescriptions.put("multicast.throttling.rate", "default multicast rate in megabits per second allowed");
 | 
			
		||||
@ -234,8 +232,6 @@ public class DatabaseConfig {
 | 
			
		||||
        s_configurationComponents.put("public.ip.capacity.threshold", "management-server");
 | 
			
		||||
        s_configurationComponents.put("private.ip.capacity.threshold", "management-server");
 | 
			
		||||
        s_configurationComponents.put("capacity.check.period", "management-server");
 | 
			
		||||
        s_configurationComponents.put("max.account.user.vms", "management-server");
 | 
			
		||||
        s_configurationComponents.put("max.account.public.ips", "management-server");
 | 
			
		||||
        s_configurationComponents.put("network.throttling.rate", "management-server");
 | 
			
		||||
        s_configurationComponents.put("multicast.throttling.rate", "management-server");
 | 
			
		||||
        s_configurationComponents.put("account.cleanup.interval", "management-server");
 | 
			
		||||
@ -313,8 +309,6 @@ public class DatabaseConfig {
 | 
			
		||||
        s_defaultConfigurationValues.put("snapshot.test.months.per.year", "12");
 | 
			
		||||
        s_defaultConfigurationValues.put("alert.wait", "1800");
 | 
			
		||||
        s_defaultConfigurationValues.put("update.wait", "600");
 | 
			
		||||
        s_defaultConfigurationValues.put("max.account.user.vms", "20");
 | 
			
		||||
        s_defaultConfigurationValues.put("max.account.public.ips", "20");
 | 
			
		||||
        s_defaultConfigurationValues.put("expunge.interval", "86400");
 | 
			
		||||
        s_defaultConfigurationValues.put("extract.url.cleanup.interval",  "120");
 | 
			
		||||
        s_defaultConfigurationValues.put("instance.name", "VM");
 | 
			
		||||
 | 
			
		||||
@ -119,6 +119,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
 | 
			
		||||
	
 | 
			
		||||
	private String _name;
 | 
			
		||||
	@Inject private AccountDao _accountDao;
 | 
			
		||||
	@Inject ConfigurationDao _configDao;
 | 
			
		||||
	@Inject private DomainDao _domainDao;
 | 
			
		||||
	@Inject private ResourceLimitDao _resourceLimitDao;
 | 
			
		||||
	@Inject private ResourceCountDao _resourceCountDao;
 | 
			
		||||
@ -250,22 +251,33 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
 | 
			
		||||
    public long findCorrectResourceLimit(AccountVO account, ResourceType type) {
 | 
			
		||||
    	long max = -1;
 | 
			
		||||
    	
 | 
			
		||||
    	// Check account
 | 
			
		||||
		ResourceLimitVO limit = _resourceLimitDao.findByAccountIdAndType(account.getId(), type);
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
    	// Check if limit is configured for account
 | 
			
		||||
		if (limit != null) {
 | 
			
		||||
			max = limit.getMax().longValue();
 | 
			
		||||
		} else {
 | 
			
		||||
			// If the account has an infinite limit, check the ROOT domain
 | 
			
		||||
			Long domainId = account.getDomainId();
 | 
			
		||||
			while ((domainId != null) && (limit == null)) {
 | 
			
		||||
				limit = _resourceLimitDao.findByDomainIdAndType(domainId, type);
 | 
			
		||||
				DomainVO domain = _domainDao.findById(domainId);
 | 
			
		||||
				domainId = domain.getParent();
 | 
			
		||||
			}
 | 
			
		||||
	
 | 
			
		||||
			if (limit != null) {
 | 
			
		||||
				max = limit.getMax().longValue();
 | 
			
		||||
			// If the account has an no limit set, then return global default account limits
 | 
			
		||||
			try {
 | 
			
		||||
				switch (type) {
 | 
			
		||||
				case public_ip:
 | 
			
		||||
					max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountPublicIPs.key()));
 | 
			
		||||
					break;
 | 
			
		||||
				case snapshot:
 | 
			
		||||
					max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountSnapshots.key()));
 | 
			
		||||
					break;
 | 
			
		||||
				case template:
 | 
			
		||||
					max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountTemplates.key()));
 | 
			
		||||
					break;
 | 
			
		||||
				case user_vm:
 | 
			
		||||
					max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountUserVms.key()));
 | 
			
		||||
					break;
 | 
			
		||||
				case volume:
 | 
			
		||||
					max = Long.parseLong(_configDao.getValue(Config.DefaultMaxAccountVolumes.key()));
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
			} catch (NumberFormatException nfe) {
 | 
			
		||||
				s_logger.error("Invalid value is set for the default account limit.");
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -310,14 +322,12 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
 | 
			
		||||
 | 
			
		||||
        if (m_resourceCountLock.lock(120)) { // 2 minutes
 | 
			
		||||
            try {
 | 
			
		||||
                // Check account
 | 
			
		||||
                ResourceLimitVO limit = _resourceLimitDao.findByAccountIdAndType(account.getId(), type);
 | 
			
		||||
                
 | 
			
		||||
                if (limit != null) {
 | 
			
		||||
                    long potentialCount = _resourceCountDao.getAccountCount(account.getId(), type) + numResources;
 | 
			
		||||
                    if (potentialCount > limit.getMax().longValue()) {
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                // Check account limits
 | 
			
		||||
            	AccountVO accountVo = _accountDao.findById(account.getAccountId());
 | 
			
		||||
                long accountLimit   = findCorrectResourceLimit(accountVo, type);
 | 
			
		||||
            	long potentialCount = _resourceCountDao.getAccountCount(account.getId(), type) + numResources;
 | 
			
		||||
                if (potentialCount > accountLimit) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // check all domains in the account's domain hierarchy
 | 
			
		||||
 | 
			
		||||
@ -114,7 +114,12 @@ INSERT IGNORE INTO `cloud`.`configuration` VALUES
 | 
			
		||||
('Advanced','DEFAULT','management-server','vmware.private.vswitch',NULL,'Specify the vSwitch on host for private network'),
 | 
			
		||||
('Advanced','DEFAULT','management-server','vmware.public.vswitch',NULL,'Specify the vSwitch on host for public network'),
 | 
			
		||||
('Advanced','DEFAULT','management-server','vmware.service.console','Service Console','Specify the service console network name (ESX host only)'),
 | 
			
		||||
('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return');
 | 
			
		||||
('Advanced','DEFAULT','AgentManager','xapiwait','600','Time (in seconds) to wait for XAPI to return'),
 | 
			
		||||
('Account Defaults','DEFAULT','management-server','max.account.user.vms','20','The default maximum number of user VMs that can be deployed for an account'),
 | 
			
		||||
('Account Defaults','DEFAULT','management-server','max.account.public.ips','20','The default maximum number of public IPs that can be consumed by an account'),
 | 
			
		||||
('Account Defaults','DEFAULT','management-server','max.account.templates','20','The default maximum number of templates that can be deployed for an account'),
 | 
			
		||||
('Account Defaults','DEFAULT','management-server','max.account.snapshots','20','The default maximum number of snapshots that can be created for an account'),
 | 
			
		||||
('Account Defaults','DEFAULT','management-server','max.account.volumes','20','The default maximum number of volumes that can be created for an account');
 | 
			
		||||
 | 
			
		||||
ALTER TABLE `cloud`.`op_dc_ip_address_alloc` CHANGE COLUMN `instance_id` `nic_id` bigint unsigned DEFAULT NULL;
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user