blob: 69cf7df29266d33753bec48fc5ea40afb7ba675e [file] [log] [blame]
Patricia Reinoso52431352023-04-05 15:35:48 +00001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Dario Faccinf5d65b52023-06-19 12:35:33 +020017from temporalio import activity
Patricia Reinoso52431352023-04-05 15:35:48 +000018from time import time
Daniel Arndtc56d3362023-04-18 11:26:16 -030019
Dario Faccinf5d65b52023-06-19 12:35:33 +020020from osm_common.temporal.activities.ns import (
21 GetNsRecord,
22 GetVnfDetails,
23 UpdateNsState,
Daniel Arndtc56d3362023-04-18 11:26:16 -030024)
Daniel Arndtfde85132023-04-21 09:32:04 -030025
Patricia Reinoso52431352023-04-05 15:35:48 +000026
Mark Beierl82629422023-06-29 20:22:36 +000027@activity.defn(name=GetVnfDetails.__name__)
Dario Faccinf5d65b52023-06-19 12:35:33 +020028class GetVnfDetailsImpl(GetVnfDetails):
Dario Faccinf5d65b52023-06-19 12:35:33 +020029 async def __call__(
30 self, activity_input: GetVnfDetails.Input
31 ) -> GetVnfDetails.Output:
32 vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": activity_input.ns_uuid})
33 return GetVnfDetails.Output(
Gulsum Atici50d12e02023-04-27 16:41:43 +030034 vnf_details=[(vnfr["id"], vnfr["member-vnf-index-ref"]) for vnfr in vnfrs]
Daniel Arndt0d2142a2023-04-20 17:14:58 -030035 )
Gulsum Atici50d12e02023-04-27 16:41:43 +030036
Gulsum Atici50d12e02023-04-27 16:41:43 +030037
Mark Beierl82629422023-06-29 20:22:36 +000038@activity.defn(name=GetNsRecord.__name__)
Dario Faccinf5d65b52023-06-19 12:35:33 +020039class GetNsRecordImpl(GetNsRecord):
Dario Faccinf5d65b52023-06-19 12:35:33 +020040 async def __call__(self, activity_input: GetNsRecord.Input) -> GetNsRecord.Output:
41 nsr = self.db.get_one("nsrs", {"_id": activity_input.nsr_uuid})
Gulsum Atici50d12e02023-04-27 16:41:43 +030042 self.logger.debug("Got the nsr from Database for VNF operations.")
Dario Faccinf5d65b52023-06-19 12:35:33 +020043 return GetNsRecord.Output(nsr=nsr)
Patricia Reinoso52431352023-04-05 15:35:48 +000044
45
Mark Beierl82629422023-06-29 20:22:36 +000046@activity.defn(name=UpdateNsState.__name__)
Dario Faccinf5d65b52023-06-19 12:35:33 +020047class UpdateNsStateImpl(UpdateNsState):
Dario Faccinf5d65b52023-06-19 12:35:33 +020048 async def __call__(self, activity_input: UpdateNsState.Input) -> None:
Patricia Reinoso52431352023-04-05 15:35:48 +000049 update_ns_state = {
Dario Faccinf5d65b52023-06-19 12:35:33 +020050 "nsState": activity_input.state.name,
Patricia Reinoso52431352023-04-05 15:35:48 +000051 # "errorDescription" : data.message,
Dario Faccinf5d65b52023-06-19 12:35:33 +020052 "_admin.nsState": activity_input.state.name,
53 "_admin.detailed-status": activity_input.message,
Patricia Reinoso52431352023-04-05 15:35:48 +000054 "_admin.modified": time(),
55 }
Dario Faccinf5d65b52023-06-19 12:35:33 +020056 self.db.set_one("nsrs", {"_id": activity_input.ns_uuid}, update_ns_state)
57 self.logger.debug(
58 f"Updated NS {activity_input.ns_uuid} to {activity_input.state.name}"
59 )