<commit_before>#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
#

ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}

DOCUMENTATION = '''
---
module: ce_vxlan_tunnel
version_added: "2.4"
short_description: Manages VXLAN tunnel configuration on HUAWEI CloudEngine devices.
description:
    - This module offers the ability to set the VNI and mapped to the BD,
      and configure an ingress replication list on HUAWEI CloudEngine devices.
author:
    - <NAME> (@CloudEngine-Ansible)
options:
    bridge_domain_id:
        description:
            - Specifies a bridge domain ID. The value is an integer ranging from 1 to 16777215.
    vni_id:
        description:
            - Specifies a VXLAN network identifier (VNI) ID. The value is an integer ranging from 1 to 16000000.
    nve_name:
        description:
            - Specifies the number of an NVE interface. The value ranges from 1 to 2.
    nve_mode:
        description:
            - Specifies the working mode of an NVE interface.
        choices: ['mode-l2','mode-l3']
    peer_list_ip:
        description:
            - Specifies the IP address of a remote VXLAN tunnel endpoints (VTEP).
              The value is in dotted decimal notation.
    protocol_type:
        description:
            - The operation type of routing protocol.
        choices: ['bgp','null']
    source_ip:
        description:
            - Specifies an IP address for a source VTEP. The value is in dotted decimal notation.
    state:
        description:
            - Manage the state of the resource.
        default: present
        choices: ['present','absent']
'''
EXAMPLES = '''
- name: vxlan tunnel module test
  hosts: ce128
  connection: local
  gather_facts: no
  vars:
    cli:
      host: "{{ inventory_hostname }}"
      port: "{{ ansible_ssh_port }}"
      username: "{{ username }}"
      password: "{{ password }}"
      transport: cli

  tasks:

  - name: Make sure nve_name is exist, ensure vni_id and protocol_type is configured on Nve1 interface.
    ce_vxlan_tunnel:
      nve_name: Nve1
      vni_id: 100
      protocol_type: bgp
      state: present
      provider: "{{ cli }}"
'''

RETURN = '''
proposed:
    description: k/v pairs of parameters passed into module
    returned: always
    type: dict
    sample: {nve_interface_name": "Nve1", nve_mode": "mode-l2", "source_ip": "0.0.0.0"}
existing:
    description:
        - k/v pairs of existing rollback
    returned: always
    type: dict
    sample: {nve_interface_name": "Nve1", nve_mode": "mode-l3", "source_ip": "0.0.0.0"}

updates:
    description: command sent to the device
    returned: always
    type: list
    sample: ["interface Nve1",
             "mode l3"]
changed:
    description: check to see if a change was made on the device
    returned: always
    type: boolean
    sample: true
end_state:
    description: k/v pairs of configuration after module execution
    returned: always
    type: dict
    sample: {nve_interface_name": "Nve1", nve_mode": "mode-l3", "source_ip": "0.0.0.0"}
'''

from xml.etree import ElementTree
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cloudengine.ce import get_nc_config, set_nc_config, get_config, ce_argument_spec

CE_NC_GET_VNI_BD_INFO = """
<filter type="subtree">
  <nvo3 xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
    <nvo3Vni2Bds>
      <nvo3Vni2Bd>
        <vniId></vniId>
        <bdId></bdId>
      </nvo3Vni2Bd>
    </nvo3Vni2Bds>
  </nvo3>
</filter>
"""

CE_NC_GET_NVE_INFO = """
<filter type="subtree">
  <nvo3 xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
    <nvo3Nves>
      <nvo3Nve>
        <ifName>%s</ifName>
      </nvo3Nve>
    </nvo3Nves>
  </nvo3>
</filter>
</filter>
"""

CE_NC_MERGE_VNI_BD_ID = """
<config>
  <nvo3 xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
    <nvo3Vni2Bds>
      <nvo3Vni2Bd operation="create">
        <vniId>%s</vniId>
        <bdId>%s</bdId>
      </nvo3Vni2Bd>
    </nvo3Vni2Bds>
  </nvo3>
</config>
"""
<commit_msg>ce_vxlan_tunnel: remove redundant xml end tag (#47806)<commit_after>#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
#

ANSIBLE_METADATA = {'metadata_version': '1.1',
                    'status': ['preview'],
                    'supported_by': 'community'}

DOCUMENTATION = '''
---
module: ce_vxlan_tunnel
version_added: "2.4"
short_description: Manages VXLAN tunnel configuration on HUAWEI CloudEngine devices.
description:
    - This module offers the ability to set the VNI and mapped to the BD,
      and configure an ingress replication list on HUAWEI CloudEngine devices.
author:
    - <NAME> (@CloudEngine-Ansible)
options:
    bridge_domain_id:
        description:
            - Specifies a bridge domain ID. The value is an integer ranging from 1 to 16777215.
    vni_id:
        description:
            - Specifies a VXLAN network identifier (VNI) ID. The value is an integer ranging from 1 to 16000000.
    nve_name:
        description:
            - Specifies the number of an NVE interface. The value ranges from 1 to 2.
    nve_mode:
        description:
            - Specifies the working mode of an NVE interface.
        choices: ['mode-l2','mode-l3']
    peer_list_ip:
        description:
            - Specifies the IP address of a remote VXLAN tunnel endpoints (VTEP).
              The value is in dotted decimal notation.
    protocol_type:
        description:
            - The operation type of routing protocol.
        choices: ['bgp','null']
    source_ip:
        description:
            - Specifies an IP address for a source VTEP. The value is in dotted decimal notation.
    state:
        description:
            - Manage the state of the resource.
        default: present
        choices: ['present','absent']
'''
EXAMPLES = '''
- name: vxlan tunnel module test
  hosts: ce128
  connection: local
  gather_facts: no
  vars:
    cli:
      host: "{{ inventory_hostname }}"
      port: "{{ ansible_ssh_port }}"
      username: "{{ username }}"
      password: "{{ password }}"
      transport: cli

  tasks:

  - name: Make sure nve_name is exist, ensure vni_id and protocol_type is configured on Nve1 interface.
    ce_vxlan_tunnel:
      nve_name: Nve1
      vni_id: 100
      protocol_type: bgp
      state: present
      provider: "{{ cli }}"
'''

RETURN = '''
proposed:
    description: k/v pairs of parameters passed into module
    returned: always
    type: dict
    sample: {nve_interface_name": "Nve1", nve_mode": "mode-l2", "source_ip": "0.0.0.0"}
existing:
    description:
        - k/v pairs of existing rollback
    returned: always
    type: dict
    sample: {nve_interface_name": "Nve1", nve_mode": "mode-l3", "source_ip": "0.0.0.0"}

updates:
    description: command sent to the device
    returned: always
    type: list
    sample: ["interface Nve1",
             "mode l3"]
changed:
    description: check to see if a change was made on the device
    returned: always
    type: boolean
    sample: true
end_state:
    description: k/v pairs of configuration after module execution
    returned: always
    type: dict
    sample: {nve_interface_name": "Nve1", nve_mode": "mode-l3", "source_ip": "0.0.0.0"}
'''

from xml.etree import ElementTree
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cloudengine.ce import get_nc_config, set_nc_config, get_config, ce_argument_spec

CE_NC_GET_VNI_BD_INFO = """
<filter type="subtree">
  <nvo3 xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
    <nvo3Vni2Bds>
      <nvo3Vni2Bd>
        <vniId></vniId>
        <bdId></bdId>
      </nvo3Vni2Bd>
    </nvo3Vni2Bds>
  </nvo3>
</filter>
"""

CE_NC_GET_NVE_INFO = """
<filter type="subtree">
  <nvo3 xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
    <nvo3Nves>
      <nvo3Nve>
        <ifName>%s</ifName>
      </nvo3Nve>
    </nvo3Nves>
  </nvo3>
</filter>
"""

CE_NC_MERGE_VNI_BD_ID = """
<config>
  <nvo3 xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
    <nvo3Vni2Bds>
      <nvo3Vni2Bd operation="create">
        <vniId>%s</vniId>
        <bdId>%s</bdId>
      </nvo3Vni2Bd>
    </nvo3Vni2Bds>
  </nvo3>
</config>
"""

{'fraction_non_alphanumeric': 0.10860803968171955, 'fraction_numerical': 0.019737521959284902, 'mean_word_length': 2.835909631391201, 'pattern_counts': {'":': 18, '<': 76, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 9}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6644710', 'n_tokens_mistral': 3260, 'n_tokens_neox': 3169, 'n_words': 967}