diff options
author | 2017-09-15 10:31:19 +0800 | |
---|---|---|
committer | 2017-09-15 10:31:19 +0800 | |
commit | 4f9fbb9d7a7831b3dac61e295ba824438ab5f424 (patch) | |
tree | 596526acdad2048c0ea846290e90a2bb95699569 | |
parent | d0739a3fc1347f0c5b55c055cceab1ffda81ec50 (diff) |
Update vfc catalog query vim from aai esr
Change-Id: I25cfb0793fc664101c48cd4f49a153fdfe0f4dce
Issue-ID: VFC-362
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | catalog/pub/msapi/extsys.py | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/catalog/pub/msapi/extsys.py b/catalog/pub/msapi/extsys.py index 9f6b43d5..93866568 100644 --- a/catalog/pub/msapi/extsys.py +++ b/catalog/pub/msapi/extsys.py @@ -20,6 +20,7 @@ from catalog.pub.config.config import AAI_BASE_URL, AAI_USER, AAI_PASSWD from catalog.pub.exceptions import NSLCMException from catalog.pub.utils import restcall from catalog.pub.utils.restcall import req_by_msb +from catalog.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) @@ -40,20 +41,73 @@ def call_aai(resource, method, content=''): additional_headers) +# def get_vims(): +# ret = req_by_msb("/api/extsys/v1/vims", "GET") +# if ret[0] != 0: +# logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) +# raise NSLCMException("Failed to query vims from extsys.") +# return json.JSONDecoder().decode(ret[1]) + def get_vims(): - ret = req_by_msb("/api/extsys/v1/vims", "GET") + ret = call_aai("/cloud-infrastructure/cloud-regions?depth=all", "GET") if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Failed to query vims from extsys.") - return json.JSONDecoder().decode(ret[1]) + # convert vim_info_aai to internal vim_info + vims_aai = json.JSONDecoder().decode(ret[1]) + vims_aai = ignore_case_get(vims_aai, "cloud-region") + vims_info = [] + for vim in vims_aai: + vim = convert_vim_info(vim) + vims_info.append(vim) + return vims_info + +def split_vim_to_owner_region(vim_id): + split_vim = vim_id.split('_') + cloud_owner = split_vim[0] + cloud_region = "".join(split_vim[1:]) + return cloud_owner, cloud_region + +def convert_vim_info(vim_info_aai): + vim_id = vim_info_aai["cloud-owner"] + "_" + vim_info_aai["cloud-region-id"] + esr_system_info = ignore_case_get(ignore_case_get(vim_info_aai, "esr-system-info-list"), "esr-system-info") + # tenants = ignore_case_get(vim_info_aai, "tenants") + vim_info = { + "vimId": vim_id, + "name": vim_id, + "url": ignore_case_get(esr_system_info[0], "service-url"), + "userName": ignore_case_get(esr_system_info[0], "user-name"), + "password": ignore_case_get(esr_system_info[0], "password"), + # "tenant": ignore_case_get(tenants[0], "tenant-id"), + "tenant": ignore_case_get(esr_system_info[0], "default-tenant"), + "vendor": ignore_case_get(esr_system_info[0], "vendor"), + "version": ignore_case_get(esr_system_info[0], "version"), + "description": "vim", + "domain": "", + "type": ignore_case_get(esr_system_info[0], "type"), + "createTime": "2016-07-18 12:22:53" + } + return vim_info +# def get_vim_by_id(vim_id): +# ret = req_by_msb("/api/extsys/v1/vims/%s" % vim_id, "GET") +# if ret[0] != 0: +# logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) +# raise NSLCMException("Failed to query vim(%s) from extsys." % vim_id) +# return json.JSONDecoder().decode(ret[1]) + def get_vim_by_id(vim_id): - ret = req_by_msb("/api/extsys/v1/vims/%s" % vim_id, "GET") + cloud_owner, cloud_region = split_vim_to_owner_region(vim_id) + ret = call_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s?depth=all" + % (cloud_owner, cloud_region), "GET") if ret[0] != 0: logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Failed to query vim(%s) from extsys." % vim_id) - return json.JSONDecoder().decode(ret[1]) + # convert vim_info_aai to internal vim_info + vim_info_aai = json.JSONDecoder().decode(ret[1]) + vim_info = convert_vim_info(vim_info_aai) + return vim_info def get_sdn_controller_by_id(sdn_ontroller_id): |