Loading src/context/service/database/OpticalConfig.py +12 −10 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): OpticalConfig_data = [] config_type=None is_transpondre=False opticalconfig_uuid =opticalconfig_get_uuid(device_id) LOGGER.info(f"cofigy_type {request.config}") if request.config: Loading @@ -62,7 +63,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): config_type= config["type"] if config_type == "optical-transponder": is_transpondre=True transceivers = [] Loading @@ -78,7 +79,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): { # "opticalconfig_uuid":opticalconfig_uuid, "transponder_uuid" : transponder_get_uuid(device_id), "channel_uuid":channel_get_uuid(channel_params['name']['index']), "channel_uuid" : channel_get_uuid(channel_params['name']['index'],device_uuid), "channel_name" : channel_params['name']['index'], "frequency" : int(channel_params["frequency"]) if "frequency" in channel_params else 0, "operational_mode" : int(channel_params["operational-mode"]) if "operational-mode" in channel_params else 0, Loading @@ -94,6 +95,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): "opticalconfig_uuid":opticalconfig_uuid, }) Loading @@ -102,14 +104,14 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): "opticalconfig_uuid":opticalconfig_uuid, # "transcievers" : transceivers, # "interfaces" :"", "channel_namespace" : config.get("channel_namespace",None), "channel_namespace" : config['transponder'].get("channel_namespace",None) if is_transpondre else None , "endpoints" : [json.dumps(endpoint) for endpoint in config.get("endpoints",[])], "device_uuid": device_uuid, "type":config_type } ) LOGGER.info(f"added OpticalConfig_data {OpticalConfig_data}") def callback(session:Session)->bool: stmt = insert(OpticalConfigModel).values(OpticalConfig_data) Loading Loading @@ -153,7 +155,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): ) stmt = stmt.returning(OpticalChannelModel.channel_uuid) opticalChannel_id = session.execute(stmt).fetchone() LOGGER.info(f"added successfully {opticalChannel_id}") opticalconfig_id = run_transaction(sessionmaker(bind=db_engine), callback) return {'opticalconfig_uuid': opticalconfig_id} Loading src/context/service/database/models/OpticalConfigModel.py +8 −4 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json import json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship Loading Loading @@ -45,16 +45,20 @@ class OpticalConfigModel(_Base): } def dump(self): return { obj={ # "channels" : [channel.dump() for channel in self.channels], # "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, # "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "channel_namespace" : self.channel_namespace, "endpoints" : [json.loads(endpoint) for endpoint in self.endpoints if endpoint], "device_name" : self.device.device_name, "transponder" : [transponer.dump() for transponer in self.transponders if self.type =="optical-transponder" ], "type" : self.type } if self.type =="optical-transponder" : channels= [transponer.dump() for transponer in self.transponders ][0] obj['transponder']=channels logging.info(f"optical_config_model {obj}") return obj class TransponderTypeModel (_Base): Loading @@ -76,7 +80,7 @@ class TransponderTypeModel (_Base): def dump (self): return { #"channels" : [channel.dump() for channel in self.channels], "channels" : [channel.dump() for channel in self.channels], "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "trasponder_uuid" : self.dump_id() Loading src/context/service/database/uuids/OpticalConfig.py +3 −2 Original line number Diff line number Diff line Loading @@ -4,12 +4,12 @@ from ._Builder import get_uuid_from_string, get_uuid_random from common.proto.context_pb2 import DeviceId def channel_get_uuid( channel_name :str , allow_random : bool = False channel_name :str , device_id:str, allow_random : bool = False ) -> str: if len(channel_name) > 0: return get_uuid_from_string(channel_name) return get_uuid_from_string(channel_name) + device_id if allow_random: return get_uuid_random() raise InvalidArgumentsException([ Loading @@ -17,6 +17,7 @@ def channel_get_uuid( ], extra_details=['Channel name is required to produce a channel UUID']) def transponder_get_uuid( opticalconfig_id :str , allow_random : bool = False ) -> str: Loading src/device/service/DeviceServiceServicerImpl.py +1 −1 Original line number Diff line number Diff line Loading @@ -158,7 +158,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): #for endpoint in request.device_endpoints: # #endpoint.endpoint_id.device_id.CopyFrom(device.device_id) # pass LOGGER.info(f"add_device {new_optial_configs}") if ('new_optical_config' in new_optial_configs and 'opticalconfig' in new_optial_configs["new_optical_config"]): context_client.SetOpticalConfig(new_optial_configs["new_optical_config"]['opticalconfig']) Loading src/device/service/drivers/oc_driver/OCDriver.py +4 −1 Original line number Diff line number Diff line Loading @@ -273,10 +273,11 @@ class OCDriver(_Driver): ports_result=[] oc_values["type"]=self.__type try: oc_values["transponder"]={} xml_data = self.__netconf_handler.get().data_xml logging.info(f"type {self.__type}") if (self.__type == "optical-transponder"): oc_values["transponder"]={} extracted_values=transponder_values_extractor(data_xml=xml_data,resource_keys=transponder_filter_fields,dic=config) transceivers,optical_channels_params,channel_namespace,endpoints,ports_result=extracted_values oc_values["transponder"]["channels"]=optical_channels_params Loading Loading @@ -319,6 +320,8 @@ class OCDriver(_Driver): @metered_subclass_method(METRICS_POOL) def SetConfig(self, resources : List[Tuple[str, Any]],conditions:dict) -> List[Union[bool, Exception]]: logging.info(f"from setConfig {resources}") logging.info(f"from setConfig condititons {conditions}") if len(resources) == 0: return [] results=[] with self.__lock: Loading Loading
src/context/service/database/OpticalConfig.py +12 −10 Original line number Diff line number Diff line Loading @@ -54,6 +54,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): OpticalConfig_data = [] config_type=None is_transpondre=False opticalconfig_uuid =opticalconfig_get_uuid(device_id) LOGGER.info(f"cofigy_type {request.config}") if request.config: Loading @@ -62,7 +63,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): config_type= config["type"] if config_type == "optical-transponder": is_transpondre=True transceivers = [] Loading @@ -78,7 +79,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): { # "opticalconfig_uuid":opticalconfig_uuid, "transponder_uuid" : transponder_get_uuid(device_id), "channel_uuid":channel_get_uuid(channel_params['name']['index']), "channel_uuid" : channel_get_uuid(channel_params['name']['index'],device_uuid), "channel_name" : channel_params['name']['index'], "frequency" : int(channel_params["frequency"]) if "frequency" in channel_params else 0, "operational_mode" : int(channel_params["operational-mode"]) if "operational-mode" in channel_params else 0, Loading @@ -94,6 +95,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): "opticalconfig_uuid":opticalconfig_uuid, }) Loading @@ -102,14 +104,14 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): "opticalconfig_uuid":opticalconfig_uuid, # "transcievers" : transceivers, # "interfaces" :"", "channel_namespace" : config.get("channel_namespace",None), "channel_namespace" : config['transponder'].get("channel_namespace",None) if is_transpondre else None , "endpoints" : [json.dumps(endpoint) for endpoint in config.get("endpoints",[])], "device_uuid": device_uuid, "type":config_type } ) LOGGER.info(f"added OpticalConfig_data {OpticalConfig_data}") def callback(session:Session)->bool: stmt = insert(OpticalConfigModel).values(OpticalConfig_data) Loading Loading @@ -153,7 +155,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): ) stmt = stmt.returning(OpticalChannelModel.channel_uuid) opticalChannel_id = session.execute(stmt).fetchone() LOGGER.info(f"added successfully {opticalChannel_id}") opticalconfig_id = run_transaction(sessionmaker(bind=db_engine), callback) return {'opticalconfig_uuid': opticalconfig_id} Loading
src/context/service/database/models/OpticalConfigModel.py +8 −4 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import json import json , logging from sqlalchemy import Column, String, Integer , ForeignKey, Boolean from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship Loading Loading @@ -45,16 +45,20 @@ class OpticalConfigModel(_Base): } def dump(self): return { obj={ # "channels" : [channel.dump() for channel in self.channels], # "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, # "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "channel_namespace" : self.channel_namespace, "endpoints" : [json.loads(endpoint) for endpoint in self.endpoints if endpoint], "device_name" : self.device.device_name, "transponder" : [transponer.dump() for transponer in self.transponders if self.type =="optical-transponder" ], "type" : self.type } if self.type =="optical-transponder" : channels= [transponer.dump() for transponer in self.transponders ][0] obj['transponder']=channels logging.info(f"optical_config_model {obj}") return obj class TransponderTypeModel (_Base): Loading @@ -76,7 +80,7 @@ class TransponderTypeModel (_Base): def dump (self): return { #"channels" : [channel.dump() for channel in self.channels], "channels" : [channel.dump() for channel in self.channels], "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, "trasponder_uuid" : self.dump_id() Loading
src/context/service/database/uuids/OpticalConfig.py +3 −2 Original line number Diff line number Diff line Loading @@ -4,12 +4,12 @@ from ._Builder import get_uuid_from_string, get_uuid_random from common.proto.context_pb2 import DeviceId def channel_get_uuid( channel_name :str , allow_random : bool = False channel_name :str , device_id:str, allow_random : bool = False ) -> str: if len(channel_name) > 0: return get_uuid_from_string(channel_name) return get_uuid_from_string(channel_name) + device_id if allow_random: return get_uuid_random() raise InvalidArgumentsException([ Loading @@ -17,6 +17,7 @@ def channel_get_uuid( ], extra_details=['Channel name is required to produce a channel UUID']) def transponder_get_uuid( opticalconfig_id :str , allow_random : bool = False ) -> str: Loading
src/device/service/DeviceServiceServicerImpl.py +1 −1 Original line number Diff line number Diff line Loading @@ -158,7 +158,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): #for endpoint in request.device_endpoints: # #endpoint.endpoint_id.device_id.CopyFrom(device.device_id) # pass LOGGER.info(f"add_device {new_optial_configs}") if ('new_optical_config' in new_optial_configs and 'opticalconfig' in new_optial_configs["new_optical_config"]): context_client.SetOpticalConfig(new_optial_configs["new_optical_config"]['opticalconfig']) Loading
src/device/service/drivers/oc_driver/OCDriver.py +4 −1 Original line number Diff line number Diff line Loading @@ -273,10 +273,11 @@ class OCDriver(_Driver): ports_result=[] oc_values["type"]=self.__type try: oc_values["transponder"]={} xml_data = self.__netconf_handler.get().data_xml logging.info(f"type {self.__type}") if (self.__type == "optical-transponder"): oc_values["transponder"]={} extracted_values=transponder_values_extractor(data_xml=xml_data,resource_keys=transponder_filter_fields,dic=config) transceivers,optical_channels_params,channel_namespace,endpoints,ports_result=extracted_values oc_values["transponder"]["channels"]=optical_channels_params Loading Loading @@ -319,6 +320,8 @@ class OCDriver(_Driver): @metered_subclass_method(METRICS_POOL) def SetConfig(self, resources : List[Tuple[str, Any]],conditions:dict) -> List[Union[bool, Exception]]: logging.info(f"from setConfig {resources}") logging.info(f"from setConfig condititons {conditions}") if len(resources) == 0: return [] results=[] with self.__lock: Loading