2022-10-17 03:22:21 +00:00
|
|
|
from common.utils import get_logger
|
2022-10-25 10:43:34 +00:00
|
|
|
from assets.const import AutomationTypes
|
2022-10-12 10:08:57 +00:00
|
|
|
from ..base.manager import BasePlaybookManager
|
|
|
|
|
2022-10-17 03:22:21 +00:00
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
2022-10-12 10:08:57 +00:00
|
|
|
|
|
|
|
class GatherFactsManager(BasePlaybookManager):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2022-10-14 10:59:28 +00:00
|
|
|
self.host_asset_mapper = {}
|
2022-10-12 10:08:57 +00:00
|
|
|
|
2022-10-14 10:59:28 +00:00
|
|
|
@classmethod
|
|
|
|
def method_type(cls):
|
2022-10-25 10:43:34 +00:00
|
|
|
return AutomationTypes.gather_facts
|
2022-10-12 10:08:57 +00:00
|
|
|
|
2022-10-14 10:59:28 +00:00
|
|
|
def host_callback(self, host, asset=None, **kwargs):
|
|
|
|
super().host_callback(host, asset=asset, **kwargs)
|
|
|
|
self.host_asset_mapper[host['name']] = asset
|
2022-10-17 03:22:21 +00:00
|
|
|
return host
|
2022-10-12 10:08:57 +00:00
|
|
|
|
2022-10-14 10:59:28 +00:00
|
|
|
def on_host_success(self, host, result):
|
2022-10-25 10:43:34 +00:00
|
|
|
info = result.get('debug', {}).get('res', {}).get('info', {})
|
2022-10-17 03:22:21 +00:00
|
|
|
asset = self.host_asset_mapper.get(host)
|
|
|
|
if asset and info:
|
|
|
|
asset.info = info
|
|
|
|
asset.save()
|
|
|
|
else:
|
2022-10-28 10:28:41 +00:00
|
|
|
logger.error("Not found info: {}".format(host))
|