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 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)