Skip to content

Commit

Permalink
Module: tenant_group - Add parent_tenant_group argument (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-foxworth authored Sep 15, 2021
1 parent f424efe commit c97e0f8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions plugins/module_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
nat_outside="address",
parent_rack_group="slug",
parent_region="slug",
parent_tenant_group="slug",
power_panel="name",
power_port="name",
power_port_template="name",
Expand Down Expand Up @@ -173,6 +174,7 @@
"platform": "platforms",
"parent_rack_group": "rack_groups",
"parent_region": "regions",
"parent_tenant_group": "tenant_groups",
"power_panel": "power_panels",
"power_port": "power_ports",
"power_port_template": "power_port_templates",
Expand Down Expand Up @@ -306,6 +308,7 @@
"nat_inside": set(["vrf", "address"]),
"parent_rack_group": set(["slug"]),
"parent_region": set(["slug"]),
"parent_tenant_group": set(["slug"]),
"platform": set(["slug"]),
"power_feed": set(["name", "power_panel"]),
"power_outlet": set(["name", "device"]),
Expand Down Expand Up @@ -396,6 +399,7 @@
"cluster_group": "group",
"parent_rack_group": "parent",
"parent_region": "parent",
"parent_tenant_group": "parent",
"power_port_template": "power_port",
"prefix_role": "role",
"rack_group": "group",
Expand Down
20 changes: 18 additions & 2 deletions plugins/modules/tenant_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__metaclass__ = type

ANSIBLE_METADATA = {
"metadata_version": "1.1",
"metadata_version": "1.2",
"status": ["preview"],
"supported_by": "community",
}
Expand Down Expand Up @@ -62,6 +62,12 @@
choices: [ absent, present ]
default: present
type: str
parent_tenant_group:
description:
- Name of the parent tenant group
required: false
type: raw
version_added: "3.1.0"
query_params:
description:
- This can be used to override the specified values in ALLOWED_QUERY_PARAMS that is defined
Expand Down Expand Up @@ -94,13 +100,22 @@
slug: "tenant_group_abc"
state: present
- name: Delete tenant within nautobot
- name: Delete tenant within Nautobot
networktocode.nautobot.tenant_group:
url: http://nautobot.local
token: thisIsMyToken
name: Tenant ABC
state: absent
- name: Update tenant within Nautobot with a parent tenant group
networktocode.nautobot.tenant_group:
url: http://nautobot.local
token: thisIsMyToken
name: Tenant Group ABC
parent_tenant_group: Customer Tenants
slug: "tenant_group_abc"
state: present
"""

RETURN = r"""
Expand Down Expand Up @@ -135,6 +150,7 @@ def main():
name=dict(required=True, type="str"),
slug=dict(required=False, type="str"),
description=dict(required=False, type="str"),
parent_tenant_group=dict(required=False, type="raw"),
)
)

Expand Down
8 changes: 8 additions & 0 deletions tests/integration/targets/latest/tasks/tenant_group.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
### PYNAUTOBOT_TENANT_GROUP
##
##

- set_fact:
tenant_group_object: "{{ lookup('networktocode.nautobot.lookup', 'tenant-groups', api_endpoint=nautobot_url, token=nautobot_token, api_filter='slug=test-tenant-group') }}"

- name: "1 - Test tenant group creation"
networktocode.nautobot.tenant_group:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: "Test Tenant Group Two"
parent_tenant_group: "test-tenant-group"
register: test_one

- name: "1 - ASSERT"
Expand All @@ -20,12 +25,14 @@
- test_one['tenant_group']['name'] == "Test Tenant Group Two"
- test_one['tenant_group']['slug'] == "test-tenant-group-two"
- test_one['msg'] == "tenant_group Test Tenant Group Two created"
- test_one['tenant_group']['parent'] == tenant_group_object['value']['id']

- name: "Test duplicate tenant group"
networktocode.nautobot.tenant_group:
url: "{{ nautobot_url }}"
token: "{{ nautobot_token }}"
name: "Test Tenant Group Two"
parent_tenant_group: "test-tenant-group"
register: test_two

- name: "2 - ASSERT"
Expand All @@ -35,6 +42,7 @@
- test_two['tenant_group']['name'] == "Test Tenant Group Two"
- test_two['tenant_group']['slug'] == "test-tenant-group-two"
- test_two['msg'] == "tenant_group Test Tenant Group Two already exists"
- test_two['tenant_group']['parent'] == tenant_group_object['value']['id']

- name: "3 - Test delete"
networktocode.nautobot.tenant_group:
Expand Down

0 comments on commit c97e0f8

Please sign in to comment.