diff --git a/src/nbi/service/rest_server/nbi_plugins/ietf_hardware/YangHandler.py b/src/nbi/service/rest_server/nbi_plugins/ietf_hardware/YangHandler.py index 4ddf8522a20c869bef056723e0bda0c65305f1a5..aa0a90908dabefa2e6fbeb59539bc5cbdec8eb4b 100644 --- a/src/nbi/service/rest_server/nbi_plugins/ietf_hardware/YangHandler.py +++ b/src/nbi/service/rest_server/nbi_plugins/ietf_hardware/YangHandler.py @@ -12,13 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import libyang, os from common.proto.context_pb2 import Device from typing import Dict, Optional +import datetime import json import logging +import libyang +import os import re -import datetime LOGGER = logging.getLogger(__name__) YANG_DIR = os.path.join(os.path.dirname(__file__), 'yang') @@ -88,9 +89,6 @@ class YangHandler: if component_type == "FRU" : component_type = "slack" - component_new.create_path('is-fru', True) - else : - component_new.create_path('is-fru', False) component_type = component_type.replace("_", "-").lower() component_type = 'iana-hardware:' + component_type @@ -101,14 +99,15 @@ class YangHandler: physical_index += 1 - component_new.create_path('description', attributes["description"]) - - parent_component_references = component_new.create_path('parent-component-references') - parent = parent_component_references.create_path('component-reference[index="{:d}"]'.format(physical_index)) - for component2 in device.components: - if component.parent == component2.name : - parent.create_path('uuid', component2.component_uuid.uuid) - break + component_new.create_path('description', attributes["description"].replace('/"',"")) + + if "CHASSIS" not in component.type: + parent_component_references = component_new.create_path('parent-component-references') + parent = parent_component_references.create_path('component-reference[index="{:d}"]'.format(physical_index)) + for component_parent in device.components: + if component.parent == component_parent.name : + parent.create_path('uuid', component_parent.component_uuid.uuid) + break if attributes["mfg-date"] != "": mfg_date = self.convert_to_iso_date(attributes["mfg-date"]) @@ -119,11 +118,22 @@ class YangHandler: component_new.create_path('firmware-rev', attributes["firmware-version"]) component_new.create_path('serial-num', attributes["serial-num"]) component_new.create_path('mfg-name', attributes["mfg-name"]) + if attributes["removable"]: + removable = attributes["removable"].lower() + if 'true' in removable: + component_new.create_path('is-fru', True) + elif 'false' in removable: + component_new.create_path('is-fru', False) + if attributes["id"]: try: - parent_rel_pos = int(attributes["id"].replace("\"", "")) - component_new.create_path('parent-rel-pos', parent_rel_pos) + if "CHASSIS" in component.type : + component_new.create_path('parent-rel-pos', 0) + else: + parent_rel_pos = int(attributes["id"].replace("\"", "")) + component_new.create_path('parent-rel-pos', parent_rel_pos) except ValueError: + LOGGER.info('ERROR:{:s} '.format(component.name )) continue component_new.create_path('uri', component.name) @@ -131,15 +141,9 @@ class YangHandler: component_new.create_path('uuid', component.component_uuid.uuid) - contained_child = [] - for component2 in device.components: - if component.name == component2.parent : - child_uuid = component2.component_uuid.uuid.strip("'") - contained_child.append(child_uuid) - LOGGER.info('parent: {:s}'.format(str(component))) - LOGGER.info('child: {:s}'.format(str(component2))) - - component_new.create_path('contained-child', contained_child) + for child in device.components: + if component.name == child.parent : + component_new.create_path('contained-child', child.component_uuid.uuid) return json.loads(hardware.print_mem('json'))