Skip to content
Snippets Groups Projects
Commit d9d65afa authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

clean code phase 1

parent 142f8f38
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!284Resolve: "(CNIT) Multi-Granular Optical Nodes and Optical Transpoders management"
Showing
with 56 additions and 68 deletions
......@@ -108,7 +108,7 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi
is_oc_driver = DeviceDriverEnum.DEVICEDRIVER_OC in set(request.device_drivers)
#optical_endpoints_data : List[Dict] = list()
LOGGER.info(f"is_oc_driver {is_oc_driver}")
endpoints_data : List[Dict] = list()
for i, endpoint in enumerate(request.device_endpoints):
endpoint_device_uuid = endpoint.endpoint_id.device_id.device_uuid.uuid
......
......@@ -61,9 +61,9 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):
channel_namespace= None
OpticalConfig_data = []
config_type=None
is_transpondre=False
#is_transpondre=False
opticalconfig_uuid =opticalconfig_get_uuid(device_id)
LOGGER.info(f"cofigy_type {request.config}")
if request.config:
config = json.loads(request.config)
if 'channel_namespace' in config:
......@@ -179,8 +179,6 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):
}
)
LOGGER.info(f"added OpticalConfig_data {OpticalConfig_data}")
LOGGER.info(f"added channels {channels}")
def callback(session:Session)->bool:
stmt = insert(OpticalConfigModel).values(OpticalConfig_data)
......@@ -279,9 +277,9 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig):
channel_namespace= None
OpticalConfig_data = []
config_type=None
is_transpondre=False
#is_transpondre=False
opticalconfig_uuid =opticalconfig_get_uuid(device_id)
LOGGER.info(f"udpate_cofigy_type {request.config}")
if request.config :
config = json.loads(request.config)
......@@ -432,8 +430,7 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig):
}
)
LOGGER.info(f"udpate_ OpticalConfig_data {OpticalConfig_data}")
LOGGER.info(f"udpate_ channels {channels}")
def callback(session:Session)->bool:
stmt = insert(OpticalConfigModel).values(OpticalConfig_data)
......@@ -530,7 +527,7 @@ def select_opticalconfig(db_engine:Engine,request:OpticalConfigId):
result.opticalconfig_id.opticalconfig_uuid = ids_obj["opticalconfig_uuid"]
result.device_id.device_uuid.uuid=ids_obj["device_uuid"]
LOGGER.info(f"select_opticalconfig {result}")
return result
return run_transaction(sessionmaker(bind=db_engine, expire_on_commit=False), callback)
......@@ -556,7 +553,7 @@ def delete_opticalchannel(db_engine : Engine ,messagebroker : MessageBroker, re
opticalconfig_uuid = request.opticalconfig_id.opticalconfig_uuid
channels=[]
config_type=None
LOGGER.info(f"delete_optical_channel config {config}")
if "type" in config :
config_type= config["type"]
if 'new_config' in config:
......@@ -612,7 +609,7 @@ def delete_opticalchannel(db_engine : Engine ,messagebroker : MessageBroker, re
else :
return
LOGGER.info(f"delete channel {channels}")
def callback(session : Session):
......
......@@ -103,8 +103,7 @@ def optical_link_set(db_engine : Engine, messagebroker : MessageBroker, request
LOGGER.info(f"update_link_uuid {link_uuid}")
LOGGER.info(f"c_slots {request.optical_details.c_slots }")
optical_link_data = [{
'opticallink_uuid' : link_uuid,
'name' : link_name,
......
......@@ -60,8 +60,7 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
device_uuid = request.device_id.device_uuid.uuid
connection_config_rules = check_connect_rules(request.device_config)
LOGGER.info(f"connection_config_rules {connection_config_rules}")
LOGGER.info(f"lenght of connection_config_rules {len(connection_config_rules)}")
check_no_endpoints(request.device_endpoints)
......@@ -158,7 +157,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'])
......
......@@ -80,7 +80,7 @@ class OpenConfigServicer(DeviceServiceServicer):
is_all_good=True
config =json.loads(request.config)
results=None
LOGGER.info(f" config from openconfigservicer {config}")
try:
context_client = ContextClient()
device = get_device(
......@@ -89,23 +89,23 @@ class OpenConfigServicer(DeviceServiceServicer):
if device is None:
raise NotFoundException('Device', device_uuid, extra_details='loading in ConfigureDevice')
LOGGER.info(f"device is {device.name}")
resources,conditions=extract_resources(config=config,device=device)
LOGGER.info(f"from openconfigservicer {resources} and conditions {conditions}")
driver : _Driver = get_driver(self.driver_instance_cache, device)
results = driver.SetConfig(resources=resources,conditions=conditions)
for result in results:
if not result :
is_all_good=False
LOGGER.info(f"resluts {results} and is_all_good {is_all_good}")
if is_all_good:
#driver.GetConfig(resource_keys=[])
config = json.loads(request.config)
handled_flow=next((i for i in resources if i['resource_key']=='handled_flow'),None)
flow_handled=[ ]
LOGGER.info(f"flow_handled {handled_flow}")
if handled_flow is not None and len(handled_flow)>0:
config['flow_handled']=handled_flow['value']
......@@ -126,7 +126,6 @@ class OpenConfigServicer(DeviceServiceServicer):
device_uuid = configs.device_id.device_uuid.uuid
LOGGER.info(f" Get DeviceConfigure {device_uuid}")
try:
device = get_device(
......@@ -164,7 +163,7 @@ class OpenConfigServicer(DeviceServiceServicer):
resources:list[dict]=[]
is_all_good=True
config =json.loads(request.config)
LOGGER.info(f"Disable config from openconfigservicer {config}")
try:
context_client = ContextClient()
device = get_device(
......@@ -173,9 +172,9 @@ class OpenConfigServicer(DeviceServiceServicer):
if device is None:
raise NotFoundException('Device', device_uuid, extra_details='loading in ConfigureDevice')
LOGGER.info(f"device is {device.name}")
resources,conditions=extract_resources(config=config,device=device)
LOGGER.info(f" Disable resources from openconfigservicer {resources} and conditions {conditions}")
driver : _Driver = get_driver(self.driver_instance_cache, device)
if 'edit_type' in conditions and conditions['edit_type'] == 'optical-band':
roadm_configuration = driver.GetConfig()
......@@ -187,7 +186,7 @@ class OpenConfigServicer(DeviceServiceServicer):
for result in results:
if not result :
is_all_good=False
LOGGER.info(f"Disable resluts {results} and is_all_good {is_all_good}")
if is_all_good:
config = json.loads(request.config)
flow_handled=[ ]
......
......@@ -115,7 +115,7 @@ def populate_endpoints(
resources_to_get = [RESOURCE_ENDPOINTS]
results_getconfig = driver.GetConfig(resources_to_get)
LOGGER.debug('results_getconfig = {:s}'.format(str(results_getconfig)))
LOGGER.info('results_getconfig = {:s}'.format(str(results_getconfig)))
# first quick pass to identify need of mgmt endpoints and links
add_mgmt_port = False
......
......@@ -284,7 +284,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
# to get the reply form the optical module
reply_txt = add_lightpath(src, dst, bitrate, bidir, ob_band)
LOGGER.info('reply_text={:s}'.format(reply_txt))
# reply with 2 transponders and 2 roadms
reply_json = json.loads(reply_txt)
optical_band_txt = ""
......@@ -295,7 +295,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
parent_ob = reply_json["parent_opt_band"]
LOGGER.debug('Parent optical-band={}'.format(parent_ob))
optical_band_txt = get_optical_band(parent_ob)
LOGGER.info('optical-band details={}'.format(optical_band_txt))
else:
LOGGER.debug('expected optical band not found')
else:
......@@ -309,8 +309,6 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
optical_reply = adapt_reply(
devices, _service, reply_json, context_uuid_x, topology_uuid_x, optical_band_txt
)
LOGGER.info('optical_reply={:s}'.format(
grpc_message_to_json_string(optical_reply)))
tasks_scheduler.compose_from_pathcompreply(
optical_reply, is_delete=False)
......@@ -392,7 +390,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
service.service_config.config_rules[0].custom.resource_value)
ob_id=None
flow_id=None
LOGGER.info(f"DELETE configuration rules {c_rules_dict}")
if "ob_id" in c_rules_dict:
ob_id=c_rules_dict["ob_id"]
if ("flow_id" in c_rules_dict):
......
......@@ -112,7 +112,7 @@ class SettingsHandler:
raw_data = SettingsHandler._config_rule_to_raw(config_rule)
if raw_data is None: return
action, key_or_path, value = raw_data
LOGGER.info(f"update_config_rule action {action} key_or_path:{key_or_path} and value {value}")
if action == ConfigActionEnum.CONFIGACTION_SET:
self.set(key_or_path, value)
elif action == ConfigActionEnum.CONFIGACTION_DELETE:
......
......@@ -51,11 +51,11 @@ class OCServiceHandler(_ServiceHandler):
settings=None
if self.__settings_handler.get('/settings-ob_{}'.format(connection_uuid)):
LOGGER.info(f"setEndpoint ob {connection_uuid}")
is_opticalband=True
settings = self.__settings_handler.get('/settings-ob_{}'.format(connection_uuid))
else:
LOGGER.info(f"setEndpoint {connection_uuid}")
settings = self.__settings_handler.get('/settings')
bidir = settings.value.get("bidir")
......@@ -69,11 +69,11 @@ class OCServiceHandler(_ServiceHandler):
#handled_flows=handle_flows_names(flows=flows,task_executor=self.__task_executor)
LOGGER.info(f"Computed Flows {flows}")
results = []
#new cycle for setting optical devices
LOGGER.info(f"settings_oc_service: {settings}")
for device_uuid in flows.keys():
try:
dev_flows = flows[device_uuid]
......@@ -111,17 +111,17 @@ class OCServiceHandler(_ServiceHandler):
settings = self.__settings_handler.get('/settings')
LOGGER.info(f"from DeleteEndpoint settings {settings.value}")
dev_flows=[]
results = []
for device_uuid in flows.keys():
try:
channel_indexes= []
dev_flows = flows[device_uuid]
LOGGER.info(f"from DeleteEndpoint dev_flows {dev_flows}")
device_obj = self.__task_executor.get_device(DeviceId(**json_device_id(device_uuid)))
LOGGER.info(f"from DeleteEndpoint device type {device_obj.device_type}")
if (device_obj.device_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_):
for endpoint in dev_flows:
src , dst = endpoint
......@@ -142,8 +142,7 @@ class OCServiceHandler(_ServiceHandler):
elif is_opticalband:
if "ob_id" in settings.value:
channel_indexes.append(settings.value["ob_id"])
LOGGER.info(f"from DeleteEndpoint channel_indexes {channel_indexes}")
if len(channel_indexes)>0:
errors=self.__task_executor.deconfigure_optical_device(device=device_obj
,channel_indexes=channel_indexes
......
......@@ -54,7 +54,7 @@ class QKDServiceHandler(_ServiceHandler):
chk_type('endpoints', endpoints, list)
if len(endpoints) < 2 or len(endpoints) % 2: return []
LOGGER.info('Endpoints: ' + str(endpoints))
service_uuid = self.__service.service_id.service_uuid.uuid
......
......@@ -151,7 +151,7 @@ class TaskExecutor:
new_config["flow"] = flows
result.config = json.dumps(new_config)
optical_config.CopyFrom(result)
LOGGER.info("resul from select optical config %s",optical_config)
self._device_client.ConfigureOpticalDevice(optical_config)
self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device)
......@@ -233,7 +233,7 @@ class TaskExecutor:
connection_uuid=connection.connection_id.connection_uuid
if class_service_handler is None:
class_service_handler=self.get_service_handler(connection, service,**service_handler_settings)
LOGGER.info(f"checking media_channel for service {connection_uuid}")
if class_service_handler.check_media_channel(connection_uuid):
return True
return False
......
......@@ -76,7 +76,7 @@ class TasksScheduler:
return service_planned_key, service_active_key
def _service_remove(self, service_id : ServiceId) -> Tuple[str, str]:
LOGGER.info(f"adding service into _dag {service_id}")
service_removing_key = self._add_task_if_not_exists(Task_ServiceSetStatus(
self._executor, service_id, ServiceStatusEnum.SERVICESTATUS_PENDING_REMOVAL))
......@@ -87,7 +87,7 @@ class TasksScheduler:
return service_removing_key, service_delete_key
def _optical_service_remove(self, service_id : ServiceId,has_media_channel:bool,has_optical_band=True) -> Tuple[str, str]:
LOGGER.info(f"adding service into _dag {service_id}")
service_removing_key = self._add_task_if_not_exists(Task_ServiceSetStatus(
self._executor, service_id, ServiceStatusEnum.SERVICESTATUS_ACTIVE))
......@@ -114,7 +114,7 @@ class TasksScheduler:
return connection_configure_key
def _connection_deconfigure(self, connection_id : ConnectionId, service_id : ServiceId) -> str:
LOGGER.info(f"adding connection into _dag {connection_id}")
connection_deconfigure_key = self._add_task_if_not_exists(Task_ConnectionDeconfigure(
self._executor, connection_id))
......@@ -133,7 +133,7 @@ class TasksScheduler:
def _optical_connection_deconfigure(self, connection_id : ConnectionId, service_id : ServiceId,has_media_channel:bool,has_optical_band=True) -> str:
LOGGER.info(f"adding connection into _dag {connection_id}")
connection_deconfigure_key = self._add_task_if_not_exists(Task_OpticalConnectionDeconfigure(
self._executor, connection_id,has_media_channel=has_media_channel))
......@@ -152,7 +152,7 @@ class TasksScheduler:
def _optical_service_config_remove(self, connection_id : ConnectionId
, service_id : ServiceId
) -> str:
LOGGER.info(f"_optical_service_config_remove {connection_id}")
service_config_key = self._add_task_if_not_exists(Task_OpticalServiceConfigDelete(
self._executor,connection_id, service_id
......@@ -251,7 +251,7 @@ class TasksScheduler:
if code == 400 and reply_not_allowed in reply :
MSG = 'Deleteion for the service is not Allowed , Served Lightpaths is not empty'
raise Exception(MSG)
LOGGER.info('entered')
include_service(item.service_id,has_media_channel=has_media_channel,has_optical_band=has_optical_band)
self._add_service_to_executor_cache(item)
......
......@@ -72,7 +72,7 @@ def show_details(config_uuid):
response = context_client.SelectOpticalConfig(opticalconfigId)
context_client.close()
if (response and response.opticalconfig_id.opticalconfig_uuid !=''):
LOGGER.info("response from show detail %s",response)
opticalConfig = OpticalConfig()
opticalConfig.CopyFrom(response)
......@@ -84,7 +84,6 @@ def show_details(config_uuid):
if config_type == 'optical-transponder':
LOGGER.info("config details from show detail %s",config)
if 'channels' in config:
......@@ -102,7 +101,7 @@ def show_details(config_uuid):
if config_type == 'optical-roadm':
LOGGER.info("config details from show detail %s",config)
if 'channels' in config:
......@@ -120,7 +119,7 @@ def show_details(config_uuid):
new_config['channel_index']= channel['channel_index'] if 'channel_index' 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,type=config_type)
......@@ -147,16 +146,16 @@ def update_externally () :
if (request.method == 'POST'):
device_list= []
data = request.get_json()
LOGGER.info(f"data {data}")
devices=data.get('devices')
LOGGER.info(f"devices {devices}")
myResponse =[]
status_code=''
for device in devices :
port = device.get("port")
channel_name= f"channel-{port}"
device_name=device.get("device_name")
LOGGER.info(f"device from post {device}")
if (device_name):
......@@ -166,9 +165,7 @@ def update_externally () :
context_client.connect()
opticalconfig = context_client.SelectOpticalConfig(opticalconfigId)
context_client.close()
LOGGER.info(f"opticalconfig {opticalconfig}")
LOGGER.info(f"opticalconfig opticalconfig_uuid {opticalconfig.opticalconfig_id.opticalconfig_uuid}")
LOGGER.info(f"device is existed {opticalconfig.opticalconfig_id.opticalconfig_uuid != ''}")
if opticalconfig and opticalconfig.opticalconfig_id.opticalconfig_uuid != '' :
new_opticalconfig = OpticalConfig()
......@@ -176,12 +173,12 @@ def update_externally () :
config =json.loads(opticalconfig.config)
channels= config['channels']
target_channel =next((item for item in channels if item["name"]['index'] == channel_name) , None)
LOGGER.info(f"target channel {target_channel}")
target_power=device.get( "target-output-power")
freq = device.get("frequency")
mode = device.get("operational-mode")
status= device.get("status","ENABLED")
LOGGER.info(f"target power {target_power} freq {freq} mode {mode}")
if target_channel:
if target_power is not None :
......@@ -199,7 +196,7 @@ def update_externally () :
config["new_config"]["channel_name"]=channel_name
config["flow"]=[(port,'0')]
opticalconfig.config =json.dumps(config)
LOGGER.info(f"new Config {config}")
try:
device_client.connect()
device_client.ConfigureOpticalDevice(opticalconfig)
......@@ -248,7 +245,7 @@ def update(config_uuid,channel_name):
context_client.connect()
response = context_client.SelectOpticalConfig(opticalconfigId)
context_client.close()
LOGGER.info("response %s",response)
opticalconfig = OpticalConfig()
opticalconfig.CopyFrom(response)
config =json.loads(opticalconfig.config)
......@@ -274,7 +271,7 @@ def update(config_uuid,channel_name):
new_config["line-port"]=form.line_port.data if form.line_port.data != '' else new_config['line-port']
opticalconfig.config =json.dumps(new_config)
LOGGER.info("myconfig copied %s",opticalconfig)
try:
device_client.connect()
device_client.ConfigureOpticalDevice(opticalconfig)
......@@ -350,7 +347,7 @@ def update_status (config_uuid,channel_name):
opticlConfig.config=json.dumps(config)
try:
LOGGER.info(f"update status {opticlConfig}")
device_client.connect()
device_client.ConfigureOpticalDevice(opticlConfig)
device_client.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment