mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Reformat everything.
This commit is contained in:
@@ -73,7 +73,7 @@ from ansible_collections.community.general.plugins.plugin_utils.unsafe import ma
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin):
|
||||
NAME = 'community.general.online'
|
||||
NAME = "community.general.online"
|
||||
API_ENDPOINT = "https://api.online.net"
|
||||
|
||||
def extract_public_ipv4(self, host_infos):
|
||||
@@ -140,7 +140,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||
return None
|
||||
|
||||
try:
|
||||
raw_data = to_text(response.read(), errors='surrogate_or_strict')
|
||||
raw_data = to_text(response.read(), errors="surrogate_or_strict")
|
||||
except UnicodeError:
|
||||
raise AnsibleError("Incorrect encoding of fetched payload from Online servers")
|
||||
|
||||
@@ -168,26 +168,33 @@ class InventoryModule(BaseInventoryPlugin):
|
||||
"last_reboot",
|
||||
"anti_ddos",
|
||||
"hardware_watch",
|
||||
"support"
|
||||
"support",
|
||||
)
|
||||
for attribute in targeted_attributes:
|
||||
self.inventory.set_variable(hostname, attribute, make_unsafe(host_infos[attribute]))
|
||||
|
||||
if self.extract_public_ipv4(host_infos=host_infos):
|
||||
self.inventory.set_variable(hostname, "public_ipv4", make_unsafe(self.extract_public_ipv4(host_infos=host_infos)))
|
||||
self.inventory.set_variable(hostname, "ansible_host", make_unsafe(self.extract_public_ipv4(host_infos=host_infos)))
|
||||
self.inventory.set_variable(
|
||||
hostname, "public_ipv4", make_unsafe(self.extract_public_ipv4(host_infos=host_infos))
|
||||
)
|
||||
self.inventory.set_variable(
|
||||
hostname, "ansible_host", make_unsafe(self.extract_public_ipv4(host_infos=host_infos))
|
||||
)
|
||||
|
||||
if self.extract_private_ipv4(host_infos=host_infos):
|
||||
self.inventory.set_variable(hostname, "public_ipv4", make_unsafe(self.extract_private_ipv4(host_infos=host_infos)))
|
||||
self.inventory.set_variable(
|
||||
hostname, "public_ipv4", make_unsafe(self.extract_private_ipv4(host_infos=host_infos))
|
||||
)
|
||||
|
||||
if self.extract_os_name(host_infos=host_infos):
|
||||
self.inventory.set_variable(hostname, "os_name", make_unsafe(self.extract_os_name(host_infos=host_infos)))
|
||||
|
||||
if self.extract_os_version(host_infos=host_infos):
|
||||
self.inventory.set_variable(hostname, "os_version", make_unsafe(self.extract_os_name(host_infos=host_infos)))
|
||||
self.inventory.set_variable(
|
||||
hostname, "os_version", make_unsafe(self.extract_os_name(host_infos=host_infos))
|
||||
)
|
||||
|
||||
def _filter_host(self, host_infos, hostname_preferences):
|
||||
|
||||
for pref in hostname_preferences:
|
||||
if self.extractors[pref](host_infos):
|
||||
return self.extractors[pref](host_infos)
|
||||
@@ -195,9 +202,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||
return None
|
||||
|
||||
def do_server_inventory(self, host_infos, hostname_preferences, group_preferences):
|
||||
|
||||
hostname = self._filter_host(host_infos=host_infos,
|
||||
hostname_preferences=hostname_preferences)
|
||||
hostname = self._filter_host(host_infos=host_infos, hostname_preferences=hostname_preferences)
|
||||
|
||||
# No suitable hostname were found in the attributes and the host won't be in the inventory
|
||||
if not hostname:
|
||||
@@ -239,13 +244,13 @@ class InventoryModule(BaseInventoryPlugin):
|
||||
self.group_extractors = {
|
||||
"location": self.extract_location,
|
||||
"offer": self.extract_offer,
|
||||
"rpn": self.extract_rpn
|
||||
"rpn": self.extract_rpn,
|
||||
}
|
||||
|
||||
self.headers = {
|
||||
'Authorization': f"Bearer {token}",
|
||||
'User-Agent': f"ansible {ansible_version} Python {python_version.split(' ', 1)[0]}",
|
||||
'Content-type': 'application/json'
|
||||
"Authorization": f"Bearer {token}",
|
||||
"User-Agent": f"ansible {ansible_version} Python {python_version.split(' ', 1)[0]}",
|
||||
"Content-type": "application/json",
|
||||
}
|
||||
|
||||
servers_url = urljoin(InventoryModule.API_ENDPOINT, "api/v1/server")
|
||||
@@ -257,13 +262,14 @@ class InventoryModule(BaseInventoryPlugin):
|
||||
self.rpn_lookup_cache = self.extract_rpn_lookup_cache(rpn_list)
|
||||
|
||||
for server_api_path in servers_api_path:
|
||||
|
||||
server_url = urljoin(InventoryModule.API_ENDPOINT, server_api_path)
|
||||
raw_server_info = self._fetch_information(url=server_url)
|
||||
|
||||
if raw_server_info is None:
|
||||
continue
|
||||
|
||||
self.do_server_inventory(host_infos=raw_server_info,
|
||||
hostname_preferences=hostname_preferences,
|
||||
group_preferences=group_preferences)
|
||||
self.do_server_inventory(
|
||||
host_infos=raw_server_info,
|
||||
hostname_preferences=hostname_preferences,
|
||||
group_preferences=group_preferences,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user