summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--newton/newton/extensions/views/extensions.py4
-rw-r--r--newton/newton/proxy/views/identityV3.py17
-rw-r--r--newton/newton/pub/config/config.py8
-rw-r--r--newton/newton/pub/utils/restcall.py8
-rw-r--r--newton/newton/registration/views/registration.py208
5 files changed, 225 insertions, 20 deletions
diff --git a/newton/newton/extensions/views/extensions.py b/newton/newton/extensions/views/extensions.py
index a327da8a..e1901d01 100644
--- a/newton/newton/extensions/views/extensions.py
+++ b/newton/newton/extensions/views/extensions.py
@@ -48,8 +48,8 @@ class Extensions(APIView):
"alias": "epa-caps",
"description": "Multiple network support",
"name": "EPACapsQuery",
- "url": "http://%s:%s/api/multicloud-newton/v0/%s/extensions/epa-caps" \
- % (config.MSB_SERVICE_IP, config.MSB_SERVICE_PORT, vimid),
+ "url": config.MULTICLOUD_PREFIX+"/%s/extensions/epa-caps" \
+ % (vimid),
"spec": ""
}
]
diff --git a/newton/newton/proxy/views/identityV3.py b/newton/newton/proxy/views/identityV3.py
index f11a6334..49a1c1b7 100644
--- a/newton/newton/proxy/views/identityV3.py
+++ b/newton/newton/proxy/views/identityV3.py
@@ -31,7 +31,7 @@ from newton.requests.views.util import VimDriverUtils
logger = logging.getLogger(__name__)
DEBUG=True
-MULTICLOUD_PREFIX = "http://%s:%s/api/multicloud-newton/v0" %(config.MSB_SERVICE_IP, config.MSB_SERVICE_PORT)
+#MULTICLOUD_PREFIX = "http://%s:%s/api/multicloud-newton/v0" %(config.MSB_SERVICE_IP, config.MSB_SERVICE_PORT)
def update_catalog(vimid, catalog, multicould_namespace):
'''
@@ -76,16 +76,13 @@ def update_catalog(vimid, catalog, multicould_namespace):
endpoint_url = endpoint["url"]
real_prefix = None
real_suffix = None
-# m = re.search(r'^(http[s]?://[0-9.]+:[0-9]+)(/([0-9a-zA-Z/._-]+)$)?', endpoint_url)
- m = re.search(r'^(http[s]?://[0-9.]+[0-9:]*)(/([0-9a-zA-Z/._-]+)$)?', endpoint_url)
+ m = re.search(r'^(http[s]?://[0-9.]+:[0-9]+)(/([0-9a-zA-Z/._-]+)$)?', endpoint_url)
+ if not m:
+ m = re.search(r'^(http[s]?://[0-9.]+)(/([0-9a-zA-Z/._-]+)$)?', endpoint_url)
if m:
real_prefix = m.group(1)
real_suffix = m.group(3)
-# else:
-# m = re.search(r'^(http[s]?://[0-9.]+)(/([0-9a-zA-Z/._-]+)$)?', endpoint_url)
-# if m:
-# real_prefix = m.group(1)
-# real_suffix = m.group(2)
+
if real_prefix:
# populate metadata_catalog
one_catalog['prefix'] = real_prefix
@@ -123,7 +120,7 @@ class Tokens(APIView):
'interface': 'public'}
def __init__(self):
- self.proxy_prefix = MULTICLOUD_PREFIX
+ self.proxy_prefix = config.MULTICLOUD_PREFIX
self._logger = logger
def post(self, request, vimid=""):
@@ -169,7 +166,7 @@ class Catalog(APIView):
'interface': 'public'}
def __init__(self):
- self.proxy_prefix = MULTICLOUD_PREFIX
+ self.proxy_prefix = config.MULTICLOUD_PREFIX
self._logger = logger
def get(self, request, vimid=""):
diff --git a/newton/newton/pub/config/config.py b/newton/newton/pub/config/config.py
index 96837118..0dde6152 100644
--- a/newton/newton/pub/config/config.py
+++ b/newton/newton/pub/config/config.py
@@ -12,9 +12,13 @@
import os
# [MSB]
-MSB_SERVICE_IP = '127.0.0.1'
+MSB_SERVICE_ADDR = '127.0.0.1'
MSB_SERVICE_PORT = '80'
+
+#[Multicloud]
+MULTICLOUD_PREFIX = "http://%s:%s/api/multicloud-newton/v0" %(MSB_SERVICE_ADDR, MSB_SERVICE_PORT)
+
# [A&AI]
AAI_ADDR = "aai.api.simpledemo.openecomp.org"
AAI_PORT = "8443"
@@ -23,7 +27,7 @@ AAI_SCHEMA_VERSION = "v11"
AAI_USERNAME = 'AAI'
AAI_PASSWORD = 'AAI'
-AAI_APP_ID = 'MultiCloud-Newton'
+MULTICLOUD_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/utils/restcall.py b/newton/newton/pub/utils/restcall.py
index c2fa361d..871df460 100644
--- a/newton/newton/pub/utils/restcall.py
+++ b/newton/newton/pub/utils/restcall.py
@@ -23,8 +23,8 @@ 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
+from newton.pub.config.config import MSB_SERVICE_ADDR, MSB_SERVICE_PORT
+from newton.pub.config.config import MULTICLOUD_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 \
@@ -95,7 +95,7 @@ def call_req(base_url, user, passwd, auth_type,
def req_by_msb(resource, method, content=''):
- base_url = "http://%s:%s/" % (MSB_SERVICE_IP, MSB_SERVICE_PORT)
+ base_url = "http://%s:%s/" % (MSB_SERVICE_ADDR, MSB_SERVICE_PORT)
# logger.debug("requests--get::> %s" % "33")
return call_req(base_url, "", "", rest_no_auth,
resource, method, "", content)
@@ -105,7 +105,7 @@ 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):
+def req_to_aai(resource, method, content='', appid=MULTICLOUD_APP_ID):
tmp_trasaction_id = uuid.uuid1()
headers = {
'X-FromAppId': appid,
diff --git a/newton/newton/registration/views/registration.py b/newton/newton/registration/views/registration.py
index 5dd32161..0e6c4921 100644
--- a/newton/newton/registration/views/registration.py
+++ b/newton/newton/registration/views/registration.py
@@ -24,8 +24,11 @@ from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
+from newton.pub.config import config
from newton.pub.exceptions import VimDriverNewtonException
from newton.requests.views.util import VimDriverUtils
+from newton.pub.utils.restcall import req_to_aai
+from newton.pub.msapi import extsys
logger = logging.getLogger(__name__)
@@ -36,6 +39,29 @@ class Registry(APIView):
def __init__(self):
self._logger = logger
+
+ def update_tenant(self, cloud_owner, cloud_region_id, tenantinfo):
+ '''
+ populate tenant into AAI
+ :param cloud_owner:
+ :param cloud_region_id:
+ :param tenantinfo:
+ tenant-id: string
+ tenant-name: string
+ :return:
+ '''
+
+
+ if cloud_owner and cloud_region_id:
+ retcode, content, status_code = \
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/tenants/tenant/%s"
+ % (cloud_owner, cloud_region_id, tenantinfo['tenant-id']), "PUT", content=tenantinfo)
+
+ self._logger.debug("update_tenant,vimid:%s_%s req_to_aai: %s, return %s, %s, %s" \
+ % (cloud_owner,cloud_region_id, tenantinfo['tenant-id'], retcode, content, status_code))
+ return retcode
+ return 1
+
def discover_tenants(self, request, vimid="", session=None, viminfo=None):
req_resource = "/projects"
service = {'service_type': "identity",
@@ -46,14 +72,54 @@ class Registry(APIView):
content = resp.json()
self._logger.debug("vimid: %s, req: %s,resp code: %s, body: %s" \
% (vimid, req_resource, resp.status_code,content))
+
+ if resp.status_code != status.HTTP_200_OK:
+ return False #failed to discover resources
+
# iterate all projects and populate them into AAI
- # TBD
+ cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
+ tenant_info = {}
+ for tenant in content['projects']:
+ tenant_info['tenant-id'] = tenant['id']
+ tenant_info['tenant-name'] = tenant['name']
+ self.update_tenant(cloud_owner, cloud_region_id, tenant_info)
pass
+
+ def update_flavor(self, cloud_owner, cloud_region_id, flavorinfo):
+ '''
+ populate flavor into AAI
+ :param cloud_owner:
+ :param cloud_region_id:
+ :param flavorinfo:
+ flavor-id: string
+ flavor-name: string
+ flavor-vcpus: integer
+ flavor-ram: integer
+ flavor-disk: integer
+ flavor-ephemeral: integer
+ flavor-swap: string
+ flavor-is-public: boolean
+ flavor-selflink: string
+ flavor-disabled: boolean
+
+ :return:
+ '''
+
+ if cloud_owner and cloud_region_id:
+ retcode, content, status_code = \
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/flavors/flavor/%s"
+ % (cloud_owner, cloud_region_id, flavorinfo['flavor-id']), "PUT", content=flavorinfo)
+
+ self._logger.debug("update_flavor,vimid:%s_%s req_to_aai: %s, return %s, %s, %s" \
+ % (cloud_owner,cloud_region_id, flavorinfo['flavor-id'], retcode, content, status_code))
+ return retcode
+ return 1
+
def discover_flavors(self, request, vimid="", session=None, viminfo=None):
- req_resource = "/flavors"
+ req_resource = "/flavors/detail"
service = {'service_type': "compute",
'interface': 'public',
'region_id': viminfo['cloud_region_id']}
@@ -62,8 +128,81 @@ class Registry(APIView):
self._logger.debug("vimid: %s, req: %s,resp code: %s, body: %s" \
% (vimid, req_resource, resp.status_code,content))
+
+ if resp.status_code != status.HTTP_200_OK:
+ return False #failed to discover resources
+
+ cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
+ flavor_info = {}
+ for flavor in content['flavors']:
+ flavor_info['flavor-id'] = flavor['id']
+ flavor_info['flavor-name'] = flavor['name']
+ flavor_info['flavor-vcpus'] = flavor['vcpus']
+ flavor_info['flavor-ram'] = flavor['ram']
+ flavor_info['flavor-disk'] = flavor['disk']
+ flavor_info['flavor-ephemeral'] = flavor['OS-FLV-EXT-DATA:ephemeral']
+ flavor_info['flavor-swap'] = flavor['swap']
+ flavor_info['flavor-is-public'] = flavor['os-flavor-access:is_public']
+ flavor_info['flavor-selflink'] = flavor['links'][0]['href']
+ flavor_info['flavor-swap'] = flavor['swap']
+ flavor_info['flavor-disabled'] = flavor['OS-FLV-DISABLED:disabled']
+ self.update_flavor(cloud_owner, cloud_region_id, flavor_info)
+
pass
+ def update_image_metadata(self, cloud_owner, cloud_region_id, image_id, metadatainfo):
+ '''
+ populate image meta data
+ :param cloud_owner:
+ :param cloud_region_id:
+ :param image_id:
+ :param metadatainfo:
+ metaname: string
+ metaval: string
+ :return:
+ '''
+
+ if cloud_owner and cloud_region_id:
+ retcode, content, status_code = \
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/images/image/%s"
+ % (cloud_owner, cloud_region_id, image_id, metadatainfo['metaname']), "PUT", content=imageinfo)
+
+ self._logger.debug("update_image,vimid:%s_%s req_to_aai: %s/%s, return %s, %s, %s" \
+ % (cloud_owner,cloud_region_id,image_id,metadatainfo['metaname'], retcode, content, status_code))
+ return retcode
+ return 1
+
+ def update_image(self, cloud_owner, cloud_region_id, imageinfo):
+ '''
+ populate image into AAI
+ :param cloud_owner:
+ :param cloud_region_id:
+ :param imageinfo:
+ image-id: string
+ image-name: string
+ image-architecture: string
+ image-os-distro: string
+ image-os-version: string
+ application: string
+ application-vendor: string
+ application-version: string
+ image-selflink: string
+
+ :return:
+ '''
+
+
+ if cloud_owner and cloud_region_id:
+ retcode, content, status_code = \
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s/images/image/%s"
+ % (cloud_owner, cloud_region_id, imageinfo['image-id']), "PUT", content=imageinfo)
+
+ self._logger.debug("update_image,vimid:%s_%s req_to_aai: %s, return %s, %s, %s" \
+ % (cloud_owner,cloud_region_id, imageinfo['image-id'], retcode, content, status_code))
+
+ return retcode
+ return 1 #unknown cloud owner,region_id
+
def discover_images(self, request, vimid="", session=None, viminfo=None):
req_resource = "/v2/images"
@@ -75,6 +214,51 @@ class Registry(APIView):
self._logger.debug("vimid: %s, req: %s,resp code: %s, body: %s" \
% (vimid, req_resource, resp.status_code,content))
+
+ if resp.status_code != status.HTTP_200_OK:
+ return False #failed to discover resources
+
+ cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
+ image_info = {}
+ metadata_info = {}
+ for image in content['images']:
+ image_info['image-id'] = image['id']
+ image_info['image-name'] = image['name']
+ image_info['image-selflink'] = image['self']
+
+ image_info['image-os-distro'] = image['os_distro'] or ''
+ image_info['image-os-version'] = image['os_version'] or ''
+ image_info['application'] = image['application'] or ''
+ image_info['application-vendor'] = image['application_vendor'] or ''
+ image_info['application-version'] = image['application_version'] or ''
+ image_info['image-architecture'] = image['architecture'] or ''
+
+ ret = self.update_image(cloud_owner, cloud_region_id, image_info)
+ if ret != 0:
+ #failed to update image
+ self._logger.debug("failed to populate image info into AAI: %s, image id: %s, ret:%s" \
+ % (vimid, image_info['image-id'], ret))
+ continue
+
+ schema = image['schema']
+ if schema:
+ req_resource = schema
+ service = {'service_type': "image",
+ 'interface': 'public',
+ 'region_id': viminfo['cloud_region_id']}
+ resp = session.get(req_resource, endpoint_filter=service)
+ content = resp.json()
+
+ self._logger.debug("vimid: %s, req: %s,resp code: %s, body: %s" \
+ % (vimid, req_resource, resp.status_code, content))
+ if resp.status_code == status.HTTP_200_OK:
+ #parse the schema?
+ #self.update_image(cloud_owner, cloud_region_id, image_info)
+ pass
+
+
+
+
pass
def discover_availablezones(self, request, vimid="", session=None, viminfo=None):
@@ -146,11 +330,31 @@ class Registry(APIView):
pass
+ def update_proxy_identity_endpoint(self, cloud_owner, cloud_region_id, url):
+ '''
+ update cloud_region's identity url
+ :param cloud_owner:
+ :param cloud_region_id:
+ :param url:
+ :return:
+ '''
+ if cloud_owner and cloud_region_id:
+ retcode, content, status_code = \
+ req_to_aai("/cloud-infrastructure/cloud-regions/cloud-region/%s/%s"
+ % (cloud_owner, cloud_region_id), "PUT", content={'identity-url': url})
+
+ self._logger.debug("update_proxy_identity_endpoint,vimid:%s_%s req_to_aai: %s, return %s, %s, %s" \
+ % (cloud_owner,cloud_region_id, url, retcode, content, status_code))
+
def post(self, request, vimid=""):
self._logger.debug("Registration--post::data> %s" % request.data)
self._logger.debug("Registration--post::vimid > %s" % vimid)
try:
+ #populate proxy identity url
+ cloud_owner, cloud_region_id = extsys.decode_vim_id(vimid)
+ self.update_proxy_identity_endpoint(cloud_owner, cloud_region_id, config.MULTICLOUD_PREFIX+"/%s/identity/v3" % vimid )
+
# prepare request resource to vim instance
# get token:
viminfo = VimDriverUtils.get_vim_info(vimid)