Commit 17e89bb5 authored by ibuler's avatar ibuler

޸һbug

parent d5fba23d
...@@ -188,8 +188,12 @@ def get_user_hostgroup_host(username, gid): ...@@ -188,8 +188,12 @@ def get_user_hostgroup_host(username, gid):
def verify_connect(username, part_ip): def verify_connect(username, part_ip):
ip_matched = [] ip_matched = []
try:
hosts_attr = get_user_host(username) hosts_attr = get_user_host(username)
hosts = hosts_attr.values() hosts = hosts_attr.values()
except ServerError, e:
color_print(e, 'red')
return False
for ip_info in hosts: for ip_info in hosts:
for info in ip_info[1:]: for info in ip_info[1:]:
if part_ip in info: if part_ip in info:
...@@ -217,7 +221,11 @@ def print_prompt(): ...@@ -217,7 +221,11 @@ def print_prompt():
def print_user_host(username): def print_user_host(username):
try:
hosts_attr = get_user_host(username) hosts_attr = get_user_host(username)
except ServerError, e:
color_print(e, 'red')
return
hosts = hosts_attr.keys() hosts = hosts_attr.keys()
hosts.sort() hosts.sort()
for ip in hosts: for ip in hosts:
...@@ -267,7 +275,6 @@ def connect(username, password, host, port, login_name): ...@@ -267,7 +275,6 @@ def connect(username, password, host, port, login_name):
global channel global channel
win_size = get_win_size() win_size = get_win_size()
channel = ssh.invoke_shell(height=win_size[0], width=win_size[1]) channel = ssh.invoke_shell(height=win_size[0], width=win_size[1])
#channel.resize_pty(height=win_size[0], width=win_size[1])
try: try:
signal.signal(signal.SIGWINCH, set_win_size) signal.signal(signal.SIGWINCH, set_win_size)
except: except:
......
...@@ -349,7 +349,9 @@ def get_user_host(username): ...@@ -349,7 +349,9 @@ def get_user_host(username):
"""Get the hosts of under the user control.""" """Get the hosts of under the user control."""
hosts_attr = {} hosts_attr = {}
asset_all = user_perm_asset_api(username) asset_all = user_perm_asset_api(username)
user = User.objects.get(username=username) user = User.objects.filter(username=username)
if user:
user = user[0]
for asset in asset_all: for asset in asset_all:
alias = AssetAlias.objects.filter(user=user, host=asset) alias = AssetAlias.objects.filter(user=user, host=asset)
if alias and alias[0].alias != '': if alias and alias[0].alias != '':
...@@ -357,6 +359,8 @@ def get_user_host(username): ...@@ -357,6 +359,8 @@ def get_user_host(username):
else: else:
hosts_attr[asset.ip] = [asset.id, asset.ip, asset.comment] hosts_attr[asset.ip] = [asset.id, asset.ip, asset.comment]
return hosts_attr return hosts_attr
else:
raise ServerError('User %s does not exit!' % username)
def get_connect_item(username, ip): def get_connect_item(username, ip):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment