Implement query vnfm info from ESR 65/10665/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Thu, 7 Sep 2017 01:56:16 +0000 (09:56 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Thu, 7 Sep 2017 01:56:16 +0000 (09:56 +0800)
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 <ying.yunlong@zte.com.cn>
lcm/pub/config/config.py
lcm/pub/msapi/aai.py

index 5488b38..2fa6bdf 100644 (file)
@@ -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"
 
index d6e10ee..3ae685e 100644 (file)
@@ -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))