コード例 #1
0
ファイル: host.py プロジェクト: elmergonzalezb/dashboard-2
def host_unbind_get():
    host_id = request.args.get('host_id', '').strip()
    if not host_id:
        return jsonify(msg='host_id is blank')

    group_id = request.args.get('group_id', '').strip()
    if not group_id:
        return jsonify(msg='group_id is blank')

    GroupHost.unbind(int(group_id), host_id)
    return jsonify(msg='')
コード例 #2
0
ファイル: host.py プロジェクト: elmergonzalezb/dashboard-2
def host_add_post():
    group_id = request.form['group_id']
    if not group_id:
        return jsonify(msg='no group_id given')

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

    hosts = request.form['hosts'].strip()
    if not hosts:
        return jsonify(msg='hosts is blank')

    host_arr = hosts.splitlines()
    safe_host_arr = [h.strip() for h in host_arr if h]
    if not safe_host_arr:
        return jsonify(msg='hosts is blank')

    success = []
    failure = []

    for h in safe_host_arr:
        msg = GroupHost.bind(group_id, h)
        if not msg:
            success.append('%s<br>' % h)
        else:
            failure.append('%s %s<br>' % (h, msg))

    data = '<div class="alert alert-danger" role="alert">failure:<hr>' + ''.join(
        failure) + '</div><div class="alert alert-success" role="alert">success:<hr>' + ''.join(success) + '</div>'

    return jsonify(msg='', data=data)
コード例 #3
0
ファイル: host.py プロジェクト: elmergonzalezb/dashboard-2
def host_groups_get(host_id):
    host_id = int(host_id)
    h = Host.read('id = %s', params=[host_id])
    if not h:
        return jsonify(msg='no such host')

    group_ids = GroupHost.group_ids(h.id)
    groups = [HostGroup.read('id = %s', [group_id]) for group_id in group_ids]
    return render_template('portal/host/groups.html', groups=groups, host=h)
コード例 #4
0
ファイル: host.py プロジェクト: elmergonzalezb/dashboard-2
def host_templates_get(host_id):
    host_id = int(host_id)

    h = Host.read('id = %s', params=[host_id])
    if not h:
        return jsonify(msg='no such host')

    group_ids = GroupHost.group_ids(h.id)

    templates = GrpTpl.tpl_set(group_ids)
    for v in templates:
        v.parent = Template.get(v.parent_id)
    return render_template('portal/host/templates.html', **locals())
コード例 #5
0
ファイル: api.py プロジェクト: liuzongqing/dashboard
def api_host_variables(hostname):
    host = Host.read(where='hostname = %s', params=[hostname])
    if not host:
        return jsonify(msg='no such host %s' % hostname)

    groups_host = GroupHost.select_vs(where='host_id = %s' % host.id)
    if not groups_host:
        return jsonify(msg='the host %s has no group attribute' % hostname)

    data = []
    for gh in groups_host:
        variables = Variable.select_vs(where='grp_id = %s' % gh.grp_id)
        for v in variables:
            data.append({'key': v.name, 'value': v.content, 'note': v.note})

    return jsonify(msg='ok', data=data)
コード例 #6
0
ファイル: host.py プロジェクト: elmergonzalezb/dashboard-2
def host_remove_post():
    group_id = int(request.form['grp_id'].strip())
    host_ids = request.form['host_ids'].strip()
    GroupHost.unbind(group_id, host_ids)
    return jsonify(msg='')