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

Fix formatting of "component". Code cleanup

parent 167a42fa
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!150Resolve "(TID) Network device inventory management"
......@@ -40,16 +40,16 @@ def compose_components_data(
dict_components : List[Dict] = list()
for position,component in enumerate(components):
str_kind = component.WhichOneof('config_rule')
message = (grpc_message_to_json_string(getattr(component, str_kind, {})))
data = json.loads(message)
resource_key = data["resource_key"]
message = (grpc_message_to_json_string(getattr(component, str_kind, {})))
data = json.loads(message)
resource_key = data["resource_key"]
resource_value = data["resource_value"]
if '/inventory' in resource_key:
resource_value_data = json.loads(resource_value)
name = resource_value_data.pop('name', None)
type_ = resource_value_data.pop('class', None)
parent = resource_value_data.pop('parent-component-references', None)
attributes = resource_value_data.pop('attributes', {})
name = resource_value_data.pop('name', None)
type_ = resource_value_data.pop('class', None)
parent = resource_value_data.pop('parent-component-references', None)
attributes = resource_value_data.pop('attributes', {})
if len(resource_value_data) > 0:
LOGGER.warning('Discarding Component Leftovers: {:s}'.format(str(resource_value_data)))
......@@ -68,6 +68,5 @@ def compose_components_data(
'created_at' : now,
'updated_at' : now,
}
LOGGER.debug('dict_component={:s}'.format(str(dict_component)))
dict_components.append(dict_component)
return dict_components
......@@ -35,8 +35,6 @@ def compose_config_rules_data(
dict_config_rules : List[Dict] = list()
for position,config_rule in enumerate(config_rules):
#LOGGER.info("REQUEST")
#LOGGER.info(position,config_rule)
str_kind = config_rule.WhichOneof('config_rule')
kind = ConfigRuleKindEnum._member_map_.get(str_kind.upper()) # pylint: disable=no-member
dict_config_rule = {
......
......@@ -25,9 +25,9 @@ class ComponentModel(_Base): #Inherit
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 name of the component
attributes = Column(String, nullable=False) #String field that stores data about the component
parent = Column(String, nullable=False) #String field that stores data about 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
......@@ -40,11 +40,12 @@ class ComponentModel(_Base): #Inherit
}
def dump(self) -> Dict:
data = json.loads(self.attributes)
data['component_uuid'] = {'uuid': self.component_uuid},
data['name'] = self.name
data['type'] = self.type
data['parent'] = self.parent
data = dict()
data['attributes'] = json.loads(self.attributes)
data['component_uuid'] = {'uuid': self.component_uuid}
data['name'] = self.name
data['type'] = self.type
data['parent'] = self.parent
return data
def dump_name(self) -> Dict:
......
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