summaryrefslogtreecommitdiffstats
path: root/newton
diff options
context:
space:
mode:
Diffstat (limited to 'newton')
-rw-r--r--newton/.gitignore11
-rw-r--r--newton/newton/extensions/views/extensions.py9
-rw-r--r--newton/newton/pub/config/config.py10
-rw-r--r--newton/newton/pub/msapi/extsys.py36
-rw-r--r--newton/newton/pub/utils/fileutil.py3
-rw-r--r--newton/newton/pub/utils/restcall.py24
-rw-r--r--newton/newton/requests/views/image.py4
7 files changed, 72 insertions, 25 deletions
diff --git a/newton/.gitignore b/newton/.gitignore
index 821f62a6..e86d02b0 100644
--- a/newton/.gitignore
+++ b/newton/.gitignore
@@ -1,2 +1,11 @@
+.project
+.classpath
+.settings/
+.checkstyle
+target/
logs/*.log
-*.pyc \ No newline at end of file
+*.pyc
+.tox
+.coverage
+htmlcov/
+
diff --git a/newton/newton/extensions/views/extensions.py b/newton/newton/extensions/views/extensions.py
index e930f06d..a327da8a 100644
--- a/newton/newton/extensions/views/extensions.py
+++ b/newton/newton/extensions/views/extensions.py
@@ -48,12 +48,9 @@ class Extensions(APIView):
"alias": "epa-caps",
"description": "Multiple network support",
"name": "EPACapsQuery",
- 'links': [ \
- {
- "url": "http://%s:%s/api/multicloud-newton/v0/%s/extensions/epa-caps" \
- % (config.MSB_SERVICE_IP, config.MSB_SERVICE_PORT, vimid), \
- }
- ]
+ "url": "http://%s:%s/api/multicloud-newton/v0/%s/extensions/epa-caps" \
+ % (config.MSB_SERVICE_IP, config.MSB_SERVICE_PORT, vimid),
+ "spec": ""
}
]
diff --git a/newton/newton/pub/config/config.py b/newton/newton/pub/config/config.py
index fc7775b5..96837118 100644
--- a/newton/newton/pub/config/config.py
+++ b/newton/newton/pub/config/config.py
@@ -15,5 +15,15 @@ import os
MSB_SERVICE_IP = '127.0.0.1'
MSB_SERVICE_PORT = '80'
+# [A&AI]
+AAI_ADDR = "aai.api.simpledemo.openecomp.org"
+AAI_PORT = "8443"
+AAI_SERVICE_URL = 'https://%s:%s/aai' % (AAI_ADDR, AAI_PORT)
+AAI_SCHEMA_VERSION = "v11"
+AAI_USERNAME = 'AAI'
+AAI_PASSWORD = 'AAI'
+
+AAI_APP_ID = 'MultiCloud-Newton'
+
# [IMAGE LOCAL PATH]
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
diff --git a/newton/newton/pub/msapi/extsys.py b/newton/newton/pub/msapi/extsys.py
index 449ad5b5..57beb0e9 100644
--- a/newton/newton/pub/msapi/extsys.py
+++ b/newton/newton/pub/msapi/extsys.py
@@ -15,7 +15,8 @@ import re
from rest_framework import status
from newton.pub.exceptions import VimDriverNewtonException
-from newton.pub.utils.restcall import req_by_msb
+from newton.pub.utils.restcall import req_by_msb,req_to_aai
+
logger = logging.getLogger(__name__)
@@ -25,16 +26,28 @@ def get_vim_by_id(vim_id):
if cloud_owner and cloud_region_id:
retcode, content, status_code = \
- req_by_msb("/api/aai-cloudInfrastructure/v1/cloud-infrastructure/cloud-regions/cloud-region/%s/%s"
- % (cloud_owner,cloud_region_id), "GET")
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s"
+ % (cloud_owner,cloud_region_id),"GET")
if retcode != 0:
logger.error("Status code is %s, detail is %s.", status_code, content)
raise VimDriverNewtonException(
- "Failed to query VIM with id (%s:%s,%s) from extsys." % (vim_id,cloud_owner,cloud_region_id),
+ "Failed to query VIM with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id),
status_code, content)
tmp_viminfo = json.JSONDecoder().decode(content)
+
+ #assume esr-system-info-id is composed by {cloud-owner} _ {cloud-region-id}
+ retcode2,content2,status_code2 = \
+ req_to_aai("/cloud-infrastructure/esr-system-info/%s/%s/%s_%s" \
+ % (cloud_owner,cloud_region_id,cloud_owner,cloud_region_id),
+ "GET")
+ if retcode2 != 0:
+ logger.error("Status code is %s, detail is %s.", status_code, content)
+ raise VimDriverNewtonException(
+ "Failed to query ESR system with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id),
+ status_code, content)
+ tmp_authinfo = json.JSONDecoder().decode(content2)
+
#convert vim information
- #tbd
if tmp_viminfo:
viminfo = {}
@@ -47,15 +60,16 @@ def get_vim_by_id(vim_id):
viminfo['cloud_extra_info'] = tmp_viminfo['cloud-extra-info']
viminfo['cloud_epa_caps'] = tmp_viminfo['cloud-epa-caps']
- tmp_authinfo = tmp_viminfo['auth-info-items'][0]
if tmp_authinfo:
- viminfo['userName'] = tmp_authinfo['username']
+ viminfo['userName'] = tmp_authinfo['user-name']
viminfo['password'] = tmp_authinfo['password']
viminfo['domain'] = tmp_authinfo['cloud-domain']
- viminfo['url'] = tmp_authinfo['auth-url']
- viminfo['tenant'] = tmp_authinfo['defaultTenant']['name'] if not tmp_authinfo['defaultTenant'] else None
+ viminfo['url'] = tmp_authinfo['url']
+ viminfo['tenant'] = tmp_authinfo['default-tenant']
viminfo['cacert'] = tmp_authinfo['ssl-cacert']
viminfo['insecure'] = tmp_authinfo['ssl-insecure']
+ else:
+ return None
return viminfo
else:
@@ -67,12 +81,12 @@ def delete_vim_by_id(vim_id):
cloud_owner, cloud_region_id = decode_vim_id(vim_id)
if cloud_owner and cloud_region_id:
retcode, content, status_code = \
- req_by_msb("/api/aai-cloudInfrastructure/v1/cloud-infrastructure/cloud-regions/cloud-region/%s/%s"
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s"
% ( cloud_owner, cloud_region_id), "DELETE")
if retcode != 0:
logger.error("Status code is %s, detail is %s.", status_code, content)
raise VimDriverNewtonException(
- "Failed to delete VIM in AAI with id (%s:%s,%s) from extsys." % (vim_id,cloud_owner,cloud_region_id),
+ "Failed to delete VIM in AAI with id (%s:%s,%s)." % (vim_id,cloud_owner,cloud_region_id),
status_code, content)
return 0
# return non zero if failed to decode cloud owner and region id
diff --git a/newton/newton/pub/utils/fileutil.py b/newton/newton/pub/utils/fileutil.py
index 6fbbec7e..304564ad 100644
--- a/newton/newton/pub/utils/fileutil.py
+++ b/newton/newton/pub/utils/fileutil.py
@@ -36,8 +36,7 @@ def download_file_from_http(url, local_dir, file_name):
is_download_ok = False
try:
make_dirs(local_dir)
- r = urllib2.Request(url)
- req = urllib2.urlopen(r)
+ req = urllib.request.urlopen(url)
save_file = open(local_file_name, 'wb')
save_file.write(req.read())
save_file.close()
diff --git a/newton/newton/pub/utils/restcall.py b/newton/newton/pub/utils/restcall.py
index d784f09c..c2fa361d 100644
--- a/newton/newton/pub/utils/restcall.py
+++ b/newton/newton/pub/utils/restcall.py
@@ -16,10 +16,15 @@ from six.moves import urllib
import uuid
from six.moves import http_client
import httplib2
+import uuid
from rest_framework import status
-
+from newton.pub.config.config import AAI_SCHEMA_VERSION
+from newton.pub.config.config import AAI_SERVICE_URL
+from newton.pub.config.config import AAI_USERNAME
+from newton.pub.config.config import AAI_PASSWORD
from newton.pub.config.config import MSB_SERVICE_IP, MSB_SERVICE_PORT
+from newton.pub.config.config import AAI_APP_ID
rest_no_auth, rest_oneway_auth, rest_bothway_auth = 0, 1, 2
HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT, HTTP_202_ACCEPTED \
@@ -72,11 +77,11 @@ def call_req(base_url, user, passwd, auth_type,
else:
ret = [1, resp_body, resp_status]
break
- except httplib.ResponseNotReady:
+ except http.client.ResponseNotReady:
# logger.debug("retry_times=%d", retry_times)
ret = [1, "Unable to connect to %s" % full_url, resp_status]
continue
- except urllib2.URLError as err:
+ except urllib.error.URLError as err:
ret = [2, str(err), resp_status]
except Exception:
logger.error(traceback.format_exc())
@@ -100,6 +105,19 @@ def req_to_vim(base_url, resource, method, extra_headers='', content=''):
return call_req(base_url, "", "", rest_no_auth,
resource, method, extra_headers, content)
+def req_to_aai(resource, method, content='', appid=AAI_APP_ID):
+ tmp_trasaction_id = uuid.uuid1()
+ headers = {
+ 'X-FromAppId': appid,
+ 'X-TransactionId': tmp_trasaction_id,
+ 'content-type': 'application/json',
+ 'accept': 'application/json'
+ }
+ base_url = "%s/%s" % (AAI_SERVICE_URL, AAI_SCHEMA_VERSION)
+ logger.debug("req_to_aai--%s::> %s, %s" % (tmp_trasaction_id, method, resource))
+ return call_req(base_url, AAI_USERNAME, AAI_PASSWORD, rest_no_auth,
+ resource, method, content, headers)
+
def combine_url(base_url, resource):
full_url = None
diff --git a/newton/newton/requests/views/image.py b/newton/newton/requests/views/image.py
index ff507bd2..c6cfd3d0 100644
--- a/newton/newton/requests/views/image.py
+++ b/newton/newton/requests/views/image.py
@@ -158,7 +158,7 @@ class Images(APIView):
return Response(data={'error': 'imagePath is not specified'}, status=500)
#valid image url
- imagefd = urllib2.urlopen(imageurl)
+ imagefd = urllib.request.urlopen(imageurl)
if not imagefd:
logger.debug("image is not available at %s" % imageurl)
return Response(data={'error': 'cannot access to specified imagePath'}, status=500)
@@ -201,7 +201,7 @@ class Images(APIView):
return Response(data=resp_body, status=resp.status_code)
except VimDriverNewtonException as e:
return Response(data={'error': e.content}, status=e.status_code)
- except urllib2.URLError as e:
+ except urllib.error.URLError as e:
return Response(data={'error': 'image is not accessible:%s' % str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except HttpError as e: