X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fviews%2Fprovision_view.py;h=903a4bb48f925e7a3e1fd368dcd55a2411137a5c;hb=e07ca03ee134886983e420fb974ff6c38855a0d6;hp=2a389a77484c4e7b4f3a70b69487281a833aa718;hpb=f3ce354b2e6c538b50ed990ba359d3af2283c901;p=pti%2Fo2.git diff --git a/o2ims/views/provision_view.py b/o2ims/views/provision_view.py index 2a389a7..903a4bb 100644 --- a/o2ims/views/provision_view.py +++ b/o2ims/views/provision_view.py @@ -1,71 +1,71 @@ -# Copyright (C) 2021 Wind River Systems, Inc. -# -# 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. - -import logging -import uuid -from datetime import datetime - -from o2common.service import unit_of_work, messagebus -from o2ims.domain import events -from o2ims.views.provision_dto import SmoEndpointDTO -from o2ims.domain.configuration_obj import Configuration, ConfigurationTypeEnum - - -def configurations(uow: unit_of_work.AbstractUnitOfWork): - with uow: - li = uow.configurations.list() - return [r.serialize_smo() for r in li] - - -def configuration_one(configurationId: str, - uow: unit_of_work.AbstractUnitOfWork): - with uow: - first = uow.configurations.get(configurationId) - return first.serialize_smo() if first is not None else None - - -def configuration_create(configurationDto: SmoEndpointDTO.endpoint, - bus: messagebus.MessageBus): - - conf_uuid = str(uuid.uuid4()) - configuration = Configuration( - conf_uuid, configurationDto['endpoint'], ConfigurationTypeEnum.SMO) - with bus.uow as uow: - uow.configurations.add(configuration) - logging.debug('before event length {}'.format( - len(configuration.events))) - configuration.events.append(events.ConfigurationChanged( - conf_uuid, - datetime.now())) - logging.debug('after event length {}'.format( - len(configuration.events))) - uow.commit() - _handle_events(bus) - return {"id": conf_uuid} - - -def configuration_delete(configurationId: str, - uow: unit_of_work.AbstractUnitOfWork): - with uow: - uow.configurations.delete(configurationId) - uow.commit() - return True - - -def _handle_events(bus: messagebus.MessageBus): - # handle events - events = bus.uow.collect_new_events() - for event in events: - bus.handle(event) - return True +# Copyright (C) 2021 Wind River Systems, Inc. +# +# 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. + +import logging +import uuid +from datetime import datetime + +from o2common.service import unit_of_work, messagebus +from o2ims.domain import events +from o2ims.views.provision_dto import SmoEndpointDTO +from o2ims.domain.configuration_obj import Configuration, ConfigurationTypeEnum + + +def configurations(uow: unit_of_work.AbstractUnitOfWork): + with uow: + li = uow.configurations.list() + return [r.serialize_smo() for r in li] + + +def configuration_one(configurationId: str, + uow: unit_of_work.AbstractUnitOfWork): + with uow: + first = uow.configurations.get(configurationId) + return first.serialize_smo() if first is not None else None + + +def configuration_create(configurationDto: SmoEndpointDTO.endpoint, + bus: messagebus.MessageBus): + + conf_uuid = str(uuid.uuid4()) + configuration = Configuration( + conf_uuid, configurationDto['endpoint'], ConfigurationTypeEnum.SMO) + with bus.uow as uow: + uow.configurations.add(configuration) + logging.debug('before event length {}'.format( + len(configuration.events))) + configuration.events.append(events.ConfigurationChanged( + conf_uuid, + datetime.now())) + logging.debug('after event length {}'.format( + len(configuration.events))) + uow.commit() + _handle_events(bus) + return {"id": conf_uuid} + + +def configuration_delete(configurationId: str, + uow: unit_of_work.AbstractUnitOfWork): + with uow: + uow.configurations.delete(configurationId) + uow.commit() + return True + + +def _handle_events(bus: messagebus.MessageBus): + # handle events + events = bus.uow.collect_new_events() + for event in events: + bus.handle(event) + return True