Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix & new feature #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion web/controller/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from web.service import group_service
from frame.config import UIC_ADDRESS

@app.route('/group/list')
def group_list_get():
groups = HostGroup.all_groups_dict()
return jsonify(msg='',data=groups)

@app.route('/group/create', methods=['POST'])
def group_create_post():
Expand Down Expand Up @@ -91,4 +95,4 @@ def group_bind_template_get():
return jsonify(msg="grp id is blank")

GrpTpl.bind(grp_id, tpl_id, g.user_name)
return jsonify(msg='')
return jsonify(msg='')
12 changes: 9 additions & 3 deletions web/controller/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def group_hosts_list(group_id):
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)
hostid_arr = host_ids.splitlines()
for hid in hostid_arr:
GroupHost.unbind(group_id, int(hid))
return jsonify(msg='')


Expand Down Expand Up @@ -116,7 +118,6 @@ def host_add_post():
failure = []

for h in safe_host_arr:
h = h.strip()
msg = GroupHost.bind(group_id, h)
if not msg:
success.append('%s<br>' % h)
Expand Down Expand Up @@ -169,4 +170,9 @@ def host_unbind_get():
return jsonify(msg='group_id is blank')

GroupHost.unbind(int(group_id), host_id)
return jsonify(msg='')
return jsonify(msg='')

@app.route('/host/list')
def host_list_get():
hosts=Host.all_host_dict()
return jsonify(msg='', data=hosts)
7 changes: 6 additions & 1 deletion web/model/host_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def all_group_dict(cls):
rows = db.query_all('select id, grp_name from grp where come_from = 0')
return [{'id': row[0], 'name': row[1]} for row in rows]

@classmethod
def all_groups_dict(cls):
rows = db.query_all('select id, grp_name, create_user from grp')
return [{'id': row[0], 'name': row[1], 'create_user': row[2]} for row in rows]

@classmethod
def all_set(cls):
sql = 'select id, grp_name from %s' % cls._tbl
Expand All @@ -63,4 +68,4 @@ def all_set(cls):
name = row[1]
name_set[name] = set(name.split('_'))
name_id[name] = row[0]
return name_set, name_id
return name_set, name_id