Ejemplo n.º 1
0
def group_hosts_list(group_id):
    g.xbox = request.args.get('xbox', '')
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    page = int(request.args.get('p', 1))
    limit = int(request.args.get('limit', 10))
    query = request.args.get('q', '')
    maintaining = request.args.get('maintaining', '0')
    vs, total = Host.query(page, limit, query, maintaining, group_id)
    return render_template(
        'portal/host/index.html',
        data={
            'vs': vs,
            'total': total,
            'query': query,
            'limit': limit,
            'page': page,
            'maintaining': maintaining,
            'group': group,
        }
    )
Ejemplo n.º 2
0
def api_group_hosts_json(grp_name):
    group = HostGroup.read(where='id = %s', params=[grp_name])
    if not group:
        group = HostGroup.read(where='grp_name = %s', params=[grp_name])
        if not group:
            return jsonify(msg='no such group %s' % grp_name)

    vs, _ = Host.query(1, 10000000, '', '0', group.id)
    names = [v.hostname for v in vs]
    return jsonify(msg='', data=names)
Ejemplo n.º 3
0
def api_group_hosts_json(grp_name):
    group = HostGroup.read(where='id = %s', params=[grp_name])
    if not group:
        group = HostGroup.read(where='grp_name = %s', params=[grp_name])
        if not group:
            return jsonify(msg='no such group %s' % grp_name)

    vs, _ = Host.query(1, 10000000, '', '0', group.id)
    names = [v.hostname for v in vs]
    return jsonify(msg='', data=names)
Ejemplo n.º 4
0
def group_hosts_export(group_id):
    group_id = int(group_id)

    group = HostGroup.read(where='id = %s', params=[group_id])
    if not group:
        return jsonify(msg='no such group %s' % group_id)

    vs, _ = Host.query(1, 10000000, '', '0', group_id)
    names = [v.hostname for v in vs]
    response = make_response('\n'.join(names))
    response.headers["content-type"] = "text/plain"
    return response
Ejemplo n.º 5
0
def api_host_query():
    q = request.args.get('query', '').strip()
    limit = int(request.args.get('limit', '10'))
    hs, _ = Host.query(1, limit, q, '', 0)
    hs = [h.to_json() for h in hs]
    return jsonify(data=hs)