Skip to content

Commit ee11cd8

Browse files
authored
nb_inventory - extract serial and asset_tag. (#826)
* nb_inventory - extract serial and asset_tag.
1 parent 8492d59 commit ee11cd8

39 files changed

+3108
-2827
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- nb_inventory - extract serial and asset_tag from devices

plugins/inventory/nb_inventory.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ def group_extractors(self):
529529
"cluster_group": self.extract_cluster_group,
530530
"cluster_type": self.extract_cluster_type,
531531
"is_virtual": self.extract_is_virtual,
532+
"serial": self.extract_serial,
533+
"asset_tag": self.extract_asset_tag,
532534
"time_zone": self.extract_site_time_zone,
533535
"utc_offset": self.extract_site_utc_offset,
534536
self._pluralize_group_by("site"): self.extract_site,
@@ -960,6 +962,12 @@ def extract_dns_name(self, host):
960962

961963
return ip_address.get("dns_name")
962964

965+
def extract_serial(self, host):
966+
return host.get("serial", None)
967+
968+
def extract_asset_tag(self, host):
969+
return host.get("asset_tag", None)
970+
963971
def refresh_platforms_lookup(self):
964972
url = self.api_endpoint + "/api/dcim/platforms/?limit=0"
965973
platforms = self.get_resource_list(api_url=url)

tests/integration/netbox-deploy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,24 @@ def make_netbox_calls(endpoint, payload):
290290
"device_role": core_switch.id,
291291
"site": test_site.id,
292292
"local_context_data": {"ntp_servers": ["pool.ntp.org"]},
293+
"serial": "FAB01234567",
294+
"asset_tag": "123456789",
293295
},
294296
{
295297
"name": "TestDeviceR1",
296298
"device_type": cisco_test.id,
297299
"device_role": core_switch.id,
298300
"site": test_site.id,
299301
"rack": test_rack.id,
302+
"serial": "FAB12345678",
300303
},
301304
{
302305
"name": "R1-Device",
303306
"device_type": cisco_test.id,
304307
"device_role": core_switch.id,
305308
"site": test_site2.id,
306309
"rack": test_rack_site2.id,
310+
"asset_tag": "345678901",
307311
},
308312
{
309313
"name": "Test Nexus One",

tests/integration/targets/inventory-v3.1/files/test-inventory-jinja2-filter.json

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@
238238
"label": "Active",
239239
"value": "active"
240240
},
241-
"tags": []
241+
"tags": [],
242+
"serial": ""
242243
},
243244
"TestDeviceR1": {
244245
"config_context": {},
@@ -264,7 +265,8 @@
264265
"label": "Active",
265266
"value": "active"
266267
},
267-
"tags": []
268+
"tags": [],
269+
"serial": "FAB12345678"
268270
},
269271
"test100": {
270272
"config_context": {
@@ -287,7 +289,7 @@
287289
"custom_fields": {},
288290
"description": "",
289291
"device": {
290-
"display": "test100",
292+
"display": "test100 (123456789)",
291293
"id": 1,
292294
"name": "test100"
293295
},
@@ -357,7 +359,7 @@
357359
"custom_fields": {},
358360
"description": "",
359361
"device": {
360-
"display": "test100",
362+
"display": "test100 (123456789)",
361363
"id": 1,
362364
"name": "test100"
363365
},
@@ -427,7 +429,7 @@
427429
"custom_fields": {},
428430
"description": "",
429431
"device": {
430-
"display": "test100",
432+
"display": "test100 (123456789)",
431433
"id": 1,
432434
"name": "test100"
433435
},
@@ -484,7 +486,7 @@
484486
"custom_fields": {},
485487
"description": "",
486488
"device": {
487-
"display": "test100",
489+
"display": "test100 (123456789)",
488490
"id": 1,
489491
"name": "test100"
490492
},
@@ -506,7 +508,7 @@
506508
"custom_fields": {},
507509
"description": "",
508510
"device": {
509-
"display": "test100",
511+
"display": "test100 (123456789)",
510512
"id": 1,
511513
"name": "test100"
512514
},
@@ -544,7 +546,9 @@
544546
"label": "Active",
545547
"value": "active"
546548
},
547-
"tags": []
549+
"tags": [],
550+
"serial": "FAB01234567",
551+
"asset_tag": "123456789"
548552
},
549553
"test100-vm": {
550554
"cluster": "Test Cluster",
@@ -878,28 +882,28 @@
878882
}
879883
}
880884
},
881-
"all": {
882-
"children": [
883-
"cluster_Test_Cluster",
884-
"cluster_group_test_cluster_group",
885-
"cluster_type_test_cluster_type",
886-
"device_type_cisco_test",
887-
"device_type_nexus_parent",
888-
"is_virtual",
889-
"manufacturer_cisco",
890-
"rack_Test_Rack",
891-
"region_other_region",
892-
"region_parent_region",
893-
"role_core_switch",
894-
"service_http",
895-
"service_ssh",
896-
"service_telnet",
897-
"site_group_other_site_group",
898-
"site_group_parent_site_group",
899-
"site_test_site2",
900-
"status_active",
901-
"ungrouped"
902-
]
885+
"all": {
886+
"children": [
887+
"cluster_Test_Cluster",
888+
"cluster_group_test_cluster_group",
889+
"cluster_type_test_cluster_type",
890+
"device_type_cisco_test",
891+
"device_type_nexus_parent",
892+
"is_virtual",
893+
"manufacturer_cisco",
894+
"rack_Test_Rack",
895+
"region_other_region",
896+
"region_parent_region",
897+
"role_core_switch",
898+
"service_http",
899+
"service_ssh",
900+
"service_telnet",
901+
"site_group_other_site_group",
902+
"site_group_parent_site_group",
903+
"site_test_site2",
904+
"status_active",
905+
"ungrouped"
906+
]
903907
},
904908
"cluster_Test_Cluster": {
905909
"hosts": [
@@ -958,7 +962,6 @@
958962
},
959963
"manufacturer_cisco": {
960964
"hosts": [
961-
962965
"Test Nexus One",
963966
"TestDeviceR1",
964967
"test100"
@@ -1028,4 +1031,4 @@
10281031
"test103-vm"
10291032
]
10301033
}
1031-
}
1034+
}

tests/integration/targets/inventory-v3.1/files/test-inventory-jinja2.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"label": "Active",
4343
"value": "active"
4444
},
45-
"tags": []
45+
"tags": [],
46+
"serial": "",
47+
"asset_tag": "345678901"
4648
},
4749
"Test VM With Spaces": {
4850
"cluster": "Test Cluster 2",
@@ -80,7 +82,8 @@
8082
"label": "Active",
8183
"value": "active"
8284
},
83-
"tags": []
85+
"tags": [],
86+
"serial": "FAB12345678"
8487
},
8588
"VC1": {
8689
"ansible_host": "nexus.example.com",
@@ -105,7 +108,8 @@
105108
"label": "Active",
106109
"value": "active"
107110
},
108-
"tags": []
111+
"tags": [],
112+
"serial": ""
109113
},
110114
"test100": {
111115
"custom_fields": {},
@@ -132,7 +136,9 @@
132136
"label": "Active",
133137
"value": "active"
134138
},
135-
"tags": []
139+
"tags": [],
140+
"serial": "FAB01234567",
141+
"asset_tag": "123456789"
136142
},
137143
"test100-vm": {
138144
"cluster": "Test Cluster",
@@ -374,4 +380,4 @@
374380
"R1-Device"
375381
]
376382
}
377-
}
383+
}

tests/integration/targets/inventory-v3.1/files/test-inventory-legacy.json

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"label": "Active",
3232
"value": "active"
3333
},
34-
"tags": []
34+
"tags": [],
35+
"serial": "",
36+
"asset_tag": "345678901"
3537
},
3638
"Test Nexus One": {
3739
"ansible_host": "172.16.180.12",
@@ -90,7 +92,8 @@
9092
"label": "Active",
9193
"value": "active"
9294
},
93-
"tags": []
95+
"tags": [],
96+
"serial": ""
9497
},
9598
"Test VM With Spaces": {
9699
"cluster": "Test Cluster 2",
@@ -168,7 +171,8 @@
168171
"label": "Active",
169172
"value": "active"
170173
},
171-
"tags": []
174+
"tags": [],
175+
"serial": "FAB12345678"
172176
},
173177
"test100": {
174178
"custom_fields": {},
@@ -202,7 +206,7 @@
202206
"custom_fields": {},
203207
"description": "",
204208
"device": {
205-
"display": "test100",
209+
"display": "test100 (123456789)",
206210
"id": 1,
207211
"name": "test100"
208212
},
@@ -224,7 +228,7 @@
224228
"custom_fields": {},
225229
"description": "",
226230
"device": {
227-
"display": "test100",
231+
"display": "test100 (123456789)",
228232
"id": 1,
229233
"name": "test100"
230234
},
@@ -264,7 +268,9 @@
264268
"label": "Active",
265269
"value": "active"
266270
},
267-
"tags": []
271+
"tags": [],
272+
"serial": "FAB01234567",
273+
"asset_tag": "123456789"
268274
},
269275
"test100-vm": {
270276
"cluster": "Test Cluster",
@@ -405,4 +411,4 @@
405411
"test104-vm"
406412
]
407413
}
408-
}
414+
}

0 commit comments

Comments
 (0)