Skip to content

Commit 6a65920

Browse files
Inventory: group_by status working properly (#398)
1 parent c74b7d3 commit 6a65920

11 files changed

+85
-2
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
- cluster_group
137137
- is_virtual
138138
- services
139+
- status
139140
default: []
140141
group_names_raw:
141142
description: Will not add the group_by choice name to the group names
@@ -487,7 +488,7 @@ def extract_vcpus(self, host):
487488
return host.get("vcpus")
488489

489490
def extract_status(self, host):
490-
return host.get("status")
491+
return host["status"]
491492

492493
def extract_memory(self, host):
493494
return host.get("memory")
@@ -1264,6 +1265,9 @@ def generate_group_name(self, grouping, group):
12641265
group = group["name"]
12651266
grouping = "service"
12661267

1268+
if grouping == "status":
1269+
group = group["value"]
1270+
12671271
if self.group_names_raw:
12681272
return group
12691273
else:

tests/integration/targets/inventory-latest/files/test-inventory-options-flatten.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@
736736
"Test_Cluster_2",
737737
"Test_Rack",
738738
"Test_Rack_Site_2",
739+
"active",
739740
"cisco",
740741
"cisco_test",
741742
"core_switch",
@@ -800,6 +801,20 @@
800801
"test_region"
801802
]
802803
},
804+
"active": {
805+
"hosts": [
806+
"R1-Device",
807+
"Test Nexus One",
808+
"Test VM With Spaces",
809+
"TestDeviceR1",
810+
"test100",
811+
"test100-vm",
812+
"test101-vm",
813+
"test102-vm",
814+
"test103-vm",
815+
"test104-vm"
816+
]
817+
},
803818
"test_cluster_group": {
804819
"hosts": [
805820
"test100-vm",

tests/integration/targets/inventory-latest/files/test-inventory-options-flatten.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ cache_timeout: 3600
99
cache_plugin: jsonfile
1010
cache_connection: /tmp/inventory_netbox
1111

12-
1312
config_context: True
1413
flatten_config_context: True
1514
flatten_custom_fields: True
@@ -37,3 +36,4 @@ group_by:
3736
- cluster_group
3837
- cluster_type
3938
- is_virtual
39+
- status

tests/integration/targets/inventory-latest/files/test-inventory-options.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@
212212
"Test_Cluster_2",
213213
"Test_Rack",
214214
"Test_Rack_Site_2",
215+
"active",
215216
"cisco",
216217
"cisco_test",
217218
"core_switch",
@@ -283,6 +284,20 @@
283284
"test_region"
284285
]
285286
},
287+
"active": {
288+
"hosts": [
289+
"R1-Device",
290+
"Test VM With Spaces",
291+
"TestDeviceR1",
292+
"VC1",
293+
"test100",
294+
"test100-vm",
295+
"test101-vm",
296+
"test102-vm",
297+
"test103-vm",
298+
"test104-vm"
299+
]
300+
},
286301
"test_cluster_group": {
287302
"hosts": [
288303
"test100-vm",

tests/integration/targets/inventory-latest/files/test-inventory-options.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ group_by:
3434
- cluster_group
3535
- cluster_type
3636
- is_virtual
37+
- status
3738

3839
query_filters:
3940

tests/integration/targets/inventory-latest/files/test-inventory-plurals-flatten.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@
271271
"Test_Cluster_2",
272272
"Test_Rack",
273273
"Test_Rack_Site_2",
274+
"active",
274275
"cisco",
275276
"cisco_test",
276277
"core_switch",
@@ -335,6 +336,20 @@
335336
"test_region"
336337
]
337338
},
339+
"active": {
340+
"hosts": [
341+
"R1-Device",
342+
"Test Nexus One",
343+
"Test VM With Spaces",
344+
"TestDeviceR1",
345+
"test100",
346+
"test100-vm",
347+
"test101-vm",
348+
"test102-vm",
349+
"test103-vm",
350+
"test104-vm"
351+
]
352+
},
338353
"test_cluster_group": {
339354
"hosts": [
340355
"test100-vm",

tests/integration/targets/inventory-latest/files/test-inventory-plurals-flatten.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ group_by:
2828
- cluster_group
2929
- cluster_type
3030
- is_virtual
31+
- status

tests/integration/targets/inventory-latest/files/test-inventory-plurals.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@
844844
"region_other_region",
845845
"region_parent_region",
846846
"sites_test_site2",
847+
"status_active",
847848
"ungrouped"
848849
]
849850
},
@@ -967,5 +968,19 @@
967968
"hosts": [
968969
"R1-Device"
969970
]
971+
},
972+
"status_active": {
973+
"hosts": [
974+
"R1-Device",
975+
"Test Nexus One",
976+
"Test VM With Spaces",
977+
"TestDeviceR1",
978+
"test100",
979+
"test100-vm",
980+
"test101-vm",
981+
"test102-vm",
982+
"test103-vm",
983+
"test104-vm"
984+
]
970985
}
971986
}

tests/integration/targets/inventory-latest/files/test-inventory-plurals.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ group_by:
3333
- cluster_group
3434
- cluster_type
3535
- is_virtual
36+
- status

tests/integration/targets/inventory-latest/files/test-inventory.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@
754754
"service_ssh",
755755
"service_telnet",
756756
"site_test_site2",
757+
"status_active",
757758
"ungrouped"
758759
]
759760
},
@@ -893,5 +894,19 @@
893894
"hosts": [
894895
"R1-Device"
895896
]
897+
},
898+
"status_active": {
899+
"hosts": [
900+
"R1-Device",
901+
"Test Nexus One",
902+
"Test VM With Spaces",
903+
"TestDeviceR1",
904+
"test100",
905+
"test100-vm",
906+
"test101-vm",
907+
"test102-vm",
908+
"test103-vm",
909+
"test104-vm"
910+
]
896911
}
897912
}

tests/integration/targets/inventory-latest/files/test-inventory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ group_by:
2525
- cluster_type
2626
- is_virtual
2727
- services
28+
- status

0 commit comments

Comments
 (0)