コード例 #1
0
ファイル: host.py プロジェクト: zhaozlgit/JimV-C
def r_get(nodes_id):

    args_rules = [Rules.IDS.value]

    try:
        ji.Check.previewing(args_rules, {args_rules[0][1]: nodes_id})

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)
        ret['data'] = list()

        if -1 == nodes_id.find(','):
            node_id = nodes_id
            if db.r.hexists(app.config['hosts_info'], node_id):
                v = json.loads(db.r.hget(app.config['hosts_info'], node_id))
                v = Host.alive_check(v)
                v['node_id'] = node_id
                ret['data'] = v

        else:
            for node_id in nodes_id.split(','):
                if db.r.hexists(app.config['hosts_info'], node_id):
                    v = json.loads(db.r.hget(app.config['hosts_info'],
                                             node_id))
                    v = Host.alive_check(v)
                    v['node_id'] = node_id
                    ret['data'].append(v)

            if ret['data'].__len__() > 1:
                ret['data'].sort(key=lambda _k: _k['boot_time'])

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #2
0
ファイル: host.py プロジェクト: showsmall/JimV-C
def r_content_search():
    keyword = request.args.get('keyword', '')

    args_rules = [Rules.KEYWORD.value]

    try:
        ji.Check.previewing(args_rules, {'keyword': keyword})

        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)
        ret['data'] = list()

        for k, v in db.r.hgetall(app.config['hosts_info']).items():
            v = json.loads(v)
            if -1 != v['hostname'].find(keyword):
                v = Host.alive_check(v)
                v['node_id'] = k
                ret['data'].append(v)

        if ret['data'].__len__() > 1:
            ret['data'].sort(key=lambda _k: _k['boot_time'])

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #3
0
ファイル: host.py プロジェクト: showsmall/JimV-C
def r_get_by_filter():

    try:
        ret = dict()
        ret['state'] = ji.Common.exchange_state(20000)
        ret['data'] = list()
        for k, v in db.r.hgetall(app.config['hosts_info']).items():
            v = json.loads(v)
            v = Host.alive_check(v)
            v['node_id'] = k
            ret['data'].append(v)

        if ret['data'].__len__() > 1:
            ret['data'].sort(key=lambda _k: _k['boot_time'])

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
コード例 #4
0
    def get_available_hosts():

        from models import Host

        hosts = list()

        for k, v in db.r.hgetall(app.config['hosts_info']).items():
            v = json.loads(v)

            v = Host.alive_check(v)

            if not v['alive']:
                continue

            v['system_load_per_cpu'] = float(v['system_load'][0]) / v['cpu']
            hosts.append(v)

        hosts.sort(key=lambda _k: _k['system_load_per_cpu'])

        return hosts