diff --git a/plugins/module_utils/mso.py b/plugins/module_utils/mso.py index cd77db1b..b881261e 100644 --- a/plugins/module_utils/mso.py +++ b/plugins/module_utils/mso.py @@ -1469,6 +1469,7 @@ def service_node_ref_str_to_dict(serviceNodeRefStr): templateName=serviceNodeRefTokens[4], ) + def mso_schema_site_contract_service_graph_spec(): return dict( cluster_interface_device=dict(type="str", required=True, aliases=["cluster_device", "device", "device_name"]), diff --git a/plugins/modules/mso_schema_site_contract_service_graph.py b/plugins/modules/mso_schema_site_contract_service_graph.py index d3fba563..bca19e6f 100644 --- a/plugins/modules/mso_schema_site_contract_service_graph.py +++ b/plugins/modules/mso_schema_site_contract_service_graph.py @@ -295,42 +295,48 @@ def main(): elif state == "present": service_graph_ref = dict(schemaId=service_graph_reference_schema_id, serviceGraphName=service_graph, templateName=service_graph_reference_template) service_node_relationship = [] - - for node_index, node in enumerate(node_relationship, 1): - service_node_ref = dict( - schemaId=service_graph_reference_schema_id, - serviceGraphName=service_graph, - serviceNodeName="node{0}".format(node_index), - templateName=service_graph_reference_template, - ) - - consumer_subnet_ips_list = [dict(ip=subnet) for subnet in node.get("consumer_subnet_ips")] if node.get("consumer_subnet_ips") else [] - consumer_connector = dict( - clusterInterface=dict( - dn="uni/tn-{0}/lDevVip-{1}/lIf-{2}".format(tenant, node.get("cluster_interface_device"), node.get("consumer_connector_cluster_interface")) - ), - redirectPolicy=dict( - dn="uni/tn-{0}/svcCont/svcRedirectPol-{1}".format( - node.get("consumer_connector_redirect_policy_tenant") or tenant, node.get("consumer_connector_redirect_policy") - ) - ), - subnets=consumer_subnet_ips_list, - ) - provider_connector = dict( - clusterInterface=dict( - dn="uni/tn-{0}/lDevVip-{1}/lIf-{2}".format(tenant, node.get("cluster_interface_device"), node.get("provider_connector_cluster_interface")) - ), - redirectPolicy=dict( - dn="uni/tn-{0}/svcCont/svcRedirectPol-{1}".format( - node.get("provider_connector_redirect_policy_tenant") or tenant, node.get("provider_connector_redirect_policy") - ) - ), - ) - service_node_relationship.append(dict(consumerConnector=consumer_connector, providerConnector=provider_connector, serviceNodeRef=service_node_ref)) - if mso.site_type == "on-premise": - payload = dict(serviceGraphRef=service_graph_ref, serviceNodesRelationship=service_node_relationship) - else: - payload = dict(serviceGraphRef=service_graph_ref, serviceNodesRelationship=[]) + if node_relationship: + for node_index, node in enumerate(node_relationship, 1): + service_node_ref = dict( + schemaId=service_graph_reference_schema_id, + serviceGraphName=service_graph, + serviceNodeName="node{0}".format(node_index), + templateName=service_graph_reference_template, + ) + + consumer_subnet_ips_list = [dict(ip=subnet) for subnet in node.get("consumer_subnet_ips")] if node.get("consumer_subnet_ips") else [] + consumer_connector = dict( + clusterInterface=dict( + dn="uni/tn-{0}/lDevVip-{1}/lIf-{2}".format( + tenant, node.get("cluster_interface_device"), node.get("consumer_connector_cluster_interface") + ) + ), + redirectPolicy=dict( + dn="uni/tn-{0}/svcCont/svcRedirectPol-{1}".format( + node.get("consumer_connector_redirect_policy_tenant") or tenant, node.get("consumer_connector_redirect_policy") + ) + ), + subnets=consumer_subnet_ips_list, + ) + provider_connector = dict( + clusterInterface=dict( + dn="uni/tn-{0}/lDevVip-{1}/lIf-{2}".format( + tenant, node.get("cluster_interface_device"), node.get("provider_connector_cluster_interface") + ) + ), + redirectPolicy=dict( + dn="uni/tn-{0}/svcCont/svcRedirectPol-{1}".format( + node.get("provider_connector_redirect_policy_tenant") or tenant, node.get("provider_connector_redirect_policy") + ) + ), + ) + service_node_relationship.append( + dict(consumerConnector=consumer_connector, providerConnector=provider_connector, serviceNodeRef=service_node_ref) + ) + if mso.site_type == "on-premise": + payload = dict(serviceGraphRef=service_graph_ref, serviceNodesRelationship=service_node_relationship) + else: + payload = dict(serviceGraphRef=service_graph_ref, serviceNodesRelationship=[]) mso.sanitize(payload, collate=True) diff --git a/plugins/modules/mso_schema_site_service_graph.py b/plugins/modules/mso_schema_site_service_graph.py index b2bcfc89..22fe4a6e 100644 --- a/plugins/modules/mso_schema_site_service_graph.py +++ b/plugins/modules/mso_schema_site_service_graph.py @@ -351,9 +351,7 @@ def main(): device_payload["providerConnectorType"] = AZURE_L4L7_CONNECTOR_TYPE_MAP.get(provider_connector_type) device_payload["consumerConnectorType"] = AZURE_L4L7_CONNECTOR_TYPE_MAP.get(consumer_connector_type) - devices_payload.append(device_payload) - - devices_payload.append(device_payload) + devices_payload.append(device_payload) payload = dict( serviceGraphRef=dict( diff --git a/tests/integration/targets/mso_schema_site_service_graph/tasks/main.yml b/tests/integration/targets/mso_schema_site_service_graph/tasks/main.yml index 708de701..3d7cd522 100644 --- a/tests/integration/targets/mso_schema_site_service_graph/tasks/main.yml +++ b/tests/integration/targets/mso_schema_site_service_graph/tasks/main.yml @@ -65,15 +65,10 @@ state: absent loop: - '{{ mso_site | default("ansible_test") }}' - - - name: Ensure Azure sites removed from tenant ansible_test # Azure Task - cisco.mso.mso_tenant_site: - <<: *mso_info - tenant: ansible_test - site: "{{ item }}" - state: absent - loop: + - 'aws_{{ mso_site | default("ansible_test") }}' + - 'azure_{{ mso_site | default("ansible_test") }}' - '{{ mso_site | default("azure_ansible_test_2") }}' + ignore_errors: true - name: Ensure tenant ansible_test exist cisco.mso.mso_tenant: @@ -83,8 +78,6 @@ - "{{ mso_username }}" state: present -<<<<<<< HEAD -======= - name: Associate site with ansible_test cisco.mso.mso_tenant_site: <<: *mso_info @@ -92,7 +85,6 @@ site: '{{ mso_site | default("ansible_test") }}' state: present ->>>>>>> 7992dcd ([minor_change] Added mso_schema_site_contract_service_graph module to manage site contract service graph) - name: Set ansible_network_os to cisco.aci.aci and ansible_connection to local ansible.builtin.set_fact: ansible_connection: local