1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from datetime import datetime
19 from o2common.service import unit_of_work, messagebus
20 from o2ims.domain import events
21 from o2ims.views.provision_dto import SmoEndpointDTO
22 from o2ims.domain.configuration_obj import Configuration, ConfigurationTypeEnum
25 def configurations(uow: unit_of_work.AbstractUnitOfWork):
27 li = uow.configurations.list()
28 return [r.serialize_smo() for r in li]
31 def configuration_one(configurationId: str,
32 uow: unit_of_work.AbstractUnitOfWork):
34 first = uow.configurations.get(configurationId)
35 return first.serialize_smo() if first is not None else None
38 def configuration_create(configurationDto: SmoEndpointDTO.endpoint,
39 bus: messagebus.MessageBus):
41 conf_uuid = str(uuid.uuid4())
42 configuration = Configuration(
43 conf_uuid, configurationDto['endpoint'], ConfigurationTypeEnum.SMO)
45 uow.configurations.add(configuration)
46 logging.debug('before event length {}'.format(
47 len(configuration.events)))
48 configuration.events.append(events.ConfigurationChanged(
51 logging.debug('after event length {}'.format(
52 len(configuration.events)))
55 return {"id": conf_uuid}
58 def configuration_delete(configurationId: str,
59 uow: unit_of_work.AbstractUnitOfWork):
61 uow.configurations.delete(configurationId)
66 def _handle_events(bus: messagebus.MessageBus):
68 events = bus.uow.collect_new_events()