4237e4f1262ffdc203a95f9de194622bce450186
1 # Copyright 2018 Whitestack, LLC
2 # *************************************************************
4 # This file is part of OSM Monitoring module
5 # All Rights Reserved to Whitestack, LLC
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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
19 # For those usages not covered by the Apache License, Version 2.0 please
20 # contact: bdiaz@whitestack.com or glavado@whitestack.com
24 from keystoneauth1
import session
25 from keystoneauth1
.identity
import v3
26 from keystoneclient
.v3
import client
28 from osm_mon
.collector
.infra_collectors
.base_vim
import BaseVimInfraCollector
29 from osm_mon
.core
.auth
import AuthManager
31 log
= logging
.getLogger(__name__
)
34 class OpenstackInfraCollector(BaseVimInfraCollector
):
35 def __init__(self
, vim_account_id
: str):
36 super().__init
__(vim_account_id
)
37 self
.auth_manager
= AuthManager()
38 self
.keystone_client
= self
._build
_keystone
_client
(vim_account_id
)
40 def is_vim_ok(self
) -> bool:
42 self
.keystone_client
.projects
.list()
45 log
.exception("VIM status is not OK!")
48 def _build_keystone_client(self
, vim_account_id
):
49 creds
= self
.auth_manager
.get_credentials(vim_account_id
)
50 verify_ssl
= self
.auth_manager
.is_verify_ssl(vim_account_id
)
51 auth
= v3
.Password(auth_url
=creds
.url
,
53 password
=creds
.password
,
54 project_name
=creds
.tenant_name
,
55 project_domain_id
='default',
56 user_domain_id
='default')
57 sess
= session
.Session(auth
=auth
, verify
=verify_ssl
)
58 return client
.Client(session
=sess
)