fix asset group judge

reviewed by: ibuler <ibuler@qq.com>
pull/194/head
ibuler 2016-04-05 11:22:31 +08:00
commit f511802db5
1 changed files with 7 additions and 4 deletions

View File

@ -470,7 +470,7 @@ class Nav(object):
gid = int(str_r.lstrip('g')) gid = int(str_r.lstrip('g'))
# 获取资产组包含的资产 # 获取资产组包含的资产
asset_group = get_object(AssetGroup, id=gid) asset_group = get_object(AssetGroup, id=gid)
if asset_group: if asset_group and asset_group in self.perm_asset_groups:
self.search_result = list(asset_group.asset_set.all()) self.search_result = list(asset_group.asset_set.all())
else: else:
color_print('没有该资产组或没有权限') color_print('没有该资产组或没有权限')
@ -489,8 +489,10 @@ class Nav(object):
except (ValueError, TypeError): except (ValueError, TypeError):
# 匹配 ip, hostname, 备注 # 匹配 ip, hostname, 备注
self.search_result = [asset for asset in self.perm_assets if str_r in str(asset.ip) str_r = str_r.lower()
or str_r in str(asset.hostname) or str_r in str(asset.comment)] self.search_result = [asset for asset in self.perm_assets if str_r in str(asset.ip).lower()
or str_r in str(asset.hostname).lower()
or str_r in str(asset.comment).lower()]
else: else:
# 如果没有输入就展现所有 # 如果没有输入就展现所有
self.search_result = self.perm_assets self.search_result = self.perm_assets
@ -532,8 +534,8 @@ class Nav(object):
color_print('没有映射用户', 'red') color_print('没有映射用户', 'red')
return return
ssh_tty = SshTty(login_user, asset, role)
print('Connecting %s ...' % asset.hostname) print('Connecting %s ...' % asset.hostname)
ssh_tty = SshTty(login_user, asset, role)
ssh_tty.connect() ssh_tty.connect()
except (KeyError, ValueError): except (KeyError, ValueError):
color_print('请输入正确ID', 'red') color_print('请输入正确ID', 'red')
@ -781,6 +783,7 @@ def main():
else: else:
nav.search(option) nav.search(option)
if len(nav.search_result) == 1: if len(nav.search_result) == 1:
print('Only match Host: %s ' % nav.search_result[0].hostname)
nav.try_connect() nav.try_connect()
else: else:
nav.print_search_result() nav.print_search_result()