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.
16 from typing import List, Set
17 # from o2ims.adapter import orm
18 from o2ims.domain import ocloud
21 class OcloudRepository(abc.ABC):
23 self.seen = set() # type: Set[ocloud.Ocloud]
25 def add(self, ocloud: ocloud.Ocloud):
29 def get(self, ocloudid) -> ocloud.Ocloud:
30 ocloud = self._get(ocloudid)
35 def list(self) -> List[ocloud.Ocloud]:
38 def update(self, ocloud: ocloud.Ocloud):
41 # def update_fields(self, ocloudid: str, updatefields: dict):
42 # self._update(ocloudid, updatefields)
45 def _add(self, ocloud: ocloud.Ocloud):
46 raise NotImplementedError
49 def _get(self, ocloudid) -> ocloud.Ocloud:
50 raise NotImplementedError
53 def _update(self, ocloud: ocloud.Ocloud):
54 raise NotImplementedError
57 class OcloudSqlAlchemyRepository(OcloudRepository):
58 def __init__(self, session):
60 self.session = session
62 def _add(self, ocloud: ocloud.Ocloud):
63 self.session.add(ocloud)
64 # self.session.add_all(ocloud.deploymentManagers)
66 def _get(self, ocloudid) -> ocloud.Ocloud:
67 return self.session.query(ocloud.Ocloud).filter_by(
68 oCloudId=ocloudid).first()
70 def _list(self) -> List[ocloud.Ocloud]:
71 return self.session.query()
73 def _update(self, ocloud: ocloud.Ocloud):
74 self.session.add(ocloud)