Skip to content

Commit

Permalink
Added support to query the object using UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana committed Jan 9, 2025
1 parent 3bd6952 commit 8c6e1a9
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 24 deletions.
14 changes: 12 additions & 2 deletions plugins/modules/ndo_dhcp_option_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
data: data_1
state: present
- name: Query a dhcp option policy with template_name
- name: Query a dhcp option policy with name
cisco.mso.ndo_dhcp_option_policy:
host: mso_host
username: admin
Expand All @@ -98,6 +98,16 @@
state: query
register: query_one
- name: Query a dhcp option policy with UUID
cisco.mso.ndo_dhcp_option_policy:
host: mso_host
username: admin
password: SomeSecretPassword
template: ansible_tenant_template
option_policy_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_uuid
- name: Query all dhcp option policy in the template
cisco.mso.ndo_dhcp_option_policy:
host: mso_host
Expand Down Expand Up @@ -173,7 +183,7 @@ def main():

path = "/tenantPolicyTemplate/template/dhcpOptionPolicies"
existing_dhcp_option_policies = mso_template.template.get("tenantPolicyTemplate", {}).get("template", {}).get("dhcpOptionPolicies", [])
if option_policy:
if option_policy or option_policy_uuid:
object_description = "DHCP Option Policy"
if option_policy_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_dhcp_option_policies, option_policy_uuid)
Expand Down
14 changes: 12 additions & 2 deletions plugins/modules/ndo_dhcp_relay_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
ip: 1.1.1.1
state: present
- name: Query a dhcp relay policy with template_name
- name: Query a dhcp relay policy with name
cisco.mso.ndo_dhcp_relay_policy:
host: mso_host
username: admin
Expand All @@ -124,6 +124,16 @@
state: query
register: query_one
- name: Query a dhcp relay policy with UUID
cisco.mso.ndo_dhcp_relay_policy:
host: mso_host
username: admin
password: SomeSecretPassword
template: ansible_tenant_template
relay_policy_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid
- name: Query all dhcp relay policy in the template
cisco.mso.ndo_dhcp_relay_policy:
host: mso_host
Expand Down Expand Up @@ -204,7 +214,7 @@ def main():

path = "/tenantPolicyTemplate/template/dhcpRelayPolicies"
existing_dhcp_relay_policies = mso_template.template.get("tenantPolicyTemplate", {}).get("template", {}).get("dhcpRelayPolicies", [])
if relay_policy:
if relay_policy or relay_policy_uuid:
object_description = "DHCP Relay Policy"
if relay_policy_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_dhcp_relay_policies, relay_policy_uuid)
Expand Down
14 changes: 12 additions & 2 deletions plugins/modules/ndo_l3_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
pool: ansible_test_vlan_pool
state: present
- name: Query a L3 domain with template_name
- name: Query a L3 domain with name
cisco.mso.ndo_l3_domain:
host: mso_host
username: admin
Expand All @@ -80,6 +80,16 @@
state: query
register: query_one
- name: Query a L3 domain with UUID
cisco.mso.ndo_l3_domain:
host: mso_host
username: admin
password: SomeSecretPassword
template: ansible_tenant_template
l3_domain_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid
- name: Query all L3 domains in the template
cisco.mso.ndo_l3_domain:
host: mso_host
Expand Down Expand Up @@ -156,7 +166,7 @@ def main():

path = "/fabricPolicyTemplate/template/l3Domains"
existing_l3_domains = mso_template.template.get("fabricPolicyTemplate", {}).get("template", {}).get("l3Domains", [])
if l3_domain:
if l3_domain or l3_domain_uuid:
object_description = "L3 Domain"
if l3_domain_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_l3_domains, l3_domain_uuid)
Expand Down
14 changes: 12 additions & 2 deletions plugins/modules/ndo_physical_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
pool: ansible_test_vlan_pool
state: present
- name: Query a physical domain with template_name
- name: Query a physical domain with name
cisco.mso.ndo_physical_domain:
host: mso_host
username: admin
Expand All @@ -80,6 +80,16 @@
state: query
register: query_one
- name: Query a physical domain with UUID
cisco.mso.ndo_physical_domain:
host: mso_host
username: admin
password: SomeSecretPassword
template: ansible_tenant_template
physical_domain_uuid: '{{ query_one.current.uuid }}
state: query
register: query_with_uuid
- name: Query all physical domains in the template
cisco.mso.ndo_physical_domain:
host: mso_host
Expand Down Expand Up @@ -156,7 +166,7 @@ def main():

path = "/fabricPolicyTemplate/template/domains"
existing_physical_domains = mso_template.template.get("fabricPolicyTemplate", {}).get("template", {}).get("domains", [])
if physical_domain:
if physical_domain or physical_domain_uuid:
object_description = "Physical Domain"
if physical_domain_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_physical_domains, physical_domain_uuid)
Expand Down
20 changes: 15 additions & 5 deletions plugins/modules/ndo_route_map_policy_multicast.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"""

EXAMPLES = r"""
- name: Create a new multicast route map policy policy
- name: Create a new multicast route map policy
cisco.mso.ndo_route_map_policy_multicast:
host: mso_host
username: admin
Expand All @@ -102,7 +102,7 @@
action: permit
state: present
- name: Query a multicast route map policy policy with template_name
- name: Query a multicast route map policy with name
cisco.mso.ndo_route_map_policy_multicast:
host: mso_host
username: admin
Expand All @@ -112,7 +112,17 @@
state: query
register: query_one
- name: Query all multicast route map policy policy in the template
- name: Query a multicast route map policy with UUID
cisco.mso.ndo_route_map_policy_multicast:
host: mso_host
username: admin
password: SomeSecretPassword
template: ansible_tenant_template
route_map_policy_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid
- name: Query all multicast route map policy in the template
cisco.mso.ndo_route_map_policy_multicast:
host: mso_host
username: admin
Expand All @@ -121,7 +131,7 @@
state: query
register: query_all
- name: Delete a multicast route map policy policy
- name: Delete a multicast route map policy
cisco.mso.ndo_route_map_policy_multicast:
host: mso_host
username: admin
Expand Down Expand Up @@ -189,7 +199,7 @@ def main():

path = "/tenantPolicyTemplate/template/mcastRouteMapPolicies"
existing_route_map_policies = mso_template.template.get("tenantPolicyTemplate", {}).get("template", {}).get("mcastRouteMapPolicies", [])
if route_map_policy:
if route_map_policy or route_map_policy_uuid:
object_description = "Multicast Route Map Policy"
if route_map_policy_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_route_map_policies, route_map_policy_uuid)
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/ndo_synce_interface_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
username: admin
password: SomeSecretPassword
template: ansible_fabric_policy_template
interface_policy_uuid: uuid
interface_policy_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_one_by_uuid
Expand Down Expand Up @@ -197,7 +197,7 @@ def main():

existing_interface_policies = mso_template.template.get("fabricPolicyTemplate", {}).get("template", {}).get("syncEthIntfPolicies", [])

if interface_policy:
if interface_policy or interface_policy_uuid:
object_description = "SyncE Interface Policy"
if interface_policy_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_interface_policies, interface_policy_uuid)
Expand Down
14 changes: 12 additions & 2 deletions plugins/modules/ndo_vlan_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
to_vlan: 400
state: present
- name: Query a vlan pool with template_name
- name: Query a vlan pool with name
cisco.mso.ndo_vlan_pool:
host: mso_host
username: admin
Expand All @@ -98,6 +98,16 @@
state: query
register: query_one
- name: Query a vlan pool with UUID
cisco.mso.ndo_vlan_pool:
host: mso_host
username: admin
password: SomeSecretPassword
template: ansible_tenant_template
vlan_pool_uuid: '{{ query_one.current.uuid }}
state: query
register: query_with_uuid
- name: Query all vlan pools in the template
cisco.mso.ndo_vlan_pool:
host: mso_host
Expand Down Expand Up @@ -171,7 +181,7 @@ def main():

path = "/fabricPolicyTemplate/template/vlanPools"
existing_vlan_pools = mso_template.template.get("fabricPolicyTemplate", {}).get("template", {}).get("vlanPools", [])
if vlan_pool:
if vlan_pool or vlan_pool_uuid:
object_description = "VLAN Pool"
if vlan_pool_uuid:
match = mso_template.get_object_by_uuid(object_description, existing_vlan_pools, vlan_pool_uuid)
Expand Down
12 changes: 11 additions & 1 deletion tests/integration/targets/ndo_dhcp_option_policy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@
state: query
register: query_one

- name: Query a dhcp option policy with uuid
cisco.mso.ndo_dhcp_option_policy:
<<: *mso_info
template: ansible_tenant_template
option_policy_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid

- name: Query all dhcp option policy in the template
cisco.mso.ndo_dhcp_option_policy:
<<: *mso_info
Expand All @@ -272,7 +280,9 @@
assert:
that:
- query_one is not changed
- query_one.current.name == "ansible_test_option_policy_2"
- query_with_uuid is not changed
- query_one.current.name == query_with_uuid.current.name == "ansible_test_option_policy_2"
- query_one.current.uuid == query_with_uuid.current.uuid
- query_all is not changed
- query_all.current | length == 2

Expand Down
12 changes: 11 additions & 1 deletion tests/integration/targets/ndo_dhcp_relay_policy/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@
state: query
register: query_one

- name: Query a dhcp relay policy with uuid
cisco.mso.ndo_dhcp_relay_policy:
<<: *mso_info
template: ansible_tenant_template
relay_policy_uuid: "{{ query_one.current.uuid }}"
state: query
register: query_with_uuid

- name: Query all dhcp relay policy in the template
cisco.mso.ndo_dhcp_relay_policy:
<<: *mso_info
Expand All @@ -362,7 +370,9 @@
assert:
that:
- query_one is not changed
- query_one.current.name == "ansible_test_relay_policy_2"
- query_with_uuid is not changed
- query_one.current.name == query_with_uuid.current.name =="ansible_test_relay_policy_2"
- query_one.current.uuid == query_with_uuid.current.uuid
- query_all is not changed
- query_all.current | length == 2

Expand Down
12 changes: 11 additions & 1 deletion tests/integration/targets/ndo_l3_domain/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@
state: query
register: query_one

- name: Query a l3 domain with UUID
cisco.mso.ndo_l3_domain:
<<: *mso_info
template: ansible_fabric_policy_template
l3_domain_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid

- name: Query all l3 domain in the template
cisco.mso.ndo_l3_domain:
<<: *mso_info
Expand All @@ -190,7 +198,9 @@
assert:
that:
- query_one is not changed
- query_one.current.name == "ansible_test_l3_domain_2"
- query_with_uuid is not changed
- query_one.current.name == query_with_uuid.current.name == "ansible_test_l3_domain_2"
- query_one.current.uuid == query_with_uuid.current.uuid
- query_all is not changed
- query_all.current | length == 2

Expand Down
12 changes: 11 additions & 1 deletion tests/integration/targets/ndo_physical_domain/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@
state: query
register: query_one

- name: Query a physical domain with uuid
cisco.mso.ndo_physical_domain:
<<: *mso_info
template: ansible_fabric_policy_template
physical_domain_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid

- name: Query all physical domain in the template
cisco.mso.ndo_physical_domain:
<<: *mso_info
Expand All @@ -190,7 +198,9 @@
assert:
that:
- query_one is not changed
- query_one.current.name == "ansible_test_physical_domain_2"
- query_with_uuid is not changed
- query_one.current.name == query_with_uuid.current.name == "ansible_test_physical_domain_2"
- query_one.current.uuid == query_with_uuid.current.uuid
- query_all is not changed
- query_all.current | length == 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@
state: query
register: query_one

- name: Query a route map policy multicast with uuid
cisco.mso.ndo_route_map_policy_multicast:
<<: *mso_info
template: ansible_tenant_template
route_map_policy_uuid: '{{ query_one.current.uuid }}'
state: query
register: query_with_uuid

- name: Query all route map policy multicast in the template
cisco.mso.ndo_route_map_policy_multicast:
<<: *mso_info
Expand All @@ -308,7 +316,9 @@
assert:
that:
- query_one is not changed
- query_one.current.name == "ansible_test_route_map_policy_2"
- query_with_uuid is not changed
- query_one.current.name == query_with_uuid.current.name == "ansible_test_route_map_policy_2"
- query_one.current.uuid == query_with_uuid.current.uuid
- query_all is not changed
- query_all.current | length == 2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
<<: *mso_info
template: ansible_fabric_policy_template
interface_policy_uuid: '{{ nm_update_synce_interface_policy.current.uuid }}'
interface_policy: ansible_test_synce_interface_policy_changed
state: query
register: query_one_uuid

Expand Down
Loading

0 comments on commit 8c6e1a9

Please sign in to comment.