Commit 3f935135 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Support for adding CISCO devices

parent 1d46bc00
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -31,7 +31,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
        component_type = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES)
        component_type = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES)
        if component_type is None or component_type.text is None: continue
        if component_type is None or component_type.text is None: continue
        component_type = component_type.text
        component_type = component_type.text
        if component_type not in {'PORT', 'oc-platform-types:PORT'}: continue
        if component_type not in {'PORT', 'oc-platform-types:PORT', 'idx:PORT'}: continue


        LOGGER.info('PORT xml_component = {:s}'.format(str(ET.tostring(xml_component))))
        LOGGER.info('PORT xml_component = {:s}'.format(str(ET.tostring(xml_component))))


+14 −4
Original line number Original line Diff line number Diff line
@@ -15,7 +15,7 @@
import logging, lxml.etree as ET
import logging, lxml.etree as ET
from typing     import Any, Dict, List, Tuple
from typing     import Any, Dict, List, Tuple
from .Namespace import NAMESPACES
from .Namespace import NAMESPACES
from .Tools import add_value_from_collection, add_value_from_tag
from .Tools     import add_value_from_tag


LOGGER = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)


@@ -37,8 +37,18 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
        #interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
        #interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
        #add_value_from_tag(interface, 'type', interface_type)
        #add_value_from_tag(interface, 'type', interface_type)


        if xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES) is not None:
            interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
            interface_type = xml_interface.find('oci:config/oci:type', namespaces=NAMESPACES)
        interface_type.text = interface_type.text.replace('ianaift:','')
        elif xml_interface.find('oci:state/oci:type', namespaces=NAMESPACES) is not None:
            interface_type = xml_interface.find('oci:state/oci:type', namespaces=NAMESPACES)
        else:
            interface_type = ''
            
        # Get the type of interface according to the vendor's type
        if 'ianaift:' in interface_type.text:
            interface_type.text = interface_type.text.replace('ianaift:', '')                       #ADVA
        elif 'idx'in interface_type.text:
            interface_type.text = interface_type.text.replace('idx:', '')                           #CISCO
        add_value_from_tag(interface, 'type', interface_type)
        add_value_from_tag(interface, 'type', interface_type)


        interface_mtu = xml_interface.find('oci:config/oci:mtu', namespaces=NAMESPACES)
        interface_mtu = xml_interface.find('oci:config/oci:mtu', namespaces=NAMESPACES)
+15 −1
Original line number Original line Diff line number Diff line
@@ -41,9 +41,23 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
        if ni_name is None or ni_name.text is None: continue
        if ni_name is None or ni_name.text is None: continue
        add_value_from_tag(network_instance, 'name', ni_name)
        add_value_from_tag(network_instance, 'name', ni_name)


        '''
        ni_type = xml_network_instance.find('ocni:config/ocni:type', namespaces=NAMESPACES)
        ni_type = xml_network_instance.find('ocni:config/ocni:type', namespaces=NAMESPACES)
        ni_type.text = ni_type.text.replace('oc-ni-types:','')
        ni_type.text = ni_type.text.replace('oc-ni-types:','')
        add_value_from_tag(network_instance, 'type', ni_type)
        add_value_from_tag(network_instance, 'type', ni_type)
        '''
        
        if xml_network_instance.find('ocni:config/ocni:type', namespaces=NAMESPACES) is not None:
            ni_type = xml_network_instance.find('ocni:config/ocni:type', namespaces=NAMESPACES)
        elif xml_network_instance.find('oci:state/oci:type', namespaces=NAMESPACES) is not None:
            ni_type = xml_network_instance.find('oci:state/oci:type', namespaces=NAMESPACES)
        else:
            continue
        if 'oc-ni-types:' in ni_type.text:
            ni_type.text = ni_type.text.replace('oc-ni-types:', '')                 #ADVA
        elif 'idx'in ni_type.text:
            ni_type.text = ni_type.text.replace('idx:', '')                         #CISCO
        add_value_from_tag(network_instance, 'type', ni_type)
        
        
        ni_router_id = xml_network_instance.find('ocni:config/ocni:router-id', namespaces=NAMESPACES)
        ni_router_id = xml_network_instance.find('ocni:config/ocni:router-id', namespaces=NAMESPACES)
        add_value_from_tag(network_instance, 'router_id', ni_router_id)
        add_value_from_tag(network_instance, 'router_id', ni_router_id)
+6 −4
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:


        for xml_statement in xml_policy_definition.xpath(XPATH_PD_STATEMENTS, namespaces=NAMESPACES):
        for xml_statement in xml_policy_definition.xpath(XPATH_PD_STATEMENTS, namespaces=NAMESPACES):
            statement_name = xml_statement.find('ocrp:name', namespaces=NAMESPACES)
            statement_name = xml_statement.find('ocrp:name', namespaces=NAMESPACES)
            if len(statement_name) != 0:                                                                        #FIX: In case there is a route policy defined without a statement name
                add_value_from_tag(policy_definition, 'statement_name', statement_name)
                add_value_from_tag(policy_definition, 'statement_name', statement_name)


            for xml_condition in xml_statement.xpath(XPATH_PD_ST_CONDITIONS, namespaces=NAMESPACES):
            for xml_condition in xml_statement.xpath(XPATH_PD_ST_CONDITIONS, namespaces=NAMESPACES):
@@ -58,6 +59,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
                policy_result = xml_action.find('ocbp:config/ocbp:policy-result', namespaces=NAMESPACES)
                policy_result = xml_action.find('ocbp:config/ocbp:policy-result', namespaces=NAMESPACES)
                add_value_from_tag(policy_definition, 'policy_result', policy_result)
                add_value_from_tag(policy_definition, 'policy_result', policy_result)


        if len(statement_name) != 0:                                                                            #FIX: In case there is a route policy defined without a statement name
            resource_key = '/routing_policy/policy_definition[{:s}]/statement[{:s}]'.format(
            resource_key = '/routing_policy/policy_definition[{:s}]/statement[{:s}]'.format(
                policy_definition['policy_name'], policy_definition['statement_name'])
                policy_definition['policy_name'], policy_definition['statement_name'])
            response.append((resource_key, copy.deepcopy(policy_definition)))
            response.append((resource_key, copy.deepcopy(policy_definition)))