blob: 272426fee2cca6814b69b0ef7e4e65bacd4e3c55 [file] [log] [blame]
Benjamin Diaza97bdb32019-04-10 15:22:22 -03001# Copyright 2018 Whitestack, LLC
2# *************************************************************
3
4# This file is part of OSM Monitoring module
5# All Rights Reserved to Whitestack, LLC
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# For those usages not covered by the Apache License, Version 2.0 please
20# contact: bdiaz@whitestack.com or glavado@whitestack.com
21##
22import json
23
24from osm_mon.collector.metric import Metric
25from osm_mon.core import database
26from osm_mon.core.database import VimCredentials, VimCredentialsRepository
27
28
29class CollectorUtils(Metric):
30
31 @staticmethod
32 def get_vim_type(vim_account_id) -> str:
33 credentials = CollectorUtils.get_credentials(vim_account_id)
34 config = json.loads(credentials.config)
35 if 'vim_type' in config:
36 vim_type = config['vim_type']
37 return str(vim_type.lower())
38 else:
39 return str(credentials.type)
40
41 @staticmethod
42 def get_credentials(vim_account_id) -> VimCredentials:
43 database.db.connect()
44 try:
45 with database.db.atomic():
46 return VimCredentialsRepository.get(VimCredentials.uuid == vim_account_id)
47 finally:
48 database.db.close()
49
50 @staticmethod
51 def is_verify_ssl(vim_credentials: VimCredentials):
52 vim_config = json.loads(vim_credentials.config)
53 return 'insecure' not in vim_config or vim_config['insecure'] is False