def get_avzone(self): global lock lock.acquire() try: list_hy_info = CommonApi.get_hvinfo()["hypervisors"] list_az_info = CommonApi.get_azinfo()["aggregates"] lock.release() except: lock.release() def _util_az(az_info): list_hosts = az_info["hosts"] list_hy_info_tmp = filter(lambda i:i["hypervisor_hostname"] in list_hosts and i["status"] == "enabled",list_hy_info) total_vcpu = 0 total_vcpu_used = 0 total_mem = 0 total_mem_free = 0 for host_info in list_hy_info_tmp: total_vcpu += host_info["vcpus"]*4 total_vcpu_used += host_info["vcpus_used"] total_mem += host_info["memory_mb"] total_mem_free += host_info["free_ram_mb"] total_mem_used = total_mem - total_mem_free if total_vcpu == 0 or total_mem == 0: util = 2 else: util = round(float(total_vcpu_used)/float(total_vcpu),2) + round(float(total_mem_used)/float(total_mem),2) return util av_zone = reduce(lambda x,y:x if _util_az(x) <= _util_az(y) else y,list_az_info)["availability_zone"] return av_zone
def get_avzone(self): global lock lock.acquire() try: list_hy_info = CommonApi.get_hvinfo()["hypervisors"] list_az_info = CommonApi.get_azinfo()["aggregates"] lock.release() except: lock.release() def _util_az(az_info): list_hosts = az_info["hosts"] list_hy_info_tmp = filter( lambda i: i["hypervisor_hostname"] in list_hosts and i[ "status"] == "enabled", list_hy_info) total_vcpu = 0 total_vcpu_used = 0 total_mem = 0 total_mem_free = 0 for host_info in list_hy_info_tmp: total_vcpu += host_info["vcpus"] * 4 total_vcpu_used += host_info["vcpus_used"] total_mem += host_info["memory_mb"] total_mem_free += host_info["free_ram_mb"] total_mem_used = total_mem - total_mem_free if total_vcpu == 0 or total_mem == 0: util = 2 else: util = round(float(total_vcpu_used) / float(total_vcpu), 2) + round( float(total_mem_used) / float(total_mem), 2) return util av_zone = reduce(lambda x, y: x if _util_az(x) <= _util_az(y) else y, list_az_info)["availability_zone"] return av_zone
def test_get_role(self): self.test_login() ret = CommonApi.get_role_id() prints(ret)
def test_get_domain(self): self.test_login() ret = CommonApi.get_domain_id() prints(ret)
def test_get_hv(self): self.test_login() ret = CommonApi.get_hvinfo() prints(ret)
def test_get_keypairs(self): self.test_login() ret = CommonApi.get_keypairs() prints(ret)
def _get_role(self): if not self.role_id: self.role_id = CommonApi.get_role_id({"name": "user"})["roles"][0]["id"]
def _get_domian(self): if not self.domain_id: self.domain_id = CommonApi.get_domain_id({"name": "default" })["domains"][0]["id"]
def _get_role(self): if not self.role_id: self.role_id = CommonApi.get_role_id({"name":"user"})["roles"][0]["id"]
def _get_domian(self): if not self.domain_id: self.domain_id = CommonApi.get_domain_id({"name":"default"})["domains"][0]["id"]