diff --git a/.context.log.swn b/.context.log.swn deleted file mode 100644 index 438f657217b971861a154b8bd3b81b1b02507337..0000000000000000000000000000000000000000 Binary files a/.context.log.swn and /dev/null differ diff --git a/.context.log.swo b/.context.log.swo deleted file mode 100644 index 49a59c9ed538de8fd9541463916ab80290aed960..0000000000000000000000000000000000000000 Binary files a/.context.log.swo and /dev/null differ diff --git a/.context.log.swp b/.context.log.swp deleted file mode 100644 index 5d3a8a7bc4f452de1e9db725e83fcbdbfbf83580..0000000000000000000000000000000000000000 Binary files a/.context.log.swp and /dev/null differ diff --git a/proto/context.proto b/proto/context.proto index 03ecd459a22ad31042ce6524ce3ac6be83e6840c..64a01526522889644ab68aa0b7a24e3db428416c 100644 --- a/proto/context.proto +++ b/proto/context.proto @@ -560,6 +560,9 @@ message Location { oneof location { string region = 1; GPS_Position gps_position = 2; + + string interface=3; + string circuit_pack=4; } } diff --git a/src/context/service/database/OpticalConfig.py b/src/context/service/database/OpticalConfig.py index b370375d3654432b0da4a476ad2e8dcda7814e44..e3248d8bde9c1abe3cc9dad655044cf7313f7334 100644 --- a/src/context/service/database/OpticalConfig.py +++ b/src/context/service/database/OpticalConfig.py @@ -207,7 +207,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): ) LOGGER.info(f"added OpticalConfig_data {OpticalConfig_data}") - LOGGER.info(f"added channels {channels}") + LOGGER.info(f"added interfaces {interfaces}") def callback(session:Session)->bool: stmt = insert(OpticalConfigModel).values(OpticalConfig_data) @@ -260,7 +260,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): stmt = stmt.on_conflict_do_update( index_elements=[RoadmTypeModel.roadm_uuid], set_=dict( - circuits=stmt.excluded.circuits + opticalconfig_uuid=stmt.excluded.opticalconfig_uuid ) ) stmt = stmt.returning(RoadmTypeModel.roadm_uuid) @@ -298,14 +298,14 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig): stmt = stmt.on_conflict_do_update( index_elements=[RoadmTypeModel.roadm_uuid], set_=dict( - interfaces=stmt.excluded.interfaces + opticalconfig_uuid=stmt.excluded.opticalconfig_uuid ) ) stmt = stmt.returning(RoadmTypeModel.roadm_uuid) roadm_id = session.execute(stmt).fetchone() - if len(interface) >0 : - stmt = insert(ORInterfaceModel).values(interface) + if len(interfaces) >0 : + stmt = insert(ORInterfaceModel).values(interfaces) stmt = stmt.on_conflict_do_update( index_elements=[ORInterfaceModel.interface_uuid ], set_=dict( diff --git a/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py b/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py index 515a21a8574a2683f41dc3ce2e5d4c5e5ef4027a..eafafaa7c87af29236724de2e73cfde2d9b91543 100644 --- a/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py +++ b/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py @@ -64,9 +64,17 @@ class OpticalConfigModel(_Base): obj['trasponder_uuid']=channels['trasponder_uuid'] if 'trasponder_uuid' in channels else None if self.type =="optical-roadm" : - channels=[roadms.dump() for roadms in self.roadms ][0] - obj['channels']=channels['channels'] if 'channels' in channels else None - obj['roadm_uuid']=channels['roadm_uuid'] if 'roadm_uuid' in channels else None + dev=[roadms.dump() for roadms in self.roadms ][0] + + obj['channels']=dev['channels'] if 'channels' in dev else None + obj['roadm_uuid']=dev['roadm_uuid'] if 'roadm_uuid' in dev else None + + if self.type =="openroadm" : + dev=[roadms.dump() for roadms in self.roadms ][0] + + obj['interfaces']=dev['interfaces'] if 'interfaces' in dev else None + obj['roadm_uuid']=dev['roadm_uuid'] if 'roadm_uuid' in dev else None + logging.info(f"optical_config_model {obj}") diff --git a/src/context/service/database/models/OpticalConfig/RoadmModel.py b/src/context/service/database/models/OpticalConfig/RoadmModel.py index 6d1ec19fafd7ed801534da09e0b715eb577d201a..52e831e73a95437749d9c737c524e4a04f211bbb 100644 --- a/src/context/service/database/models/OpticalConfig/RoadmModel.py +++ b/src/context/service/database/models/OpticalConfig/RoadmModel.py @@ -14,7 +14,7 @@ # limitations under the License. import json , logging -from sqlalchemy import Column, String, Integer , ForeignKey, Boolean +from sqlalchemy import Column, String, Integer , ForeignKey, Boolean , Float from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base @@ -27,8 +27,8 @@ class RoadmTypeModel (_Base): __tablename__ = 'roadm_type' roadm_uuid = Column(String, primary_key=True) - channels = relationship("ChannelModel") - interfaces = relationship ("ORInterfaceModel") + channels = relationship("ChannelModel") + interfaces = relationship ("ORInterfaceModel") opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) opticalconfig = relationship('OpticalConfigModel', back_populates='roadms') @@ -39,10 +39,12 @@ class RoadmTypeModel (_Base): } def dump (self): + i=[interface.dump() for interface in self.interfaces] + logging.info(f"roamd_type_model {i}") return { "channels" : [channel.dump() for channel in self.channels], "roadm_uuid" : self.dump_id(), - "interfaces" :[] + "interfaces" :[interface.dump() for interface in self.interfaces] } class ChannelModel(_Base): @@ -92,7 +94,7 @@ class ORInterfaceModel (_Base): circuit_pack_name = Column(String,nullable=True) port = Column(String,nullable=True) interface_list = Column(String ,nullable=True) - frequency = Column(Integer ,nullable=True) + frequency = Column(Float ,nullable=True) width = Column(Integer ,nullable=True) roadm_uuid = Column(ForeignKey('roadm_type.roadm_uuid', ondelete='CASCADE' ),nullable=False) diff --git a/src/device/service/Tools.py b/src/device/service/Tools.py index 68a65d1ba61102782242114f8bd1e8174439d401..c4d4efb8f208003fa68271f3ba953d7eb7194f0d 100644 --- a/src/device/service/Tools.py +++ b/src/device/service/Tools.py @@ -465,6 +465,7 @@ def get_edit_target(device : Device, is_opticalband : bool) -> str: if is_opticalband: return 'optical-band' if device.device_type == DeviceTypeEnum.OPTICAL_ROADM._value_: return 'media-channel' + if device.device_type == DeviceTypeEnum.OPEN_ROADM._value_: return 'network-media-channel' return 'optical-channel' def is_key_existed(key : str, keys_dic = dict, key_name_to_use = None) -> dict: @@ -481,63 +482,86 @@ def is_key_existed(key : str, keys_dic = dict, key_name_to_use = None) -> dict: def extract_resources(config : dict, device : Device) -> list[list[dict],dict]: conditions = {} resources:list[dict] = [] - resources.append(is_key_existed('channel_namespace', config)) - resources.append(is_key_existed('add_transceiver', config)) is_opticalband = config.get('is_opticalband', False) - conditions['is_opticalband'] = is_opticalband conditions['edit_type'] = get_edit_target(device, is_opticalband) - - if 'flow' in config: - #for tuple_value in config['flow'][device.name]: - source_vals = [] - dest_vals = [] - handled_flow=[] - for tuple_value in config['flow']: - source_port = None - destination_port = None - source_port_uuid, destination_port_uuid = tuple_value - if source_port_uuid != '0': - src_endpoint_obj = get_endpoint_matching(device, source_port_uuid) - source_port = src_endpoint_obj.name - source_vals.append(source_port) - if destination_port_uuid != '0': - dst_endpoint_obj = get_endpoint_matching(device, destination_port_uuid) - destination_port = dst_endpoint_obj.name - dest_vals.append(destination_port) - handled_flow.append((source_port,destination_port)) - resources.append({'resource_key': 'source_port', 'value': source_vals}) - resources.append({'resource_key': 'destination_port', 'value': dest_vals }) - resources.append({'resource_key':'handled_flow','value':handled_flow}) - if 'new_config' in config: - lower_frequency = None - upper_frequency = None - resources.append(is_key_existed('target-output-power', keys_dic=config['new_config'])) - resources.append(is_key_existed('frequency', keys_dic=config['new_config'])) - resources.append(is_key_existed('operational-mode', keys_dic=config['new_config'])) - resources.append(is_key_existed('line-port', keys_dic=config['new_config'])) - resources.append(is_key_existed('status', keys_dic=config['new_config'] , key_name_to_use="admin-state")) - resources.append(is_key_existed('band_type', keys_dic=config['new_config'], key_name_to_use='name')) - resources.append(is_key_existed('ob_id', keys_dic=config['new_config'], key_name_to_use='optical-band-parent')) - #resources.append(is_key_existed('name', keys_dic=config['new_config'], key_name_to_use='channel_name')) - if not is_opticalband: + - if 'frequency' in config['new_config'] and 'band' in config['new_config'] and conditions['edit_type'] == 'media-channel': - if config['new_config']['frequency'] is not None and config['new_config']['band'] is not None: - lower_frequency = int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)+1) - upper_frequency = int(int(config['new_config']['frequency']) + (int(config['new_config']['band'])/2)) - - - resources.append(is_key_existed('flow_id', keys_dic=config['new_config'], key_name_to_use='index')) - #resources.append({'resource_key':'index','value':config['new_config']['flow_id'] if 'flow_id' in config['new_config'] else None}) - else: - - lower_frequency = config['new_config']['low-freq'] if 'low-freq' in config['new_config'] else None - upper_frequency = config['new_config']['up-freq' ] if 'up-freq' in config['new_config'] else None - + if device.device_type == DeviceTypeEnum.OPEN_ROADM._value_ : + ports_dic=is_key_existed('ports',keys_dic=config['new_config']) + interfaces_list=[] + config_type= is_key_existed('config_type', keys_dic=config['new_config']) + resources.append(config_type) + resources.append(is_key_existed('administrative-state', keys_dic=config['new_config'])) + resources.append(is_key_existed('frequency', keys_dic=config['new_config'])) + resources.append(is_key_existed('width', keys_dic=config['new_config'])) + for port in ports_dic["value"]: + circuit_pack_dic=is_key_existed('supporting-circuit-pack-name', keys_dic=port) + interface_list=is_key_existed('supporting-interface-list', keys_dic=port) + supporting_port=is_key_existed('supporting-port', keys_dic=port) + interfaces_list.append([ + circuit_pack_dic, + interface_list, + supporting_port]) + + resources.append({'resource_key':'interfaces','value':interfaces_list}) + + + else : + resources.append(is_key_existed('channel_namespace', config)) + resources.append(is_key_existed('add_transceiver', config)) + + conditions['is_opticalband'] = is_opticalband + if 'flow' in config: + #for tuple_value in config['flow'][device.name]: + source_vals = [] + dest_vals = [] + handled_flow=[] + for tuple_value in config['flow']: + source_port = None + destination_port = None + source_port_uuid, destination_port_uuid = tuple_value + if source_port_uuid != '0': + src_endpoint_obj = get_endpoint_matching(device, source_port_uuid) + source_port = src_endpoint_obj.name + source_vals.append(source_port) + if destination_port_uuid != '0': + dst_endpoint_obj = get_endpoint_matching(device, destination_port_uuid) + destination_port = dst_endpoint_obj.name + dest_vals.append(destination_port) + handled_flow.append((source_port,destination_port)) + resources.append({'resource_key': 'source_port', 'value': source_vals}) + resources.append({'resource_key': 'destination_port', 'value': dest_vals }) + resources.append({'resource_key':'handled_flow','value':handled_flow}) + if 'new_config' in config: + lower_frequency = None + upper_frequency = None + resources.append(is_key_existed('target-output-power', keys_dic=config['new_config'])) + resources.append(is_key_existed('frequency', keys_dic=config['new_config'])) + resources.append(is_key_existed('operational-mode', keys_dic=config['new_config'])) + resources.append(is_key_existed('line-port', keys_dic=config['new_config'])) + resources.append(is_key_existed('status', keys_dic=config['new_config'] , key_name_to_use="admin-state")) + resources.append(is_key_existed('band_type', keys_dic=config['new_config'], key_name_to_use='name')) + resources.append(is_key_existed('ob_id', keys_dic=config['new_config'], key_name_to_use='optical-band-parent')) + #resources.append(is_key_existed('name', keys_dic=config['new_config'], key_name_to_use='channel_name')) + if not is_opticalband: + + if 'frequency' in config['new_config'] and 'band' in config['new_config'] and conditions['edit_type'] == 'media-channel': + if config['new_config']['frequency'] is not None and config['new_config']['band'] is not None: + lower_frequency = int(int(config['new_config']['frequency']) - (int(config['new_config']['band'])/2)+1) + upper_frequency = int(int(config['new_config']['frequency']) + (int(config['new_config']['band'])/2)) + - resources.append(is_key_existed('ob_id', keys_dic=config['new_config'], key_name_to_use='index')) - #resources.append({'resource_key':'index','value':config['new_config']['ob_id'] if 'ob_id' in config['new_config'] else None}) - resources.append({'resource_key': 'lower-frequency', 'value': lower_frequency}) - resources.append({'resource_key': 'upper-frequency', 'value': upper_frequency}) + resources.append(is_key_existed('flow_id', keys_dic=config['new_config'], key_name_to_use='index')) + #resources.append({'resource_key':'index','value':config['new_config']['flow_id'] if 'flow_id' in config['new_config'] else None}) + else: + + lower_frequency = config['new_config']['low-freq'] if 'low-freq' in config['new_config'] else None + upper_frequency = config['new_config']['up-freq' ] if 'up-freq' in config['new_config'] else None + + + resources.append(is_key_existed('ob_id', keys_dic=config['new_config'], key_name_to_use='index')) + #resources.append({'resource_key':'index','value':config['new_config']['ob_id'] if 'ob_id' in config['new_config'] else None}) + resources.append({'resource_key': 'lower-frequency', 'value': lower_frequency}) + resources.append({'resource_key': 'upper-frequency', 'value': upper_frequency}) return [resources, conditions] diff --git a/src/device/service/drivers/oc_driver/OCDriver.py b/src/device/service/drivers/oc_driver/OCDriver.py index 8959178b8b33a2e8dc0c5b879e9a2741482ef4bc..3d0078c85eedd72c0d8df3b5e4aec3372a6f5782 100644 --- a/src/device/service/drivers/oc_driver/OCDriver.py +++ b/src/device/service/drivers/oc_driver/OCDriver.py @@ -41,6 +41,9 @@ from common.proto.context_pb2 import ( from .templates.descovery_tool.transponders import transponder_values_extractor from .templates.descovery_tool.roadms import roadm_values_extractor ,extract_media_channels from .templates.descovery_tool.open_roadm import openroadm_values_extractor +from .templates.VPN.openroadm import network_media_channel_handler + + DEBUG_MODE = False logging.getLogger('ncclient.manager').setLevel(logging.DEBUG if DEBUG_MODE else logging.WARNING) logging.getLogger('ncclient.transport.ssh').setLevel(logging.DEBUG if DEBUG_MODE else logging.WARNING) @@ -130,7 +133,6 @@ class NetconfSessionHandler: self, config, target='running', default_operation=None, test_option=None, error_option=None, format='xml' # pylint: disable=redefined-builtin ): - response = None with self.__lock: @@ -164,7 +166,8 @@ def edit_config( ): str_method = 'DeleteConfig' if delete else 'SetConfig' results = [] - + + logging.info(f"commmit per rule {commit_per_rule}") str_config_messages=[] if str_method == 'SetConfig': if (conditions['edit_type']=='optical-channel'): @@ -172,7 +175,12 @@ def edit_config( str_config_messages = edit_optical_channel(resources) elif (conditions['edit_type']=='optical-band'): #roadm optical-band - str_config_messages = create_optical_band(resources) + str_config_messages = create_optical_band(resources) + + elif (conditions['edit_type']=='network-media-channel'): + commit_per_rule=True + #openroadm network media channel + str_config_messages = network_media_channel_handler(resources) else : #roadm media-channel str_config_messages=create_media_channel_v2(resources) @@ -196,7 +204,7 @@ def edit_config( for str_config_message in str_config_messages: # configuration of the received templates if str_config_message is None: raise UnsupportedResourceKeyException("CONFIG") - + result= netconf_handler.edit_config( # configure the device config=str_config_message, target=target, default_operation=default_operation, test_option=test_option, error_option=error_option, format=format) diff --git a/src/device/service/drivers/oc_driver/templates/VPN/openroadm.py b/src/device/service/drivers/oc_driver/templates/VPN/openroadm.py new file mode 100644 index 0000000000000000000000000000000000000000..f960c3d63be84f304b506d73a760441c8c6de396 --- /dev/null +++ b/src/device/service/drivers/oc_driver/templates/VPN/openroadm.py @@ -0,0 +1,187 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + + +from yattag import Doc, indent +import logging +from .common import seperate_port_config ,filter_config +from decimal import Decimal + + + +create_mc_err= ''' + <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> +<org-openroadm-device xmlns="http://org/openroadm/device"> + <interface> + <name>MC-TTP-DEG2-RX-193.3</name> + <description>Media-Channel-TTP-193.3THz-degree-2-in</description> + <type>openROADM-if:mediaChannelTrailTerminationPoint</type> + <administrative-state>inService</administrative-state> + <supporting-circuit-pack-name>DEG2-AMPRX</supporting-circuit-pack-name> + <supporting-port>DEG2-AMPRX-IN</supporting-port> + <supporting-interface-list>OMS-DEG2-TTP-RX</supporting-interface-list> + <mc-ttp xmlns="http://org/openroadm/media-channel-interfaces"> + <min-freq>193.25</min-freq> + <max-freq>193.35</max-freq> + </mc-ttp> + </interface> + <interface> + <name>MC-TTP-DEG2-TX-193.3</name> + <description>Media-Channel-TTP-193.3THz-degree-2-out</description> + <type>openROADM-if:mediaChannelTrailTerminationPoint</type> + <administrative-state>inService</administrative-state> + <supporting-circuit-pack-name>DEG2-AMPTX</supporting-circuit-pack-name> + <supporting-port>DEG2-AMPTX-OUT</supporting-port> + <supporting-interface-list>OMS-DEG2-TTP-TX</supporting-interface-list> + <mc-ttp xmlns="http://org/openroadm/media-channel-interfaces"> + <min-freq>193.25</min-freq> + <max-freq>193.35</max-freq> + </mc-ttp> + </interface> +</org-openroadm-device> + + +</config> + +''' + +def define_interface_name (type:str,interface_list:str,freq:int)->str: + interface_str = interface_list.split('-') + port_rank='' + port_type='' + if (len(interface_str)==4): + port_rank=interface_str[1] + port_type=interface_str[3] + elif (len(interface_str)==5): + port_rank=interface_str[2] + port_type=interface_str[3] + else : + port_rank=interface_list + port_type=interface_list+'type' + + + return f'{type.upper()}-{port_rank}-{port_type}-{freq}' + + + +def create_media_channel (resources): + + frequency_dict=next((r for r in resources if r['resource_key']== 'frequency'),None) + width_dict=next((r for r in resources if r['resource_key']== 'width'),None) + interfaces_lists =next((r for r in resources if r['resource_key']== 'interfaces'),None) + administrative_state= next((r for r in resources if r['resource_key']== 'administrative-state'),None) + min_freq= int(Decimal(frequency_dict["value"])*1000) - (int(width_dict["value"])/2) + max_freq = int(Decimal(frequency_dict["value"])*1000) + (int(width_dict["value"])/2) + #config,_,_ = filter_config(resources=resources,unwanted_keys=unwanted_keys) + + or_device_ns="http://org/openroadm/device" + or_interface_ns="http://org/openroadm/interfaces" + + results=[] + logging.info(f"from openroadm mc {resources}") + doc, tag, text = Doc().tagtext() + with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"): + with tag('org-openroadm-device', ('xmlns',or_device_ns)): + + for interface in interfaces_lists["value"]: + port = next((r for r in interface if r['resource_key']=='supporting-port'),None) + circuit_pack =next((r for r in interface if r['resource_key']=='supporting-circuit-pack-name'),None) + interface_list = next((r for r in interface if r['resource_key']=='supporting-interface-list'),None) + mc_name = define_interface_name('mc-ttp',interface_list['value'],frequency_dict['value']) + interface.append({'resource_key':'mc_name','value':mc_name}) + with tag('interface'): + + with tag('name'):text(mc_name) + with tag('description'):text(f'Media-channel-{frequency_dict["value"]}THz') + with tag('type'):text("openROADM-if:mediaChannelTrailTerminationPoint") + with tag('administrative-state'):text(administrative_state["value"]) + with tag('supporting-circuit-pack-name'):text(circuit_pack["value"]) + with tag('supporting-port'):text(port["value"]) + with tag('supporting-interface-list'):text(interface_list["value"]) + with tag('mc-ttp',xmlns="http://org/openroadm/media-channel-interfaces"): + with tag('max-freq'):text(max_freq) + with tag('min-freq'):text(min_freq) + + + + result = indent( + doc.getvalue(), + indentation = ' '*2, + newline = '' + ) + results.append(result) + logging.info(f"from openroadm mc results {results}") + return [results,resources] + + + + +def create_network_media_channel (resources): + + logging.info(f"nmc resources {resources}") + + unwanted_keys= ['max-freq','min-freq'] + #config,_,_ = filter_config(resources=resources,unwanted_keys=unwanted_keys) + + or_device_ns="http://org/openroadm/device" + frequency_dict=next((r for r in resources if r['resource_key']== 'frequency'),None) + width_dict=next((r for r in resources if r['resource_key']== 'width'),None) + interfaces_lists =next((r for r in resources if r['resource_key']== 'interfaces'),None) + administrative_state= next((r for r in resources if r['resource_key']== 'administrative-state'),None) + + + results=[] + doc, tag, text = Doc().tagtext() + with tag('config',xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"): + with tag('org-openroadm-device', ('xmlns',or_device_ns)): + for interface in interfaces_lists["value"]: + port = next((r for r in interface if r['resource_key']=='supporting-port'),None) + circuit_pack =next((r for r in interface if r['resource_key']=='supporting-circuit-pack-name'),None) + interface_list = next((r for r in interface if r['resource_key']=='mc_name'),None) + nmc_name = define_interface_name('nmc-ctp',interface_list['value'],frequency_dict['value']) + + with tag('interface'): + + with tag('name'):text(nmc_name) + with tag('description'):text(f'Media-channel-{frequency_dict["value"]}THz') + with tag('type'):text("openROADM-if:networkMediaChannelConnectionTerminationPoint") + with tag('administrative-state'):text(administrative_state["value"]) + with tag('supporting-circuit-pack-name'):text(circuit_pack["value"]) + with tag('supporting-port'):text(port["value"]) + with tag('supporting-interface-list'):text(interface_list["value"]) + with tag('nmc-ctp',xmlns="http://org/openroadm/network-media-channel-interfaces"): + with tag('frequency'):text(frequency_dict['value']) + with tag('width'):text(width_dict['value']) + + + + result = indent( + doc.getvalue(), + indentation = ' '*2, + newline = '' + ) + results.append(result) + logging.info(f"nmc message {results}") + return results + + +def network_media_channel_handler (resources): + unwanted_keys=["config_type"] + config,_,_ = filter_config(resources=resources,unwanted_keys=unwanted_keys) + mc_list,resources_updated= create_media_channel(resources=config) + nmc_list= create_network_media_channel(resources=resources_updated) + mc_list.extend(nmc_list) + + return mc_list diff --git a/src/device/service/drivers/oc_driver/templates/descovery_tool/open_roadm.py b/src/device/service/drivers/oc_driver/templates/descovery_tool/open_roadm.py index 337207072849a24f5419416a9a19555d1cfd3ab5..3c4b099a00e362d2981aaf7d572bdc86bf5c1221 100644 --- a/src/device/service/drivers/oc_driver/templates/descovery_tool/open_roadm.py +++ b/src/device/service/drivers/oc_driver/templates/descovery_tool/open_roadm.py @@ -17,7 +17,8 @@ import re,logging import json import lxml.etree as ET from typing import Collection, Dict, Any - +from common.proto.context_pb2 import Location +from decimal import Decimal def extract_roadm_circuits_pack (xml_data:str): @@ -112,8 +113,9 @@ def extract_openroadm_info(xml_data:str): def extract_openroadm_interface (xml_data:str): + or_config=[] or_interfaces=[] - + xml_bytes = xml_data.encode("utf-8") root = ET.fromstring(xml_bytes) # with open('xml.log', 'w') as f: @@ -122,24 +124,38 @@ def extract_openroadm_interface (xml_data:str): namespace = {'oc': "http://org/openroadm/device" , 'mc':"http://org/openroadm/media-channel-interfaces" - ,'nmc':"http://org/openroadm/network-media-channel-interfaces"} + ,'nmc':"http://org/openroadm/network-media-channel-interfaces" + ,'or-type':'http://org/openroadm/interfaces'} interfaces = root.findall('.//oc:interface',namespace) for interface in interfaces : mc = interface.find('.//mc:mc-ttp',namespace) name = interface.find('.//oc:name',namespace) description = interface.find('.//oc:description',namespace) - type='' + type=interface.find('.//oc:type',namespace) administrative_state=interface.find('.//oc:administrative-state',namespace) circuit_pack_name=interface.find('.//oc:supporting-circuit-pack-name',namespace) port=interface.find('.//oc:supporting-port',namespace) interface_list =interface.find('.//oc:supporting-interface-list',namespace) - + or_interfaces.append({ + 'interface_list':name.text if name is not None else None, + 'administrative_state':administrative_state.text if administrative_state is not None else None, + 'circuit_pack_name':circuit_pack_name.text if circuit_pack_name is not None else None, + 'port':port.text if port is not None else None , + 'type':type.text if type is not None else None + }) if mc is not None : print (mc) - frequency = mc.find('.//mc:min-freq',namespace) - width=mc.find('.//mc:width',namespace) + frequency=None + width=None + min_frequency = mc.find('.//mc:min-freq',namespace) + max_frequency = mc.find('.//mc:max-freq',namespace) + if min_frequency is not None and max_frequency is not None: + frequency = (Decimal(max_frequency.text) + Decimal(min_frequency.text) )/2 + width = int(( Decimal(max_frequency.text) - Decimal(min_frequency.text)) * 1000) + + mc= { 'name':name.text if name is not None else None, 'description':description.text if description is not None else None , @@ -148,13 +164,15 @@ def extract_openroadm_interface (xml_data:str): 'circuit_pack_name':circuit_pack_name.text if circuit_pack_name is not None else None, 'port':port.text if port is not None else None , 'interface_list': interface_list.text if interface_list is not None else None, - 'frequency': frequency.text if frequency is not None else None, - 'width':width.text if width is not None else None + 'frequency': str(frequency), + 'width':width } - or_interfaces.append(mc) + or_config.append(mc) else : nmc = interface.find('.//nmc:nmc-ctp',namespace) + + if nmc is not None : frequency = nmc.find('.//nmc:frequency',namespace) width=nmc.find('.//nmc:width',namespace) @@ -169,26 +187,65 @@ def extract_openroadm_interface (xml_data:str): 'frequency': frequency.text if frequency is not None else None, 'width':width.text if width is not None else None } - or_interfaces.append(nmc) - return or_interfaces + or_config.append(nmc) + logging.info(f"or_config for or {or_config}") + return [or_interfaces,or_config] def openroadm_values_extractor (data_xml:str,resource_keys:list,dic:dict): ports_result=[] openroadm_info= extract_openroadm_info(data_xml) circuits_list = extract_roadm_circuits_pack(data_xml) - interfaces = extract_openroadm_interface(data_xml) + interfaces,config = extract_openroadm_interface(data_xml) dic["openroadm_info"]=openroadm_info dic["circuits"]=circuits_list - dic['interfaces']=interfaces + dic['interfaces']=config for circuit in circuits_list : - + circuit_name=circuit['circuit_name'] + location = Location() + location.circuit_pack=circuit_name for port in circuit['ports']: if port is not None and 'port_name' in port : resource_key = '/endpoints/endpoint[{:s}]'.format(port["port_name"]) - resource_value = {'uuid': port["port_name"], 'type':port["port_qual"] if "port_qual" in port else None} + resource_value = {'uuid': port["port_name"] + , 'type':port["port_qual"] if "port_qual" in port else None, + 'location':{"circuit_pack":location.circuit_pack} + } ports_result.append((resource_key, resource_value)) + for interface in interfaces: + existed=False + circuit_name=interface['circuit_pack_name'] + interface_list=interface['interface_list'] + + location_interface=f'{interface_list}/{circuit_name}' + port = interface["port"] + type = interface['type'] + if port is not None: + for i , (key,value) in enumerate(ports_result): + if value['uuid'] == port: + new_value = value + merged_interface=None + if 'interface' in value['location']: + merged_interface= f"{value['location']['interface']},{location_interface}" + if merged_interface is not None : + new_value['location']={"interface":merged_interface} + else : + new_value['location']={"interface":location_interface} + + ports_result[i]= (key,new_value ) + existed=True + break + + if not existed: + resource_key = '/endpoints/endpoint[{:s}]'.format(port) + resource_value = {'uuid': f'{port}' + , 'type':type , + 'location':{"interface":location_interface} + } + ports_result.append((resource_key, resource_value)) + + return [dic,ports_result] diff --git a/src/tests/ofc24/r_t.sh b/src/tests/ofc24/r_t.sh old mode 100644 new mode 100755 diff --git a/src/webui/service/opticalconfig/routes.py b/src/webui/service/opticalconfig/routes.py index ace59d6705f656aa855a2cb4fccfb79bbd79b6eb..1b60bff1be780039b51ceebe286d4dfdc16e7a71 100644 --- a/src/webui/service/opticalconfig/routes.py +++ b/src/webui/service/opticalconfig/routes.py @@ -10,7 +10,7 @@ from slice.client.SliceClient import SliceClient from .forms import UpdateDeviceForm ,AddTrancseiver ,UpdateInterfaceForm ,UpdateStatusForm from common.tools.context_queries.OpticalConfig import opticalconfig_get_uuid , device_get_uuid - +from common.DeviceTypes import DeviceTypeEnum opticalconfig = Blueprint('opticalconfig', __name__,url_prefix="/opticalconfig") context_client = ContextClient() @@ -41,11 +41,15 @@ def home() : value=json.loads(configs.config) if type(configs.config)==str else configs.config config_type = value["type"] - if ('channels' in value): - - - channels_num=len(value['channels']) - value["channels_number"]=channels_num + if config_type != DeviceTypeEnum.OPEN_ROADM._value_ : + if ('channels' in value): + + + value["channels_number"]=len(value['channels']) + + else : + if ('interfaces' in value) : + value["channels_number"]=len(value['interfaces']) # value['operationalMode']=value['operational-mode'] # value['targetOutputPower']=value['target-output-power'] value['opticalconfig_id']=configs.opticalconfig_id @@ -82,7 +86,7 @@ def show_details(config_uuid): device_name= config["device_name"] config_type = config["type"] - if config_type == 'optical-transponder': + if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_: LOGGER.info("config details from show detail %s",config) @@ -100,7 +104,7 @@ def show_details(config_uuid): device_details.append(new_config) - if config_type == 'optical-roadm': + if config_type == DeviceTypeEnum.OPTICAL_ROADM._value_: LOGGER.info("config details from show detail %s",config) @@ -119,7 +123,24 @@ def show_details(config_uuid): new_config['optical_band_parent']= channel['optical_band_parent'] if 'optical_band_parent' in channel else '' new_config['channel_index']= channel['channel_index'] if 'channel_index' in channel else '' - device_details.append(new_config) + device_details.append(new_config) + if config_type == DeviceTypeEnum.OPEN_ROADM._value_: + if 'interfaces' in config : + for interface in config["interfaces"]: + new_config={} + new_config["name"]=interface["name"] if "name" in interface else '' + new_config["administrative_state"]=interface[ "administrative_state"] + new_config["circuit_pack_name"]=interface["circuit_pack_name"] + new_config["port"]=interface["port"] + new_config["interface_list"]=interface["interface_list"] + new_config["frequency"]=interface["frequency"] + new_config["width"]=interface[ "width"] + new_config["type"]=interface["type"] + + 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,type=config_type) @@ -360,6 +381,81 @@ def update_status (config_uuid,channel_name): flash(f'Problem updating the device. {e}', 'danger') return render_template('opticalconfig/update_status.html',form=form , channel_name=channel_name, submit_text='Update Device Status') + + +@opticalconfig.route('/configure_openroadm', methods=['POST']) +def update_openroadm () : + + if (request.method == 'POST'): + ports_list= [] + data = request.get_json() + LOGGER.info(f"data {data}") + devices=data.get('devices') + LOGGER.info(f"devices {devices}") + myResponse =[] + status_code='' + config={} + target_interface={} + for device in devices : + frequency = device.get("frequency") + width= device.get("width") + ports=device.get('ports') + device_name=device.get("device_name") + LOGGER.info(f"device from post {device}") + target_interface["frequency"]=frequency + target_interface["width"]=width + target_interface["administrative-state"]="inService" + target_interface["config_type"]=device.get("config_type") + + + if (device_name): + + opticalconfig_uuid = opticalconfig_get_uuid(device_name=device_name) + opticalconfigId=OpticalConfigId() + opticalconfigId.opticalconfig_uuid=opticalconfig_uuid + context_client.connect() + opticalconfig = context_client.SelectOpticalConfig(opticalconfigId) + context_client.close() + config =json.loads(opticalconfig.config) + for port in ports : + ports_list.append({ + "supporting-circuit-pack-name":port["circuit_pack"], + 'supporting-interface-list':port["interface_list"], + 'supporting-port':port["port"] + }) + target_interface["ports"]=ports_list + config["new_config"]=target_interface + opticalconfig.config =json.dumps(config) + try: + device_client.connect() + device_client.ConfigureOpticalDevice(opticalconfig) + device_client.close() + + myResponse.append(f"device {device_name} port {port} is updated successfully") + status_code = 200 + + + except Exception as e: # pylint: disable=broad-except + + myResponse.append(f"Problem updating the device. {e}") + status_code = 500 + break + + + + else : + + myResponse.append(f"requested device {device_name} is not existed") + status_code = 400 + break + + + + response=make_response(f'{myResponse}') + response.status_code=status_code + + return response + \ No newline at end of file diff --git a/src/webui/service/templates/opticalconfig/details.html b/src/webui/service/templates/opticalconfig/details.html index e1d009efd4648fc2fcfd6b0156a6ebf6dc687c71..08c22db845864b7f85f062140b00b2de3f679dc4 100644 --- a/src/webui/service/templates/opticalconfig/details.html +++ b/src/webui/service/templates/opticalconfig/details.html @@ -83,6 +83,38 @@ {% endfor %} </tbody> </table> + {% elif type == 'openroadm' %} + + <table class="table table-striped table-hover"> + <thead> + <tr> + <th scope="col"> name</th> + <th scope="col"> type</th> + <th scope="col">administrative state</th> + <th scope="col">circuit pack name</th> + <th scope="col">port</th> + <th scope="col">interface list</th> + <th scope="col">frequency</th> + <th scope="col">width</th> + </tr> + </thead> + <tbody> + + {% for channel in device %} + <tr style="background-color:{%if channel.status == 'DISABLED' %} gray {% endif %};"> + <td>{{channel.name}}</td> + <td>{{channel.type}}</td> + <td>{{channel.administrative_state}}</td> + <td> {{channel.circuit_pack_name}}</td> + <td>{{channel.port}}</td> + <td>{{channel.interface_list}}</td> + <td> {{channel.frequency}}</td> + <td> {{channel.width}}</td> + </tr> + {% endfor %} + </tbody> + </table> + {%else%} <table class="table table-striped table-hover"> <thead> diff --git a/test.py b/test.py index 4a5d82ee8cc2bdf2d7ee45b4ff4e9efc047d07ce..9595e5bb83632e52fe672a3d31ff4103d2787690 100644 --- a/test.py +++ b/test.py @@ -5,31 +5,48 @@ import re from typing import Optional, Union from uuid import UUID, uuid4, uuid5 import logging +from decimal import Decimal + + +create_mc_test = ''' +<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> +<org-openroadm-device xmlns="http://org/openroadm/device" xmlns:openROADM-if="http://org/openroadm/interfaces"> +<interface> <name>MC-TTP-DEG1-RX-193.3</name> <description>Media-channel-193.3THz</description> +<type>openROADM-if:mediaChannelTrailTerminationPoint</type> <administrative-state>inService</administrative-state> +<supporting-circuit-pack-name>DEG1-AMPTX</supporting-circuit-pack-name> <supporting-port>DEG1-AMPTX-OUT</supporting-port> +<supporting-interface-list>OMS-DEG1-TTP-RX</supporting-interface-list> <mc-ttp xmlns="http://org/openroadm/media-channel-interfaces"> +<max-freq>193350.0</max-freq> <min-freq>193250.0</min-freq> </mc-ttp> </interface> <interface> <name>MC-TTP-DEG1-TX-193.3</name> +<description>Media-channel-193.3THz</description> <type>openROADM-if:mediaChannelTrailTerminationPoint</type> +<administrative-state>inService</administrative-state> <supporting-circuit-pack-name>DEG1-AMPRX</supporting-circuit-pack-name> +<supporting-port>DEG1-AMPRX-IN</supporting-port> <supporting-interface-list>OMS-DEG1-TTP-TX</supporting-interface-list> +<mc-ttp xmlns="http://org/openroadm/media-channel-interfaces"> +<max-freq>193350.0</max-freq> <min-freq>193250.0</min-freq> </mc-ttp> </interface> </org-openroadm-device></config> +''' create_mc_err= ''' <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> -<org-openroadm-device xmlns="http://org/openroadm/device" xmlns:openROADM-if="http://org/openroadm/interfaces"> +<org-openroadm-device xmlns="http://org/openroadm/device"> <interface> - <name>MC-TTP-DEG1-RX-193.3</name> - <description>Media-Channel-TTP-193.3THz-degree-1-in</description> + <name>MC-TTP-DEG2-RX-193.3</name> + <description>Media-Channel-TTP-193.3THz-degree-2-in</description> <type>openROADM-if:mediaChannelTrailTerminationPoint</type> <administrative-state>inService</administrative-state> - <supporting-circuit-pack-name>DEG1-AMPRX</supporting-circuit-pack-name> - <supporting-port>DEG1-AMPRX-IN</supporting-port> - <supporting-interface-list>OMS-DEG1-TTP-RX</supporting-interface-list> + <supporting-circuit-pack-name>DEG2-AMPRX</supporting-circuit-pack-name> + <supporting-port>DEG2-AMPRX-IN</supporting-port> + <supporting-interface-list>OMS-DEG2-TTP-RX</supporting-interface-list> <mc-ttp xmlns="http://org/openroadm/media-channel-interfaces"> <min-freq>193.25</min-freq> <max-freq>193.35</max-freq> </mc-ttp> </interface> <interface> - <name>MC-TTP-DEG1-TX-193.3</name> - <description>Media-Channel-TTP-193.3THz-degree-1-out</description> + <name>MC-TTP-DEG2-TX-193.3</name> + <description>Media-Channel-TTP-193.3THz-degree-2-out</description> <type>openROADM-if:mediaChannelTrailTerminationPoint</type> <administrative-state>inService</administrative-state> - <supporting-circuit-pack-name>DEG1-AMPTX</supporting-circuit-pack-name> - <supporting-port>DEG1-AMPTX-OUT</supporting-port> - <supporting-interface-list>OMS-DEG1-TTP-TX</supporting-interface-list> + <supporting-circuit-pack-name>DEG2-AMPTX</supporting-circuit-pack-name> + <supporting-port>DEG2-AMPTX-OUT</supporting-port> + <supporting-interface-list>OMS-DEG2-TTP-TX</supporting-interface-list> <mc-ttp xmlns="http://org/openroadm/media-channel-interfaces"> <min-freq>193.25</min-freq> <max-freq>193.35</max-freq> @@ -42,28 +59,31 @@ create_mc_err= ''' ''' -create_srg = ''' + +create_nmc = ''' <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> - <org-openroadm-device xmlns="http://org/openroadm/device"> + <org-openroadm-device xmlns="http://org/openroadm/device"> <interface> - <name>SRG1-PP01-TX-193.3</name> - <description>Network-Media-Channel-CTP-193.3THz-srg-1-out</description> + <name>NMC-CTP-DEG2-TX-193.3</name> + <description>Network-Media-Channel-CTP-193.3THz-degree-2-out</description> <type>openROADM-if:networkMediaChannelConnectionTerminationPoint</type> <administrative-state>inService</administrative-state> - <supporting-circuit-pack-name>SRG1-WSS</supporting-circuit-pack-name> - <supporting-port>SRG1-OUT1</supporting-port> + <supporting-circuit-pack-name>DEG2-AMPTX</supporting-circuit-pack-name> + <supporting-interface-list>MC-TTP-DEG2-TX-193.3</supporting-interface-list> + <supporting-port>DEG2-AMPTX-OUT</supporting-port> <nmc-ctp xmlns="http://org/openroadm/network-media-channel-interfaces"> <frequency>193.30</frequency> <width>100</width> </nmc-ctp> </interface> <interface> - <name>SRG1-PP01-RX-193.3</name> - <description>Network-Media-Channel-CTP-193.3THz-srg-1-in</description> + <name>NMC-CTP-DEG2-RX-193.3</name> + <description>Network-Media-Channel-CTP-193.3THz-degree-2-in</description> <type>openROADM-if:networkMediaChannelConnectionTerminationPoint</type> <administrative-state>inService</administrative-state> - <supporting-circuit-pack-name>SRG1-WSS</supporting-circuit-pack-name> - <supporting-port>SRG1-IN1</supporting-port> + <supporting-circuit-pack-name>DEG2-AMPRX</supporting-circuit-pack-name> + <supporting-port>DEG2-AMPRX-IN</supporting-port> + <supporting-interface-list>MC-TTP-DEG2-RX-193.3</supporting-interface-list> <nmc-ctp xmlns="http://org/openroadm/network-media-channel-interfaces"> <frequency>193.30</frequency> <width>100</width> @@ -71,34 +91,32 @@ create_srg = ''' </interface> </org-openroadm-device> - - </config> + ''' -create_nmc = ''' + +create_srg = ''' <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> - <org-openroadm-device xmlns="http://org/openroadm/device"> + <org-openroadm-device xmlns="http://org/openroadm/device"> <interface> - <name>NMC-CTP-DEG1-TX-193.3</name> - <description>Network-Media-Channel-CTP-193.3THz-degree-1-out</description> + <name>SRG1-PP01-TX-193.3</name> + <description>Network-Media-Channel-CTP-193.3THz-srg-1-out</description> <type>openROADM-if:networkMediaChannelConnectionTerminationPoint</type> <administrative-state>inService</administrative-state> - <supporting-circuit-pack-name>DEG1-AMPTX</supporting-circuit-pack-name> - <supporting-interface-list>MC-TTP-DEG1-TX-193.3</supporting-interface-list> - <supporting-port>DEG1-AMPTX-OUT</supporting-port> + <supporting-circuit-pack-name>SRG1-WSS</supporting-circuit-pack-name> + <supporting-port>SRG1-OUT1</supporting-port> <nmc-ctp xmlns="http://org/openroadm/network-media-channel-interfaces"> <frequency>193.30</frequency> <width>100</width> </nmc-ctp> </interface> <interface> - <name>NMC-CTP-DEG1-RX-193.3</name> - <description>Network-Media-Channel-CTP-193.3THz-degree-1-in</description> + <name>SRG1-PP01-RX-193.3</name> + <description>Network-Media-Channel-CTP-193.3THz-srg-1-in</description> <type>openROADM-if:networkMediaChannelConnectionTerminationPoint</type> <administrative-state>inService</administrative-state> - <supporting-circuit-pack-name>DEG1-AMPRX</supporting-circuit-pack-name> - <supporting-port>DEG1-AMPRX-IN</supporting-port> - <supporting-interface-list>MC-TTP-DEG1-RX-193.3</supporting-interface-list> + <supporting-circuit-pack-name>SRG1-WSS</supporting-circuit-pack-name> + <supporting-port>SRG1-IN1</supporting-port> <nmc-ctp xmlns="http://org/openroadm/network-media-channel-interfaces"> <frequency>193.30</frequency> <width>100</width> @@ -106,11 +124,13 @@ create_nmc = ''' </interface> </org-openroadm-device> -</config> + +</config> ''' + create_connec= ''' <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <org-openroadm-device xmlns="http://org/openroadm/device"> @@ -130,22 +150,11 @@ create_connec= ''' </config> ''' -device = { - 'host':'172.17.0.2', # IP address or hostname of the remote machine '172.17.0.2' - 'port': 830, # SSH port (default: 22) - 'username': 'openroadm', # SSH username - 'password': 'openroadm', # SSH password - 'device_params': {'name': 'default'}, - 'hostkey_verify':False, - "allow_agent":False - ,"look_for_keys":False -} - - def extract_openroadm_interface (xml_data:str): + or_config=[] or_interfaces=[] - + xml_bytes = xml_data.encode("utf-8") root = ET.fromstring(xml_bytes) # with open('xml.log', 'w') as f: @@ -154,20 +163,27 @@ def extract_openroadm_interface (xml_data:str): namespace = {'oc': "http://org/openroadm/device" , 'mc':"http://org/openroadm/media-channel-interfaces" - ,'nmc':"http://org/openroadm/network-media-channel-interfaces"} + ,'nmc':"http://org/openroadm/network-media-channel-interfaces" + ,'or-type':'http://org/openroadm/interfaces'} interfaces = root.findall('.//oc:interface',namespace) for interface in interfaces : mc = interface.find('.//mc:mc-ttp',namespace) name = interface.find('.//oc:name',namespace) description = interface.find('.//oc:description',namespace) - type='' + type=interface.find('.//oc:type',namespace) administrative_state=interface.find('.//oc:administrative-state',namespace) circuit_pack_name=interface.find('.//oc:supporting-circuit-pack-name',namespace) port=interface.find('.//oc:supporting-port',namespace) interface_list =interface.find('.//oc:supporting-interface-list',namespace) - + or_interfaces.append({ + 'interface_list':name.text if name is not None else None, + 'administrative_state':administrative_state.text if administrative_state is not None else None, + 'circuit_pack_name':circuit_pack_name.text if circuit_pack_name is not None else None, + 'port':port.text if port is not None else None , + 'type':type.text if type is not None else None + }) if mc is not None : print (mc) frequency = mc.find('.//mc:min-freq',namespace) @@ -183,7 +199,7 @@ def extract_openroadm_interface (xml_data:str): 'frequency': frequency.text if frequency is not None else None, 'width':width.text if width is not None else None } - or_interfaces.append(mc) + or_config.append(mc) else : nmc = interface.find('.//nmc:nmc-ctp',namespace) @@ -201,26 +217,51 @@ def extract_openroadm_interface (xml_data:str): 'frequency': frequency.text if frequency is not None else None, 'width':width.text if width is not None else None } - or_interfaces.append(nmc) - return or_interfaces - - - + or_config.append(nmc) + + return [or_interfaces,or_config] + + + + + + +device = { + 'host':'172.17.0.2', # IP address or hostname of the remote machine '172.17.0.2' + 'port': 830, # SSH port (default: 22) + 'username': 'openroadm', # SSH username + 'password': 'openroadm', # SSH password + 'device_params': {'name': 'default'}, + 'hostkey_verify':False, + + + "force_running": False, + + "look_for_keys": False, + "allow_agent": False, + "commit_per_rule": False, +} + + + if __name__ == '__main__': + - with manager.connect(host=device['host'] - ,port=device['port'] + with manager.connect( host=device['host'] + ,port=device['port'] ,username=device['username'] ,password=device['password'] ,hostkey_verify=device['hostkey_verify'] ,allow_agent=device['allow_agent'] ,look_for_keys=device['look_for_keys']) as m : - #edit_result = m.edit_config (target="running",config=create_nmc ) + edit_result = m.edit_config (target="running",config=create_mc_test ) result = m.get_config (source="running").data_xml - interfaces=extract_roadm_interface(result) - print(interfaces) + #interfaces,config = extract_openroadm_interface(result) + #print (interfaces) + #interfaces=extract_roadm_interface(result) + #print(interfaces) # optical_band_namespaces="http://flex-scale-project.eu/yang/flex-scale-mg-on" #namespaces={"oc":"http://openconfig.net/yang/wavelength-router"} #obj=extract_media_channels(result,namespaces) @@ -233,8 +274,9 @@ if __name__ == '__main__': #print(f"optical_bands {obj1}") #print(f"circuits {circuits}") - # with open("xml.log","w") as f: - # print (result,file=f) + with open("xml.log","w") as f: + print (result,file=f) +