jumpserver/apps/assets/utils.py

30 lines
776 B
Python
Raw Normal View History

2016-08-09 09:27:37 +00:00
# ~*~ coding: utf-8 ~*~
#
2017-12-21 03:31:13 +00:00
from collections import defaultdict
2017-12-10 16:29:25 +00:00
from common.utils import get_object_or_none
from .models import Asset, SystemUser
2016-09-04 09:43:03 +00:00
2017-12-06 10:31:51 +00:00
def get_assets_by_id_list(id_list):
return Asset.objects.filter(id__in=id_list)
2017-12-07 05:01:33 +00:00
def get_assets_by_hostname_list(hostname_list):
return Asset.objects.filter(hostname__in=hostname_list)
2017-12-10 16:29:25 +00:00
def get_system_user_by_name(name):
system_user = get_object_or_none(SystemUser, name=name)
return system_user
2017-12-12 04:19:45 +00:00
2017-12-21 03:31:13 +00:00
def check_assets_have_system_user(assets, system_users):
errors = defaultdict(list)
for system_user in system_users:
clusters = system_user.cluster.all()
for asset in assets:
if asset.cluster not in clusters:
errors[asset].append(system_user)
return errors