diff --git a/plugins/module_utils/utils.py b/plugins/module_utils/utils.py index 8c648014..4d5a6d4f 100644 --- a/plugins/module_utils/utils.py +++ b/plugins/module_utils/utils.py @@ -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", @@ -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", @@ -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"]), @@ -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", diff --git a/plugins/modules/tenant_group.py b/plugins/modules/tenant_group.py index 6bf269df..8af93820 100644 --- a/plugins/modules/tenant_group.py +++ b/plugins/modules/tenant_group.py @@ -8,7 +8,7 @@ __metaclass__ = type ANSIBLE_METADATA = { - "metadata_version": "1.1", + "metadata_version": "1.2", "status": ["preview"], "supported_by": "community", } @@ -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 @@ -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""" @@ -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"), ) ) diff --git a/tests/integration/targets/latest/tasks/tenant_group.yml b/tests/integration/targets/latest/tasks/tenant_group.yml index 3f7126ab..4f77156f 100644 --- a/tests/integration/targets/latest/tasks/tenant_group.yml +++ b/tests/integration/targets/latest/tasks/tenant_group.yml @@ -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" @@ -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" @@ -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: