From e062ce505c14863b107413ab42fece829d7325f9 Mon Sep 17 00:00:00 2001 From: F-PMOR <52208042+F-PMOR@users.noreply.github.com> Date: Tue, 27 Jun 2023 16:08:08 +0200 Subject: [PATCH] Feat add possibility to use Bearer token (#1023) * Add possibility to use Bearer token type Co-authored-by: Philippe Morry Co-authored-by: Sean M. Collins --- plugins/inventory/nb_inventory.py | 37 +- .../files/test-inventory-bearer-token.json | 1248 ++++++++++++++++ .../files/test-inventory-bearer-token.yml | 32 + .../files/test-inventory-bearer-token.json | 1284 +++++++++++++++++ .../files/test-inventory-bearer-token.yml | 32 + .../files/test-inventory-bearer-token.json | 1284 +++++++++++++++++ .../files/test-inventory-bearer-token.yml | 32 + tests/unit/inventory/test_nb_inventory.py | 26 + 8 files changed, 3966 insertions(+), 9 deletions(-) create mode 100644 tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.json create mode 100644 tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.yml create mode 100644 tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.json create mode 100644 tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.yml create mode 100644 tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.json create mode 100644 tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.yml diff --git a/plugins/inventory/nb_inventory.py b/plugins/inventory/nb_inventory.py index 56a0b8c3d..5d88a2f82 100644 --- a/plugins/inventory/nb_inventory.py +++ b/plugins/inventory/nb_inventory.py @@ -83,8 +83,10 @@ token: required: False description: - - NetBox API token to be able to read against NetBox. - - This may not be required depending on the NetBox setup. + - NetBox API token to be able to read against NetBox. + - This may not be required depending on the NetBox setup. + - You can provide a "type" and "value" for a token if your NetBox deployment is using a more advanced authentication like OAUTH. + - If you do not provide a "type" and "value" parameter, the HTTP authorization header will be set to "Token", which is the NetBox default env: # in order of precedence - name: NETBOX_TOKEN @@ -336,6 +338,14 @@ # - "time_zone_utc_minus_7" # - "time_zone_utc_plus_1" # - "time_zone_utc_plus_10" + +# Example of using a token type + +plugin: netbox.netbox.nb_inventory +api_endpoint: http://localhost:8000 +token: + type: Bearer + value: test123456 """ import json @@ -1975,11 +1985,7 @@ def main(self): host=hostname, ) - def parse(self, inventory, loader, path, cache=True): - super(InventoryModule, self).parse(inventory, loader, path) - self._read_config_data(path=path) - self.use_cache = cache - + def _set_authorization(self): # NetBox access if version.parse(ansible_version) < version.parse("2.11"): token = self.get_option("token") @@ -1988,6 +1994,19 @@ def parse(self, inventory, loader, path, cache=True): token = self.templar.template( self.get_option("token"), fail_on_undefined=False ) + if token: + # check if token is new format + if isinstance(token, dict): + self.headers.update( + {"Authorization": f"{token['type'].capitalize()} {token['value']}"} + ) + else: + self.headers.update({"Authorization": "Token %s" % token}) + + def parse(self, inventory, loader, path, cache=True): + super(InventoryModule, self).parse(inventory, loader, path) + self._read_config_data(path=path) + self.use_cache = cache # Handle extra "/" from api_endpoint configuration and trim if necessary, see PR#49943 self.api_endpoint = self.get_option("api_endpoint").strip("/") @@ -2013,8 +2032,8 @@ def parse(self, inventory, loader, path, cache=True): self.cert = self.get_option("cert") self.key = self.get_option("key") self.ca_path = self.get_option("ca_path") - if token: - self.headers.update({"Authorization": "Token %s" % token}) + + self._set_authorization() # Filter and group_by options self.group_by = self.get_option("group_by") diff --git a/tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.json b/tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.json new file mode 100644 index 000000000..374fde8be --- /dev/null +++ b/tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.json @@ -0,0 +1,1248 @@ +{ + "_meta": { + "hostvars": { + "R1-Device": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "locations": [], + "manufacturer": "cisco", + "rack": "Test Rack Site 2", + "rack_role": "test-rack-role", + "regions": [], + "role": "core-switch", + "services": [], + "site": "test-site2", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "", + "asset_tag": "345678901" + }, + "Test Nexus One": { + "ansible_host": "172.16.180.12", + "config_context": {}, + "custom_fields": {}, + "device_type": "nexus-parent", + "dns_name": "nexus.example.com", + "interfaces": [ + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "Ethernet1/1", + "duplex": null, + "enabled": true, + "id": 1, + "ip_addresses": [ + { + "address": "172.16.180.11/24", + "custom_fields": {}, + "description": "", + "display": "172.16.180.11/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 3, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "Ethernet1/1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus Child One", + "id": 5, + "name": "Test Nexus Child One" + }, + "display": "Ethernet2/1", + "duplex": null, + "enabled": true, + "id": 2, + "ip_addresses": [ + { + "address": "172.16.180.12/24", + "custom_fields": {}, + "description": "", + "display": "172.16.180.12/24", + "dns_name": "nexus.example.com", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 4, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "Ethernet2/1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "wlink1", + "duplex": null, + "enabled": true, + "id": 6, + "ip_addresses": [], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "wlink1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "IEEE 802.11a", + "value": "ieee802.11a" + }, + "untagged_vlan": null, + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + } + ], + "is_virtual": false, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "primary_ip4": "172.16.180.12", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [ + { + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "telnet (TCP/23)", + "id": 3, + "ipaddresses": [], + "name": "telnet", + "ports": [ + 23 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + } + ], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "" + }, + "Test VM With Spaces": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 11, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 12, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [ + { + "custom_fields": {}, + "description": "", + "device": null, + "display": "ssh (TCP/22)", + "id": 4, + "ipaddresses": [], + "name": "ssh", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + } + } + ], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "TestDeviceR1": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "rack": "Test Rack", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "FAB12345678" + }, + "test100": { + "config_context": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [ + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "GigabitEthernet1", + "duplex": null, + "enabled": true, + "id": 3, + "ip_addresses": [ + { + "address": "172.16.180.1/24", + "custom_fields": {}, + "description": "", + "display": "172.16.180.1/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 1, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "GigabitEthernet1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "GigabitEthernet2", + "duplex": null, + "enabled": true, + "id": 4, + "ip_addresses": [ + { + "address": "2001::1:1/64", + "custom_fields": {}, + "description": "", + "display": "2001::1:1/64", + "dns_name": "", + "family": { + "label": "IPv6", + "value": 6 + }, + "id": 2, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "GigabitEthernet2", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "wlink1", + "duplex": null, + "enabled": true, + "id": 5, + "ip_addresses": [], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "wlink1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "IEEE 802.11a", + "value": "ieee802.11a" + }, + "untagged_vlan": null, + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + } + ], + "is_virtual": false, + "local_context_data": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [ + { + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "ssh (TCP/22)", + "id": 1, + "ipaddresses": [], + "name": "ssh", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + }, + { + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "http (TCP/80)", + "id": 2, + "ipaddresses": [ + { + "address": "172.16.180.1/24", + "display": "172.16.180.1/24", + "family": 4, + "id": 1 + }, + { + "address": "2001::1:1/64", + "display": "2001::1:1/64", + "family": 6, + "id": 2 + } + ], + "name": "http", + "ports": [ + 80 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + } + ], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "FAB01234567", + "asset_tag": "123456789" + }, + "test100-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 1, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 2, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": 3, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": 4, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": 5, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test101-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 6, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 7, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": 8, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": 9, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": 10, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test102-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test103-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test104-vm": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + } + } + }, + "all": { + "children": [ + "cluster_Test_Cluster", + "cluster_Test_Cluster_2", + "cluster_group_test_cluster_group", + "cluster_type_test_cluster_type", + "device_type_cisco_test", + "device_type_nexus_parent", + "is_virtual", + "manufacturer_cisco", + "rack_Test_Rack", + "rack_Test_Rack_Site_2", + "rack_role_test_rack_role", + "region_other_region", + "region_parent_region", + "role_core_switch", + "service_http", + "service_ssh", + "service_telnet", + "site_group_other_site_group", + "site_group_parent_site_group", + "site_test_site2", + "status_active", + "ungrouped" + ] + }, + "cluster_Test_Cluster": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_Test_Cluster_2": { + "hosts": [ + "Test VM With Spaces", + "test104-vm" + ] + }, + "cluster_group_test_cluster_group": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_type_test_cluster_type": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "device_type_cisco_test": { + "hosts": [ + "R1-Device", + "TestDeviceR1", + "test100" + ] + }, + "device_type_nexus_parent": { + "hosts": [ + "Test Nexus One" + ] + }, + "is_virtual": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "location_parent_rack_group": { + "children": [ + "location_test_rack_group" + ] + }, + "location_test_rack_group": { + "hosts": [ + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "manufacturer_cisco": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "rack_Test_Rack": { + "hosts": [ + "TestDeviceR1" + ] + }, + "rack_Test_Rack_Site_2": { + "hosts": [ + "R1-Device" + ] + }, + "rack_role_test_rack_role": { + "hosts": [ + "R1-Device" + ] + }, + "region_parent_region": { + "children": [ + "region_test_region" + ] + }, + "region_test_region": { + "children": [ + "site_test_site" + ] + }, + "role_core_switch": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "service_http": { + "hosts": [ + "test100" + ] + }, + "service_ssh": { + "hosts": [ + "Test VM With Spaces", + "test100" + ] + }, + "service_telnet": { + "hosts": [ + "Test Nexus One" + ] + }, + "site_group_parent_site_group": { + "children": [ + "site_group_test_site_group" + ] + }, + "site_test_site": { + "children": [ + "location_parent_rack_group" + ] + }, + "site_test_site2": { + "hosts": [ + "R1-Device" + ] + }, + "status_active": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "Test VM With Spaces", + "TestDeviceR1", + "test100", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + } +} \ No newline at end of file diff --git a/tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.yml b/tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.yml new file mode 100644 index 000000000..6af9a1339 --- /dev/null +++ b/tests/integration/targets/inventory-v3.3/files/test-inventory-bearer-token.yml @@ -0,0 +1,32 @@ +--- +plugin: netbox.netbox.nb_inventory +api_endpoint: "http://localhost:32768" +token: + type: Token + value: "0123456789abcdef0123456789abcdef01234567" +validate_certs: False + +config_context: True +plurals: False +interfaces: True +services: True + +group_by: + - site + - tenant + - rack + - location + - rack_role + - tag + - role + - device_type + - manufacturer + - platform + - region + - site_group + - cluster + - cluster_group + - cluster_type + - is_virtual + - services + - status diff --git a/tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.json b/tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.json new file mode 100644 index 000000000..1e52fdccd --- /dev/null +++ b/tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.json @@ -0,0 +1,1284 @@ +{ + "_meta": { + "hostvars": { + "R1-Device": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "locations": [], + "manufacturer": "cisco", + "rack": "Test Rack Site 2", + "rack_role": "test-rack-role", + "regions": [], + "role": "core-switch", + "services": [], + "site": "test-site2", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "", + "asset_tag": "345678901" + }, + "Test Nexus One": { + "ansible_host": "172.16.180.12", + "config_context": {}, + "custom_fields": {}, + "device_type": "nexus-parent", + "dns_name": "nexus.example.com", + "interfaces": [ + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "Ethernet1/1", + "duplex": null, + "enabled": true, + "id": 1, + "ip_addresses": [ + { + "address": "172.16.180.11/24", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "172.16.180.11/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 3, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "Ethernet1/1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus Child One", + "id": 5, + "name": "Test Nexus Child One" + }, + "display": "Ethernet2/1", + "duplex": null, + "enabled": true, + "id": 2, + "ip_addresses": [ + { + "address": "172.16.180.12/24", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "172.16.180.12/24", + "dns_name": "nexus.example.com", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 4, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "Ethernet2/1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "wlink1", + "duplex": null, + "enabled": true, + "id": 6, + "ip_addresses": [], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "wlink1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "IEEE 802.11a", + "value": "ieee802.11a" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + } + ], + "is_virtual": false, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "primary_ip4": "172.16.180.12", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [ + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "telnet (TCP/23)", + "id": 3, + "ipaddresses": [], + "name": "telnet", + "ports": [ + 23 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + } + ], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "" + }, + "Test VM With Spaces": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 11, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 12, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [ + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": null, + "display": "ssh (TCP/22)", + "id": 4, + "ipaddresses": [], + "name": "ssh", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + } + } + ], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "TestDeviceR1": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "rack": "Test Rack", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "FAB12345678" + }, + "test100": { + "config_context": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [ + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "GigabitEthernet1", + "duplex": null, + "enabled": true, + "id": 3, + "ip_addresses": [ + { + "address": "172.16.180.1/24", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "172.16.180.1/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 1, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "GigabitEthernet1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "GigabitEthernet2", + "duplex": null, + "enabled": true, + "id": 4, + "ip_addresses": [ + { + "address": "2001::1:1/64", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "2001::1:1/64", + "dns_name": "", + "family": { + "label": "IPv6", + "value": 6 + }, + "id": 2, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "GigabitEthernet2", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "wlink1", + "duplex": null, + "enabled": true, + "id": 5, + "ip_addresses": [], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "wlink1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "IEEE 802.11a", + "value": "ieee802.11a" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + } + ], + "is_virtual": false, + "local_context_data": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "services": [ + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "ssh (TCP/22)", + "id": 1, + "ipaddresses": [], + "name": "ssh", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + }, + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "http (TCP/80)", + "id": 2, + "ipaddresses": [ + { + "address": "172.16.180.1/24", + "display": "172.16.180.1/24", + "family": 4, + "id": 1 + }, + { + "address": "2001::1:1/64", + "display": "2001::1:1/64", + "family": 6, + "id": 2 + } + ], + "name": "http", + "ports": [ + 80 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + } + ], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "serial": "FAB01234567", + "asset_tag": "123456789" + }, + "test100-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 1, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 2, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": 3, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": 4, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": 5, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test101-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 6, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 7, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": 8, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": 9, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": 10, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test102-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test103-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test104-vm": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + } + } + }, + "all": { + "children": [ + "cluster_Test_Cluster", + "cluster_Test_Cluster_2", + "cluster_group_test_cluster_group", + "cluster_type_test_cluster_type", + "device_type_cisco_test", + "device_type_nexus_parent", + "is_virtual", + "manufacturer_cisco", + "rack_Test_Rack", + "rack_Test_Rack_Site_2", + "rack_role_test_rack_role", + "region_other_region", + "region_parent_region", + "role_core_switch", + "service_http", + "service_ssh", + "service_telnet", + "site_group_other_site_group", + "site_group_parent_site_group", + "site_test_site2", + "status_active", + "ungrouped" + ] + }, + "cluster_Test_Cluster": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_Test_Cluster_2": { + "hosts": [ + "Test VM With Spaces", + "test104-vm" + ] + }, + "cluster_group_test_cluster_group": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_type_test_cluster_type": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "device_type_cisco_test": { + "hosts": [ + "R1-Device", + "TestDeviceR1", + "test100" + ] + }, + "device_type_nexus_parent": { + "hosts": [ + "Test Nexus One" + ] + }, + "is_virtual": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "location_parent_rack_group": { + "children": [ + "location_test_rack_group" + ] + }, + "location_test_rack_group": { + "hosts": [ + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "manufacturer_cisco": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "rack_Test_Rack": { + "hosts": [ + "TestDeviceR1" + ] + }, + "rack_Test_Rack_Site_2": { + "hosts": [ + "R1-Device" + ] + }, + "rack_role_test_rack_role": { + "hosts": [ + "R1-Device" + ] + }, + "region_parent_region": { + "children": [ + "region_test_region" + ] + }, + "region_test_region": { + "children": [ + "site_test_site" + ] + }, + "role_core_switch": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "service_http": { + "hosts": [ + "test100" + ] + }, + "service_ssh": { + "hosts": [ + "Test VM With Spaces", + "test100" + ] + }, + "service_telnet": { + "hosts": [ + "Test Nexus One" + ] + }, + "site_group_parent_site_group": { + "children": [ + "site_group_test_site_group" + ] + }, + "site_test_site": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ], + "children": [ + "location_parent_rack_group" + ] + }, + "site_test_site2": { + "hosts": [ + "R1-Device" + ] + }, + "status_active": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "Test VM With Spaces", + "TestDeviceR1", + "test100", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + } +} \ No newline at end of file diff --git a/tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.yml b/tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.yml new file mode 100644 index 000000000..6af9a1339 --- /dev/null +++ b/tests/integration/targets/inventory-v3.4/files/test-inventory-bearer-token.yml @@ -0,0 +1,32 @@ +--- +plugin: netbox.netbox.nb_inventory +api_endpoint: "http://localhost:32768" +token: + type: Token + value: "0123456789abcdef0123456789abcdef01234567" +validate_certs: False + +config_context: True +plurals: False +interfaces: True +services: True + +group_by: + - site + - tenant + - rack + - location + - rack_role + - tag + - role + - device_type + - manufacturer + - platform + - region + - site_group + - cluster + - cluster_group + - cluster_type + - is_virtual + - services + - status diff --git a/tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.json b/tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.json new file mode 100644 index 000000000..360a7ac33 --- /dev/null +++ b/tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.json @@ -0,0 +1,1284 @@ +{ + "_meta": { + "hostvars": { + "R1-Device": { + "asset_tag": "345678901", + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "locations": [], + "manufacturer": "cisco", + "rack": "Test Rack Site 2", + "rack_role": "test-rack-role", + "regions": [], + "role": "core-switch", + "serial": "", + "services": [], + "site": "test-site2", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "Test Nexus One": { + "ansible_host": "172.16.180.12", + "config_context": {}, + "custom_fields": {}, + "device_type": "nexus-parent", + "dns_name": "nexus.example.com", + "interfaces": [ + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "Ethernet1/1", + "duplex": null, + "enabled": true, + "id": 1, + "ip_addresses": [ + { + "address": "172.16.180.11/24", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "172.16.180.11/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 3, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "Ethernet1/1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus Child One", + "id": 5, + "name": "Test Nexus Child One" + }, + "display": "Ethernet2/1", + "duplex": null, + "enabled": true, + "id": 2, + "ip_addresses": [ + { + "address": "172.16.180.12/24", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "172.16.180.12/24", + "dns_name": "nexus.example.com", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 4, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "Ethernet2/1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "wlink1", + "duplex": null, + "enabled": true, + "id": 6, + "ip_addresses": [], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "wlink1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "IEEE 802.11a", + "value": "ieee802.11a" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + } + ], + "is_virtual": false, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "primary_ip4": "172.16.180.12", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "serial": "", + "services": [ + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": { + "display": "Test Nexus One", + "id": 4, + "name": "Test Nexus One" + }, + "display": "telnet (TCP/23)", + "id": 3, + "ipaddresses": [], + "name": "telnet", + "ports": [ + 23 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + } + ], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "Test VM With Spaces": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 11, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 12, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [ + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": null, + "display": "ssh (TCP/22)", + "id": 4, + "ipaddresses": [], + "name": "ssh", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": { + "display": "Test VM With Spaces", + "id": 6, + "name": "Test VM With Spaces" + } + } + ], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "TestDeviceR1": { + "config_context": {}, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [], + "is_virtual": false, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "rack": "Test Rack", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "serial": "FAB12345678", + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test100": { + "asset_tag": "123456789", + "config_context": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "custom_fields": {}, + "device_type": "cisco-test", + "interfaces": [ + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "GigabitEthernet1", + "duplex": null, + "enabled": true, + "id": 3, + "ip_addresses": [ + { + "address": "172.16.180.1/24", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "172.16.180.1/24", + "dns_name": "", + "family": { + "label": "IPv4", + "value": 4 + }, + "id": 1, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "GigabitEthernet1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 1, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "GigabitEthernet2", + "duplex": null, + "enabled": true, + "id": 4, + "ip_addresses": [ + { + "address": "2001::1:1/64", + "comments": "", + "custom_fields": {}, + "description": "", + "display": "2001::1:1/64", + "dns_name": "", + "family": { + "label": "IPv6", + "value": 6 + }, + "id": 2, + "nat_inside": null, + "nat_outside": [], + "role": null, + "status": { + "label": "Active", + "value": "active" + }, + "tags": [], + "tenant": null, + "vrf": null + } + ], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "GigabitEthernet2", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "1000BASE-T (1GE)", + "value": "1000base-t" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + }, + { + "_occupied": false, + "bridge": null, + "cable": null, + "cable_end": "", + "connected_endpoints": null, + "connected_endpoints_reachable": null, + "connected_endpoints_type": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "wlink1", + "duplex": null, + "enabled": true, + "id": 5, + "ip_addresses": [], + "l2vpn_termination": null, + "label": "", + "lag": null, + "link_peers": [], + "link_peers_type": null, + "mac_address": null, + "mark_connected": false, + "mgmt_only": false, + "mode": null, + "module": null, + "mtu": null, + "name": "wlink1", + "parent": null, + "poe_mode": null, + "poe_type": null, + "rf_channel": null, + "rf_channel_frequency": null, + "rf_channel_width": null, + "rf_role": null, + "speed": null, + "tagged_vlans": [], + "tags": [], + "tx_power": null, + "type": { + "label": "IEEE 802.11a", + "value": "ieee802.11a" + }, + "untagged_vlan": null, + "vdcs": [], + "vrf": null, + "wireless_lans": [], + "wireless_link": null, + "wwn": null + } + ], + "is_virtual": false, + "local_context_data": { + "ntp_servers": [ + "pool.ntp.org" + ] + }, + "locations": [ + "test-rack-group", + "parent-rack-group" + ], + "manufacturer": "cisco", + "regions": [ + "test-region", + "parent-region" + ], + "role": "core-switch", + "serial": "FAB01234567", + "services": [ + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "ssh (TCP/22)", + "id": 1, + "ipaddresses": [], + "name": "ssh", + "ports": [ + 22 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + }, + { + "comments": "", + "custom_fields": {}, + "description": "", + "device": { + "display": "test100 (123456789)", + "id": 1, + "name": "test100" + }, + "display": "http (TCP/80)", + "id": 2, + "ipaddresses": [ + { + "address": "172.16.180.1/24", + "display": "172.16.180.1/24", + "family": 4, + "id": 1 + }, + { + "address": "2001::1:1/64", + "display": "2001::1:1/64", + "family": 6, + "id": 2 + } + ], + "name": "http", + "ports": [ + 80 + ], + "protocol": { + "label": "TCP", + "value": "tcp" + }, + "tags": [], + "virtual_machine": null + } + ], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test100-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 1, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 2, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": 3, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": 4, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": 5, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test100-vm", + "id": 1, + "name": "test100-vm" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test101-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [ + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth0", + "enabled": true, + "id": 6, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth0", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth1", + "enabled": true, + "id": 7, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth1", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth2", + "enabled": true, + "id": 8, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth2", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth3", + "enabled": true, + "id": 9, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth3", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + }, + { + "bridge": null, + "count_fhrp_groups": 0, + "count_ipaddresses": 0, + "custom_fields": {}, + "description": "", + "display": "Eth4", + "enabled": true, + "id": 10, + "ip_addresses": [], + "l2vpn_termination": null, + "mac_address": null, + "mode": null, + "mtu": null, + "name": "Eth4", + "parent": null, + "tagged_vlans": [], + "tags": [], + "untagged_vlan": null, + "virtual_machine": { + "display": "test101-vm", + "id": 2, + "name": "test101-vm" + }, + "vrf": null + } + ], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test102-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test103-vm": { + "cluster": "Test Cluster", + "cluster_group": "test-cluster-group", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [ + "test-region", + "parent-region" + ], + "services": [], + "site": "test-site", + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + }, + "test104-vm": { + "cluster": "Test Cluster 2", + "cluster_type": "test-cluster-type", + "config_context": {}, + "custom_fields": {}, + "interfaces": [], + "is_virtual": true, + "locations": [], + "regions": [], + "services": [], + "site_groups": [], + "status": { + "label": "Active", + "value": "active" + }, + "tags": [] + } + } + }, + "all": { + "children": [ + "ungrouped", + "site_test_site2", + "region_other_region", + "region_parent_region", + "site_group_other_site_group", + "site_group_parent_site_group", + "rack_Test_Rack_Site_2", + "rack_role_test_rack_role", + "role_core_switch", + "device_type_cisco_test", + "manufacturer_cisco", + "status_active", + "device_type_nexus_parent", + "service_telnet", + "rack_Test_Rack", + "service_ssh", + "service_http", + "cluster_Test_Cluster_2", + "cluster_type_test_cluster_type", + "is_virtual", + "cluster_Test_Cluster", + "cluster_group_test_cluster_group" + ] + }, + "cluster_Test_Cluster": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_Test_Cluster_2": { + "hosts": [ + "Test VM With Spaces", + "test104-vm" + ] + }, + "cluster_group_test_cluster_group": { + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "cluster_type_test_cluster_type": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "device_type_cisco_test": { + "hosts": [ + "R1-Device", + "TestDeviceR1", + "test100" + ] + }, + "device_type_nexus_parent": { + "hosts": [ + "Test Nexus One" + ] + }, + "is_virtual": { + "hosts": [ + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + }, + "location_parent_rack_group": { + "children": [ + "location_test_rack_group" + ] + }, + "location_test_rack_group": { + "hosts": [ + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "manufacturer_cisco": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "rack_Test_Rack": { + "hosts": [ + "TestDeviceR1" + ] + }, + "rack_Test_Rack_Site_2": { + "hosts": [ + "R1-Device" + ] + }, + "rack_role_test_rack_role": { + "hosts": [ + "R1-Device" + ] + }, + "region_parent_region": { + "children": [ + "region_test_region" + ] + }, + "region_test_region": { + "children": [ + "site_test_site" + ] + }, + "role_core_switch": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100" + ] + }, + "service_http": { + "hosts": [ + "test100" + ] + }, + "service_ssh": { + "hosts": [ + "test100", + "Test VM With Spaces" + ] + }, + "service_telnet": { + "hosts": [ + "Test Nexus One" + ] + }, + "site_group_parent_site_group": { + "children": [ + "site_group_test_site_group" + ] + }, + "site_test_site": { + "children": [ + "location_parent_rack_group" + ], + "hosts": [ + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm" + ] + }, + "site_test_site2": { + "hosts": [ + "R1-Device" + ] + }, + "status_active": { + "hosts": [ + "R1-Device", + "Test Nexus One", + "TestDeviceR1", + "test100", + "Test VM With Spaces", + "test100-vm", + "test101-vm", + "test102-vm", + "test103-vm", + "test104-vm" + ] + } +} \ No newline at end of file diff --git a/tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.yml b/tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.yml new file mode 100644 index 000000000..6af9a1339 --- /dev/null +++ b/tests/integration/targets/inventory-v3.5/files/test-inventory-bearer-token.yml @@ -0,0 +1,32 @@ +--- +plugin: netbox.netbox.nb_inventory +api_endpoint: "http://localhost:32768" +token: + type: Token + value: "0123456789abcdef0123456789abcdef01234567" +validate_certs: False + +config_context: True +plurals: False +interfaces: True +services: True + +group_by: + - site + - tenant + - rack + - location + - rack_role + - tag + - role + - device_type + - manufacturer + - platform + - region + - site_group + - cluster + - cluster_group + - cluster_type + - is_virtual + - services + - status diff --git a/tests/unit/inventory/test_nb_inventory.py b/tests/unit/inventory/test_nb_inventory.py index 99e63699c..9adfc3e3e 100644 --- a/tests/unit/inventory/test_nb_inventory.py +++ b/tests/unit/inventory/test_nb_inventory.py @@ -49,6 +49,13 @@ def inventory_fixture( return inventory +@pytest.fixture +def templar_fixture(): + templar = Mock() + + return templar + + @pytest.fixture def allowed_device_query_parameters_fixture(): # Subset of parameters - real list is fetched dynamically from NetBox openapi endpoint @@ -220,3 +227,22 @@ def test_fetch_api_docs(inventory_fixture, netbox_ver): assert filemock.call_args_list == ref_args_list assert str(inventory_fixture.api_version) == netbox_ver[:-2] + + +def test_new_token(inventory_fixture, templar_fixture): + mock_get_option = Mock() + + mock_templar_template_token = Mock() + mock_templar_template_token.return_value = {"type": "foo", "value": "bar"} + + inventory_fixture.templar = templar_fixture + inventory_fixture.templar.template = mock_templar_template_token + + inventory_fixture.get_option = mock_get_option + + inventory_fixture.headers = {} + + inventory_fixture._set_authorization() + + assert "Authorization" in inventory_fixture.headers + assert inventory_fixture.headers["Authorization"] == "Foo bar"