mirror of https://github.com/jumpserver/jumpserver
添加资产权限查询,添加生成resource文件api
parent
dc06426ada
commit
e041a49ad7
|
@ -79,12 +79,13 @@ class MyInventory(object):
|
|||
for host in hosts:
|
||||
# set connection variables
|
||||
hostname = host.get("hostname")
|
||||
hostip = host.get('ip', hostname)
|
||||
hostport = host.get("port")
|
||||
username = host.get("username")
|
||||
password = host.get("password")
|
||||
ssh_key = host.get("ssh_key")
|
||||
my_host = Host(name=hostname, port=hostport)
|
||||
my_host.set_variable('ansible_ssh_host', hostname)
|
||||
my_host.set_variable('ansible_ssh_host', hostip)
|
||||
my_host.set_variable('ansible_ssh_port', hostport)
|
||||
my_host.set_variable('ansible_ssh_user', username)
|
||||
my_host.set_variable('ansible_ssh_pass', password)
|
||||
|
|
|
@ -27,4 +27,4 @@ class PermRule(models.Model):
|
|||
role = models.ManyToManyField(PermRole, related_name='perm_rule')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
return self.name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# coding: utf-8
|
||||
|
||||
|
||||
from django.db.models.query import QuerySet
|
||||
from jumpserver.api import *
|
||||
import uuid
|
||||
import re
|
||||
|
@ -130,6 +130,40 @@ def get_group_asset_perm(ob):
|
|||
return perm
|
||||
|
||||
|
||||
def gen_resource(ob):
|
||||
"""
|
||||
生成MyInventory需要的 resource文件
|
||||
"""
|
||||
res = []
|
||||
if isinstance(ob, User):
|
||||
perm = get_group_user_perm(ob)
|
||||
for asset, asset_info in perm.get('asset').items():
|
||||
info = {'hostname': asset.hostname, 'ip': asset.ip, 'port': asset.port}
|
||||
try:
|
||||
role = sorted(list(asset_info.get('role')))[0]
|
||||
except IndexError:
|
||||
continue
|
||||
info['username'] = role.name
|
||||
info['password'] = role.password
|
||||
info['key_path'] = role.key_path
|
||||
res.append(info)
|
||||
elif isinstance(ob, (list, QuerySet)):
|
||||
default = get_object(Setting, name='default')
|
||||
for asset in ob:
|
||||
info = {'hostname': asset.hostname, 'ip': asset.ip}
|
||||
if asset.use_default_auth:
|
||||
if default:
|
||||
info['port'] = default.default_port
|
||||
info['username'] = default.default_user
|
||||
info['password'] = default.default_password
|
||||
info['ssh_key'] = default.default_pri_key_path
|
||||
else:
|
||||
info['port'] = asset.port
|
||||
info['username'] = asset.username
|
||||
res.append(info)
|
||||
return res
|
||||
|
||||
|
||||
def get_object_list(model, id_list):
|
||||
"""根据id列表获取对象列表"""
|
||||
object_list = []
|
||||
|
|
Loading…
Reference in New Issue