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 |
1 |
from osm_lcm.data_utils.database.database import Database |
21 |
|
|
22 |
1 |
__author__ = ( |
23 |
|
"Lluis Gifre <lluis.gifre@cttc.es>, Ricard Vilalta <ricard.vilalta@cttc.es>" |
24 |
|
) |
25 |
|
|
26 |
|
|
27 |
1 |
class WimAccountDB: |
28 |
1 |
db = None |
29 |
1 |
db_wims = {} |
30 |
|
|
31 |
1 |
def initialize_db(): |
32 |
0 |
WimAccountDB.db = Database().instance.db |
33 |
|
|
34 |
1 |
def get_wim_account_with_id(wim_account_id): |
35 |
0 |
if not WimAccountDB.db: |
36 |
0 |
WimAccountDB.initialize_db() |
37 |
0 |
if wim_account_id in WimAccountDB.db_wims: |
38 |
0 |
return WimAccountDB.db_wims[wim_account_id] |
39 |
0 |
db_wim = WimAccountDB.db.get_one("wim_accounts", {"_id": wim_account_id}) or {} |
40 |
0 |
WimAccountDB.db_wims[wim_account_id] = db_wim |
41 |
0 |
return db_wim |
42 |
|
|
43 |
1 |
def get_all_wim_accounts(): |
44 |
0 |
if not WimAccountDB.db: |
45 |
0 |
WimAccountDB.initialize_db() |
46 |
0 |
db_wims_list = WimAccountDB.db.get_list("wim_accounts") |
47 |
0 |
WimAccountDB.db_wims.update({db_wim["_id"]: db_wim for db_wim in db_wims_list}) |
48 |
0 |
return WimAccountDB.db_wims |