def updateSharedQuota(self): # calculate the the total limit per cores and ram total_memory = float(0) total_vcpus = float(0) static_memory = float(0) static_vcpus = float(0) shared_memory = float(0) shared_vcpus = float(0) try: cpu_ratio = self.nova_manager.getParameter("cpu_allocation_ratio") ram_ratio = self.nova_manager.getParameter("ram_allocation_ratio") hypervisors = self.nova_manager.getHypervisors() for hv in hypervisors: if hv.getState() == "down" or hv.getStatus() == "disabled": continue if hv.getMemory() > 0: total_memory += hv.getMemory() if hv.getVCPUs() > 0: total_vcpus += hv.getVCPUs() total_memory *= float(ram_ratio) total_vcpus *= float(cpu_ratio) domain = self.keystone_manager.getDomains(name="default") if not domain: raise Exception("domain 'default' not found!") domain = domain[0] dom_id = domain.getId() kprojects = self.keystone_manager.getProjects(domain_id=dom_id) for kproject in kprojects: project = self.getProject(kproject.getId()) if project: quota = self.nova_manager.getQuota(project.getId(), is_class=True) pquota = project.getQuota() vcpus_size = quota.getSize("vcpus") vcpus_usage = pquota.getUsage("vcpus") mem_size = quota.getSize("memory") mem_usage = pquota.getUsage("memory") if vcpus_usage > vcpus_size or mem_usage > mem_size: LOG.info("cannot shrink the private quota for project" " %r (id=%s) because the usage of current " "quota exceeds the new size (vcpus=%s, " "memory=%s)" % (project.getName(), project.getId(), quota.getSize("vcpus"), quota.getSize("memory"))) self.nova_manager.updateQuota(pquota, is_class=True) quota = pquota else: pquota.setSize("vcpus", value=quota.getSize("vcpus")) pquota.setSize("memory", value=quota.getSize("memory")) pquota.setSize("instances", value=quota.getSize("instances")) else: quota = self.nova_manager.getQuota(kproject.getId()) if quota.getSize("vcpus") > 0: static_vcpus += quota.getSize("vcpus") if quota.getSize("memory") > 0: static_memory += quota.getSize("memory") enabled = False if total_vcpus < static_vcpus: if self.getProjects(): LOG.warn("shared quota: the total statically " "allocated vcpus (%s) is greater than the " "total amount of vcpus allowed (%s)" % (static_vcpus, total_vcpus)) else: shared_vcpus = total_vcpus - static_vcpus if total_memory < static_memory: if self.getProjects(): LOG.warn("shared quota: the total statically " "allocated memory (%s) is greater than " "the total amount of memory allowed (%s)" % (static_memory, total_memory)) else: enabled = True shared_memory = total_memory - static_memory if enabled: LOG.info("shared quota enabled: vcpus=%s memory=%s" % (shared_vcpus, shared_memory)) SharedQuota.enable() SharedQuota.setSize("vcpus", shared_vcpus) SharedQuota.setSize("memory", shared_memory) else: LOG.info("shared quota disabled") SharedQuota.disable() SharedQuota.setSize("vcpus", 0) SharedQuota.setSize("memory", 0) for project in self.getProjects().values(): quota = project.getQuota() quota.setSize("vcpus", shared_vcpus, private=False) quota.setSize("memory", shared_memory, private=False) except Exception as ex: LOG.error(ex) raise ex
def updateSharedQuota(self): # calculate the the total limit per cores and ram total_memory = float(0) total_vcpus = float(0) static_memory = float(0) static_vcpus = float(0) shared_memory = float(0) shared_vcpus = float(0) try: cpu_ratio = self.nova_manager.getParameter("cpu_allocation_ratio") ram_ratio = self.nova_manager.getParameter("ram_allocation_ratio") hypervisors = self.nova_manager.getHypervisors() for hv in hypervisors: if hv.getState() == "down" or hv.getStatus() == "disabled": continue if hv.getMemory() > 0: total_memory += hv.getMemory() if hv.getVCPUs() > 0: total_vcpus += hv.getVCPUs() total_memory *= float(ram_ratio) total_vcpus *= float(cpu_ratio) domain = self.keystone_manager.getDomains(name="default") if not domain: raise SynergyError("domain 'default' not found!") domain = domain[0] dom_id = domain.getId() kprojects = self.keystone_manager.getProjects(domain_id=dom_id) for kproject in kprojects: quota = self.nova_manager.getQuota(kproject.getId()) if quota.getSize("vcpus") == -1 and\ quota.getSize("memory") == -1: quota = self.nova_manager.getQuota(kproject.getId(), is_class=True) if quota.getSize("vcpus") > 0: static_vcpus += quota.getSize("vcpus") if quota.getSize("memory") > 0: static_memory += quota.getSize("memory") enabled = False if total_vcpus < static_vcpus: if self.project_manager.getProjects(): LOG.warn("shared quota: the total statically " "allocated vcpus (%s) is greater than the " "total amount of vcpus allowed (%s)" % (static_vcpus, total_vcpus)) else: shared_vcpus = total_vcpus - static_vcpus if total_memory < static_memory: if self.project_manager.getProjects(): LOG.warn("shared quota: the total statically " "allocated memory (%s) is greater than " "the total amount of memory allowed (%s)" % (static_memory, total_memory)) else: enabled = True shared_memory = total_memory - static_memory if enabled: LOG.info("shared quota enabled: vcpus=%s memory=%s" % (shared_vcpus, shared_memory)) SharedQuota.enable() SharedQuota.setSize("vcpus", shared_vcpus) SharedQuota.setSize("memory", shared_memory) else: LOG.info("shared quota disabled") SharedQuota.disable() SharedQuota.setSize("vcpus", 0) SharedQuota.setSize("memory", 0) for project in self.project_manager.getProjects(): quota = project.getQuota() quota.setSize("vcpus", shared_vcpus, private=False) quota.setSize("memory", shared_memory, private=False) except SynergyError as ex: LOG.error(ex) raise ex