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

Merge branch 'feat/173-tid-add-inventory-nbi-to-webui' of...

Merge branch 'feat/173-tid-add-inventory-nbi-to-webui' of https://labs.etsi.org/rep/tfs/controller into feat/173-tid-add-inventory-nbi-to-webui
parents e1f2aef3 35b24718
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!251Resolve "(TID) Add inventory NBI to WebUI"
...@@ -12,13 +12,14 @@ ...@@ -12,13 +12,14 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import libyang, os
from common.proto.context_pb2 import Device from common.proto.context_pb2 import Device
from typing import Dict, Optional from typing import Dict, Optional
import datetime
import json import json
import logging import logging
import libyang
import os
import re import re
import datetime
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
YANG_DIR = os.path.join(os.path.dirname(__file__), 'yang') YANG_DIR = os.path.join(os.path.dirname(__file__), 'yang')
...@@ -88,9 +89,6 @@ class YangHandler: ...@@ -88,9 +89,6 @@ class YangHandler:
if component_type == "FRU" : if component_type == "FRU" :
component_type = "slack" 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 = component_type.replace("_", "-").lower()
component_type = 'iana-hardware:' + component_type component_type = 'iana-hardware:' + component_type
...@@ -101,14 +99,15 @@ class YangHandler: ...@@ -101,14 +99,15 @@ class YangHandler:
physical_index += 1 physical_index += 1
component_new.create_path('description', attributes["description"]) component_new.create_path('description', attributes["description"].replace('/"',""))
parent_component_references = component_new.create_path('parent-component-references') if "CHASSIS" not in component.type:
parent = parent_component_references.create_path('component-reference[index="{:d}"]'.format(physical_index)) parent_component_references = component_new.create_path('parent-component-references')
for component2 in device.components: parent = parent_component_references.create_path('component-reference[index="{:d}"]'.format(physical_index))
if component.parent == component2.name : for component_parent in device.components:
parent.create_path('uuid', component2.component_uuid.uuid) if component.parent == component_parent.name :
break parent.create_path('uuid', component_parent.component_uuid.uuid)
break
if attributes["mfg-date"] != "": if attributes["mfg-date"] != "":
mfg_date = self.convert_to_iso_date(attributes["mfg-date"]) mfg_date = self.convert_to_iso_date(attributes["mfg-date"])
...@@ -119,11 +118,22 @@ class YangHandler: ...@@ -119,11 +118,22 @@ class YangHandler:
component_new.create_path('firmware-rev', attributes["firmware-version"]) component_new.create_path('firmware-rev', attributes["firmware-version"])
component_new.create_path('serial-num', attributes["serial-num"]) component_new.create_path('serial-num', attributes["serial-num"])
component_new.create_path('mfg-name', attributes["mfg-name"]) 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"]: if attributes["id"]:
try: try:
parent_rel_pos = int(attributes["id"].replace("\"", "")) if "CHASSIS" in component.type :
component_new.create_path('parent-rel-pos', parent_rel_pos) 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: except ValueError:
LOGGER.info('ERROR:{:s} '.format(component.name ))
continue continue
component_new.create_path('uri', component.name) component_new.create_path('uri', component.name)
...@@ -131,15 +141,9 @@ class YangHandler: ...@@ -131,15 +141,9 @@ class YangHandler:
component_new.create_path('uuid', component.component_uuid.uuid) component_new.create_path('uuid', component.component_uuid.uuid)
contained_child = [] for child in device.components:
for component2 in device.components: if component.name == child.parent :
if component.name == component2.parent : component_new.create_path('contained-child', child.component_uuid.uuid)
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)
return json.loads(hardware.print_mem('json')) return json.loads(hardware.print_mem('json'))
......
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