Commit 2a8dccd9 authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

Optical Service Deletion Logic

parent cca3e72c
Loading
Loading
Loading
Loading

.context.log.swo

0 → 100644
+16 KiB

File added.

No diff preview for this file type.

+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ spec:
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "DEBUG"
              value: "INFO"
          startupProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:2020"]
+2 −2
Original line number Diff line number Diff line
@@ -99,10 +99,10 @@ export CRDB_DATABASE="tfs"
export CRDB_DEPLOY_MODE="single"

# Disable flag for dropping database, if it exists.
export CRDB_DROP_DATABASE_IF_EXISTS="YES"
export CRDB_DROP_DATABASE_IF_EXISTS=""

# Disable flag for re-deploying CockroachDB from scratch.
export CRDB_REDEPLOY=""
export CRDB_REDEPLOY="YES"


# ----- NATS -------------------------------------------------------------------
+1 −0
Original line number Diff line number Diff line
@@ -317,6 +317,7 @@ enum ServiceStatusEnum {
  SERVICESTATUS_UPDATING = 3;
  SERVICESTATUS_PENDING_REMOVAL = 4;
  SERVICESTATUS_SLA_VIOLATED = 5;

}

message ServiceStatus {
+43 −25
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
import json, logging
from sqlalchemy.dialects.postgresql import insert
from common.message_broker.MessageBroker import MessageBroker
from common.DeviceTypes import DeviceTypeEnum
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Session, sessionmaker
from sqlalchemy_cockroachdb import run_transaction
@@ -70,7 +71,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):
        if "type" in config:
           
            config_type= config["type"]
            if config_type == "optical-transponder":
            if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_:
                is_transpondre=True
                transceivers = []
                if channel_namespace is None and  'channel_namespace' in config:
@@ -107,7 +108,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):

                })
                
            if config_type == "optical-roadm":
            if config_type == DeviceTypeEnum.OPTICAL_ROADM._value_:
                
                    
                if channel_namespace is None and  'channel_namespace' in config:
@@ -120,7 +121,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):
                    #channels = [channel['name']['index'] for channel in config['channels']]
                    channel_num=0
                    for channel_params in config['media_channels']:
                        channel_index=channel_params['channel_index'] if 'channel_index' is not None else None
                        channel_index=channel_params['channel_index'] if channel_params['channel_index'] is not None else None
                        channels.append(
                                        {
                                            # "opticalconfig_uuid":opticalconfig_uuid,
@@ -192,7 +193,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):
        )
        stmt = stmt.returning(OpticalConfigModel.opticalconfig_uuid)
        opticalconfig_id = session.execute(stmt).fetchone()
        if config_type == 'optical-transponder':
        if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_:
            if (len(transponder)>0):
                stmt = insert(TransponderTypeModel).values(transponder)
            
@@ -225,7 +226,7 @@ def set_opticalconfig(db_engine : Engine, request : OpticalConfig):
                    opticalChannel_id = session.execute(stmt).fetchone()
            
            
        if config_type == 'optical-roadm':
        if config_type == DeviceTypeEnum.OPTICAL_ROADM._value_:
            if (len(roadms)>0):
                stmt = insert(RoadmTypeModel).values(roadms)
            
@@ -294,11 +295,11 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig):
                        channel_namespace=config['new_config'] ['channel_namespace']
           
                
            if config_type == "optical-transponder":
            if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_:
                is_transpondre=True
                transceivers = []
                if channel_namespace is None and  'channel_namespace' in config['new_config']:
                    channel_namespace=config['new_config']['channel_namespace']
                if channel_namespace is None and  'channel_namespace' in config:
                    channel_namespace=config['channel_namespace']

                if 'transceivers' in config['new_config'] and len(config['new_config']['transceivers']['transceiver']) > 0:
                    transceivers = [transceiver for transceiver in config['new_config'] ['transceivers']['transceiver']]
@@ -354,7 +355,7 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig):
                })
                
                
            if config_type == "optical-roadm":
            if config_type == DeviceTypeEnum.OPTICAL_ROADM._value_:
                
                if channel_namespace is None and  'channel_namespace' in config['new_config']:
                    channel_namespace=config['new_config']['channel_namespace']
@@ -445,7 +446,7 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig):
        )
        stmt = stmt.returning(OpticalConfigModel.opticalconfig_uuid)
        opticalconfig_id = session.execute(stmt).fetchone()
        if config_type == 'optical-transponder':
        if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_:
            if (len(transponder)>0):
                stmt = insert(TransponderTypeModel).values(transponder)
            
@@ -477,7 +478,7 @@ def update_opticalconfig(db_engine : Engine, request : OpticalConfig):
                    )
                    stmt = stmt.returning(OpticalChannelModel.channel_uuid)
                    opticalChannel_id = session.execute(stmt).fetchone()
        if config_type == 'optical-roadm':
        if config_type == DeviceTypeEnum.OPTICAL_ROADM._value_:
            if (len(roadms)>0):
                stmt = insert(RoadmTypeModel).values(roadms)
            
@@ -561,7 +562,7 @@ def delete_opticalchannel(db_engine : Engine ,messagebroker : MessageBroker, re
    if 'new_config' in config:
   
         
        if config_type == 'optical-transponder':  
        if config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_:  
            for flow in config['flow']:
                
                src,dest = flow
@@ -579,18 +580,35 @@ def delete_opticalchannel(db_engine : Engine ,messagebroker : MessageBroker, re
                                            "status"                :"DISABLED"
                                        } 
                                    )   
        elif config_type == 'optical-roadm':
        elif config_type == DeviceTypeEnum.OPTICAL_ROADM._value_:
        
            channel_num=0
            if 'flow' in config['new_config'] :
                if config['new_config']['flow'] ==0:
            if 'flow' in config :
                if 'is_opticalband' in config:
                    if config['is_opticalband']:
                        ob_id =config['new_config']['ob_id'] if 'ob_id' in config['new_config'] else None
                        if len(config['flow']) ==0:
                            channel_index=ob_id+channel_num

                            channel_name=f'optical_bands_{channel_index}' 
                            channels.append(  channel_get_uuid(channel_name,device_uuid))
                        else :
                            for flow in config['flow']:
                                channel_index=ob_id+channel_num
                                channel_num +=1
                                channel_name=f'optical_bands_{channel_index}' 
                                channels.append(  channel_get_uuid(channel_name,device_uuid))
                    else :
                        if config['flow'] ==0:
                            channel_num=1
                    channel_name=f'optical_bands_{channel_num}' if config['new_config']['is_opticalband'] else f'media_channel_{channel_num}'
                    channels.append(  channel_get_uuid(channel_name,device_uuid),device_uuid)
                            channel_name=f'media_channel_{channel_num}' 
                            channels.append(  channel_get_uuid(channel_name,device_uuid))
                        else :
                    for flow in config['new_config']['flow']:
                            for flow in config['flow']:
                                channel_num +=1
                        channel_name=f'optical_bands_{channel_num}' if config['new_config']['is_opticalband'] else f'media_channel_{channel_num}'
                        channels.append(  channel_get_uuid(channel_name,device_uuid),device_uuid)
                                channel_name=f'media_channel_{channel_num}' 
                                channels.append(  channel_get_uuid(channel_name,device_uuid))
                                    
        else :
            return                
                   
@@ -599,13 +617,13 @@ def delete_opticalchannel(db_engine : Engine ,messagebroker : MessageBroker, re
    
    def callback(session : Session):
        all_suceed=[]
        if config_type =='optical-roadm':
        if config_type ==DeviceTypeEnum.OPTICAL_ROADM._value_:
            query = session.query(ChannelModel)
            for channel_uuid in channels:
                num_deleted = session.query(ChannelModel).filter_by(channel_uuid=channel_uuid).delete()
                all_suceed.append(num_deleted > 0)
            return all_suceed    
        elif config_type == 'optical-transponder' :
        elif config_type == DeviceTypeEnum.OPTICAL_TRANSPONDER._value_ :
            if (len(channels)>0) :

                    stmt = insert(OpticalChannelModel).values(channels)
Loading