Add vfc catalog call esr function from aai 13/12613/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Fri, 15 Sep 2017 02:22:43 +0000 (10:22 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Fri, 15 Sep 2017 02:22:43 +0000 (10:22 +0800)
Change-Id: I025e0a70cda41aa764085c98528c4747083392c1
Issue-ID: VFC-361
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
catalog/pub/config/config.py
catalog/pub/msapi/extsys.py
catalog/pub/utils/restcall.py

index 0f51115..d6acc2b 100644 (file)
@@ -17,6 +17,11 @@ import os
 MSB_SERVICE_IP = '127.0.0.1'
 MSB_SERVICE_PORT = '80'
 
+# [aai config]
+AAI_BASE_URL = "https://127.0.0.1:8443/aai/v11"
+AAI_USER = "AAI"
+AAI_PASSWD = "AAI"
+
 # [REDIS]
 REDIS_HOST = '127.0.0.1'
 REDIS_PORT = '6379'
index 3418385..9f6b43d 100644 (file)
 
 import json
 import logging
+import uuid
 
+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
 
 logger = logging.getLogger(__name__)
 
 
+def call_aai(resource, method, content=''):
+    additional_headers = {
+        'X-FromAppId': 'VFC-NFVO-LCM',
+        'X-TransactionId': str(uuid.uuid1())
+    }
+
+    return restcall.call_req(AAI_BASE_URL,
+                             AAI_USER,
+                             AAI_PASSWD,
+                             restcall.rest_no_auth,
+                             resource,
+                             method,
+                             content,
+                             additional_headers)
+
+
 def get_vims():
     ret = req_by_msb("/api/extsys/v1/vims", "GET")
     if ret[0] != 0:
index 1753285..2825a0c 100644 (file)
@@ -29,7 +29,7 @@ HTTP_404_NOTFOUND, HTTP_403_FORBIDDEN, HTTP_401_UNAUTHORIZED, HTTP_400_BADREQUES
 logger = logging.getLogger(__name__)
 
 
-def call_req(base_url, user, passwd, auth_type, resource, method, 
+def call_req(base_url, user, passwd, auth_type, resource, method,
     content='', additional_headers={}):
     callid = str(uuid.uuid1())
     logger.debug("[%s]call_req('%s','%s','%s',%s,'%s','%s','%s')" % (
@@ -42,6 +42,8 @@ def call_req(base_url, user, passwd, auth_type, resource, method,
         if user:
             headers['Authorization'] = 'Basic ' + ('%s:%s' % (user, passwd)).encode("base64")
         ca_certs = None
+        if additional_headers:
+            headers.update(additional_headers)
         for retry_times in range(3):
             http = httplib2.Http(ca_certs=ca_certs, disable_ssl_certificate_validation=(auth_type == rest_no_auth))
             http.follow_all_redirects = True