def get(self): """ 查看宿主机列表(不包含忽略的宿主机). """ area = self.get_argument("area", None) idc = self.get_argument("idc", None) self.write(json.dumps(utils.get_vmhs(area, idc)))
def sync(): for vmh in utils.get_vmhs(): try: ip = asset_utils.get_ip_from_hostname(vmh) network = utils.get_network_from_ip(ip) utils.add_network(vmh, network) utils.update_info_from_rpc(vmh) logger.info("sync vmh info succ, vmh:{vmh}".format(vmh=vmh)) except Exception, e: logger.warning( "sync vmh info fail, vmh:{vmh}, exception:{exception}".format( vmh=vmh, exception=traceback.format_exc()))
def get(self): """ 查看资源状况. """ area = self.get_argument("area", None) idc = self.get_argument("idc", None) sort = self.get_argument("sort", 1) show_ignores = self.get_argument("show_ignores", 0) show_vms = self.get_argument("show_vms", 0) vmhs = utils.get_vmhs(area, idc) return_list = list() for vmh in vmhs: _dict = { "vmh": vmh, "data": { "vcpu": utils.get_info(vmh, "vcpu"), "mem": utils.get_info(vmh, "mem"), "space": utils.get_info(vmh, "space"), "vmlist": utils.get_info(vmh, "vmlist"), "type": utils.get_info(vmh, "type"), } } return_list.append(_dict) if show_ignores != 0 and show_ignores != "0": ignore_vmhs = utils.get_ignore_vmhs() for i in xrange(len(return_list)): if return_list[i]["vmh"] in ignore_vmhs: return_list[i]["ignored"] = True else: return_list[i]["ignored"] = False if show_vms != 0 and show_vms != "0": for i in xrange(len(return_list)): if return_list[i]["data"]["vmlist"] == []: return_list[i]["vms"] = [] else: sn = asset_utils.get_sn_from_hostname( return_list[i]["vmh"]) try: return_list[i]["vms"] = [ x["hostname"] for x in asset_utils.query_from_sn(sn)["vms"] ] except Exception, e: return_list[i]["vms"] = []
def get_resource(area, idc): return_list = list() ignore_vmhs = utils.get_ignore_vmhs() for vmh in utils.get_vmhs(area, idc): _dict = { "area": area, "idc": idc, "vmh": vmh, "vcpu": utils.get_info(vmh, "vcpu")["free"], "mem": utils.get_info(vmh, "mem")["free"], "space": utils.get_info(vmh, "space")["free"] } if vmh in ignore_vmhs: _dict["ignored"] = True else: _dict["ignored"] = False return_list.append(_dict) return_list.sort(key=lambda t: (t["vcpu"], t["mem"], t["space"]), reverse=True) return_list = return_list[:100] return return_list