Browse Source

fix: 资产不存在指定用户的时候,没有用特权用户任务未执行

pull/13050/head
wangruidong 7 months ago committed by Bryan
parent
commit
e8d717d174
  1. 9
      apps/ops/ansible/inventory.py
  2. 3
      apps/ops/models/job.py

9
apps/ops/ansible/inventory.py

@ -214,13 +214,18 @@ class JMSInventory:
)
return host
def get_asset_sorted_accounts(self, asset):
accounts = list(asset.accounts.filter(is_active=True))
@staticmethod
def sorted_accounts(accounts):
connectivity_score = {'ok': 2, '-': 1, 'err': 0}
sort_key = lambda x: (x.privileged, connectivity_score.get(x.connectivity, 0), x.date_updated)
accounts_sorted = sorted(accounts, key=sort_key, reverse=True)
return accounts_sorted
def get_asset_sorted_accounts(self, asset):
accounts = list(asset.accounts.filter(is_active=True))
accounts_sorted = self.sorted_accounts(accounts)
return accounts_sorted
@staticmethod
def get_account_prefer(account_prefer):
account_usernames = []

3
apps/ops/models/job.py

@ -94,7 +94,8 @@ class JMSPermedInventory(JMSInventory):
def get_asset_sorted_accounts(self, asset):
accounts = self.assets_accounts_mapper.get(asset.id, [])
return list(accounts)
accounts_sorted = self.sorted_accounts(accounts)
return list(accounts_sorted)
def get_assets_accounts_mapper(self):
mapper = defaultdict(set)

Loading…
Cancel
Save