修改批量执行命令2

pull/26/head
ibuler 2015-11-27 13:24:57 +08:00
parent 66610fb3e7
commit b64ab276fb
2 changed files with 10 additions and 10 deletions

View File

@ -560,7 +560,7 @@ class Nav(object):
if pattern == 'q': if pattern == 'q':
break break
else: else:
res = gen_resource(self.user, {'asset': assets, 'role': role}, perm=self.user_perm) res = gen_resource({'user': self.user, 'asset': assets, 'role': role}, perm=self.user_perm)
cmd = Command(res) cmd = Command(res)
logger.debug("res: %s" % res) logger.debug("res: %s" % res)
for inv in cmd.inventory.get_hosts(pattern=pattern): for inv in cmd.inventory.get_hosts(pattern=pattern):

View File

@ -150,23 +150,23 @@ def user_have_perm(user, asset):
return [] return []
def gen_resource(ob, ex='', perm=None): def gen_resource(ob, perm=None):
""" """
ob为用户或资产列表或资产queryset, 如果同时输入用户和资产则获取用户在这些资产上的信息 ob为用户或资产列表或资产queryset, 如果同时输入用户和{'role': role1, 'asset': []}则获取用户在这些资产上的信息
生成MyInventory需要的 resource文件 生成MyInventory需要的 resource文件
""" """
res = [] res = []
if isinstance(ob, User) and isinstance(ex, dict): if isinstance(ob, dict):
role = ob.get('role')
asset_r = ob.get('asset')
user = ob.get('user')
if not perm: if not perm:
perm = get_group_user_perm(ob) perm = get_group_user_perm(user)
role = ex.get('role')
asset_r = ex.get('asset')
roles = perm.get('role', {}).keys() roles = perm.get('role', {}).keys()
if role not in roles: if role not in roles:
return {} return {}
role_assets_all = perm.get('role').get(ex.get('role')).get('asset') role_assets_all = perm.get('role').get(role).get('asset')
assets = set(role_assets_all) & set(asset_r) assets = set(role_assets_all) & set(asset_r)
for asset in assets: for asset in assets:
@ -176,7 +176,7 @@ def gen_resource(ob, ex='', perm=None):
'port': asset_info.get('port', 22), 'port': asset_info.get('port', 22),
'username': role.name, 'username': role.name,
'password': CRYPTOR.decrypt(role.password), 'password': CRYPTOR.decrypt(role.password),
'ssh_key': get_role_key(ob, role) 'ssh_key': get_role_key(user, role)
} }
res.append(info) res.append(info)