Adoption of base framework code for azure plugin
[multicloud/azure.git] / azure / azure / pub / msapi / extsys.py
1 # Copyright (c) 2018 Amdocs
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
13 import logging
14
15 from azure.pub.utils.restcall import AAIClient
16
17 logger = logging.getLogger(__name__)
18
19
20 def split_vim_to_owner_region(vim_id):
21     split_vim = vim_id.split('_')
22     cloud_owner = split_vim[0]
23     cloud_region = "".join(split_vim[1:])
24     return cloud_owner, cloud_region
25
26
27 def get_vim_by_id(vim_id):
28     cloud_owner, cloud_region = split_vim_to_owner_region(vim_id)
29     client = AAIClient(cloud_owner, cloud_region)
30     ret = client.get_vim(get_all=True)
31     esrInfo = ret['esr-system-info-list']['esr-system-info'][0]
32     data = {
33         'type': ret['cloud-type'],
34         'version': ret['cloud-region-version'],
35         'vimId': vim_id,
36         'name': vim_id,
37         'userName': esrInfo['user-name'],
38         'password': esrInfo['password'],
39         'tenant': esrInfo['default-tenant'],
40         'url': esrInfo['service-url'],
41         'domain': esrInfo['cloud-domain'],
42         'cacert': esrInfo.get('ssl-cacert', ""),
43         'insecure': esrInfo.get('ssl-insecure', False)
44     }
45     ret.update(data)
46     return ret