Skip to content

Commit

Permalink
Update unit & inventory integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
pszulczewski committed Sep 21, 2023
1 parent 6ad8a79 commit d7847aa
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 491 deletions.
5 changes: 2 additions & 3 deletions plugins/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@
from typing import Iterable
from itertools import chain
from collections import defaultdict
from ipaddress import ip_interface

from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
from ansible.module_utils.ansible_release import __version__ as ansible_version
Expand Down Expand Up @@ -1223,11 +1222,11 @@ def _fill_host_variables(self, host, hostname):

extracted_primary_ip4 = self.extract_primary_ip4(host=host)
if extracted_primary_ip4:
self.inventory.set_variable(hostname, "primary_ip4", extracted_primary_ip4)
self.inventory.set_variable(hostname, "primary_ip4", extracted_primary_ip4["host"])

extracted_primary_ip6 = self.extract_primary_ip6(host=host)
if extracted_primary_ip6:
self.inventory.set_variable(hostname, "primary_ip6", extracted_primary_ip6)
self.inventory.set_variable(hostname, "primary_ip6", extracted_primary_ip6["host"])

location = self.extract_location(host=host)
if location:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
KEYS_REMOVE = frozenset(["created", "id", "last_updated", "rack_id", "url", "notes_url"])

# Ignore these when performing diffs as they will be different for each test run
KEYS_IGNORE = frozenset()
KEYS_IGNORE = frozenset(["natural_slug"])


def all_keys_to_ignore():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand All @@ -62,36 +62,7 @@
"manufacturers": [
"Cisco"
],
"primary_ip4": {
"address": "172.16.180.11/24",
"composite_key": "Global;172.16.180.11",
"custom_fields": {},
"description": "",
"display": "172.16.180.11/24",
"dns_name": "nexus.example.com",
"host": "172.16.180.11",
"interfaces": [
{
"object_type": "dcim.interface"
}
],
"ip_version": 4,
"mask_length": 24,
"nat_inside": null,
"nat_outside_list": [],
"natural_slug": "global_172-16-180-11_8457",
"object_type": "ipam.ipaddress",
"parent": {
"object_type": "ipam.prefix"
},
"role": null,
"status": {
"object_type": "extras.status"
},
"tenant": null,
"type": "host",
"vm_interfaces": []
},
"primary_ip4": "172.16.180.11",
"services": [
{
"composite_key": "telnet;%00;%00;%00;Test+Nexus+One;%00;Child+Test+Location;Parent+Test+Location",
Expand All @@ -118,7 +89,7 @@
"object_type": "dcim.location"
},
"name": "Test Nexus One",
"natural_slug": "test-nexus-one__child-test-location_parent-test-location_f89b",
"natural_slug": "test-nexus-one__child-test-location_parent-test-location_2622",
"object_type": "dcim.device",
"parent_bay": null,
"platform": null,
Expand Down Expand Up @@ -146,7 +117,7 @@
"display": "telnet (TCP/23)",
"ip_addresses": [],
"name": "telnet",
"natural_slug": "telnet____test-nexus-one__child-test-location_parent-test-location_1812",
"natural_slug": "telnet____test-nexus-one__child-test-location_parent-test-location_733a",
"object_type": "ipam.service",
"ports": [
23
Expand All @@ -166,7 +137,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand All @@ -189,7 +160,7 @@
"display": "ssh (TCP/22)",
"ip_addresses": [],
"name": "ssh",
"natural_slug": "ssh_test-cluster-2__test-vm-with-spaces_4cbc",
"natural_slug": "ssh_test-cluster-2__test-vm-with-spaces_e2bd",
"object_type": "ipam.service",
"ports": [
22
Expand All @@ -214,7 +185,7 @@
"local_config_context_schema": null,
"memory": null,
"name": "Test VM With Spaces",
"natural_slug": "test-cluster-2__test-vm-with-spaces_d9f4",
"natural_slug": "test-cluster-2__test-vm-with-spaces_7afe",
"object_type": "virtualization.virtualmachine",
"platform": null,
"primary_ip4": null,
Expand All @@ -235,7 +206,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand Down Expand Up @@ -276,7 +247,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand Down Expand Up @@ -335,7 +306,7 @@
"object_type": "dcim.location"
},
"name": "test100",
"natural_slug": "test100_test-tenant_child-test-location_parent-test-location_03fb",
"natural_slug": "test100_test-tenant_child-test-location_parent-test-location_c10a",
"object_type": "dcim.device",
"parent_bay": null,
"platform": null,
Expand Down Expand Up @@ -377,7 +348,7 @@
"mask_length": 24,
"nat_inside": null,
"nat_outside_list": [],
"natural_slug": "global_172-16-180-1_798b",
"natural_slug": "global_172-16-180-1_54cf",
"object_type": "ipam.ipaddress",
"parent": {
"object_type": "ipam.prefix"
Expand Down Expand Up @@ -407,7 +378,7 @@
"mask_length": 64,
"nat_inside": null,
"nat_outside_list": [],
"natural_slug": "global_2001-1-1_1a06",
"natural_slug": "global_2001-1-1_9768",
"object_type": "ipam.ipaddress",
"parent": {
"object_type": "ipam.prefix"
Expand All @@ -422,7 +393,7 @@
}
],
"name": "http",
"natural_slug": "http____test100_test-tenant_child-test-location_parent-test-location_e2b7",
"natural_slug": "http____test100_test-tenant_child-test-location_parent-test-location_6045",
"object_type": "ipam.service",
"ports": [
80
Expand Down Expand Up @@ -463,7 +434,7 @@
"object_type": "dcim.location"
},
"name": "test100",
"natural_slug": "test100_test-tenant_child-test-location_parent-test-location_03fb",
"natural_slug": "test100_test-tenant_child-test-location_parent-test-location_c10a",
"object_type": "dcim.device",
"parent_bay": null,
"platform": null,
Expand All @@ -489,7 +460,7 @@
"display": "ssh (TCP/22)",
"ip_addresses": [],
"name": "ssh",
"natural_slug": "ssh____test100_test-tenant_child-test-location_parent-test-location_82a9",
"natural_slug": "ssh____test100_test-tenant_child-test-location_parent-test-location_ed27",
"object_type": "ipam.service",
"ports": [
22
Expand All @@ -509,7 +480,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": [],
Expand Down Expand Up @@ -540,7 +511,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand All @@ -567,7 +538,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand All @@ -594,7 +565,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand All @@ -621,7 +592,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand All @@ -643,7 +614,7 @@
"description": "Unit is active",
"display": "Active",
"name": "Active",
"natural_slug": "active_c774",
"natural_slug": "active_aabd",
"object_type": "extras.status"
},
"tags": []
Expand Down
Loading

0 comments on commit d7847aa

Please sign in to comment.