Extend rest call param to support aai 19/9319/1
authorfujinhua <fu.jinhua@zte.com.cn>
Wed, 30 Aug 2017 07:34:20 +0000 (15:34 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Wed, 30 Aug 2017 07:34:20 +0000 (15:34 +0800)
Change-Id: Ib33154e78b8549bcf4c0bad1b3ab3167bec821c9
Issue-Id: VFC-191
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/pub/msapi/aai.py
lcm/pub/utils/restcall.py

index 93a1421..2f8cf93 100644 (file)
@@ -14,6 +14,7 @@
 
 import json
 import logging
+import uuid
 
 from lcm.pub.exceptions import NSLCMException
 from lcm.pub.utils import restcall
@@ -23,11 +24,17 @@ 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(base_url=AAI_BASE_URL, 
         user=AAI_USER, 
         passwd=AAI_PASSWD, 
         auth_type=restcall.rest_no_auth, 
         resource=resource, 
         method=method, 
-        content=content)
+        content=content,
+        additional_headers=additional_headers)
+
 
index 0ef2056..d05d30b 100644 (file)
@@ -29,7 +29,8 @@ 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, content=''):
+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')" % (
         callid, base_url, user, passwd, auth_type, resource, method, content))
@@ -41,6 +42,8 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content=''):
         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