

@auth
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 = ('%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):
            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()
        elif (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(self)):
                    self.kvc.close()
        elif (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:
        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

dataset/ETHPy150Open karesansui/karesansui/karesansui/gadget/hostby1.py HostBy1._GET/original