1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: bdiaz@whitestack.com or glavado@whitestack.com
27 from osm_mon
.core
import database
28 from osm_mon
.core
.common_db
import CommonDbClient
29 from osm_mon
.core
.config
import Config
30 from osm_mon
.core
.database
import VimCredentialsRepository
, VimCredentials
, AlarmRepository
, Alarm
32 log
= logging
.getLogger(__name__
)
37 def __init__(self
, config
: Config
):
38 self
.common_db
= CommonDbClient(config
)
40 def upsert_vim_account(self
,
49 config
: dict) -> VimCredentials
:
50 decrypted_vim_password
= self
.common_db
.decrypt_vim_password(password
,
54 vim_config_encrypted
= ("admin_password", "nsx_password", "vcenter_password")
56 if key
in vim_config_encrypted
:
57 config
[key
] = self
.common_db
.decrypt_vim_password(config
[key
],
62 with database
.db
.atomic():
63 return VimCredentialsRepository
.upsert(
69 password
=decrypted_vim_password
,
70 tenant_name
=tenant_name
,
71 config
=json
.dumps(config
)
76 def delete_vim_account(self
, vim_uuid
: str) -> None:
79 with database
.db
.atomic():
80 vim_credentials
= VimCredentialsRepository
.get(VimCredentials
.uuid
== vim_uuid
)
81 vim_credentials
.delete_instance()
85 def create_alarm(self
,
93 vnf_member_index
: str,
94 nsr_id
: str) -> Alarm
:
97 with database
.db
.atomic():
98 return AlarmRepository
.create(
99 uuid
=str(uuid
.uuid4()),
102 operation
=operation
.lower(),
103 severity
=severity
.lower(),
104 statistic
=statistic
.lower(),
105 monitoring_param
=metric_name
,
107 vnf_member_index
=vnf_member_index
,
114 def delete_alarm(self
,
115 alarm_uuid
: str) -> None:
116 database
.db
.connect()
118 with database
.db
.atomic():
119 alarm
= AlarmRepository
.get(Alarm
.uuid
== alarm_uuid
)
120 alarm
.delete_instance()