def check_ip_quotas(self): """Checks user's quota for unattached public ips.""" dict_quotas = get_user_quota(self.auth) list_float_ips = self.net_client.list_floatingips() pending_ips = self.pending_quota['Ip'] limit_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['limit'] usage_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['usage'] project_limit_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['project_limit'] project_usage_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['project_usage'] available_ips = limit_ips-usage_ips if (available_ips > (project_limit_ips - project_usage_ips)): # Quotas are allocated per project and per user account. # So some other account in the same project may have bind some of user quota since project_quota maybe be different than number_of_users*user_quota # The result is user limit quota might be less than it seems so we have to consider project limit as well available_ips = project_limit_ips - project_usage_ips available_ips -= pending_ips for d in list_float_ips: if d['instance_id'] is None and d['port_id'] is None: available_ips += 1 if available_ips > 0: logging.log(REPORT, ' Floating IP quota is ok') return 0 else: msg = 'Floating IP not available in project: ' + self.opts['project_name'] raise ClientError(msg, error_get_ip)
def check_cluster_size_quotas(self): """ Checks if the user quota is enough to create the requested number of VMs. """ dict_quotas = get_user_quota(self.auth) pending_vm = self.pending_quota['VMs'] limit_vm = dict_quotas[self.project_id]['cyclades.vm']['limit'] usage_vm = dict_quotas[self.project_id]['cyclades.vm']['usage'] available_vm = limit_vm - usage_vm - pending_vm if available_vm < self.opts['cluster_size']: msg = 'Cyclades VMs out of limit' raise ClientError(msg, error_quotas_cluster_size) else: return 0
def check_disk_valid(self): """ Checks if the requested disk resources are available for the user. Subtracts the number of disk used and pending from the max allowed disk size. """ dict_quotas = get_user_quota(self.auth) pending_cd = self.pending_quota['Disk'] limit_cd = dict_quotas[self.project_id]['cyclades.disk']['limit'] usage_cd = dict_quotas[self.project_id]['cyclades.disk']['usage'] cyclades_disk_req = self.opts['disk_master'] + \ self.opts['disk_slaves'] * (self.opts['cluster_size'] - 1) available_cyclades_disk_GB = (limit_cd - usage_cd) / Bytes_to_GB - pending_cd if available_cyclades_disk_GB < cyclades_disk_req: msg = 'Cyclades disk out of limit' raise ClientError(msg, error_quotas_cyclades_disk) else: return 0
def check_ram_valid(self): """ Checks if the user quota is enough to bind the requested ram resources. Subtracts the number of ram used and pending from the max allowed number of ram. """ dict_quotas = get_user_quota(self.auth) pending_ram = self.pending_quota['Ram'] limit_ram = dict_quotas[self.project_id]['cyclades.ram']['limit'] usage_ram = dict_quotas[self.project_id]['cyclades.ram']['usage'] available_ram = (limit_ram - usage_ram) / Bytes_to_MB - pending_ram ram_req = self.opts['ram_master'] + \ self.opts['ram_slaves'] * (self.opts['cluster_size'] - 1) if available_ram < ram_req: msg = 'Cyclades ram out of limit' raise ClientError(msg, error_quotas_ram) else: return 0
def check_cpu_valid(self): """ Checks if the user quota is enough to bind the requested cpu resources. Subtracts the number of cpus used and pending from the max allowed number of cpus. """ dict_quotas = get_user_quota(self.auth) pending_cpu = self.pending_quota['Cpus'] limit_cpu = dict_quotas[self.project_id]['cyclades.cpu']['limit'] usage_cpu = dict_quotas[self.project_id]['cyclades.cpu']['usage'] available_cpu = limit_cpu - usage_cpu - pending_cpu cpu_req = self.opts['cpu_master'] + \ self.opts['cpu_slaves'] * (self.opts['cluster_size'] - 1) if available_cpu < cpu_req: msg = 'Cyclades cpu out of limit' raise ClientError(msg, error_quotas_cpu) else: return 0
def check_network_quotas(self): """ Checks if the user quota is enough to create a new private network Subtracts the number of networks used and pending from the max allowed number of networks """ dict_quotas = get_user_quota(self.auth) pending_net = self.pending_quota['Network'] limit_net = dict_quotas[self.project_id]['cyclades.network.private']['limit'] usage_net = dict_quotas[self.project_id]['cyclades.network.private']['usage'] project_limit_net = dict_quotas[self.project_id]['cyclades.network.private']['project_limit'] project_usage_net = dict_quotas[self.project_id]['cyclades.network.private']['project_usage'] available_networks = limit_net - usage_net if (available_networks > (project_limit_net - project_usage_net)): available_networks = project_limit_net - project_usage_net available_networks -= pending_net if available_networks >= 1: logging.log(REPORT, ' Private Network quota is ok') return 0 else: msg = 'Private Network quota exceeded in project: ' + self.opts['project_name'] raise ClientError(msg, error_quotas_network)
def check_ip_quotas(self): """Checks user's quota for unattached public ips.""" dict_quotas = get_user_quota(self.auth) list_float_ips = self.net_client.list_floatingips() pending_ips = self.pending_quota['Ip'] limit_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['limit'] usage_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['usage'] project_limit_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['project_limit'] project_usage_ips = dict_quotas[self.project_id]['cyclades.floating_ip']['project_usage'] available_ips = limit_ips-usage_ips if (available_ips > (project_limit_ips - project_usage_ips)): available_ips = project_limit_ips - project_usage_ips available_ips -= pending_ips for d in list_float_ips: if d['instance_id'] is None and d['port_id'] is None: available_ips += 1 if available_ips > 0: logging.log(REPORT, ' Floating IP quota is ok') return 0 else: msg = 'Floating IP not available in project: ' + self.opts['project_name'] raise ClientError(msg, error_get_ip)
def check_project_quota(self): """Checks that for a given project actual quota exist""" dict_quotas = get_user_quota(self.auth) if self.project_id in dict_quotas: return 0 return error_project_quota