Fix archived machine bu (#43017)

pull/27117/merge
Rémy Léone 6 years ago committed by ansibot
parent 06f5e49dfb
commit 267c7667f6

@ -102,15 +102,24 @@ def extract_public_ipv4(server_info):
def extract_private_ipv4(server_info): def extract_private_ipv4(server_info):
try:
return server_info["private_ip"] return server_info["private_ip"]
except (KeyError, TypeError):
return None
def extract_hostname(server_info): def extract_hostname(server_info):
try:
return server_info["hostname"] return server_info["hostname"]
except (KeyError, TypeError):
return None
def extract_server_id(server_info): def extract_server_id(server_info):
try:
return server_info["id"] return server_info["id"]
except (KeyError, TypeError):
return None
def extract_public_ipv6(server_info): def extract_public_ipv6(server_info):
@ -120,6 +129,19 @@ def extract_public_ipv6(server_info):
return None return None
def extract_tags(server_info):
try:
return server_info["tags"]
except (KeyError, TypeError):
return None
def extract_zone(server_info):
try:
return server_info["location"]["zone_id"]
except (KeyError, TypeError):
return None
extractors = { extractors = {
"public_ipv4": extract_public_ipv4, "public_ipv4": extract_public_ipv4,
"private_ipv4": extract_private_ipv4, "private_ipv4": extract_private_ipv4,
@ -161,8 +183,12 @@ class InventoryModule(BaseInventoryPlugin):
return set(SCALEWAY_LOCATION.keys()).intersection(config_zones) return set(SCALEWAY_LOCATION.keys()).intersection(config_zones)
def match_groups(self, server_info, tags): def match_groups(self, server_info, tags):
server_zone = server_info["location"]["zone_id"] server_zone = extract_zone(server_info=server_info)
server_tags = server_info["tags"] server_tags = extract_tags(server_info=server_info)
# If a server does not have a zone, it means it is archived
if server_zone is None:
return set()
# If no filtering is defined, all tags are valid groups # If no filtering is defined, all tags are valid groups
if tags is None: if tags is None:

Loading…
Cancel
Save