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, } )
def api_host_get(host_id): host_id = int(host_id) h = Host.get(host_id) if not h: return jsonify(msg='no such host') return jsonify(msg='', data=h.to_json())
def host_maintain_post(): begin = int(request.form['begin'].strip()) end = int(request.form['end'].strip()) host_ids = request.form['host_ids'].strip() if begin <= 0 or end <= 0: return jsonify(msg='begin or end is invalid') return jsonify(msg=Host.maintain(begin, end, host_ids))
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)
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)
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)
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
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())
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)
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)
def host_reset_post(): host_ids = request.form['host_ids'].strip() return jsonify(msg=Host.no_maintain(host_ids))