def _GET(self, *param, **params): if self.input.has_key('job_id') is True: self.view.job_id = self.input.job_id else: self.view.job_id = None host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() model = findbyhost1(self.orm, host_id) uris = available_virt_uris() if model.attribute == 0 and model.hypervisor == 1: uri = uris["XEN"] elif model.attribute == 0 and model.hypervisor == 2: uri = uris["KVM"] else: uri = None # other_url other_url = "%s://%s%s/" % ( self.view.ctx.protocol, model.hostname, karesansui.config['application.url.prefix']) if self.is_mode_input() is False: if karesansui.config["application.uniqkey"] == model.uniq_key: # My host host_cpuinfo = get_proc_cpuinfo() cpuinfo = {} cpuinfo["number"] = len(host_cpuinfo) cpuinfo["vendor"] = host_cpuinfo[0]["vendor_id"] cpuinfo["model"] = host_cpuinfo[0]["model name"] cpuinfo["frequency"] = host_cpuinfo[0]["cpu MHz"] host_meminfo = get_proc_meminfo() meminfo = {} meminfo["total"] = host_meminfo["MemTotal"][0] meminfo["free"] = host_meminfo["MemFree"][0] meminfo["buffers"] = host_meminfo["Buffers"][0] meminfo["cached"] = host_meminfo["Cached"][0] host_diskinfo = get_partition_info(VENDOR_DATA_DIR) diskinfo = {} diskinfo["total"] = host_diskinfo[1] diskinfo["free"] = host_diskinfo[3] self.kvc = KaresansuiVirtConnection(uri) try: host = MergeHost(self.kvc, model) if self.is_json() is True: json_host = host.get_json(self.me.languages) self.view.data = json_dumps({ "model": json_host["model"], "cpuinfo": cpuinfo, "meminfo": meminfo, "diskinfo": diskinfo, }) else: self.view.model = host.info["model"] self.view.virt = host.info["virt"] finally: self.kvc.close() else: # other uri if model.attribute == 2: segs = uri_split(model.hostname) uri = uri_join(segs, without_auth=True) creds = '' if segs["user"] is not None: creds += segs["user"] if segs["passwd"] is not None: creds += ':' + segs["passwd"] try: self.kvc = KaresansuiVirtConnectionAuth(uri, creds) host = MergeHost(self.kvc, model) if self.is_json() is True: json_host = host.get_json(self.me.languages) self.view.data = json_dumps({ "model": json_host["model"], "uri": uri, "num_of_guests": len(host.guests), }) else: self.view.model = host.info["model"] self.view.virt = host.info["virt"] self.view.uri = uri try: self.view.auth_user = segs["user"] except: self.view.auth_user = "" try: self.view.auth_passwd = segs["passwd"] except: self.view.auth_passwd = "" except: pass finally: #if 'kvc' in dir(locals()["self"]) if 'kvc' in dir(self): self.kvc.close() # other host else: if self.is_json() is True: self.view.data = json_dumps({ "model": model.get_json(self.me.languages), "other_url": other_url, }) else: self.view.model = model self.view.virt = None self.view.other_url = other_url return True else: # mode=input if model.attribute == 2: segs = uri_split(model.hostname) uri = uri_join(segs, without_auth=True) creds = '' if segs["user"] is not None: creds += segs["user"] if segs["passwd"] is not None: creds += ':' + segs["passwd"] self.view.model = model self.view.uri = uri try: self.view.auth_user = segs["user"] except: self.view.auth_user = "" try: self.view.auth_passwd = segs["passwd"] except: self.view.auth_passwd = "" else: self.kvc = KaresansuiVirtConnection(uri) try: host = MergeHost(self.kvc, model) self.view.model = host.info["model"] finally: self.kvc.close() self.view.application_uniqkey = karesansui.config[ 'application.uniqkey'] return True
def _GET(self, *param, **params): if self.input.has_key('job_id') is True: self.view.job_id = self.input.job_id else: self.view.job_id = None host_id = param[0] host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() uri_id = param[1] if uri_id is None: return web.notfound() model = findbyhost1(self.orm, host_id) if self.is_mode_input() is False: if model.attribute == 2: info = {} segs = uri_split(model.hostname) uri = uri_join(segs, without_auth=True) creds = '' if segs["user"] is not None: creds += segs["user"] if segs["passwd"] is not None: creds += ':' + segs["passwd"] self.kvc = KaresansuiVirtConnectionAuth(uri,creds) try: host = MergeHost(self.kvc, model) for guest in host.guests: if not '__guest' in locals(): _virt = self.kvc.search_kvg_guests(guest.info["model"].name) if 0 < len(_virt): for _v in _virt: info = _v.get_info() if info["uuid"] == uri_id or (uri[0:5] == "test:"): __guest = MergeGuest(guest.info["model"],_v) autostart = _v.autostart() status = _v.status() is_creatable = _v.is_creatable() is_shutdownable = _v.is_shutdownable() is_suspendable = _v.is_suspendable() is_resumable = _v.is_resumable() is_destroyable = _v.is_destroyable() is_active = _v.is_active() break if self.is_json() is True: json_host = host.get_json(self.me.languages) json_guest = __guest.get_json(self.me.languages) self.view.data = json_dumps( { "parent_model": json_host["model"], "parent_virt": json_host["virt"], "model": json_guest["model"], "virt": json_guest["virt"], "info": info, "autostart": autostart, "status": status, "is_creatable": is_creatable, "is_shutdownable": is_shutdownable, "is_suspendable": is_suspendable, "is_resumable": is_resumable, "is_destroyable": is_destroyable, "is_active": is_active, } ) else: self.view.parent_model = host.info["model"] self.view.parent_virt = host.info["virt"] self.view.model = __guest.info["model"] self.view.virt = __guest.info["virt"] self.view.info = info self.view.autostart = autostart self.view.status = status self.view.is_creatable = is_creatable self.view.is_shutdownable = is_shutdownable self.view.is_suspendable = is_suspendable self.view.is_resumable = is_resumable self.view.is_destroyable = is_destroyable self.view.is_active = is_active finally: self.kvc.close() return True