Commit 167a42fa authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Modified database/Component to properly store attributes in database, report raw component, and dump component leftovers
parent 9df78fb0
Loading
Loading
Loading
Loading
+7 −6
Original line number Original line Diff line number Diff line





# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -48,25 +47,27 @@ def compose_components_data(
        if '/inventory' in resource_key:
        if '/inventory' in resource_key:
            resource_value_data = json.loads(resource_value)
            resource_value_data = json.loads(resource_value)
            name = resource_value_data.pop('name', None)
            name = resource_value_data.pop('name', None)
            type = resource_value_data.pop('class', None)
            type_ = resource_value_data.pop('class', None)
            uuid = resource_value_data.pop('uuid', None)
            parent = resource_value_data.pop('parent-component-references', None)
            parent = resource_value_data.pop('parent-component-references', None)
            resource_value_data.pop('component-reference', None)
            attributes = resource_value_data.pop('attributes', {})
            if len(resource_value_data) > 0:
                LOGGER.warning('Discarding Component Leftovers: {:s}'.format(str(resource_value_data)))


            attributes = {
            attributes = {
                attr_name:json.dumps(attr_value)
                attr_name:json.dumps(attr_value)
                for attr_name,attr_value in resource_value_data.items()
                for attr_name,attr_value in attributes.items()
            }
            }
            component_uuid = get_uuid_from_string(component.custom.resource_key, prefix_for_name=device_uuid)            
            component_uuid = get_uuid_from_string(component.custom.resource_key, prefix_for_name=device_uuid)            
            dict_component = {
            dict_component = {
                'component_uuid': component_uuid,
                'component_uuid': component_uuid,
                'device_uuid'   : device_uuid,
                'device_uuid'   : device_uuid,
                'name'          : name,
                'name'          : name,
                'type'          : type,
                'type'          : type_,
                'attributes'    : json.dumps(attributes),  #Store the remaining fields in 'attributes'
                'attributes'    : json.dumps(attributes),  #Store the remaining fields in 'attributes'
                'parent'        : parent,
                'parent'        : parent,
                'created_at'    : now,
                'created_at'    : now,
                'updated_at'    : now,
                'updated_at'    : now,
            }
            }
            LOGGER.debug('dict_component={:s}'.format(str(dict_component)))
            dict_components.append(dict_component)
            dict_components.append(dict_component)
    return dict_components
    return dict_components