def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() self.view.host_id = host_id config = ServiceConfigParam(SERVICE_XML_FILE) config.load_xml_config() service = config.findby1service(param[1]) if not service: self.logger.debug("Get service status failed. Service not found.") return web.notfound("Service not found") sysv = SysVInit_RH(service['system_name'], service['system_command']) status = {"status":sysv.status(), "autostart":sysv.onboot(), "readonly":service["system_readonly"], } if self.__template__["media"] == 'json': self.view.status = json_dumps(status) else: self.view.status = status return True
def _GET(self, *param, **params): tags = findbyhostall(self.orm) if not tags: return web.notfound(self._("No tag")) if self.is_part() is True: self.view.tags = tags machine_ids = {} for tag in tags: tag_id = str(tag.id) machine_ids[tag_id] = [] for machine in tag.machine: machine_ids[tag_id].append("tag_machine%s"% machine.id) machine_ids[tag_id] = " ".join(machine_ids[tag_id]) self.view.machine_ids = machine_ids return True elif self.is_json() is True: tags_json = [] for tag in tags: tags_json.append(tag.get_json(self.me.languages)) self.view.tags = json_dumps(tags_json) return True else: return web.nomethod()
def _GET(self, *param, **params): """<comment-ja> ネットワークがアクティブかどうかのステータス - inactive = 0 - active = 1 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() # TODO valid network_name =param[1] if not network_name: return web.badrequest() kvc = KaresansuiVirtConnection() try: kvn = kvc.search_kvn_networks(network_name)[0] status = NETWORK_INACTIVE if kvn.is_active(): status = NETWORK_ACTIVE if self.__template__["media"] == 'json': self.view.status = json_dumps(status) else: self.view.status = status self.__template__.dir = 'hostby1networkby1' finally: kvc.close() return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() target = param[1] if target is None: return web.notfound() lang = param[2] if lang is None: return web.notfound() if not validates_watch(self, target, lang): self.logger.debug( "Get watch mail template failed. Did not validate.") return web.badrequest(self.view.alert) template_dir = "%s/%s" % ( TEMPLATE_DIR, lang[0:2], ) mail_template_warning = read_file( "%s/%s" % (template_dir, MAIL_TEMPLATE_COLLECTD_WARNING[target])) mail_template_failure = read_file( "%s/%s" % (template_dir, MAIL_TEMPLATE_COLLECTD_FAILURE[target])) mail_template_okay = read_file( "%s/%s" % (template_dir, MAIL_TEMPLATE_COLLECTD_OKAY[target])) data = { "mail_template_warning": mail_template_warning, "mail_template_failure": mail_template_failure, "mail_template_okay": mail_template_okay, } self.view.data = json_dumps(data) return True
def _GET(self, *param, **params): """<comment-ja> ネットワークがアクティブかどうかのステータス - inactive = 0 - active = 1 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() # TODO valid network_name = param[1] if not network_name: return web.badrequest() kvc = KaresansuiVirtConnection() try: kvn = kvc.search_kvn_networks(network_name)[0] status = NETWORK_INACTIVE if kvn.is_active(): status = NETWORK_ACTIVE if self.__template__["media"] == 'json': self.view.status = json_dumps(status) else: self.view.status = status self.__template__.dir = 'hostby1networkby1' finally: kvc.close() return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() target = param[1] if target is None: return web.notfound() lang = param[2] if lang is None: return web.notfound() if not validates_watch(self, target, lang): self.logger.debug("Get watch mail template failed. Did not validate.") return web.badrequest(self.view.alert) template_dir = "%s/%s" % (TEMPLATE_DIR,lang[0:2],) mail_template_warning = read_file("%s/%s" % (template_dir,MAIL_TEMPLATE_COLLECTD_WARNING[target])) mail_template_failure = read_file("%s/%s" % (template_dir,MAIL_TEMPLATE_COLLECTD_FAILURE[target])) mail_template_okay = read_file("%s/%s" % (template_dir,MAIL_TEMPLATE_COLLECTD_OKAY[target])) data = { "mail_template_warning" : mail_template_warning, "mail_template_failure" : mail_template_failure, "mail_template_okay" : mail_template_okay, } self.view.data = json_dumps(data) return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() self.view.host_id = host_id config = ServiceConfigParam(SERVICE_XML_FILE) config.load_xml_config() service = config.findby1service(param[1]) if not service: self.logger.debug("Get service status failed. Service not found.") return web.notfound("Service not found") sysv = SysVInit_RH(service['system_name'], service['system_command']) status = { "status": sysv.status(), "autostart": sysv.onboot(), "readonly": service["system_readonly"], } if self.__template__["media"] == 'json': self.view.status = json_dumps(status) else: self.view.status = status return True
def _GET(self, *param, **params): """<comment-ja> virDomainState - VIR_DOMAIN_NOSTATE = 0 - VIR_DOMAIN_RUNNING = 1 - VIR_DOMAIN_BLOCKED = 2 - VIR_DOMAIN_PAUSED = 3 - VIR_DOMAIN_SHUTDOWN = 4 - VIR_DOMAIN_SHUTOFF = 5 - VIR_DOMAIN_CRASHED = 6 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ 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: _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) status = _v.status() break if self.is_json() is True: self.view.status = json_dumps(status) else: self.view.status = status finally: self.kvc.close() return True
def _GET(self, *param, **params): """<comment-ja> virDomainState - VIR_DOMAIN_NOSTATE = 0 - VIR_DOMAIN_RUNNING = 1 - VIR_DOMAIN_BLOCKED = 2 - VIR_DOMAIN_PAUSED = 3 - VIR_DOMAIN_SHUTDOWN = 4 - VIR_DOMAIN_SHUTOFF = 5 - VIR_DOMAIN_CRASHED = 6 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ 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: _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) status = _v.status() break if self.is_json() is True: self.view.status = json_dumps(status) else: self.view.status = status finally: self.kvc.close() return True
def _GET(self, *param, **params): self.__template__.dir = "hostby1logby1appby1" self.__template__.file = "hostby1logby1appby1" self.__template__.media = "part" appname = param[1] log_config = None if not validates_log(self): self.logger.debug("Get log failed. Did not validate.") return web.badrequest(self.view.alert) config = LogViewConfigParam(LOG_VIEW_XML_FILE) config.load_xml_config() app = config.findby1application(appname) lines = [] param_value = {} if self.input.has_key("k"): param_value["k"] = self.input.k else: param_value["k"] = "" start_day = str2datetime(self.input.s, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) end_day = str2datetime(self.input.e, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) (start_hour, start_minute) = self.input.st.split(':', 2) (end_hour, end_minute) = self.input.et.split(':', 2) start_time = create_epochsec(start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute), ) end_time = create_epochsec(end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute), ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest(_('Getting reports failed. Start time > end time.')) param_value["start_datetime"] = "%s %s" % (start_day.strftime("%Y/%m/%d"), self.input.st) param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et) lines = read_all_log(app, int(self.input.m), param_value["start_datetime"], param_value["end_datetime"], param_value["k"]) self.view.log_json = json_dumps(lines) return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() tags = findbyhost1guestall(self.orm, host_id) if not tags: self.logger.debug("No tags is found.") return web.notfound() if self.is_part() is True: self.view.tags = tags machine_ids = {} for tag in tags: tag_id = str(tag.id) machine_ids[tag_id] = [] for machine in tag.machine: if not machine.is_deleted: machine_ids[tag_id].append("tag_machine%s" % machine.id) machine_ids[tag_id] = " ".join(machine_ids[tag_id]) self.view.machine_ids = machine_ids return True elif self.is_json() is True: tags_json = [] for tag in tags: tags_json.append(tag.get_json(self.me.languages)) self.view.tags = json_dumps(tags_json) return True else: return web.nomethod()
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() tags = findbyhost1guestall(self.orm, host_id) if not tags: self.logger.debug("No tags is found.") return web.notfound() if self.is_part() is True: self.view.tags = tags machine_ids = {} for tag in tags: tag_id = str(tag.id) machine_ids[tag_id] = [] for machine in tag.machine: if not machine.is_deleted: machine_ids[tag_id].append("tag_machine%s"% machine.id) machine_ids[tag_id] = " ".join(machine_ids[tag_id]) self.view.machine_ids = machine_ids return True elif self.is_json() is True: tags_json = [] for tag in tags: tags_json.append(tag.get_json(self.me.languages)) self.view.tags = json_dumps(tags_json) return True else: return web.nomethod()
def _GET(self, *param, **params): """<comment-ja> virDomainState - VIR_DOMAIN_NOSTATE = 0 - VIR_DOMAIN_RUNNING = 1 - VIR_DOMAIN_BLOCKED = 2 - VIR_DOMAIN_PAUSED = 3 - VIR_DOMAIN_SHUTDOWN = 4 - VIR_DOMAIN_SHUTOFF = 5 - VIR_DOMAIN_CRASHED = 6 </comment-ja> <comment-en> TODO: English Comment </comment-en> """ (host_id, guest_id) = self.chk_guestby1(param) if guest_id is None: return web.notfound() model = findbyguest1(self.orm, guest_id) # virt kvc = KaresansuiVirtConnection() try: domname = kvc.uuid_to_domname(model.uniq_key) if not domname: return web.conflict(web.ctx.path) virt = kvc.search_kvg_guests(domname) if self.__template__["media"] == 'json': self.view.status = json_dumps(virt[0].status()) else: self.view.status = virt[0].status() finally: kvc.close() #self.__template__.dir = 'guestby1' return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() model = findbyhost1(self.orm, host_id) uris = available_virt_uris() self.kvc = KaresansuiVirtConnection() try: # libvirt connection scope --> # Storage Pool #inactive_pool = self.kvc.list_inactive_storage_pool() inactive_pool = [] active_pool = self.kvc.list_active_storage_pool() pools = inactive_pool + active_pool pools.sort() if not pools: return web.badrequest('One can not start a storage pool.') # Output .input if self.is_mode_input() is True: self.view.pools = pools pools_info = {} pools_vols_info = {} pools_iscsi_blocks = {} already_vols = [] guests = [] guests += self.kvc.list_inactive_guest() guests += self.kvc.list_active_guest() for guest in guests: already_vol = self.kvc.get_storage_volume_bydomain(domain=guest, image_type=None, attr='path') if already_vol: already_vols += already_vol.keys() for pool in pools: pool_obj = self.kvc.search_kvn_storage_pools(pool)[0] if pool_obj.is_active() is True: pools_info[pool] = pool_obj.get_info() blocks = None if pools_info[pool]['type'] == 'iscsi': blocks = self.kvc.get_storage_volume_iscsi_block_bypool(pool) if blocks: pools_iscsi_blocks[pool] = [] vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc) vols_info = {} for vol_obj in vols_obj: vol_name = vol_obj.get_storage_volume_name() vols_info[vol_name] = vol_obj.get_info() if blocks: if vol_name in blocks and vol_name not in already_vols: pools_iscsi_blocks[pool].append(vol_obj.get_info()) pools_vols_info[pool] = vols_info self.view.pools_info = pools_info self.view.pools_vols_info = pools_vols_info self.view.pools_iscsi_blocks = pools_iscsi_blocks bridge_prefix = { "XEN":"xenbr", "KVM":KVM_BRIDGE_PREFIX, } self.view.host_id = host_id self.view.DEFAULT_KEYMAP = DEFAULT_KEYMAP self.view.DISK_NON_QEMU_FORMAT = DISK_NON_QEMU_FORMAT self.view.DISK_QEMU_FORMAT = DISK_QEMU_FORMAT self.view.hypervisors = {} self.view.mac_address = {} self.view.keymaps = {} self.view.phydev = {} self.view.virnet = {} used_ports = {} for k,v in MACHINE_HYPERVISOR.iteritems(): if k in available_virt_mechs(): self.view.hypervisors[k] = v uri = uris[k] mem_info = self.kvc.get_mem_info() active_networks = self.kvc.list_active_network() used_graphics_ports = self.kvc.list_used_graphics_port() bus_types = self.kvc.bus_types self.view.bus_types = bus_types self.view.max_mem = mem_info['host_max_mem'] self.view.free_mem = mem_info['host_free_mem'] self.view.alloc_mem = mem_info['guest_alloc_mem'] self.view.mac_address[k] = generate_mac_address(k) self.view.keymaps[k] = eval("get_keymaps(%s_KEYMAP_DIR)" % k) # Physical device phydev = [] phydev_regex = re.compile(r"%s" % bridge_prefix[k]) for dev,dev_info in get_ifconfig_info().iteritems(): try: if phydev_regex.match(dev): phydev.append(dev) except: pass if len(phydev) == 0: phydev.append("%s0" % bridge_prefix[k]) phydev.sort() self.view.phydev[k] = phydev # Physical device # Virtual device self.view.virnet[k] = sorted(active_networks) used_ports[k] = used_graphics_ports exclude_ports = [] for k, _used_port in used_ports.iteritems(): exclude_ports = exclude_ports + _used_port exclude_ports = sorted(exclude_ports) exclude_ports = [p for p, q in zip(exclude_ports, exclude_ports[1:] + [None]) if p != q] self.view.graphics_port = next_number(GRAPHICS_PORT_MIN_NUMBER, PORT_MAX_NUMBER, exclude_ports) else: # .part models = findbyhost1guestall(self.orm, host_id) guests = [] if models: # Physical Guest Info self.view.hypervisors = {} for model in models: for k,v in MACHINE_HYPERVISOR.iteritems(): if k in available_virt_mechs(): self.view.hypervisors[k] = v uri = uris[k] if hasattr(self, "kvc") is not True: self.kvc = KaresansuiVirtConnection(uri) domname = self.kvc.uuid_to_domname(model.uniq_key) #if not domname: return web.conflict(web.ctx.path) _virt = self.kvc.search_kvg_guests(domname) if 0 < len(_virt): guests.append(MergeGuest(model, _virt[0])) else: guests.append(MergeGuest(model, None)) # Exported Guest Info exports = {} for pool_name in pools: files = [] pool = self.kvc.search_kvn_storage_pools(pool_name) path = pool[0].get_info()["target"]["path"] if os.path.exists(path): for _afile in glob.glob("%s/*/info.dat" % (path,)): param = ExportConfigParam() param.load_xml_config(_afile) _dir = os.path.dirname(_afile) uuid = param.get_uuid() name = param.get_domain() created = param.get_created() title = param.get_title() if title != "": title = re.sub("[\r\n]","",title) if title == "": title = _('untitled') if created != "": created_str = time.strftime("%Y/%m/%d %H:%M:%S", \ time.localtime(float(created))) else: created_str = _("N/A") files.append({"dir": _dir, "pool" : pool_name, #"b64dir" : base64_encode(_dir), "uuid" : uuid, "name" : name, "created" : int(created), "created_str" : created_str, "title" : title, "icon" : param.get_database()["icon"], }) exports[pool_name] = files # .json if self.is_json() is True: guests_json = [] for x in guests: guests_json.append(x.get_json(self.me.languages)) self.view.guests = json_dumps(guests_json) else: self.view.exports = exports self.view.guests = guests return True finally: #self.kvc.close() pass # libvirt connection scope --> Guest#_post()
def _GET(self, *param, **params): (host_id, guest_id) = self.chk_guestby1(param) if self.input.has_key('job_id') is True: self.view.job_id = self.input.job_id else: self.view.job_id = None if guest_id is None: return web.notfound() model = findbyguest1(self.orm, guest_id) self.kvc = KaresansuiVirtConnection() if self.is_mode_input() is True: try: domname = self.kvc.uuid_to_domname(model.uniq_key) if not domname: return web.notfound() virt = self.kvc.search_kvg_guests(domname)[0] guest = MergeGuest(model, virt) self.view.model = guest.info["model"] return True except: self.kvc.close() raise else: try: domname = self.kvc.uuid_to_domname(model.uniq_key) if not domname: return web.notfound() virt = self.kvc.search_kvg_guests(domname)[0] guest = MergeGuest(model, virt) guest_info = guest.info["virt"].get_info() info = {} info['memory'] = guest_info["memory"] info['cpu'] = guest_info["cpuTime"] info['os'] = guest_info["OSType"] info['hypervisor'] = guest_info["hypervisor"] info['type'] = guest_info["VMType"] info['hv_version'] = guest_info["hv_version"] disk_info = guest.info["virt"].get_disk_info() interface_info = guest.info["virt"].get_interface_info() net_info = guest.info["virt"].get_netinfo() graphics_info = guest.info["virt"].get_graphics_info() vcpu_info = guest.info["virt"].get_vcpus_info() pool_info = [] pool_vols_info = [] already_vols = [] pools = self.kvc.get_storage_pool_name_bydomain(domname) if len(pools) > 0: for pool in pools: pool_obj = self.kvc.search_kvn_storage_pools(pool)[0] if pool_obj.is_active() is True: pool_info = pool_obj.get_info() vols_obj = pool_obj.search_kvn_storage_volumes( self.kvc) vols_info = {} for vol_obj in vols_obj: vol_name = vol_obj.get_storage_volume_name() vols_info[vol_name] = vol_obj.get_info() pool_vols_info = vols_info if self.__template__["media"] == 'json': json_guest = guest.get_json(self.me.languages) self.view.data = json_dumps({ "model": json_guest["model"], "virt": json_guest["virt"], "autostart": guest.info["virt"].autostart(), "info": info, "disk_info": disk_info, "net_info": net_info, "interface_info": interface_info, "pool_info": pool_info, "pool_vols_info": pool_vols_info, "graphics_info": graphics_info, "vcpu_info": vcpu_info, }) else: self.view.model = guest.info["model"] self.view.virt = guest.info["virt"] self.view.autostart = guest.info["virt"].autostart() self.view.info = info self.view.disk_info = disk_info self.view.net_info = net_info self.view.interface_info = interface_info self.view.pool_info = pool_info self.view.pool_vols_info = pool_vols_info self.view.graphics_info = graphics_info self.view.vcpu_info = vcpu_info except: self.kvc.close() raise 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 = 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 = 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 host 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 self.kvc = KaresansuiVirtConnection(uri) try: host = MergeHost(self.kvc, model) self.view.model = host.info["model"] self.view.application_uniqkey = karesansui.config['application.uniqkey'] finally: self.kvc.close() return True
def _GET(self, *param, **params): (host_id, guest_id) = self.chk_guestby1(param) if self.input.has_key('job_id') is True: self.view.job_id = self.input.job_id else: self.view.job_id = None if guest_id is None: return web.notfound() model = findbyguest1(self.orm, guest_id) self.kvc = KaresansuiVirtConnection() if self.is_mode_input() is True: try: domname = self.kvc.uuid_to_domname(model.uniq_key) if not domname: return web.notfound() virt = self.kvc.search_kvg_guests(domname)[0] guest = MergeGuest(model, virt) self.view.model = guest.info["model"] return True except: self.kvc.close() raise else: try: domname = self.kvc.uuid_to_domname(model.uniq_key) if not domname: return web.notfound() virt = self.kvc.search_kvg_guests(domname)[0] guest = MergeGuest(model, virt) guest_info = guest.info["virt"].get_info() info = {} info['memory'] = guest_info["memory"] info['cpu'] = guest_info["cpuTime"] info['os'] = guest_info["OSType"] info['hypervisor'] = guest_info["hypervisor"] info['type'] = guest_info["VMType"] info['hv_version'] = guest_info["hv_version"] disk_info = guest.info["virt"].get_disk_info() interface_info = guest.info["virt"].get_interface_info() net_info = guest.info["virt"].get_netinfo() graphics_info = guest.info["virt"].get_graphics_info() vcpu_info = guest.info["virt"].get_vcpus_info() pool_info = [] pool_vols_info = [] already_vols = [] pools = self.kvc.get_storage_pool_name_bydomain(domname) if len(pools) > 0: for pool in pools: pool_obj = self.kvc.search_kvn_storage_pools(pool)[0] if pool_obj.is_active() is True: pool_info = pool_obj.get_info() vols_obj = pool_obj.search_kvn_storage_volumes(self.kvc) vols_info = {} for vol_obj in vols_obj: vol_name = vol_obj.get_storage_volume_name() vols_info[vol_name] = vol_obj.get_info() pool_vols_info = vols_info if self.__template__["media"] == 'json': json_guest = guest.get_json(self.me.languages) self.view.data = json_dumps( { "model": json_guest["model"], "virt": json_guest["virt"], "autostart": guest.info["virt"].autostart(), "info": info, "disk_info": disk_info, "net_info": net_info, "interface_info": interface_info, "pool_info": pool_info, "pool_vols_info": pool_vols_info, "graphics_info": graphics_info, "vcpu_info": vcpu_info, } ) else: self.view.model = guest.info["model"] self.view.virt = guest.info["virt"] self.view.autostart = guest.info["virt"].autostart() self.view.info = info self.view.disk_info = disk_info self.view.net_info = net_info self.view.interface_info = interface_info self.view.pool_info = pool_info self.view.pool_vols_info = pool_vols_info self.view.graphics_info = graphics_info self.view.vcpu_info = vcpu_info except: self.kvc.close() raise return True
log_config, param_value["start_datetime"], param_value["end_datetime"], param_value["k"], ) if lines is False: return web.notfound() except Exception, e: self.logger.warning("log file open error: %s" % e) else: log_dir = "/var/log/%s" % log_config["dir"] try: lines = read_log( "%s/%s" % (log_dir, log_config["filename"]), self.input.m, log_config, param_value["statrt_datetime"], param_value["end_datetime"], param_value["k"], ) if lines is False: return web.notfound() except Exception, e: self.logger.warning("log file open error: %s" % e) self.view.log_json = json_dumps(lines) return True urls = ("/host/(\d+)/log/([0-9a-zA-Z\-]+)/([0-9a-zA-Z\-\.]+)$", HostBy1LogBy1AppBy1)
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() # valid self.view.uuid = param[1] kvc = KaresansuiVirtConnection() try: # libvirt connection scope --> # Storage Pool #inactive_pool = kvc.list_inactive_storage_pool() inactive_pool = [] active_pool = kvc.list_active_storage_pool() pools = inactive_pool + active_pool pools.sort() export = [] for pool_name in pools: pool = kvc.search_kvn_storage_pools(pool_name) path = pool[0].get_info()["target"]["path"] if os.path.exists(path): for _afile in glob.glob("%s/*/info.dat" % (path, )): e_param = ExportConfigParam() e_param.load_xml_config(_afile) if e_param.get_uuid() != self.view.uuid: continue e_name = e_param.get_domain() _dir = os.path.dirname(_afile) param = ConfigParam(e_name) path = "%s/%s.xml" % (_dir, e_name) if os.path.isfile(path) is False: self.logger.error( 'Export corrupt data.(file not found) - path=%s' % path) return web.internalerror() param.load_xml_config(path) if e_name != param.get_domain_name(): self.logger.error('Export corrupt data.(The name does not match) - info=%s, xml=%s' \ % (e_name, param.get_name())) return web.internalerror() _dir = os.path.dirname(_afile) title = e_param.get_title() if title != "": title = re.sub("[\r\n]", "", title) if title == "": title = _('untitled') created = e_param.get_created() if created != "": created_str = time.strftime("%Y/%m/%d %H:%M:%S", \ time.localtime(float(created))) else: created_str = _("N/A") export.append({ "info": { "dir": _dir, "pool": pool_name, "uuid": e_param.get_uuid(), "name": e_name, "created": int(created), "created_str": created_str, "title": title, }, "xml": { "on_reboot": param.get_behavior('on_reboot'), "on_poweroff": param.get_behavior('on_poweroff'), "on_crash": param.get_behavior('on_crash'), "boot_dev": param.get_boot_dev(), #"bootloader" : param.get_bootloader(), #"commandline" : param.get_commandline(), #"current_snapshot" : param.get_current_snapshot(), 'disk': param.get_disk(), "domain_name": param.get_domain_name(), "domain_type": param.get_domain_type(), "features_acpi": param.get_features_acpi(), "features_apic": param.get_features_apic(), "features_pae": param.get_features_pae(), #"initrd" : param.get_initrd(), "interface": param.get_interface(), #"kernel" : param.get_kernel(), "max_memory": param.get_max_memory(), 'max_vcpus': param.get_max_vcpus(), "max_vcpus_limit": param.get_max_vcpus_limit(), "memory": param.get_memory(), "uuid": param.get_uuid(), "vcpus": param.get_vcpus(), "vcpus_limit": param.get_vcpus_limit(), "graphics_autoport": param.get_graphics_autoport(), "keymap": param.get_graphics_keymap(), "graphics_listen": param.get_graphics_listen(), "graphics_passwd": param.get_graphics_passwd(), "graphics_port": param.get_graphics_port(), }, "pool": pool[0].get_info(), }) if len(export) != 1: self.logger.info("Export does not exist. - uuid=%s" % self.view.uuid) return web.badrequest() # .json if self.is_json() is True: self.view.export = json_dumps(export[0]) else: self.view.export = export return True finally: kvc.close()
if lines is False: return web.notfound() except Exception, e: self.logger.warning("log file open error: %s" % e) else: if log_config['dir'] is None: log_dir = "/var/log" else: if log_config['dir'][0] == "/": log_dir = log_config['dir'] else: log_dir = "/var/log/%s" % log_config['dir'] try: lines = read_log("%s/%s" % (log_dir, log_config['filename']), self.input.m, log_config, param_value["start_datetime"], param_value["end_datetime"], param_value["k"]) if lines is False: return web.notfound() except Exception, e: self.logger.warning("log file open error: %s" % e) self.view.log_json = json_dumps(lines) return True urls = ( '/host/(\d+)/log/([0-9a-zA-Z\-]+)/([0-9a-zA-Z\-\.]+)$', HostBy1LogBy1AppBy1, )
def _GET(self, *param, **params): (host_id, guest_id) = self.chk_guestby1(param) if guest_id is None: return web.notfound() snapshot_id = param[2] if not validates_param_id(self, snapshot_id): return web.notfound(self.view.alert) guest = m_findbyguest1(self.orm, guest_id) if not guest: return web.notfound() kvs = KaresansuiVirtSnapshot(readonly=False) snapshot_list = [] try: domname = kvs.kvc.uuid_to_domname(guest.uniq_key) if not domname: return web.notfound() self.view.is_creatable = kvs.isSupportedDomain(domname) try: snapshot_list = kvs.listNames(domname)[domname] except: pass parent_name = kvs.getParentName(snapshot_id,domain=domname) if parent_name is None: parent_name = _('None') children_names = kvs.getChildrenNames(snapshot_id,domain=domname) if len(children_names) == 0: children_name = _('None') else: children_name = ",".join(children_names) model = s_findbyname_guestby1(self.orm, snapshot_id, guest_id) if model is None: name = snapshot_id notebook_title = "" notebook_value = "" created_user = _("N/A") created = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(snapshot_id))) modified_user = _("N/A") modified = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(snapshot_id))) else: name = model.name notebook_title = model.notebook.title notebook_value = model.notebook.value created_user = model.created_user.nickname created = model.created modified_user = model.modified_user.nickname modified = model.modified current_snapshot = kvs.getCurrentSnapshotName(domname) current = False if snapshot_id == current_snapshot: current = True finally: kvs.finish() if not snapshot_id in snapshot_list: self.logger.error(_("The specified snapshot does not exist. - %s") % snapshot_id) return web.notfound() if self.__template__["media"] == 'json': self.view.snapshot = json_dumps(( snapshot_id, notebook_title, notebook_value, domname, created_user, created, modified_user, modified, current, parent_name, children_name, )) else: self.view.snapshot = (snapshot_id, notebook_title, notebook_value, domname, created_user, created, modified_user, modified, current, parent_name, children_name, ) return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() model = findbyhost1(self.orm, host_id) uris = available_virt_uris() #import pdb; pdb.set_trace() if model.attribute == MACHINE_ATTRIBUTE["URI"]: uri_guests = [] uri_guests_status = {} uri_guests_kvg = {} uri_guests_info = {} uri_guests_name = {} 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"] # Output .part if self.is_mode_input() is not True: try: self.kvc = KaresansuiVirtConnectionAuth(uri, creds) host = MergeHost(self.kvc, model) for guest in host.guests: _virt = self.kvc.search_kvg_guests( guest.info["model"].name) if 0 < len(_virt): for _v in _virt: uuid = _v.get_info()["uuid"] uri_guests_info[uuid] = guest.info uri_guests_kvg[uuid] = _v uri_guests_name[uuid] = guest.info[ "model"].name.encode("utf8") for name in sorted(uri_guests_name.values(), key=str.lower): for uuid in dict_search(name, uri_guests_name): uri_guests.append( MergeGuest(uri_guests_info[uuid]["model"], uri_guests_kvg[uuid])) uri_guests_status[uuid] = uri_guests_info[uuid][ 'virt'].status() finally: self.kvc.close() # .json if self.is_json() is True: guests_json = [] for x in uri_guests: guests_json.append(x.get_json(self.me.languages)) self.view.uri_guests = json_dumps(guests_json) else: self.view.uri_guests = uri_guests self.view.uri_guests_status = uri_guests_status self.kvc = KaresansuiVirtConnection() try: # libvirt connection scope --> # Storage Pool #inactive_pool = self.kvc.list_inactive_storage_pool() inactive_pool = [] active_pool = self.kvc.list_active_storage_pool() pools = inactive_pool + active_pool pools.sort() if not pools: return web.badrequest('One can not start a storage pool.') # Output .input if self.is_mode_input() is True: self.view.pools = pools pools_info = {} pools_vols_info = {} pools_iscsi_blocks = {} already_vols = [] guests = [] guests += self.kvc.list_inactive_guest() guests += self.kvc.list_active_guest() for guest in guests: already_vol = self.kvc.get_storage_volume_bydomain( domain=guest, image_type=None, attr='path') if already_vol: already_vols += already_vol.keys() for pool in pools: pool_obj = self.kvc.search_kvn_storage_pools(pool)[0] if pool_obj.is_active() is True: pools_info[pool] = pool_obj.get_info() blocks = None if pools_info[pool]['type'] == 'iscsi': blocks = self.kvc.get_storage_volume_iscsi_block_bypool( pool) if blocks: pools_iscsi_blocks[pool] = [] vols_obj = pool_obj.search_kvn_storage_volumes( self.kvc) vols_info = {} for vol_obj in vols_obj: vol_name = vol_obj.get_storage_volume_name() vols_info[vol_name] = vol_obj.get_info() if blocks: if vol_name in blocks and vol_name not in already_vols: pools_iscsi_blocks[pool].append( vol_obj.get_info()) pools_vols_info[pool] = vols_info self.view.pools_info = pools_info self.view.pools_vols_info = pools_vols_info self.view.pools_iscsi_blocks = pools_iscsi_blocks bridge_prefix = { "XEN": "xenbr", "KVM": KVM_BRIDGE_PREFIX, } self.view.host_id = host_id self.view.DEFAULT_KEYMAP = DEFAULT_KEYMAP self.view.DISK_NON_QEMU_FORMAT = DISK_NON_QEMU_FORMAT self.view.DISK_QEMU_FORMAT = DISK_QEMU_FORMAT self.view.hypervisors = {} self.view.mac_address = {} self.view.keymaps = {} self.view.phydev = {} self.view.virnet = {} used_ports = {} for k, v in MACHINE_HYPERVISOR.iteritems(): if k in available_virt_mechs(): self.view.hypervisors[k] = v uri = uris[k] mem_info = self.kvc.get_mem_info() active_networks = self.kvc.list_active_network() used_graphics_ports = self.kvc.list_used_graphics_port( ) bus_types = self.kvc.bus_types self.view.bus_types = bus_types self.view.max_mem = mem_info['host_max_mem'] self.view.free_mem = mem_info['host_free_mem'] self.view.alloc_mem = mem_info['guest_alloc_mem'] self.view.mac_address[k] = generate_mac_address(k) self.view.keymaps[k] = eval( "get_keymaps(%s_KEYMAP_DIR)" % k) # Physical device phydev = [] phydev_regex = re.compile(r"%s" % bridge_prefix[k]) for dev, dev_info in get_ifconfig_info().iteritems(): try: if phydev_regex.match(dev): phydev.append(dev) except: pass if len(phydev) == 0: phydev.append("%s0" % bridge_prefix[k]) phydev.sort() self.view.phydev[k] = phydev # Physical device # Virtual device self.view.virnet[k] = sorted(active_networks) used_ports[k] = used_graphics_ports exclude_ports = [] for k, _used_port in used_ports.iteritems(): exclude_ports = exclude_ports + _used_port exclude_ports = sorted(exclude_ports) exclude_ports = [ p for p, q in zip(exclude_ports, exclude_ports[1:] + [None]) if p != q ] self.view.graphics_port = next_number(GRAPHICS_PORT_MIN_NUMBER, PORT_MAX_NUMBER, exclude_ports) else: # .part models = findbyhost1guestall(self.orm, host_id) guests = [] if models: # Physical Guest Info self.view.hypervisors = {} for model in models: for k, v in MACHINE_HYPERVISOR.iteritems(): if k in available_virt_mechs(): self.view.hypervisors[k] = v uri = uris[k] if hasattr(self, "kvc") is not True: self.kvc = KaresansuiVirtConnection(uri) domname = self.kvc.uuid_to_domname( model.uniq_key) #if not domname: return web.conflict(web.ctx.path) _virt = self.kvc.search_kvg_guests(domname) if 0 < len(_virt): guests.append(MergeGuest(model, _virt[0])) else: guests.append(MergeGuest(model, None)) # Exported Guest Info exports = {} for pool_name in pools: files = [] pool = self.kvc.search_kvn_storage_pools(pool_name) path = pool[0].get_info()["target"]["path"] if os.path.exists(path): for _afile in glob.glob("%s/*/info.dat" % (path, )): param = ExportConfigParam() param.load_xml_config(_afile) _dir = os.path.dirname(_afile) uuid = param.get_uuid() name = param.get_domain() created = param.get_created() title = param.get_title() if title != "": title = re.sub("[\r\n]", "", title) if title == "": title = _('untitled') if created != "": created_str = time.strftime("%Y/%m/%d %H:%M:%S", \ time.localtime(float(created))) else: created_str = _("N/A") files.append({ "dir": _dir, "pool": pool_name, #"b64dir" : base64_encode(_dir), "uuid": uuid, "name": name, "created": int(created), "created_str": created_str, "title": title, "icon": param.get_database()["icon"], }) exports[pool_name] = files # .json if self.is_json() is True: guests_json = [] for x in guests: guests_json.append(x.get_json(self.me.languages)) self.view.guests = json_dumps(guests_json) else: self.view.exports = exports self.view.guests = guests return True except: pass finally: #self.kvc.close() pass # libvirt connection scope --> Guest#_post()
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() kvc = KaresansuiVirtConnection() try: # Storage Pool #inactive_pool = kvc.list_inactive_storage_pool() inactive_pool = [] active_pool = kvc.list_active_storage_pool() pools = inactive_pool + active_pool pools.sort() if self.is_mode_input() is True: # (*.input) if not validates_sid(self): return web.badrequest(self.view.alert) sid = self.input.sid model = findbyguest1(self.orm, sid) if not model: return web.badrequest() domname = kvc.uuid_to_domname(model.uniq_key) src_pools = kvc.get_storage_pool_name_bydomain(domname) if not src_pools: return web.badrequest( _("Source storage pool is not found.")) for src_pool in src_pools: src_pool_type = kvc.get_storage_pool_type(src_pool) if src_pool_type != 'dir': return web.badrequest( _("'%s' disk contains the image.") % src_pool_type) virt = kvc.search_kvg_guests(domname)[0] if virt.is_active() is True: return web.badrequest( _("Guest is running. Please stop and try again. name=%s" % domname)) self.view.domname = virt.get_domain_name() non_iscsi_pool = [] for pool in pools: if kvc.get_storage_pool_type(pool) != 'iscsi': non_iscsi_pool.append(pool) self.view.pools = non_iscsi_pool self.view.sid = sid return True # Exported Guest Info (*.json) exports = {} for pool_name in pools: files = [] pool = kvc.search_kvn_storage_pools(pool_name) path = pool[0].get_info()["target"]["path"] if os.path.exists(path): for _afile in glob.glob("%s/*/info.dat" % (path, )): param = ExportConfigParam() param.load_xml_config(_afile) _dir = os.path.dirname(_afile) uuid = param.get_uuid() name = param.get_domain() created = param.get_created() title = param.get_title() if title != "": title = re.sub("[\r\n]", "", title) if title == "": title = _('untitled') if created != "": created_str = time.strftime("%Y/%m/%d %H:%M:%S", \ time.localtime(float(created))) else: created_str = _("N/A") files.append({ "dir": _dir, "pool": pool_name, #"b64dir" : base64_encode(_dir), "uuid": uuid, "name": name, "created": int(created), "created_str": created_str, "title": title, }) exports[pool_name] = files # .json if self.is_json() is True: self.view.exports = json_dumps(exports) else: self.view.exports = exports return True finally: kvc.close()
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() kvc = KaresansuiVirtConnection() try: # Storage Pool #inactive_pool = kvc.list_inactive_storage_pool() inactive_pool = [] active_pool = kvc.list_active_storage_pool() pools = inactive_pool + active_pool pools.sort() if self.is_mode_input() is True: # (*.input) if not validates_sid(self): return web.badrequest(self.view.alert) sid = self.input.sid model = findbyguest1(self.orm, sid) if not model: return web.badrequest() domname = kvc.uuid_to_domname(model.uniq_key) src_pools = kvc.get_storage_pool_name_bydomain(domname) if not src_pools: return web.badrequest(_("Source storage pool is not found.")) for src_pool in src_pools : src_pool_type = kvc.get_storage_pool_type(src_pool) if src_pool_type != 'dir': return web.badrequest(_("'%s' disk contains the image.") % src_pool_type) virt = kvc.search_kvg_guests(domname)[0] if virt.is_active() is True: return web.badrequest(_("Guest is running. Please stop and try again. name=%s" % domname)) self.view.domname = virt.get_domain_name() non_iscsi_pool = [] for pool in pools: if kvc.get_storage_pool_type(pool) != 'iscsi': non_iscsi_pool.append(pool) self.view.pools = non_iscsi_pool self.view.sid = sid return True # Exported Guest Info (*.json) exports = {} for pool_name in pools: files = [] pool = kvc.search_kvn_storage_pools(pool_name) path = pool[0].get_info()["target"]["path"] if os.path.exists(path): for _afile in glob.glob("%s/*/info.dat" % (path,)): param = ExportConfigParam() param.load_xml_config(_afile) _dir = os.path.dirname(_afile) uuid = param.get_uuid() name = param.get_domain() created = param.get_created() title = param.get_title() if title != "": title = re.sub("[\r\n]","",title) if title == "": title = _('untitled') if created != "": created_str = time.strftime("%Y/%m/%d %H:%M:%S", \ time.localtime(float(created))) else: created_str = _("N/A") files.append({"dir": _dir, "pool" : pool_name, #"b64dir" : base64_encode(_dir), "uuid" : uuid, "name" : name, "created" : int(created), "created_str" : created_str, "title" : title, }) exports[pool_name] = files # .json if self.is_json() is True: self.view.exports = json_dumps(exports) else: self.view.exports = exports return True finally: kvc.close()
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() # valid self.view.uuid = param[1] kvc = KaresansuiVirtConnection() try: # libvirt connection scope --> # Storage Pool #inactive_pool = kvc.list_inactive_storage_pool() inactive_pool = [] active_pool = kvc.list_active_storage_pool() pools = inactive_pool + active_pool pools.sort() export = [] for pool_name in pools: pool = kvc.search_kvn_storage_pools(pool_name) path = pool[0].get_info()["target"]["path"] if os.path.exists(path): for _afile in glob.glob("%s/*/info.dat" % (path,)): e_param = ExportConfigParam() e_param.load_xml_config(_afile) if e_param.get_uuid() != self.view.uuid: continue e_name = e_param.get_domain() _dir = os.path.dirname(_afile) param = ConfigParam(e_name) path = "%s/%s.xml" % (_dir, e_name) if os.path.isfile(path) is False: self.logger.error('Export corrupt data.(file not found) - path=%s' % path) return web.internalerror() param.load_xml_config(path) if e_name != param.get_domain_name(): self.logger.error('Export corrupt data.(The name does not match) - info=%s, xml=%s' \ % (e_name, param.get_name())) return web.internalerror() _dir = os.path.dirname(_afile) title = e_param.get_title() if title != "": title = re.sub("[\r\n]","",title) if title == "": title = _('untitled') created = e_param.get_created() if created != "": created_str = time.strftime("%Y/%m/%d %H:%M:%S", \ time.localtime(float(created))) else: created_str = _("N/A") export.append({"info" : {"dir" : _dir, "pool" : pool_name, "uuid" : e_param.get_uuid(), "name" : e_name, "created" : int(created), "created_str" : created_str, "title" : title, }, "xml" : {"on_reboot" : param.get_behavior('on_reboot'), "on_poweroff" : param.get_behavior('on_poweroff'), "on_crash" : param.get_behavior('on_crash'), "boot_dev" : param.get_boot_dev(), #"bootloader" : param.get_bootloader(), #"commandline" : param.get_commandline(), #"current_snapshot" : param.get_current_snapshot(), 'disk' : param.get_disk(), "domain_name" : param.get_domain_name(), "domain_type" : param.get_domain_type(), "features_acpi" : param.get_features_acpi(), "features_apic" : param.get_features_apic(), "features_pae" : param.get_features_pae(), #"initrd" : param.get_initrd(), "interface" : param.get_interface(), #"kernel" : param.get_kernel(), "max_memory" : param.get_max_memory(), 'max_vcpus' : param.get_max_vcpus(), "max_vcpus_limit" : param.get_max_vcpus_limit(), "memory" : param.get_memory(), "uuid" : param.get_uuid(), "vcpus" : param.get_vcpus(), "vcpus_limit" : param.get_vcpus_limit(), "vnc_autoport" : param.get_vnc_autoport(), "keymap" : param.get_vnc_keymap(), "vnc_listen" : param.get_vnc_listen(), "vnc_passwd" : param.get_vnc_passwd(), "vnc_port" : param.get_vnc_port(), }, "pool" : pool[0].get_info(), }) if len(export) != 1: self.logger.info("Export does not exist. - uuid=%s" % self.view.uuid) return web.badrequest() # .json if self.is_json() is True: self.view.export = json_dumps(export[0]) else: self.view.export = export return True finally: kvc.close()
def _GET(self, *param, **params): self.__template__.dir = "hostby1logby1appby1" self.__template__.file = "hostby1logby1appby1" self.__template__.media = "part" appname = param[1] log_config = None if not validates_log(self): self.logger.debug("Get log failed. Did not validate.") return web.badrequest(self.view.alert) config = LogViewConfigParam(LOG_VIEW_XML_FILE) config.load_xml_config() app = config.findby1application(appname) lines = [] param_value = {} if self.input.has_key("k"): param_value["k"] = self.input.k else: param_value["k"] = "" start_day = str2datetime( self.input.s, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) end_day = str2datetime( self.input.e, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) (start_hour, start_minute) = self.input.st.split(':', 2) (end_hour, end_minute) = self.input.et.split(':', 2) start_time = create_epochsec( start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute), ) end_time = create_epochsec( end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute), ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest( _('Getting reports failed. Start time > end time.')) param_value["start_datetime"] = "%s %s" % ( start_day.strftime("%Y/%m/%d"), self.input.st) param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et) lines = read_all_log(app, int(self.input.m), param_value["start_datetime"], param_value["end_datetime"], param_value["k"]) self.view.log_json = json_dumps(lines) 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
def _GET(self, *param, **params): (host_id, guest_id) = self.chk_guestby1(param) if guest_id is None: return web.notfound() snapshot_id = param[2] if not validates_param_id(self, snapshot_id): return web.notfound(self.view.alert) guest = m_findbyguest1(self.orm, guest_id) if not guest: return web.notfound() kvs = KaresansuiVirtSnapshot(readonly=False) snapshot_list = [] try: domname = kvs.kvc.uuid_to_domname(guest.uniq_key) if not domname: return web.notfound() self.view.is_creatable = kvs.isSupportedDomain(domname) try: snapshot_list = kvs.listNames(domname)[domname] except: pass parent_name = kvs.getParentName(snapshot_id, domain=domname) if parent_name is None: parent_name = _('None') children_names = kvs.getChildrenNames(snapshot_id, domain=domname) if len(children_names) == 0: children_name = _('None') else: children_name = ",".join(children_names) model = s_findbyname_guestby1(self.orm, snapshot_id, guest_id) if model is None: name = snapshot_id notebook_title = "" notebook_value = "" created_user = _("N/A") created = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(snapshot_id))) modified_user = _("N/A") modified = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(snapshot_id))) else: name = model.name notebook_title = model.notebook.title notebook_value = model.notebook.value created_user = model.created_user.nickname created = model.created modified_user = model.modified_user.nickname modified = model.modified current_snapshot = kvs.getCurrentSnapshotName(domname) current = False if snapshot_id == current_snapshot: current = True finally: kvs.finish() if not snapshot_id in snapshot_list: self.logger.error( _("The specified snapshot does not exist. - %s") % snapshot_id) return web.notfound() if self.__template__["media"] == 'json': self.view.snapshot = json_dumps(( snapshot_id, notebook_title, notebook_value, domname, created_user, created, modified_user, modified, current, parent_name, children_name, )) else: self.view.snapshot = ( snapshot_id, notebook_title, notebook_value, domname, created_user, created, modified_user, modified, current, parent_name, children_name, ) return True