Commit cc8c3f8e authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Code cleanup

parent f991f748
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -187,8 +187,6 @@ message Component { //Defined previously to this section
  string parent         = 5;
}

// -----------------------------------------------------

message DeviceConfig {
  repeated ConfigRule config_rules = 1;
}
+1 −4
Original line number Diff line number Diff line


# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +14,6 @@

import datetime, json, logging
from sqlalchemy import delete
#from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.orm import Session
from typing import Dict, List, Optional, Set
@@ -63,7 +60,7 @@ def compose_components_data(
                'device_uuid'   : device_uuid,
                'name'          : name,
                'type'          : type_,
                'attributes'    : json.dumps(attributes),  #Store the remaining fields in 'attributes'
                'attributes'    : json.dumps(attributes),
                'parent'        : parent,
                'created_at'    : now,
                'updated_at'    : now,
+1 −4
Original line number Diff line number Diff line
@@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime, logging
import json
import datetime, logging, json
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Session, selectinload, sessionmaker
@@ -55,7 +54,6 @@ def device_list_objs(db_engine : Engine) -> DeviceList:
            .options(selectinload(DeviceModel.config_rules))\
            .options(selectinload(DeviceModel.components))\
            .all()
            #.options(selectinload(DeviceModel.components))\
        return [obj.dump() for obj in obj_list]
    devices = run_transaction(sessionmaker(bind=db_engine), callback)
    return DeviceList(devices=devices)
@@ -67,7 +65,6 @@ def device_get(db_engine : Engine, request : DeviceId) -> Device:
            .options(selectinload(DeviceModel.endpoints))\
            .options(selectinload(DeviceModel.config_rules))\
            .filter_by(device_uuid=device_uuid).one_or_none()
            #.options(selectinload(DeviceModel.components))\
        return None if obj is None else obj.dump()
    obj = run_transaction(sessionmaker(bind=db_engine), callback)
    if obj is None:
+13 −14
Original line number Diff line number Diff line
@@ -19,20 +19,19 @@ from sqlalchemy.orm import relationship
from typing import Dict
from ._Base import _Base                                                

class ComponentModel(_Base):                                            #Inherited functionality from the base class _Base 
    __tablename__ = 'device_component'                                  #Name of the table in the DB associtaed with this model
class ComponentModel(_Base):
    __tablename__ = 'device_component'
    
    component_uuid  = Column(UUID(as_uuid=False), primary_key=True)     #Unique identifier that serves as a primary key for this table
    device_uuid     = Column(ForeignKey('device.device_uuid',ondelete='CASCADE' ), nullable=False, index=True)  #Foreign Key relationship with the field device_uuid from the Device table (CASCADE' behavior for deletion, meaning when a device is deleted, its components will also be dele)
    name            = Column(String, nullable=False)                    #String field that stores the name of the component
    type            = Column(String, nullable=False)                    #String field that stores the type of the component
    attributes      = Column(String, nullable=False)                    #String field that stores the attributes of the component 
    parent          = Column(String, nullable=False)                    #String field that stores the parent of the component 
    created_at      = Column(DateTime, nullable=False)                  #Stores the creaton timestamp for the component
    updated_at      = Column(DateTime, nullable=False)                  #Stores the last upadted timestamp for the component
    component_uuid  = Column(UUID(as_uuid=False), primary_key=True)
    device_uuid     = Column(ForeignKey('device.device_uuid',ondelete='CASCADE' ), nullable=False, index=True)
    name            = Column(String, nullable=False)
    type            = Column(String, nullable=False)
    attributes      = Column(String, nullable=False)
    parent          = Column(String, nullable=False)
    created_at      = Column(DateTime, nullable=False)
    updated_at      = Column(DateTime, nullable=False)
    
    device           = relationship('DeviceModel', back_populates='components')# lazy='selectin'#Defines a relationship between ComponentModel and DeviceModel
    #Represents a 1:n relationship where 1 device -> N components // The relationship is defined by the FK device_uuid
    device           = relationship('DeviceModel', back_populates='components')
    def dump_id(self) -> Dict:
        return{
            'device_id'     : self.device.dump_id(),
+23 −29
Original line number Diff line number Diff line
@@ -12,6 +12,14 @@
# 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"

"""
#Method Name: parse
@@ -42,19 +50,8 @@ the dictionary.
#Return: 
    List[Tuple[str, Dict[str, Any]]] The response list containing the tuples (path, dictionary) 
    with the information extracted from the XML document components is returned.

"""


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.debug("InventoryPrueba")
@@ -126,7 +123,6 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
            add_value_from_tag(inventory['attributes'], 'mfg-date', component_mfg_date)

        #Transceiver Information
        
        component_serial_t = xml_component.find('ocptr:transceiver/ocptr:state/ocptr:serial-no', namespaces=NAMESPACES)
        if not component_serial_t is None:
            add_value_from_tag(inventory['attributes'], 'serial-num', component_serial_t)
@@ -152,8 +148,6 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:

        component_reference.extend([parent_types[inventory['parent-component-references']]])
        
        

        response.append(('/inventory/{:s}'.format(inventory['name']), inventory))

        for tupla in response: