Skip to content

Commit f3e29b9

Browse files
authored
Enchancement: add parent_tenant_group/description suboption for netbox_tenant_group (#460)
1 parent 569fd46 commit f3e29b9

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-2
lines changed

plugins/module_utils/netbox_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
nat_inside="address",
106106
nat_outside="address",
107107
parent_region="slug",
108+
parent_tenant_group="slug",
108109
power_panel="name",
109110
power_port="name",
110111
platform="slug",
@@ -170,6 +171,7 @@
170171
"nat_outside": "ip_addresses",
171172
"platform": "platforms",
172173
"parent_region": "regions",
174+
"parent_tenant_group": "tenant_groups",
173175
"power_panel": "power_panels",
174176
"power_port": "power_ports",
175177
"prefix_role": "roles",
@@ -299,6 +301,7 @@
299301
"master": set(["name"]),
300302
"nat_inside": set(["vrf", "address"]),
301303
"parent_region": set(["slug"]),
304+
"parent_tenant_group": set(["slug"]),
302305
"platform": set(["slug"]),
303306
"power_feed": set(["name", "power_panel"]),
304307
"power_outlet": set(["name", "device"]),
@@ -388,6 +391,7 @@
388391
"cluster_type": "type",
389392
"cluster_group": "group",
390393
"parent_region": "parent",
394+
"parent_tenant_group": "parent",
391395
"prefix_role": "role",
392396
"rack_group": "group",
393397
"rack_role": "role",

plugins/modules/netbox_tenant_group.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353
- URL-friendly unique shorthand
5454
required: false
5555
type: str
56+
parent_tenant_group:
57+
description:
58+
- Slug of the parent tenant group
59+
required: false
60+
type: str
61+
description:
62+
description:
63+
- The description of the tenant group
64+
required: false
65+
type: str
5666
required: true
5767
state:
5868
description:
@@ -137,6 +147,8 @@ def main():
137147
options=dict(
138148
name=dict(required=True, type="str"),
139149
slug=dict(required=False, type="str"),
150+
parent_tenant_group=dict(required=False, type="str"),
151+
description=dict(required=False, type="str"),
140152
),
141153
),
142154
)

tests/integration/targets/latest/tasks/netbox_tenant_group.yml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
- test_three['diff']['after']['state'] == "absent"
5656
- test_three['msg'] == "tenant_group Test Tenant Group Two deleted"
5757

58-
- name: "4 - Test another tenant group creation"
58+
- name: "4 - Test tenant group creation with custom slug"
5959
netbox.netbox.netbox_tenant_group:
6060
netbox_url: http://localhost:32768
6161
netbox_token: 0123456789abcdef0123456789abcdef01234567
@@ -73,3 +73,57 @@
7373
- test_four['tenant_group']['name'] == "Test Tenant Group ABC"
7474
- test_four['tenant_group']['slug'] == "test_tenant_group_four"
7575
- test_four['msg'] == "tenant_group Test Tenant Group ABC created"
76+
77+
- name: "5 - Test child tenant group creation"
78+
netbox.netbox.netbox_tenant_group:
79+
netbox_url: http://localhost:32768
80+
netbox_token: 0123456789abcdef0123456789abcdef01234567
81+
data:
82+
name: "Child Test Tenant Group"
83+
parent_tenant_group: "{{ test_four.tenant_group.slug }}"
84+
register: test_five
85+
86+
- name: "5 - ASSERT"
87+
assert:
88+
that:
89+
- test_five is changed
90+
- test_five['diff']['before']['state'] == "absent"
91+
- test_five['diff']['after']['state'] == "present"
92+
- test_five['tenant_group']['name'] == "Child Test Tenant Group"
93+
- test_five['tenant_group']['parent'] == {{ test_four.tenant_group.id }}
94+
- test_five['msg'] == "tenant_group Child Test Tenant Group created"
95+
96+
- name: "6 - Test child tenant group deletion"
97+
netbox.netbox.netbox_tenant_group:
98+
netbox_url: http://localhost:32768
99+
netbox_token: 0123456789abcdef0123456789abcdef01234567
100+
data:
101+
name: "Child Test Tenant Group"
102+
state: "absent"
103+
register: test_six
104+
105+
- name: "6 - ASSERT"
106+
assert:
107+
that:
108+
- test_six is changed
109+
- test_six['diff']['before']['state'] == "present"
110+
- test_six['diff']['after']['state'] == "absent"
111+
- test_six['msg'] == "tenant_group Child Test Tenant Group deleted"
112+
113+
- name: "7 - Test deletion of the tenant group with custom slug"
114+
netbox.netbox.netbox_tenant_group:
115+
netbox_url: http://localhost:32768
116+
netbox_token: 0123456789abcdef0123456789abcdef01234567
117+
data:
118+
name: "Test Tenant Group ABC"
119+
slug: "test_tenant_group_four"
120+
state: "absent"
121+
register: test_seven
122+
123+
- name: "7 - ASSERT"
124+
assert:
125+
that:
126+
- test_seven is changed
127+
- test_seven['diff']['before']['state'] == "present"
128+
- test_seven['diff']['after']['state'] == "absent"
129+
- test_seven['msg'] == "tenant_group Test Tenant Group ABC deleted"

tests/integration/targets/v2.9/tasks/netbox_tenant_group.yml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
- test_three['diff']['after']['state'] == "absent"
5656
- test_three['msg'] == "tenant_group Test Tenant Group Two deleted"
5757

58-
- name: "4 - Test another tenant group creation"
58+
- name: "4 - Test tenant group creation with custom slug"
5959
netbox.netbox.netbox_tenant_group:
6060
netbox_url: http://localhost:32768
6161
netbox_token: 0123456789abcdef0123456789abcdef01234567
@@ -73,3 +73,57 @@
7373
- test_four['tenant_group']['name'] == "Test Tenant Group ABC"
7474
- test_four['tenant_group']['slug'] == "test_tenant_group_four"
7575
- test_four['msg'] == "tenant_group Test Tenant Group ABC created"
76+
77+
- name: "5 - Test child tenant group creation"
78+
netbox.netbox.netbox_tenant_group:
79+
netbox_url: http://localhost:32768
80+
netbox_token: 0123456789abcdef0123456789abcdef01234567
81+
data:
82+
name: "Child Test Tenant Group"
83+
parent_tenant_group: "{{ test_four.tenant_group.slug }}"
84+
register: test_five
85+
86+
- name: "5 - ASSERT"
87+
assert:
88+
that:
89+
- test_five is changed
90+
- test_five['diff']['before']['state'] == "absent"
91+
- test_five['diff']['after']['state'] == "present"
92+
- test_five['tenant_group']['name'] == "Child Test Tenant Group"
93+
- test_five['tenant_group']['parent'] == {{ test_four.tenant_group.id }}
94+
- test_five['msg'] == "tenant_group Child Test Tenant Group created"
95+
96+
- name: "6 - Test child tenant group deletion"
97+
netbox.netbox.netbox_tenant_group:
98+
netbox_url: http://localhost:32768
99+
netbox_token: 0123456789abcdef0123456789abcdef01234567
100+
data:
101+
name: "Child Test Tenant Group"
102+
state: "absent"
103+
register: test_six
104+
105+
- name: "6 - ASSERT"
106+
assert:
107+
that:
108+
- test_six is changed
109+
- test_six['diff']['before']['state'] == "present"
110+
- test_six['diff']['after']['state'] == "absent"
111+
- test_six['msg'] == "tenant_group Child Test Tenant Group deleted"
112+
113+
- name: "7 - Test deletion of the tenant group with custom slug"
114+
netbox.netbox.netbox_tenant_group:
115+
netbox_url: http://localhost:32768
116+
netbox_token: 0123456789abcdef0123456789abcdef01234567
117+
data:
118+
name: "Test Tenant Group ABC"
119+
slug: "test_tenant_group_four"
120+
state: "absent"
121+
register: test_seven
122+
123+
- name: "7 - ASSERT"
124+
assert:
125+
that:
126+
- test_seven is changed
127+
- test_seven['diff']['before']['state'] == "present"
128+
- test_seven['diff']['after']['state'] == "absent"
129+
- test_seven['msg'] == "tenant_group Test Tenant Group ABC deleted"

0 commit comments

Comments
 (0)