From 3fe677680da6ed4914908dcbb1ddaa2feabac31b Mon Sep 17 00:00:00 2001 From: "ying.yunlong" Date: Thu, 7 Sep 2017 09:56:16 +0800 Subject: [PATCH] Implement query vnfm info from ESR Add get_vnfm_by_id and select_vnfm methods to get vnfm info from esr. Change-Id: I8331ae0ef41c3265ef930c6309c3113344fa277c Issue-ID: VFC-302 Signed-off-by: ying.yunlong --- lcm/pub/config/config.py | 2 +- lcm/pub/msapi/aai.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lcm/pub/config/config.py b/lcm/pub/config/config.py index 5488b382..2fa6bdf4 100644 --- a/lcm/pub/config/config.py +++ b/lcm/pub/config/config.py @@ -57,7 +57,7 @@ CATALOG_ROOT_PATH = None CATALOG_URL_PATH = None # [aai config] -AAI_BASE_URL = "https://127.0.0.1:8443/api/aai/v1" +AAI_BASE_URL = "https://127.0.0.1:8443/aai/v11" AAI_USER = "AAI" AAI_PASSWD = "AAI" diff --git a/lcm/pub/msapi/aai.py b/lcm/pub/msapi/aai.py index d6e10ee7..3ae685e4 100644 --- a/lcm/pub/msapi/aai.py +++ b/lcm/pub/msapi/aai.py @@ -19,6 +19,7 @@ import uuid from lcm.pub.exceptions import NSLCMException from lcm.pub.utils import restcall from lcm.pub.config.config import AAI_BASE_URL, AAI_USER, AAI_PASSWD +from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) @@ -181,3 +182,50 @@ def delete_ns_relationship(global_customer_id, service_type, service_instance_id logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) raise NSLCMException("Delete ns instance relationship exception in AAI") return json.JSONDecoder().decode(ret[1]) + + +def get_vnfm_by_id(vnfm_inst_id): + uri = '/external-system/esr-vnfm-list/esr-vnfm/%s' % vnfm_inst_id + ret = call_aai(uri, "GET") + if ret[0] > 0: + logger.error('Send get VNFM information request to extsys failed.') + raise NSLCMException('Send get VNFM information request to extsys failed.') + + # convert vnfm_info_aai to internal vnfm_info + vnfm_info = convert_vnfm_info(json.JSONDecoder().decode(ret[1])) + return vnfm_info + +def convert_vnfm_info(vnfm_info_aai): + esr_system_info = ignore_case_get(vnfm_info_aai, "esr-system-info") + vnfm_info = { + "vnfmId": vnfm_info_aai["vnfm-id"], + "name": vnfm_info_aai["vnfm-id"], + "type": ignore_case_get(esr_system_info, "type"), + "vimId": vnfm_info_aai["vim-id"], + "vendor": ignore_case_get(esr_system_info, "vendor"), + "version": ignore_case_get(esr_system_info, "version"), + "description": "vnfm", + "certificateUrl": vnfm_info_aai["certificate-url"], + "url": ignore_case_get(esr_system_info, "service-url"), + "userName": ignore_case_get(esr_system_info, "service-url"), + "password": ignore_case_get(esr_system_info, "service-url"), + "createTime": "2016-07-06 15:33:18" + } + return vnfm_info + + +def select_vnfm(vnfm_type, vim_id): + uri = '/external-system/esr-vnfm-list' + ret = call_aai(uri, "GET") + if ret[0] > 0: + logger.error("Failed to call %s: %s", uri, ret[1]) + raise NSLCMException('Failed to get vnfms from extsys.') + vnfms = json.JSONDecoder().decode(ret[1]) + for vnfm in vnfms: + esr_system_info = ignore_case_get(vnfm, "esr-system-info") + type = ignore_case_get(esr_system_info, "type") + vimId = vnfm["vnfm-id"] + if type == vnfm_type and vimId == vim_id: + vnfm = convert_vnfm_info(vnfm) + return vnfm + raise NSLCMException('No vnfm found with %s in vim(%s)' % (vnfm_type, vim_id)) -- 2.16.6