a1f17993d5e681d7af68f9b422a56dd67459484b
[osm/LCM.git] / osm_lcm / data_utils / database / wim_account.py
1 # -*- coding: utf-8 -*-
2
3 # This file is part of OSM Life-Cycle Management module
4 #
5 # Copyright 2022 ETSI
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License"); you may
8 # not use this file except in compliance with the License. You may obtain
9 # a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
17 # under the License.
18 ##
19
20 from osm_lcm.data_utils.database.database import Database
21
22 __author__ = (
23 "Lluis Gifre <lluis.gifre@cttc.es>, Ricard Vilalta <ricard.vilalta@cttc.es>"
24 )
25
26
27 class WimAccountDB:
28 db = None
29 db_wims = {}
30
31 @classmethod
32 def initialize_db(cls):
33 cls.db = Database().instance.db
34
35 @classmethod
36 def get_wim_account_with_id(cls, wim_account_id):
37 if not cls.db:
38 cls.initialize_db()
39 if wim_account_id in cls.db_wims:
40 return cls.db_wims[wim_account_id]
41 db_wim = cls.db.get_one("wim_accounts", {"_id": wim_account_id}) or {}
42 cls.db_wims[wim_account_id] = db_wim
43 return db_wim
44
45 @classmethod
46 def get_all_wim_accounts(cls):
47 if not cls.db:
48 cls.initialize_db()
49 db_wims_list = cls.db.get_list("wim_accounts")
50 cls.db_wims.update({db_wim["_id"]: db_wim for db_wim in db_wims_list})
51 return cls.db_wims