Skip to content
Snippets Groups Projects
Commit 48269f02 authored by Pablo Armingol's avatar Pablo Armingol
Browse files

NBI Inventory

parent 41e52b80
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!150Resolve "(TID) Network device inventory management"
......@@ -23,6 +23,7 @@ RESOURCE_INTERFACES = '__interfaces__'
RESOURCE_NETWORK_INSTANCES = '__network_instances__'
RESOURCE_ROUTING_POLICIES = '__routing_policies__'
RESOURCE_ACL = '__acl__'
RESOURCE_INVENTORY = '__inventory__'
class _Driver:
......
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging, lxml.etree as ET
from typing import Any, Dict, List, Tuple
from .Namespace import NAMESPACES
from .Tools import add_value_from_tag
LOGGER = logging.getLogger(__name__)
XPATH_PORTS = "//ocp:components/ocp:component"
def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
response = []
LOGGER.info("InventoryPrueba")
for xml_component in xml_data.xpath(XPATH_PORTS, namespaces=NAMESPACES):
#LOGGER.info('xml_component = {:s}'.format(str(ET.tostring(xml_component))))
inventory = {}
inventory['name'] = ''
inventory['type'] = ''
inventory['datos'] = {}
component_name = xml_component.find('ocp:name', namespaces=NAMESPACES)
if component_name is None or component_name.text is None: continue
add_value_from_tag(inventory, 'name', component_name)
component_type = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES)
component_type.text = component_type.text.replace('oc-platform-types:','')
if component_type is None: continue
add_value_from_tag(inventory, 'type', component_type)
component_present = xml_component.find('ocptr:transceiver/ocptr:state/ocptr:present', namespaces=NAMESPACES)
if not component_present is None:
add_value_from_tag(inventory['datos'], 'present', component_present)
if 'present' in inventory['datos'] and inventory['datos']['present'] == 'NOT_PRESENT': continue
component_vendor = xml_component.find('ocptr:transceiver/ocptr:state/ocptr:vendor', namespaces=NAMESPACES)
if not component_vendor is None:
add_value_from_tag(inventory['datos'], 'vendor', component_vendor)
component_connector = xml_component.find('ocptr:transceiver/ocptr:state/ocptr:connector-type', namespaces=NAMESPACES)
if not component_connector is None:
component_connector.text = component_connector.text.replace('oc-opt-types:','')
add_value_from_tag(inventory['datos'], 'connector-type', component_connector)
component_serial = xml_component.find('ocptr:transceiver/ocptr:state/ocptr:serial-no', namespaces=NAMESPACES)
if not component_serial is None:
add_value_from_tag(inventory['datos'], 'serial-no', component_serial)
component_form = xml_component.find('ocptr:transceiver/ocptr:state/ocptr:form-factor', namespaces=NAMESPACES)
if not component_form is None:
component_form.text = component_form.text.replace('oc-platform-types:','')
add_value_from_tag(inventory['datos'], 'form-factor', component_form)
component_parent = xml_component.find('ocp:state/ocp:parent', namespaces=NAMESPACES)
component_HW = xml_component.find('ocp:state/ocp:hardware-version', namespaces=NAMESPACES)
if not component_HW is None:
add_value_from_tag(inventory['datos'], 'hardware-version', component_HW)
component_SW = xml_component.find('ocp:state/ocp:software-version', namespaces=NAMESPACES)
if not component_SW is None:
add_value_from_tag(inventory['datos'], 'software-version', component_SW)
component_serial = xml_component.find('ocp:state/ocp:serial-no', namespaces=NAMESPACES)
if not component_serial is None:
add_value_from_tag(inventory['datos'], 'serial-no', component_serial)
component_oper_status = xml_component.find('ocp:state/ocp:oper-status', namespaces=NAMESPACES)
if not component_oper_status is None and inventory['type'] != 'CHASSIS' and inventory['type'] != 'CPU':
component_oper_status.text = component_oper_status.text.replace('oc-platform-types:','')
add_value_from_tag(inventory['datos'], 'oper-status', component_oper_status)
component_parent = xml_component.find('ocp:state/ocp:parent', namespaces=NAMESPACES)
if not component_parent is None and inventory['type'] != 'CHASSIS':
add_value_from_tag(inventory['datos'], 'parent', component_parent)
if 'type' not in inventory: inventory['type'] = '-'
#LOGGER.info('Inventoty = {:s}'.format(str(inventory)))
if len(inventory) == 0: continue
response.append(('/inventory[{:s}]'.format(inventory['name']), inventory))
return response
......@@ -28,6 +28,7 @@ NAMESPACE_POLICY_TYPES = 'http://openconfig.net/yang/policy-types'
NAMESPACE_POLICY_TYPES_2 = 'http://openconfig.net/yang/policy_types'
NAMESPACE_ROUTING_POLICY = 'http://openconfig.net/yang/routing-policy'
NAMESPACE_VLAN = 'http://openconfig.net/yang/vlan'
NAMESPACE_PLATFORM_TRANSCEIVER = 'http://openconfig.net/yang/platform/transceiver'
NAMESPACES = {
'nc' : NAMESPACE_NETCONF,
......@@ -44,4 +45,5 @@ NAMESPACES = {
'ocpt2': NAMESPACE_POLICY_TYPES_2,
'ocrp' : NAMESPACE_ROUTING_POLICY,
'ocv' : NAMESPACE_VLAN,
'ocptr' : NAMESPACE_PLATFORM_TRANSCEIVER,
}
......@@ -16,14 +16,16 @@ import json, logging, lxml.etree as ET, re
from typing import Any, Dict, Optional
from jinja2 import Environment, PackageLoader, select_autoescape
from device.service.driver_api._Driver import (
RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES, RESOURCE_ROUTING_POLICIES, RESOURCE_ACL)
RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES, RESOURCE_ROUTING_POLICIES, RESOURCE_ACL, RESOURCE_INVENTORY)
from .EndPoints import parse as parse_endpoints
from .Interfaces import parse as parse_interfaces, parse_counters
from .NetworkInstances import parse as parse_network_instances
from .RoutingPolicy import parse as parse_routing_policy
from .Acl import parse as parse_acl
from .Inventory import parse as parse_inventory
ALL_RESOURCE_KEYS = [
RESOURCE_INVENTORY,
RESOURCE_ENDPOINTS,
RESOURCE_INTERFACES,
RESOURCE_ROUTING_POLICIES, # routing policies should come before network instances
......@@ -32,6 +34,7 @@ ALL_RESOURCE_KEYS = [
]
RESOURCE_KEY_MAPPINGS = {
RESOURCE_INVENTORY : 'inventory',
RESOURCE_ENDPOINTS : 'component',
RESOURCE_INTERFACES : 'interface',
RESOURCE_NETWORK_INSTANCES: 'network_instance',
......@@ -40,6 +43,7 @@ RESOURCE_KEY_MAPPINGS = {
}
RESOURCE_PARSERS = {
'inventory' : parse_inventory,
'component' : parse_endpoints,
'interface' : parse_interfaces,
'network_instance': parse_network_instances,
......
<components xmlns="http://openconfig.net/yang/platform">
<component/>
</components>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment