Commit 1b5e1ea1 authored by Luis/TID's avatar Luis/TID
Browse files

working

parent 19f2281b
Loading
Loading
Loading
Loading

file.txt

0 → 100644
+392 −0

File added.

Preview size limit exceeded, changes collapsed.

+12 −23
Original line number Diff line number Diff line
@@ -20,14 +20,23 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
        if interface_name is None or interface_name.text is None: continue
        add_value_from_tag(interface, 'name', interface_name)

        interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
        add_value_from_tag(interface, 'type', interface_type)
#        interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
#        add_value_from_tag(interface, 'type', interface_type)

        interface_mtu = xml_interface.find('oci:config/oci:mtu', namespaces=NAMESPACES)
        add_value_from_tag(interface, 'mtu',interface_mtu)
        

        interface_description = xml_interface.find('oci:config/oci:description', namespaces=NAMESPACES)
        add_value_from_tag(interface, 'description', interface_description)

        LOGGER.info('AAAAAAAAAAAAAAAAAAAAA: {:s}'.format(str(interface)))

        for xml_subinterface in xml_interface.xpath(XPATH_SUBINTERFACES, namespaces=NAMESPACES):
            LOGGER.info('xml_subinterface = {:s}'.format(str(ET.tostring(xml_subinterface))))

            subinterface = {}

            add_value_from_tag(subinterface, 'name', interface_name)
            subinterface_index = xml_subinterface.find('oci:index', namespaces=NAMESPACES)
            if subinterface_index is None or subinterface_index.text is None: continue
            add_value_from_tag(subinterface, 'index', subinterface_index)
@@ -35,26 +44,6 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
            vlan_id = xml_subinterface.find('ocv:vlan/ocv:config/ocv:vlan-id', namespaces=NAMESPACES)
            add_value_from_tag(subinterface, 'vlan_id', vlan_id, cast=int)

            ipv4_addresses = []
            for xml_ipv4_address in xml_subinterface.xpath(XPATH_IPV4ADDRESSES, namespaces=NAMESPACES):
                LOGGER.info('xml_ipv4_address = {:s}'.format(str(ET.tostring(xml_ipv4_address))))

                ipv4_address = {}

                origin = xml_ipv4_address.find('ociip:state/ociip:origin', namespaces=NAMESPACES)
                add_value_from_tag(ipv4_address, 'origin', origin)

                address = xml_ipv4_address.find('ociip:state/ociip:ip', namespaces=NAMESPACES)
                add_value_from_tag(ipv4_address, 'ip', address)

                prefix = xml_ipv4_address.find('ociip:state/ociip:prefix-length', namespaces=NAMESPACES)
                add_value_from_tag(ipv4_address, 'prefix_length', prefix)

                if len(ipv4_address) == 0: continue
                ipv4_addresses.append(ipv4_address)

            add_value_from_collection(subinterface, 'ipv4_addresses', ipv4_addresses)

            if len(subinterface) == 0: continue
            resource_key = 'interface[{:s}]/subinterface[{:s}]'.format(interface['name'], subinterface['index'])
            response.append((resource_key, subinterface))
+74 −0
Original line number Diff line number Diff line
import logging, lxml.etree as ET
from typing import Any, Dict, List, Tuple
from .Namespace import NAMESPACES
from .Tools import add_value_from_collection, add_value_from_tag

LOGGER = logging.getLogger(__name__)

XPATH_INTERFACES    = "//oci:interfaces/oci:interface"
XPATH_SUBINTERFACES = ".//oci:subinterfaces/oci:subinterface"
XPATH_IPV4ADDRESSES = ".//ociip:ipv4/ociip:addresses/ociip:address"

def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
    response = []
    for xml_interface in xml_data.xpath(XPATH_INTERFACES, namespaces=NAMESPACES):
        LOGGER.info('xml_interface = {:s}'.format(str(ET.tostring(xml_interface))))

        interface = {}

        interface_name = xml_interface.find('oci:name', namespaces=NAMESPACES)
        if interface_name is None or interface_name.text is None: continue
        add_value_from_tag(interface, 'name', interface_name)

#        interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
#        add_value_from_tag(interface, 'type', interface_type)

        interface_mtu = xml_interface.find('oci:config/oci:mtu', namespaces=NAMESPACES)
        add_value_from_tag(interface, 'mtu',interface_mtu)
        

        interface_description = xml_interface.find('oci:config/oci:description', namespaces=NAMESPACES)
        add_value_from_tag(interface, 'description', interface_description)

        LOGGER.info('AAAAAAAAAAAAAAAAAAAAA: {:s}'.format(str(interface)))

        for xml_subinterface in xml_interface.xpath(XPATH_SUBINTERFACES, namespaces=NAMESPACES):
            LOGGER.info('xml_subinterface = {:s}'.format(str(ET.tostring(xml_subinterface))))

            subinterface = {}

            subinterface_index = xml_subinterface.find('oci:index', namespaces=NAMESPACES)
            if subinterface_index is None or subinterface_index.text is None: continue
            add_value_from_tag(subinterface, 'index', subinterface_index)

            vlan_id = xml_subinterface.find('ocv:vlan/ocv:config/ocv:vlan-id', namespaces=NAMESPACES)
            add_value_from_tag(subinterface, 'vlan_id', vlan_id, cast=int)

            ipv4_addresses = []
            for xml_ipv4_address in xml_subinterface.xpath(XPATH_IPV4ADDRESSES, namespaces=NAMESPACES):
                LOGGER.info('xml_ipv4_address = {:s}'.format(str(ET.tostring(xml_ipv4_address))))

                ipv4_address = {}

                origin = xml_ipv4_address.find('ociip:state/ociip:origin', namespaces=NAMESPACES)
                add_value_from_tag(ipv4_address, 'origin', origin)

                address = xml_ipv4_address.find('ociip:state/ociip:ip', namespaces=NAMESPACES)
                add_value_from_tag(ipv4_address, 'ip', address)

                prefix = xml_ipv4_address.find('ociip:state/ociip:prefix-length', namespaces=NAMESPACES)
                add_value_from_tag(ipv4_address, 'prefix_length', prefix)

                if len(ipv4_address) == 0: continue
                ipv4_addresses.append(ipv4_address)

            add_value_from_collection(subinterface, 'ipv4_addresses', ipv4_addresses)

            if len(subinterface) == 0: continue
            resource_key = 'interface[{:s}]/subinterface[{:s}]'.format(interface['name'], subinterface['index'])
            response.append((resource_key, subinterface))

        if len(interface) == 0: continue
        response.append(('interface[{:s}]'.format(interface['name']), interface))

    return response
+0 −2
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@
        {% if operation is not defined or operation != 'delete' %}
        <config>
            <name>{{name}}</name>
            <description>{{description}}</description>
            <mtu>{{mtu}}</mtu>
        </config>
        {% endif %}
        <subinterfaces>
+2 −2
Original line number Diff line number Diff line
@@ -7,8 +7,8 @@
                {% if operation is not defined or operation != 'delete' %}
                <config>
                    <id>{{id}}</id>
                    <interface>13/1/3</interface>
                    <subinterface>500</subinterface>
                    <interface>13/1/2</interface>
                    <subinterface>1</subinterface>
                </config>
                {% endif %}
            </interface>
Loading