diff --git a/src/context/service/database/OpticalConfig.py b/src/context/service/database/OpticalConfig.py index 89ad3253caeaac5aff06acbedf723b0ba994aca9..a3618e2bac8a06b1aaa0c2162e4a4ab79588680c 100644 --- a/src/context/service/database/OpticalConfig.py +++ b/src/context/service/database/OpticalConfig.py @@ -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: @@ -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 = [] @@ -77,13 +78,13 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): channels.append( { # "opticalconfig_uuid":opticalconfig_uuid, - "transponder_uuid":transponder_get_uuid(device_id), - "channel_uuid":channel_get_uuid(channel_params['name']['index']), + "transponder_uuid" : transponder_get_uuid(device_id), + "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, - "target_output_power" : channel_params["target-output-power"] if "target-output-power" in channel_params else '', - "status":channel_params["status"] if "status" in channel_params else "" + "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, + "target_output_power" : channel_params["target-output-power"] if "target-output-power" in channel_params else '', + "status" : channel_params["status"] if "status" in channel_params else "" } ) @@ -92,6 +93,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): "transcievers":transceivers, "interfaces":None, "opticalconfig_uuid":opticalconfig_uuid, + }) @@ -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) @@ -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} diff --git a/src/context/service/database/models/OpticalConfigModel.py b/src/context/service/database/models/OpticalConfigModel.py index e6a6fca0a61e42ced27dd7b33ec1b46dc34ebbcf..46aaf2f9a15ee7fa5d95b88ccf2a1e867824359f 100644 --- a/src/context/service/database/models/OpticalConfigModel.py +++ b/src/context/service/database/models/OpticalConfigModel.py @@ -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 @@ -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): @@ -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() diff --git a/src/context/service/database/uuids/OpticalConfig.py b/src/context/service/database/uuids/OpticalConfig.py index 203c424823f910379b399c85ae7caccf417c638f..2af60cd0102faf4c3f8706c571ac1b146422999d 100644 --- a/src/context/service/database/uuids/OpticalConfig.py +++ b/src/context/service/database/uuids/OpticalConfig.py @@ -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([ @@ -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: diff --git a/src/device/service/DeviceServiceServicerImpl.py b/src/device/service/DeviceServiceServicerImpl.py index b4d9a1c9d1fbb1574b23acee207c52ea7a084cb8..f7f723c2947287c6687fca87efc5d2a89a84cf93 100644 --- a/src/device/service/DeviceServiceServicerImpl.py +++ b/src/device/service/DeviceServiceServicerImpl.py @@ -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']) diff --git a/src/device/service/drivers/oc_driver/OCDriver.py b/src/device/service/drivers/oc_driver/OCDriver.py index 0b985e0292ad259d3d3a66e6b83865dc4c051502..4e398f227c3ad4167b1176d37b6dc32889366175 100644 --- a/src/device/service/drivers/oc_driver/OCDriver.py +++ b/src/device/service/drivers/oc_driver/OCDriver.py @@ -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 @@ -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: diff --git a/src/device/service/drivers/oc_driver/templates/VPN/transponder.py b/src/device/service/drivers/oc_driver/templates/VPN/transponder.py index 689cbff6b07d3bd7f8ecdd684678e7f716cd5d1f..0ec952e7444706bc1a20557c4e5ebe7912029546 100644 --- a/src/device/service/drivers/oc_driver/templates/VPN/transponder.py +++ b/src/device/service/drivers/oc_driver/templates/VPN/transponder.py @@ -141,17 +141,19 @@ def change_optical_channel_status (state:str,ports:list[dict]) : def edit_optical_channel (resources:list[dict]): + logging.info(f"building xml {resources}") unwanted_keys=['destination_port','source_port','channel_namespace','optical-band-parent','index', 'name','admin-state'] config,ports,index=seperate_port_config(resources,unwanted_keys=unwanted_keys) results = [] - channel_name=next((i["value"] for i in resources if i["resource_key"]=="channel_name" and i["value"] != None),None) - admin_state= next((i["value"] for i in resources if i["resource_key"]== "admin-state" and i["value"] != None) , None) + # channel_name=next((i["value"] for i in resources if i["resource_key"]=="channel_name" and i["value"] != None),None) + # admin_state= next((i["value"] for i in resources if i["resource_key"]== "admin-state" and i["value"] != None) , None) - logging.info(f"admin state is {admin_state}") - if channel_name is not None : - if (admin_state is not None): - results.extend(change_optical_channel_status(state=admin_state,ports=ports)) - if admin_state is None : - results.extend(create_optical_channel(resources=resources,ports=ports,config=config) ) + # logging.info(f"channel_name {channel_name}") + + # results.extend(change_optical_channel_status(state=admin_state,ports=ports)) + # else : + logging.info(f"config_xml {config}") + logging.info(f"ports_xml {ports}") + results.extend(create_optical_channel(resources=resources,ports=ports,config=config) ) return results \ No newline at end of file diff --git a/src/device/service/drivers/oc_driver/templates/descovery_tool/transponders.py b/src/device/service/drivers/oc_driver/templates/descovery_tool/transponders.py index fdba2649c62a97989ffa7c6af870abca2e6f610f..892ef98dc1f001a859b5ad8e102218607e204540 100644 --- a/src/device/service/drivers/oc_driver/templates/descovery_tool/transponders.py +++ b/src/device/service/drivers/oc_driver/templates/descovery_tool/transponders.py @@ -266,6 +266,7 @@ def transponder_values_extractor(data_xml:str,resource_keys:list,dic:dict): # channel_names=extract_channels_based_on_type(xml_data=data_xml) # if len(channel_names)==0 : channel_names= extract_channels_based_on_channelnamespace(xml_data=data_xml,channel_namespace=channel_namespace,is_opticalband=is_opticalband) + logging.info(f"channel_names {channel_names}") ports = extract_ports_based_on_type(data_xml) optical_channels_params=[] ports_result=[] diff --git a/src/webui/service/opticalconfig/routes.py b/src/webui/service/opticalconfig/routes.py index 7272a2f60cc620e03bf90e0dcb542cffb3d39942..5882ef74ce8ca3a8d95b416b655c8e8a2bcfcdbf 100644 --- a/src/webui/service/opticalconfig/routes.py +++ b/src/webui/service/opticalconfig/routes.py @@ -42,7 +42,8 @@ def home() : value=json.loads(configs.config) if type(configs.config)==str else configs.config config_type = value["type"] if (config_type == 'optical-transponder'): - value["channels_number"]=len(value['transponder']['channels']) + channels_num = value['transponder'] + value["channels_number"]=len(channels_num['channels']) if 'channels' in channels_num else 0 # value['operationalMode']=value['operational-mode'] # value['targetOutputPower']=value['target-output-power'] @@ -85,18 +86,18 @@ def show_details(config_uuid): LOGGER.info("config details from show detail %s",config) - + if 'channels' in config['transponder']: - for channel in config['transponder']['channels'] : - new_config={} - new_config["name"]=channel['name'] - new_config['operationalMode']=channel['operational-mode'] if 'operational-mode' in channel else '' - new_config['targetOutputPower']=channel['target-output-power'] if 'target-output-power' in channel else '' - new_config["frequency"]=channel['frequency'] if 'frequency' in channel else '' - new_config['line_port']=channel["line-port"] if 'line-port' in channel else '' - new_config["status"] = channel['status'] if 'status' in channel else "" - - device_details.append(new_config) + for channel in config['transponder']['channels'] : + new_config={} + new_config["name"]=channel['name'] + new_config['operationalMode']=channel['operational-mode'] if 'operational-mode' in channel else '' + new_config['targetOutputPower']=channel['target-output-power'] if 'target-output-power' in channel else '' + new_config["frequency"]=channel['frequency'] if 'frequency' in channel else '' + new_config['line_port']=channel["line-port"] if 'line-port' in channel else '' + new_config["status"] = channel['status'] if 'status' in channel else "" + + device_details.append(new_config) LOGGER.info("device details %s",device_details) return render_template('opticalconfig/details.html', device=device_details,config_id=config_uuid,device_name=device_name) @@ -259,36 +260,36 @@ def update(config_uuid,channel_name): flash(f'Problem updating the device. {e}', 'danger') return render_template('myabout/update.html', device=response, form=form, submit_text='Update Device',channel_name=channel_name) -@opticalconfig.route('<path:config_uuid>/<path:interface_name>/update_interface', methods=['GET', 'POST']) -def update_interface (config_uuid,interface_name): - form = UpdateInterfaceForm() - opticalconfigId=OpticalConfigId() - opticalconfigId.opticalconfig_uuid=config_uuid - context_client.connect() - response = context_client.SelectOpticalConfig(myid) - context_client.close() - LOGGER.info("response %s",response) - opticalconfig = OpticalConfig() - opticalconfig.CopyFrom(response) - config =json.loads(opticalconfig.config) - new_config={} - if form.validate_on_submit(): - new_config["ip"]=form.ip.data if form.ip.data != "" else config["interfaces"]["interface"]["ip"] - new_config["prefix-length"]=form.prefix_length.data if form.prefix_length.data != "" else config["interfaces"]["interface"]["prefix-length"] - new_config["name"]=config["interfaces"]["interface"]["name"] - new_config["enabled"]=config["interfaces"]["interface"]["enabled"] +# @opticalconfig.route('<path:config_uuid>/<path:interface_name>/update_interface', methods=['GET', 'POST']) +# def update_interface (config_uuid,interface_name): +# form = UpdateInterfaceForm() +# opticalconfigId=OpticalConfigId() +# opticalconfigId.opticalconfig_uuid=config_uuid +# context_client.connect() +# response = context_client.SelectOpticalConfig(myid) +# context_client.close() +# LOGGER.info("response %s",response) +# opticalconfig = OpticalConfig() +# opticalconfig.CopyFrom(response) +# config =json.loads(opticalconfig.config) +# new_config={} +# if form.validate_on_submit(): +# new_config["ip"]=form.ip.data if form.ip.data != "" else config["interfaces"]["interface"]["ip"] +# new_config["prefix-length"]=form.prefix_length.data if form.prefix_length.data != "" else config["interfaces"]["interface"]["prefix-length"] +# new_config["name"]=config["interfaces"]["interface"]["name"] +# new_config["enabled"]=config["interfaces"]["interface"]["enabled"] - opticalconfig.config=json.dumps({"update_interface":new_config}) - try: - device_client.connect() - device_client.ConfigureOpticalDevice(opticalconfig) - device_client.close() - flash(f' device was updated.', 'success') - return redirect(url_for('opticalconfig.show_details',config_uuid=config_uuid)) - except Exception as e: # pylint: disable=broad-except - flash(f'Problem updating the device. {e}', 'danger') - return render_template('opticalconfig/update_interface.html', - device=response, form=form, submit_text='Update interface',interface_name=interface_name) +# opticalconfig.config=json.dumps({"update_interface":new_config}) +# try: +# device_client.connect() +# device_client.ConfigureOpticalDevice(opticalconfig) +# device_client.close() +# flash(f' device was updated.', 'success') +# return redirect(url_for('opticalconfig.show_details',config_uuid=config_uuid)) +# except Exception as e: # pylint: disable=broad-except +# flash(f'Problem updating the device. {e}', 'danger') +# return render_template('opticalconfig/update_interface.html', +# device=response, form=form, submit_text='Update interface',interface_name=interface_name) @opticalconfig.route('<path:config_uuid>/add_transceiver', methods=['GET','POST']) def add_transceiver (config_uuid): diff --git a/src/webui/service/templates/opticalconfig/home.html b/src/webui/service/templates/opticalconfig/home.html index 581024cd709f7c17319fefdf0722d20622aad066..1a49c0e003d32f3b60c92c6ba4becceba9ccf619 100644 --- a/src/webui/service/templates/opticalconfig/home.html +++ b/src/webui/service/templates/opticalconfig/home.html @@ -13,13 +13,31 @@ See the License for the specific language governing permissions and limitations under the License. --> - + <a class="nav-link active" aria-current="page" href="{{ url_for('base_optical.home') }}">Optical Config</a> {% extends 'base.html' %} {% block content %} <h1>My Configurations</h1> <div class="row"> + <div class="col-sm-12"> + <div class="row mb-3 "> + + <div class="col-sm-3"> + <button type="button" class="btn btn-success" onclick="window.location.href='{{ url_for('base_optical.home') }}'"> + <i class="bi bi-box-arrow-in-left"></i> + Back to main + </button> + </div> + <div class="col-sm-3"> + <!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete device</button> --> + <!-- <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal"> + <i class="bi bi-x-square"></i> + Delete All + </button> --> + </div> + </div> + </div> {% if config %} <table class="table table-striped table-hover"> @@ -27,6 +45,7 @@ <tr> <th scope="col">UUID</th> <th scope="col">Device Name</th> + <th scope="col">Device Type</th> <th scope="col">Channels Number</th> </tr> @@ -37,7 +56,12 @@ <tr> <td>{{device.opticalconfig_id.opticalconfig_uuid}}</td> <td>{{device.device_name}}</td> + <td> {{device.type}}</td> + {% if device.type == 'optical-transponder'%} <td>{{ device.channels_number }}</td> + {%else%} + <td>__ </td> + {%endif%} <td> <a href="{{ url_for('opticalconfig.show_details', config_uuid=device.opticalconfig_id.opticalconfig_uuid) }}">