diff --git a/src/context/client/ContextClient.py b/src/context/client/ContextClient.py index 96a2f3f8d025e924f24b54f20e5456b0f46ecbc8..48a635cccd19f5985721a6a737fb8a2e5bd260b2 100644 --- a/src/context/client/ContextClient.py +++ b/src/context/client/ContextClient.py @@ -27,7 +27,8 @@ from common.proto.context_pb2 import ( Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, - OpticalConfig,OpticalConfigId,OpticalConfigList) + OpticalConfig, OpticalConfigId, OpticalConfigList +) from common.proto.context_pb2_grpc import ContextServiceStub from common.proto.context_policy_pb2_grpc import ContextPolicyServiceStub from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule @@ -437,24 +438,26 @@ class ContextClient: response = self.policy_stub.RemovePolicyRule(request) LOGGER.debug('RemovePolicyRule result: {:s}'.format(grpc_message_to_json_string(response))) return response - #//////////////// Experimental ////////////////// + + #//////////////// Experimental ////////////////// + @RETRY_DECORATOR - def SetOpticalConfig (self,request:OpticalConfig) ->OpticalConfigId: - LOGGER.debug('SettingOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) + def SetOpticalConfig(self, request : OpticalConfig) -> OpticalConfigId: + LOGGER.debug('SetOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) response = self.stub.SetOpticalConfig(request) - LOGGER.debug('SettingOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) + LOGGER.debug('SetOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) return response - + @RETRY_DECORATOR - def GetOpticalConfig (self,request:Empty) ->OpticalConfigList: - LOGGER.debug('GettingOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) + def GetOpticalConfig(self, request : Empty) -> OpticalConfigList: + LOGGER.debug('GetOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) response = self.stub.GetOpticalConfig(request) LOGGER.debug('GetOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) return response - + @RETRY_DECORATOR - def SelectOpticalConfig (self,request:OpticalConfigId) ->OpticalConfigList: - LOGGER.debug('Selecting request: {:s}'.format(grpc_message_to_json_string(request))) + def SelectOpticalConfig(self,request : OpticalConfigId) -> OpticalConfigList: + LOGGER.debug('SelectOpticalConfig request: {:s}'.format(grpc_message_to_json_string(request))) response = self.stub.SelectOpticalConfig(request) - LOGGER.debug('GetOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) + LOGGER.debug('SelectOpticalConfig result: {:s}'.format(grpc_message_to_json_string(response))) return response diff --git a/src/context/service/ContextServiceServicerImpl.py b/src/context/service/ContextServiceServicerImpl.py index 2cfe39b0cdbb9080f84a76c335077020c9631a80..de6b02a5622408d26d966be56a7390660e96922c 100644 --- a/src/context/service/ContextServiceServicerImpl.py +++ b/src/context/service/ContextServiceServicerImpl.py @@ -24,7 +24,8 @@ from common.proto.context_pb2 import ( Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, - OpticalConfigList,OpticalConfigId,OpticalConfig) + OpticalConfigList, OpticalConfigId, OpticalConfig +) from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.context_policy_pb2_grpc import ContextPolicyServiceServicer @@ -298,21 +299,22 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def RemovePolicyRule(self, request : PolicyRuleId, context: grpc.ServicerContext) -> Empty: return policyrule_delete(self.db_engine, self.messagebroker, request) - # ---------------------------- Experimental ------------------- - @safe_and_metered_rpc_method(METRICS_POOL,LOGGER) - def GetOpticalConfig(self,request:Empty,context:grpc.ServicerContext) -> OpticalConfigList: - - result =get_opticalconfig(db_engine=self.db_engine) - + + # ---------------------------- Experimental ------------------- + + @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) + def GetOpticalConfig(self, request : Empty, context : grpc.ServicerContext) -> OpticalConfigList: + result = get_opticalconfig(self.db_engine) return OpticalConfigList(OpticalConfigs=result) - def SetOpticalConfig(self,request:OpticalConfig,context:grpc.ServicerContext)-> OpticalConfigId: - - OpticalConfig_id= set_opticalconfig(db_engine=self.db_engine,request=request) - - return OpticalConfigId(**OpticalConfig_id) - def SelectOpticalConfig (self,request:OpticalConfigId,context:grpc.ServicerContext) -> OpticalConfig: - result =select_opticalconfig(db_engine=self.db_engine,request=request) - logging.info(f"FromSelectOpticalConfig {result}") - myid =OpticalConfigId() - myid.CopyFrom(result.OpticalConfig_id) - return OpticalConfig(config=result.config,OpticalConfig_id=myid) + + @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) + def SetOpticalConfig(self, request : OpticalConfig, context : grpc.ServicerContext) -> OpticalConfigId: + result = set_opticalconfig(self.db_engine, request) + return OpticalConfigId(**result) + + @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) + def SelectOpticalConfig(self, request : OpticalConfigId, context : grpc.ServicerContext) -> OpticalConfig: + result = select_opticalconfig(self.db_engine, request) + optical_config_id = OpticalConfigId() + optical_config_id.CopyFrom(result.OpticalConfig_id) + return OpticalConfig(config=result.config, OpticalConfig_id=optical_config_id) diff --git a/src/context/service/database/ConfigModel.py b/src/context/service/database/ConfigModel.py deleted file mode 100644 index 94519dcecf230429ff61d2a38edb06bd42315f07..0000000000000000000000000000000000000000 --- a/src/context/service/database/ConfigModel.py +++ /dev/null @@ -1,125 +0,0 @@ -# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) -# -# 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. -# Todo check if the file is in use by the TFS -import functools, logging, operator -from enum import Enum -from typing import Dict, List, Optional, Tuple, Union -from common.orm.Database import Database -from common.orm.HighLevel import get_object, get_or_create_object, update_or_create_object -from common.orm.backend.Tools import key_to_str -from common.orm.fields.EnumeratedField import EnumeratedField -from common.orm.fields.ForeignKeyField import ForeignKeyField -from common.orm.fields.IntegerField import IntegerField -from common.orm.fields.PrimaryKeyField import PrimaryKeyField -from common.orm.fields.StringField import StringField -from common.orm.model.Model import Model -from context.proto.context_pb2 import ConfigActionEnum -from .Tools import fast_hasher, grpc_to_enum, remove_dict_key - -LOGGER = logging.getLogger(__name__) - -class ORM_ConfigActionEnum(Enum): - UNDEFINED = ConfigActionEnum.CONFIGACTION_UNDEFINED - SET = ConfigActionEnum.CONFIGACTION_SET - DELETE = ConfigActionEnum.CONFIGACTION_DELETE - -grpc_to_enum__config_action = functools.partial( - grpc_to_enum, ConfigActionEnum, ORM_ConfigActionEnum) - -class ConfigModel(Model): # pylint: disable=abstract-method - pk = PrimaryKeyField() - - def dump(self) -> List[Dict]: - db_config_rule_pks = self.references(ConfigRuleModel) - config_rules = [ConfigRuleModel(self.database, pk).dump(include_position=True) for pk,_ in db_config_rule_pks] - config_rules = sorted(config_rules, key=operator.itemgetter('position')) - return [remove_dict_key(config_rule, 'position') for config_rule in config_rules] - -class ConfigRuleModel(Model): # pylint: disable=abstract-method - pk = PrimaryKeyField() - config_fk = ForeignKeyField(ConfigModel) - position = IntegerField(min_value=0, required=True) - action = EnumeratedField(ORM_ConfigActionEnum, required=True) - key = StringField(required=True, allow_empty=False) - value = StringField(required=True, allow_empty=False) - - def dump(self, include_position=True) -> Dict: # pylint: disable=arguments-differ - result = { - 'action': self.action.value, - 'resource_key': self.key, - 'resource_value': self.value, - } - if include_position: result['position'] = self.position - return result - -def set_config_rule( - database : Database, db_config : ConfigModel, position : int, resource_key : str, resource_value : str - ) -> Tuple[ConfigRuleModel, bool]: - - str_rule_key_hash = fast_hasher(resource_key) - str_config_rule_key = key_to_str([db_config.pk, str_rule_key_hash], separator=':') - result : Tuple[ConfigRuleModel, bool] = update_or_create_object(database, ConfigRuleModel, str_config_rule_key, { - 'config_fk': db_config, 'position': position, 'action': ORM_ConfigActionEnum.SET, - 'key': resource_key, 'value': resource_value}) - db_config_rule, updated = result - return db_config_rule, updated - -def delete_config_rule( - database : Database, db_config : ConfigModel, resource_key : str - ) -> None: - - str_rule_key_hash = fast_hasher(resource_key) - str_config_rule_key = key_to_str([db_config.pk, str_rule_key_hash], separator=':') - db_config_rule : Optional[ConfigRuleModel] = get_object( - database, ConfigRuleModel, str_config_rule_key, raise_if_not_found=False) - if db_config_rule is None: return - db_config_rule.delete() - -def delete_all_config_rules( - database : Database, db_config : ConfigModel - ) -> None: - - db_config_rule_pks = db_config.references(ConfigRuleModel) - for pk,_ in db_config_rule_pks: ConfigRuleModel(database, pk).delete() - -def grpc_config_rules_to_raw(grpc_config_rules) -> List[Tuple[ORM_ConfigActionEnum, str, str]]: - def translate(grpc_config_rule): - action = grpc_to_enum__config_action(grpc_config_rule.action) - return action, grpc_config_rule.resource_key, grpc_config_rule.resource_value - return [translate(grpc_config_rule) for grpc_config_rule in grpc_config_rules] - -def update_config( - database : Database, db_parent_pk : str, config_name : str, - raw_config_rules : List[Tuple[ORM_ConfigActionEnum, str, str]] - ) -> List[Tuple[Union[ConfigModel, ConfigRuleModel], bool]]: - - str_config_key = key_to_str([db_parent_pk, config_name], separator=':') - result : Tuple[ConfigModel, bool] = get_or_create_object(database, ConfigModel, str_config_key) - db_config, created = result - - db_objects : List[Tuple[Union[ConfigModel, ConfigRuleModel], bool]] = [(db_config, created)] - - for position,(action, resource_key, resource_value) in enumerate(raw_config_rules): - if action == ORM_ConfigActionEnum.SET: - result : Tuple[ConfigRuleModel, bool] = set_config_rule( - database, db_config, position, resource_key, resource_value) - db_config_rule, updated = result - db_objects.append((db_config_rule, updated)) - elif action == ORM_ConfigActionEnum.DELETE: - delete_config_rule(database, db_config, resource_key) - else: - msg = 'Unsupported action({:s}) for resource_key({:s})/resource_value({:s})' - raise AttributeError(msg.format(str(ConfigActionEnum.Name(action)), str(resource_key), str(resource_value))) - - return db_objects diff --git a/src/context/service/database/Device.py b/src/context/service/database/Device.py index 76eac944ed55be45cdf15a6500d06640223a2328..737ad7add7a27580503e7f812e3064b879c191b5 100644 --- a/src/context/service/database/Device.py +++ b/src/context/service/database/Device.py @@ -21,8 +21,9 @@ from typing import Dict, List, Optional, Set, Tuple from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException from common.message_broker.MessageBroker import MessageBroker from common.proto.context_pb2 import ( - Device, DeviceFilter, DeviceId, DeviceIdList - , DeviceList, Empty, EventTypeEnum, TopologyId,DeviceDriverEnum) + Device, DeviceDriverEnum, DeviceFilter, DeviceId, DeviceIdList, DeviceList, + Empty, EventTypeEnum, TopologyId +) from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Device import json_device_id from context.service.database.uuids.Topology import topology_get_uuid @@ -77,7 +78,6 @@ def device_get(db_engine : Engine, request : DeviceId) -> Device: return Device(**obj) def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Device) -> DeviceId: - raw_device_uuid = request.device_id.device_uuid.uuid raw_device_name = request.name device_name = raw_device_uuid if len(raw_device_name) == 0 else raw_device_name @@ -89,7 +89,6 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi controller_uuid = None device_type = request.device_type - oper_status = grpc_to_enum__device_operational_status(request.device_operational_status) device_drivers = [grpc_to_enum__device_driver(d) for d in request.device_drivers] @@ -97,7 +96,7 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi topology_uuids : Set[str] = set() related_topologies : List[Dict] = list() - + # By default, always add device to default Context/Topology _,topology_uuid = topology_get_uuid(TopologyId(), allow_random=False, allow_default=True) related_topologies.append({ @@ -106,10 +105,8 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi }) topology_uuids.add(topology_uuid) + is_oc_driver = DeviceDriverEnum.DEVICEDRIVER_OC in set(request.device_drivers) - is_oc_driver= [d for d in request.device_drivers][0]==DeviceDriverEnum.DEVICEDRIVER_OC - - endpoints_data : List[Dict] = list() for i, endpoint in enumerate(request.device_endpoints): endpoint_device_uuid = endpoint.endpoint_id.device_id.device_uuid.uuid diff --git a/src/context/service/database/OpticalConfig.py b/src/context/service/database/OpticalConfig.py index 33227a0166a2d2c0f1269df7d70d982aaa3cc56f..9e7552bc111e40245bb649d2eb1ffa910c6f8588 100644 --- a/src/context/service/database/OpticalConfig.py +++ b/src/context/service/database/OpticalConfig.py @@ -11,119 +11,78 @@ # 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. -import uuid,json -import datetime, logging +import json, logging from sqlalchemy.dialects.postgresql import insert from sqlalchemy.engine import Engine -from sqlalchemy.orm import Session, selectinload, sessionmaker +from sqlalchemy.orm import Session, sessionmaker from sqlalchemy_cockroachdb import run_transaction -from typing import Dict, List, Optional, Set, Tuple -from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException -from common.proto.context_pb2 import Device, DeviceFilter, DeviceId, TopologyId,OpticalConfig,OpticalConfigId,OpticalConfigList -from common.tools.grpc.Tools import grpc_message_to_json_string -from common.tools.object_factory.Device import json_device_id -from context.service.database.uuids.Topology import topology_get_uuid -from .models.DeviceModel import DeviceModel -from .models.EndPointModel import EndPointModel -from .models.TopologyModel import TopologyDeviceModel -from .models.enums.DeviceDriver import grpc_to_enum__device_driver -from .models.enums.DeviceOperationalStatus import grpc_to_enum__device_operational_status -from .models.enums.KpiSampleType import grpc_to_enum__kpi_sample_type -from .uuids.Device import device_get_uuid -from .uuids.EndPoint import endpoint_get_uuid -from .ConfigRule import compose_config_rules_data, upsert_config_rules +from common.proto.context_pb2 import OpticalConfig, OpticalConfigId from .models.OpticalConfigModel import OpticalConfigModel + LOGGER = logging.getLogger(__name__) -def get_opticalconfig (db_engine:Engine): - +def get_opticalconfig(db_engine : Engine): def callback(session:Session): - - lst = list() + optical_configs = list() results = session.query(OpticalConfigModel).all() - for obj in results: - OpticalConfig=OpticalConfig() - OpticalConfig.config=json.dump(obj.config) - myid=OpticalConfigId() - myid.opticalconfig_uuid=obj.opticalconfig_uuid - OpticalConfig.opticalconfig_id.CopyFrom(myid) - - lst.append(OpticalConfig) - return lst - obj=run_transaction(sessionmaker(bind=db_engine),callback) + optical_config = OpticalConfig() + optical_config.config = json.dump(obj.config) + optical_config.opticalconfig_id.opticalconfig_uuid = obj.opticalconfig_uuid + optical_configs.append(optical_config) + return optical_configs + obj = run_transaction(sessionmaker(bind=db_engine), callback) return obj - - - -def set_opticalconfig (db_engine:Engine,request:OpticalConfig): - - opticalconfig_id=OpticalConfigId() - opticalconfig_id.opticalconfig_uuid=request.opticalconfig_id.opticalconfig_uuid - my_config_data=[] - if (request.config): - channels=[] - transceivers=[] +def set_opticalconfig(db_engine : Engine, request : OpticalConfig): + opticalconfig_id = OpticalConfigId() + opticalconfig_id.opticalconfig_uuid = request.opticalconfig_id.opticalconfig_uuid + my_config_data = [] + if request.config: + channels = [] + transceivers = [] config = json.loads(request.config) - - if ( "channels" in config and len(config["channels"])>0): - channels=[channel['name']['index'] for channel in config["channels"]] - if ("transceivers" in config and len(config["transceivers"]["transceiver"])>0): - transceivers=[transceiver for transceiver in config["transceivers"]["transceiver"]] - - - my_config_data=[ + if 'channels' in config and len(config['channels']) > 0: + channels = [channel['name']['index'] for channel in config['channels']] + if 'transceivers' in config and len(config['transceivers']['transceiver']) > 0: + transceivers = [transceiver for transceiver in config['transceivers']['transceiver']] + + my_config_data = [ { - "opticalconfig_uuid":request.opticalconfig_id.opticalconfig_uuid, - "channels":channels, - "transcievers":transceivers, - "interfaces":json.dumps(config["interfaces"]["interface"]), - "channel_namespace":config["channel_namespace"], - "endpoints":[json.dumps(endpoint) for endpoint in config["endpoints"]], - "frequency":config["frequency"] if "frequency" in config else 0, - "operational_mode":config["operational_mode"] if "operational_mode" in config else 0, - "output_power":config["output_power"] if "output_power" in config else '', + "opticalconfig_uuid": request.opticalconfig_id.opticalconfig_uuid, + "channels" : channels, + "transcievers" : transceivers, + "interfaces" : json.dumps(config["interfaces"]["interface"]), + "channel_namespace" : config["channel_namespace"], + "endpoints" : [json.dumps(endpoint) for endpoint in config["endpoints"]], + "frequency" : config["frequency"] if "frequency" in config else 0, + "operational_mode" : config["operational_mode"] if "operational_mode" in config else 0, + "output_power" : config["output_power"] if "output_power" in config else '', } ] def callback(session:Session)->bool: - stmt = insert(OpticalConfigModel).values(my_config_data) stmt = stmt.on_conflict_do_update( index_elements=[OpticalConfigModel.opticalconfig_uuid], set_=dict( - channel_namespace=stmt.excluded.channel_namespace ) ) - stmt = stmt.returning(OpticalConfigModel.opticalconfig_uuid) - id = session.execute(stmt).fetchone() - - opticalconfig_id =run_transaction(sessionmaker(bind=db_engine),callback) - - return {'opticalconfig_uuid': opticalconfig_id} - - - + opticalconfig_id = run_transaction(sessionmaker(bind=db_engine), callback) + return {'opticalconfig_uuid': opticalconfig_id} + def select_opticalconfig(db_engine:Engine,request:OpticalConfigId): - def callback(session : Session) -> OpticalConfig: - result=OpticalConfig() - obj = session.query(OpticalConfigModel).filter_by(opticalconfig_uuid=request.opticalconfig_uuid).first() - - if (obj is not None): - - - myid=OpticalConfigId() - myid.opticalconfig_uuid=obj.opticalconfig_uuid - result.config=json.dumps(obj.dump()) - result.opticalconfig_id.CopyFrom(myid) - - + result = OpticalConfig() + stmt = session.query(OpticalConfigModel) + stmt = stmt.filter_by(opticalconfig_uuid=request.opticalconfig_uuid) + obj = stmt.first() + if obj is not None: + result.config = json.dumps(obj.dump()) + result.opticalconfig_id.opticalconfig_uuid = obj.opticalconfig_uuid return result - - return run_transaction(sessionmaker(bind=db_engine,expire_on_commit=False), callback) \ No newline at end of file + return run_transaction(sessionmaker(bind=db_engine, expire_on_commit=False), callback) diff --git a/src/context/service/database/Service.py b/src/context/service/database/Service.py index 38e5d5ec1e48b21c09832858296fb22e902aba38..337bf592f785db97d5924aa7da17772c35eac1b2 100644 --- a/src/context/service/database/Service.py +++ b/src/context/service/database/Service.py @@ -20,7 +20,9 @@ from sqlalchemy.orm import Session, selectinload, sessionmaker from sqlalchemy_cockroachdb import run_transaction from typing import Dict, List, Optional, Set from common.proto.context_pb2 import ( - ContextId, Empty, EventTypeEnum, Service, ServiceFilter, ServiceId, ServiceIdList, ServiceList) + ContextId, Empty, EventTypeEnum, Service, ServiceFilter, ServiceId, ServiceIdList, + ServiceList, ServiceTypeEnum +) from common.message_broker.MessageBroker import MessageBroker from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException from common.tools.object_factory.Context import json_context_id @@ -82,10 +84,11 @@ def service_set(db_engine : Engine, messagebroker : MessageBroker, request : Ser raw_service_name = request.name service_name = raw_service_uuid if len(raw_service_name) == 0 else raw_service_name context_uuid,service_uuid = service_get_uuid(request.service_id, service_name=service_name, allow_random=True) - + service_type = grpc_to_enum__service_type(request.service_type) - service_type="OPTICAL_CONNECTIVITY" if service_type is None and request.service_type==6 else service_type - + if service_type is None and request.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY: + service_type = "OPTICAL_CONNECTIVITY" + service_status = grpc_to_enum__service_status(request.service_status.service_status) now = datetime.datetime.utcnow() diff --git a/src/context/service/database/models/OpticalConfigModel.py b/src/context/service/database/models/OpticalConfigModel.py index 34a8c41f0058811a7c9aa5e1e82e4dbd15413d29..10cf197f9a8a728b8fd02bdcdaf255677551bf17 100644 --- a/src/context/service/database/models/OpticalConfigModel.py +++ b/src/context/service/database/models/OpticalConfigModel.py @@ -12,40 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json,logging -from sqlalchemy import Column, String ,Integer +import json +from sqlalchemy import Column, String, Integer from sqlalchemy.dialects.postgresql import ARRAY - - from ._Base import _Base - - - -class OpticalConfigModel (_Base): - __tablename__="OpticalConfig" +class OpticalConfigModel(_Base): + __tablename__ = 'optical_config' opticalconfig_uuid = Column(String, primary_key=True) - channels=Column(ARRAY(String),nullable=True) - transcievers= Column(ARRAY(String),nullable=True) - interfaces =Column(String,nullable=True) - channel_namespace=Column(String,nullable=True) - endpoints=Column(ARRAY(String),nullable=True) - frequency=Column(Integer,nullable=True) - operational_mode=Column(Integer,nullable=True) - output_power=Column(String,nullable=True) - - - - def dump (self): - + channels = Column(ARRAY(String), nullable=True) + transcievers = Column(ARRAY(String), nullable=True) + interfaces = Column(String, nullable=True) + channel_namespace = Column(String, nullable=True) + endpoints = Column(ARRAY(String), nullable=True) + frequency = Column(Integer, nullable=True) + operational_mode = Column(Integer, nullable=True) + output_power = Column(String, nullable=True) + + def dump(self): return { - "channels":[{'name':{'index':channel}} for channel in self.channels], - "transceivers":{"transceiver":[transciever for transciever in self.transcievers]}, - "interfaces":{"interface":json.loads(self.interfaces)}, - "channel_namespace":self.channel_namespace, - "endpoints":[json.loads(endpoint) for endpoint in self.endpoints], - "frequency":self.frequency, - "output_power":self.output_power, - "operational_mode":self.operational_mode + "channels" : [{'name': {'index': channel}} for channel in self.channels], + "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, + "interfaces" : {"interface": json.loads(self.interfaces)}, + "channel_namespace" : self.channel_namespace, + "endpoints" : [json.loads(endpoint) for endpoint in self.endpoints], + "frequency" : self.frequency, + "output_power" : self.output_power, + "operational_mode" : self.operational_mode, } -