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

first version

parent f344a62c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ spec:
        - containerPort: 9192
        env:
        - name: LOG_LEVEL
          value: "INFO"
          value: "DEBUG"
        - name: SLICE_GROUPING
          value: "DISABLE"
        envFrom:
+3 −2
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ class DescriptorLoader:
        self.__devices     = self.__descriptors.get('devices'    , [])
        self.__links       = self.__descriptors.get('links'      , [])
        self.__services    = self.__descriptors.get('services'   , [])
        self.__slices      = self.__descriptors.get('slices'     , [])
        self.__slices      = self.__descriptors.get('data', []) #Coge de la file el campo slices
        self.__connections = self.__descriptors.get('connections', [])

        self.__contexts_add   = None
@@ -194,7 +194,7 @@ class DescriptorLoader:
        _slices = {}
        for slice_ in self.__slices:
            context_uuid = slice_['slice_id']['context_id']['context_uuid']['uuid']
            _slices.setdefault(context_uuid, []).append(slice_)
            _slices.setdefault(context_uuid, []).append(slice_) #no tenemos context_uuid en este formato, lo meto a mano?
        return _slices

    @property
@@ -215,6 +215,7 @@ class DescriptorLoader:
        # Format CustomConfigRules in Devices, Services and Slices provided in JSON format
        self.__devices  = [format_device_custom_config_rules (device ) for device  in self.__devices ]
        self.__services = [format_service_custom_config_rules(service) for service in self.__services]
        LOGGERS.INFO(self.__slices)
        self.__slices   = [format_slice_custom_config_rules  (slice_ ) for slice_  in self.__slices  ]

        # Context and Topology require to create the entity first, and add devices, links, services,
+8 −3
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
import copy, json
from typing import Dict, List, Optional, Tuple, Union

#context es la db, al inicio esta vacía
def get_descriptors_add_contexts(contexts : List[Dict]) -> List[Dict]:
    contexts_add = copy.deepcopy(contexts)
    for context in contexts_add:
@@ -52,7 +53,7 @@ def get_descriptors_add_slices(slices : List[Dict]) -> List[Dict]:
TypeResourceValue = Union[str, int, bool, float, dict, list]
def format_custom_config_rules(config_rules : List[Dict]) -> List[Dict]:
    for config_rule in config_rules:
        if 'custom' not in config_rule: continue
       # if 'custom' not in config_rule: continue #suponemos que siempre son custom, quitamos esta linea
        custom_resource_value : TypeResourceValue = config_rule['custom']['resource_value']
        if isinstance(custom_resource_value, (dict, list)):
            custom_resource_value = json.dumps(custom_resource_value, sort_keys=True, indent=0)
@@ -71,10 +72,14 @@ def format_service_custom_config_rules(service : Dict) -> Dict:
    service['service_config']['config_rules'] = config_rules
    return service

#UTILIZA LA FUNCION FORMAT_CUSTOM_CONFIG_RULES 
#cambio
def format_slice_custom_config_rules(slice_ : Dict) -> Dict:
    config_rules = slice_.get('slice_config', {}).get('config_rules', [])
    #donde cojo los config_rules
    #las config_rules parecen estar en ACs?
    config_rules = slice_.get('sdps', []) 
    config_rules = format_custom_config_rules(config_rules)
    slice_['slice_config']['config_rules'] = config_rules
    slice_['sdps']['sdp']['attachment-circuits'] = config_rules
    return slice_

def split_devices_by_rules(devices : List[Dict]) -> Tuple[List[Dict], List[Dict]]:
+32 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
import logging, lxml.etree as ET
from typing import Any, Dict, List, Tuple
from .Namespace import NAMESPACES
from .Tools import add_value_from_tag
from .Tools import add_value_from_tag, add_int_from_tag

LOGGER = logging.getLogger(__name__)

@@ -56,6 +56,8 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
    response = []
    LOGGER.debug("InventoryPrueba")
    parent_types = {}
    #Initialized count to 0 for index
    count = 0
    for xml_component in xml_data.xpath(XPATH_PORTS, namespaces=NAMESPACES):
        LOGGER.info('xml_component inventario = {:s}'.format(str(ET.tostring(xml_component))))
        inventory = {}
@@ -65,6 +67,7 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
        inventory['attributes'] = {}
        component_reference = []
        

        component_name = xml_component.find('ocp:name', namespaces=NAMESPACES)
        if component_name is None or component_name.text is None: continue
        add_value_from_tag(inventory, 'name', component_name)        
@@ -84,6 +87,34 @@ def parse(xml_data : ET.Element) -> List[Tuple[str, Dict[str, Any]]]:
        
        if inventory['class'] == 'CPU' or inventory['class'] == 'STORAGE': continue

        ##Added (after the checking of the name and the class)
        #Physical index- Index of the component in the array
    
        add_int_from_tag(inventory['attributes'], 'physical-index', count)
        count +=1

        ##Added
        #FRU
        if inventory['class'] == 'FRU':
            component_isfru = xml_component.find('ocp:state/ocp:type', namespaces=NAMESPACES)
            add_value_from_tag(inventory['attributes'], 'isfru', component_isfru)
        ##ID
        component_id = xml_component.find('ocp:state/ocp:id', namespaces=NAMESPACES)
        if not component_id is None:
            add_value_from_tag(inventory['attributes'], 'id', component_id)

        ##OPER_STATUS
        component_oper_status = xml_component.find('ocp:state/ocp:oper-status', namespaces=NAMESPACES)
        if not component_oper_status is None:
            add_value_from_tag(inventory['attributes'], 'oper-status', component_oper_status)

        ##MODEL_ID  
        component_model_id = xml_component.find('ocp:state/ocp:entity-id', namespaces=NAMESPACES)
        if not component_model_id is None:
            add_value_from_tag(inventory['attributes'], 'model-id', component_model_id)
    
    ##
        
        component_empty = xml_component.find('ocp:state/ocp:empty', namespaces=NAMESPACES)
        if not component_empty is None:
            add_value_from_tag(inventory['attributes'], 'empty', component_empty)
+5 −0
Original line number Diff line number Diff line
@@ -26,6 +26,11 @@ def add_value_from_tag(target : Dict, field_name: str, field_value : ET.Element,
    if cast is not None: field_value = cast(field_value)
    target[field_name] = field_value

def add_int_from_tag(target : Dict, field_name: str, field_value : int, cast=None) -> None:
    if field_value is None: return
    if cast is not None: field_value = cast(field_value)
    target[field_name] = field_value

def add_value_from_collection(target : Dict, field_name: str, field_value : Collection) -> None:
    if field_value is None or len(field_value) == 0: return
    target[field_name] = field_value
Loading