Example #1
0
def GetAssetInfo(tgt):
    '''
    Salt API获取主机信息并进行格式化输出
    '''
    info = {}
    sapi = SaltAPI(url=settings.SALT_API['url'],
                   username=settings.SALT_API['user'],
                   password=settings.SALT_API['password'])
    ret = sapi.remote_server_info(tgt, 'grains.items')
    info['sn'] = GetInfo(ret, 'serialnumber')
    info['hostname'] = GetInfo(ret, 'fqdn')
    info['nodename'] = tgt
    info['os'] = GetInfo(ret, 'os') + GetInfo(
        ret, 'osrelease') + ' ' + GetInfo(ret, 'osarch')
    info['manufacturer'] = GetInfo(ret, 'manufacturer')
    info['cpu_model'] = GetInfo(ret, 'cpu_model')
    info['productname'] = GetInfo(ret, 'productname')
    info['cpu_nums'] = GetInfo(ret, 'num_cpus')
    info['disk'] = str(DISKINFO[0]) + "GB"
    info['network'] = GetInfo(ret, 'PublicIp')
    info['kernel'] = GetInfo(ret, 'kernel') + GetInfo(ret, 'kernelrelease')
    info['zmqversion'] = GetInfo(ret, 'zmqversion')
    info['shell'] = GetInfo(ret, 'shell')
    info['saltversion'] = GetInfo(ret, 'saltversion')
    info['locale'] = GetInfoDict(ret, 'locale_info')
    info['selinux'] = GetInfoDict(ret, 'selinux')
    info['networkarea'] = GetInfo(ret, 'netRegion')

    if 'virtual_subtype' in ret:
        virtual = GetInfo(ret, 'virtual') + '-' + GetInfo(
            ret, 'virtual_subtype')
    else:
        virtual = GetInfo(ret, 'virtual')
    info['virtual'] = virtual

    mem = GetInfo(ret, 'mem_total')
    if mem > 1000:
        mem = int(mem) / 1000.0
        memory = ('%.1f' % mem) + 'G'
    else:
        memory = str(mem) + 'M'
    info['memory'] = memory

    return info
Example #2
0
def GetAssetInfo(tgt):
    '''
    Salt API获取主机信息并进行格式化输出
    '''
    global asset_info
    info = {}
    sapi = SaltAPI()
    ret = sapi.remote_server_info(tgt, 'grains.items')
    info['sn'] = GetInfo(ret, 'serialnumber')
    info['hostname'] = GetInfo(ret, 'fqdn')
    info['nodename'] = tgt
    info['os'] = GetInfo(ret, 'os') + GetInfo(
        ret, 'osrelease') + ' ' + GetInfo(ret, 'osarch')
    info['manufacturer'] = GetInfo(ret, 'manufacturer')
    info['cpu_model'] = GetInfo(ret, 'cpu_model')
    info['productname'] = GetInfo(ret, 'productname')
    info['cpu_nums'] = GetInfo(ret, 'num_cpus')
    info['kernel'] = GetInfo(ret, 'kernel') + GetInfo(ret, 'kernelrelease')
    info['zmqversion'] = GetInfo(ret, 'zmqversion')
    info['shell'] = GetInfo(ret, 'shell')
    info['saltversion'] = GetInfo(ret, 'saltversion')
    info['locale'] = GetInfoDict(ret, 'locale_info')
    info['selinux'] = GetInfoDict(ret, 'selinux')

    if 'virtual_subtype' in ret:
        virtual = GetInfo(ret, 'virtual') + '-' + GetInfo(
            ret, 'virtual_subtype')
    else:
        virtual = GetInfo(ret, 'virtual')
    info['virtual'] = virtual

    try:
        hwaddr = ret['hwaddr_interfaces']
        ipaddr = ret['ip4_interfaces']
        hwaddr.pop('lo')
        ipaddr.pop('lo')
        network = ''
        for i in ipaddr:
            ip = ''
            for j in ipaddr[i]:
                ip = ip + j + '/'
            network = network + i + ': ' + ip.strip(
                '/') + '-' + hwaddr[i] + '\n'
        info['network'] = network
    except:
        info['network'] = 'Nan'

    mem = GetInfo(ret, 'mem_total')
    if mem > 1000:
        mem = int(mem) / 1000.0
        memory = ('%.1f' % mem) + 'G'
    else:
        memory = str(mem) + 'M'
    info['memory'] = memory

    ret = sapi.remote_server_info(tgt, 'disk.usage')
    disk = ''
    for i in ret:
        r = int(ret[i]['1K-blocks']) / 1000
        if r > 1000:
            r = r / 1000
            s = str(r) + 'G'
            if r > 1000:
                r = r / 1000.0
                s = ('%.1f' % r) + 'T'
        else:
            s = str(r) + 'M'
        disk = disk + i + ': ' + s + '\n'
    info['disk'] = disk

    asset_info.append(info)
Example #3
0
def GetAssetInfo(tgt):
    '''
    Salt API获取主机信息并进行格式化输出
    '''
    global asset_info
    info = {}
    sapi = SaltAPI(url=settings.SALT_API['url'],
                   username=settings.SALT_API['user'],
                   password=settings.SALT_API['password'])
    ret = sapi.remote_server_info(tgt, 'grains.items')
    info['sn'] = GetInfo(ret, 'serialnumber')
    info['hostname'] = GetInfo(ret, 'fqdn')
    info['nodename'] = tgt
    info['os'] = GetInfo(ret, 'os') + GetInfo(
        ret, 'osrelease') + ' ' + GetInfo(ret, 'osarch')
    info['manufacturer'] = GetInfo(ret, 'manufacturer')
    info['cpu_model'] = GetInfo(ret, 'cpu_model')
    info['productname'] = GetInfo(ret, 'productname')
    info['cpu_nums'] = GetInfo(ret, 'num_cpus')
    info['disk'] = str(DISKINFO[0]) + "GB"
    info['network'] = GetInfo(ret, 'PublicIp')
    info['kernel'] = GetInfo(ret, 'kernel') + GetInfo(ret, 'kernelrelease')
    info['zmqversion'] = GetInfo(ret, 'zmqversion')
    info['shell'] = GetInfo(ret, 'shell')
    info['saltversion'] = GetInfo(ret, 'saltversion')
    info['locale'] = GetInfoDict(ret, 'locale_info')
    info['selinux'] = GetInfoDict(ret, 'selinux')
    info['networkarea'] = GetInfo(ret, 'netRegion')

    if 'virtual_subtype' in ret:
        virtual = GetInfo(ret, 'virtual') + '-' + GetInfo(
            ret, 'virtual_subtype')
    else:
        virtual = GetInfo(ret, 'virtual')
    info['virtual'] = virtual

    #    try:
    #        hwaddr = ret['hwaddr_interfaces']
    #        ipaddr = ret['ip4_interfaces']
    #        hwaddr.pop('lo')
    #        ipaddr.pop('lo')
    #        network = ''
    #        for i in ipaddr:
    #            ip = ''
    #            for j in ipaddr[i]:
    #                ip = ip + j + '/'
    #            network = network + i + ': ' + ip.strip('/') + '-' + hwaddr[i] + '\n'
    #        info['network'] =  network
    #    except:
    #        info['network'] = 'Nan'
    #
    mem = GetInfo(ret, 'mem_total')
    if mem > 1000:
        mem = int(mem) / 1000.0
        memory = ('%.1f' % mem) + 'G'
    else:
        memory = str(mem) + 'M'
    info['memory'] = memory

    #    ret = sapi.remote_server_info(tgt, 'disk.usage')
    #    disk = ''
    #    for i in ret:
    #        r = int(ret[i]['1K-blocks'])/1000
    #        if r > 1000:
    #            r = r/1000
    #            s = str(r) + 'G'
    #            if r > 1000:
    #                r = r/1000.0
    #                s = ('%.1f'%r) + 'T'
    #        else:
    #            s = str(r) + 'M'
    #        disk = disk + i + ': ' + s + '\n'
    #    info['disk'] = disk

    asset_info.append(info)
Example #4
0
def GetAssetInfo(tgt):
    '''
    Salt API获取主机信息并进行格式化输出
    '''
    global asset_info
    info = {}
    sapi = SaltAPI(url=settings.SALT_API['url'],username=settings.SALT_API['user'],password=settings.SALT_API['password'])
    ret = sapi.remote_server_info(tgt, 'grains.items')
    info['sn']=GetInfo(ret,'serialnumber')
    info['hostname']=GetInfo(ret,'fqdn')
    info['nodename']=tgt
    info['os']=GetInfo(ret,'os')+GetInfo(ret,'osrelease')+' '+GetInfo(ret,'osarch')
    info['manufacturer']=GetInfo(ret,'manufacturer')
    info['cpu_model']=GetInfo(ret,'cpu_model')
    info['productname']=GetInfo(ret,'productname')
    info['cpu_nums']=GetInfo(ret,'num_cpus')
    info['kernel'] = GetInfo(ret,'kernel') + GetInfo(ret,'kernelrelease')
    info['zmqversion'] = GetInfo(ret,'zmqversion')
    info['shell'] = GetInfo(ret,'shell')
    info['saltversion'] = GetInfo(ret,'saltversion')
    info['locale'] = GetInfoDict(ret, 'locale_info')
    info['selinux'] = GetInfoDict(ret, 'selinux')

    if 'virtual_subtype' in ret:
        virtual = GetInfo(ret,'virtual') + '-' + GetInfo(ret,'virtual_subtype')
    else:
        virtual=GetInfo(ret,'virtual')
    info['virtual'] = virtual

    try:
        hwaddr = ret['hwaddr_interfaces']
        ipaddr = ret['ip4_interfaces']
        hwaddr.pop('lo')
        ipaddr.pop('lo')
        network = ''
        for i in ipaddr:
            ip = ''
            for j in ipaddr[i]:
                ip = ip + j + '/'
            network = network + i + ': ' + ip.strip('/') + '-' + hwaddr[i] + '\n'
        info['network'] =  network
    except:
        info['network'] = 'Nan'

    mem=GetInfo(ret,'mem_total')
    if mem > 1000:
        mem = int(mem)/1000.0
        memory = ('%.1f'%mem) + 'G'
    else:
        memory = str(mem) + 'M'
    info['memory'] = memory

    ret = sapi.remote_server_info(tgt, 'disk.usage')
    disk = ''
    for i in ret:
        r = int(ret[i]['1K-blocks'])/1000
        if r > 1000:
            r = r/1000
            s = str(r) + 'G'
            if r > 1000:
                r = r/1000.0
                s = ('%.1f'%r) + 'T'
        else:
            s = str(r) + 'M'
        disk = disk + i + ': ' + s + '\n'
    info['disk'] = disk

    asset_info.append(info)