Example #1
0
def r_get_by_filter():

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

        alive = None

        if 'alive' in request.args:
            alive = request.args['alive']

            if str(alive).lower() in ['false', '0']:
                alive = False

            else:
                alive = True

        for host in Host.get_all():
            if alive is not None and alive is not host['alive']:
                continue

            ret['data'].append(host)

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
Example #2
0
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 host in Host.get_all():
            if -1 != host['hostname'].find(keyword):
                ret['data'].append(host)

        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)
Example #3
0
def r_nonrandom(hosts_name, random):

    args_rules = [Rules.HOSTS_NAME.value]

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

        if str(random).lower() in ['false', '0']:
            random = False

        else:
            random = True

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

        Host.set_allocation_mode(hosts_name=hosts_name.split(','),
                                 random=random)

        ret['data'] = Host.get_all()
        return ret

    except ji.PreviewingError, e:
        return json.loads(e.message)