1 # Copyright (C) 2021 Wind River Systems, Inc.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
15 from sqlalchemy import select
\r
17 from o2common.service import unit_of_work
\r
18 from o2dms.adapter.orm import nfDeploymentDesc
\r
19 from o2dms.api.dms_dto import DmsLcmNfDeploymentDescriptorDTO
\r
20 from o2dms.domain.dms import NfDeploymentDesc
\r
21 from o2common.helper import o2logging
\r
22 logger = o2logging.get_logger(__name__)
\r
25 def lcm_nfdeploymentdesc_list(deploymentManagerID: str,
\r
26 uow: unit_of_work.AbstractUnitOfWork):
\r
28 res = uow.session.execute(select(nfDeploymentDesc).where(
\r
29 nfDeploymentDesc.c.deploymentManagerId == deploymentManagerID))
\r
30 return [dict(r) for r in res]
\r
33 def lcm_nfdeploymentdesc_one(nfdeploymentdescriptorid: str,
\r
34 uow: unit_of_work.AbstractUnitOfWork):
\r
36 res = uow.session.execute(select(nfDeploymentDesc).where(
\r
37 nfDeploymentDesc.c.id == nfdeploymentdescriptorid))
\r
39 return None if first is None else dict(first)
\r
42 def _check_duplication(name: str, uow: unit_of_work.AbstractUnitOfWork):
\r
43 if uow.nfdeployment_descs.count(name=name) > 0:
\r
45 "NfDeploymentDescriptor with name {} exists already".format(name))
\r
48 def lcm_nfdeploymentdesc_create(
\r
49 deploymentManagerId: str,
\r
50 input: DmsLcmNfDeploymentDescriptorDTO.
\r
51 NfDeploymentDescriptor_create,
\r
52 uow: unit_of_work.AbstractUnitOfWork):
\r
55 _check_duplication(input['name'], uow)
\r
56 id = str(uuid.uuid4())
\r
57 entity = NfDeploymentDesc(
\r
58 id, input['name'], deploymentManagerId, input['description'],
\r
59 input['inputParams'], input['outputParams'],
\r
60 input['artifactRepoUrl'], input['artifactName'])
\r
61 uow.nfdeployment_descs.add(entity)
\r
66 def lcm_nfdeploymentdesc_update(
\r
67 nfdeploymentdescriptorid: str,
\r
68 input: DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_update,
\r
69 uow: unit_of_work.AbstractUnitOfWork):
\r
72 entity = uow.nfdeployment_descs.get(nfdeploymentdescriptorid)
\r
73 entity.name = input['name']
\r
74 entity.description = input['description']
\r
75 entity.inputParams = input['inputParams']
\r
76 entity.outputParams = input['outputParams']
\r
77 entity.artifactRepoUrl = input['artifactRepoUrl']
\r
78 entity.artifactName = input['artifactName']
\r
83 def lcm_nfdeploymentdesc_delete(
\r
84 nfdeploymentdescriptorid: str, uow: unit_of_work.AbstractUnitOfWork):
\r
88 _check_dependencies(nfdeploymentdescriptorid, uow)
\r
89 uow.nfdeployment_descs.delete(nfdeploymentdescriptorid)
\r
94 def _check_dependencies(
\r
95 descriptorId: str, uow: unit_of_work.AbstractUnitOfWork
\r
97 # check if nfdeployment depends on it
\r
98 if uow.nfdeployments.count(descriptorId=descriptorId) > 0:
\r
100 "NfDeployment with descriptorId {} exists".format(
\r