diff options
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/assembly.xml | 8 | ||||
-rw-r--r-- | multivimbroker/docker/Dockerfile | 23 | ||||
-rw-r--r-- | multivimbroker/docker/build_image.sh | 32 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/base.py | 1 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/urls.py | 12 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/views.py | 21 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/pub/config/config.py | 24 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/pub/msapi/extsys.py | 27 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/pub/utils/restcall.py | 17 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/pub/utils/syscomm.py | 18 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/swagger/multivim.identity.swagger.json | 2 | ||||
-rw-r--r-- | multivimbroker/pom.xml | 48 | ||||
-rwxr-xr-x | multivimbroker/run.sh | 28 |
13 files changed, 186 insertions, 75 deletions
diff --git a/multivimbroker/assembly.xml b/multivimbroker/assembly.xml index 58117d8..2fa7ebd 100644 --- a/multivimbroker/assembly.xml +++ b/multivimbroker/assembly.xml @@ -38,6 +38,14 @@ </includes> </fileSet> <fileSet> + <directory>docker</directory> + <outputDirectory>/docker</outputDirectory> + <includes> + <include>*.sh</include> + <include>Dockerfile</include> + </includes> + </fileSet> + <fileSet> <directory>.</directory> <outputDirectory>/</outputDirectory> <includes> diff --git a/multivimbroker/docker/Dockerfile b/multivimbroker/docker/Dockerfile new file mode 100644 index 0000000..4cd71c0 --- /dev/null +++ b/multivimbroker/docker/Dockerfile @@ -0,0 +1,23 @@ +FROM python:2 + +ENV MSB_ADDR "127.0.0.1" +ENV MSB_PORT "80" +ENV AAI_ADDR "aai.api.simpledemo.openecomp.org" +ENV AAI_PORT "8443" +ENV AAI_SCHEMA_VERSION "v11" +ENV AAI_USERNAME "AAI" +ENV AAI_PASSWORD "AAI" + +EXPOSE 9001 + +# COPY ./ /opt/multivimbroker/ +RUN apt-get update && \ + apt-get install -y unzip && \ + cd /opt/ && \ + wget -O multicloud-framework.zip "https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.multicloud.framework&a=multicloud-framework&e=zip&v=LATEST" && \ + unzip -q -o -B multicloud-framework.zip && \ + rm -f multicloud-framework.zip && \ + pip install -r /opt/multivimbroker/requirements.txt + +WORKDIR /opt/multivimbroker +CMD /bin/sh -c /opt/multivimbroker/run.sh
\ No newline at end of file diff --git a/multivimbroker/docker/build_image.sh b/multivimbroker/docker/build_image.sh new file mode 100644 index 0000000..73a8db6 --- /dev/null +++ b/multivimbroker/docker/build_image.sh @@ -0,0 +1,32 @@ +#!/bin/bash +DIRNAME=`dirname $0` +DOCKER_BUILD_DIR=`cd $DIRNAME/; pwd` +echo "DOCKER_BUILD_DIR=${DOCKER_BUILD_DIR}" +cd ${DOCKER_BUILD_DIR} + +BUILD_ARGS="--no-cache" +ORG="onap" +VERSION="1.0.0-SNAPSHOT" +PROJECT="multicloud" +IMAGE="framework" +DOCKER_REPOSITORY="nexus3.onap.org:10003" +IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}" + +if [ $HTTP_PROXY ]; then + BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}" +fi +if [ $HTTPS_PROXY ]; then + BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" +fi + +function build_image { + docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:${VERSION} -t ${IMAGE_NAME}:latest . +} + +function push_image { + docker push ${IMAGE_NAME}:${VERSION} + docker push ${IMAGE_NAME}:latest +} + +build_image +push_image
\ No newline at end of file diff --git a/multivimbroker/multivimbroker/forwarder/base.py b/multivimbroker/multivimbroker/forwarder/base.py index c96461a..7477842 100644 --- a/multivimbroker/multivimbroker/forwarder/base.py +++ b/multivimbroker/multivimbroker/forwarder/base.py @@ -53,7 +53,6 @@ class BaseHandler(object): try: url = getMultivimDriver(vimid, full_path=full_path) - except exceptions.VimBrokerException as e: logging.exception("vimbroker exception: %s" % e) return HttpResponse(e.content, status=e.status_code) diff --git a/multivimbroker/multivimbroker/forwarder/urls.py b/multivimbroker/multivimbroker/forwarder/urls.py index 2caa219..ee4098b 100644 --- a/multivimbroker/multivimbroker/forwarder/urls.py +++ b/multivimbroker/multivimbroker/forwarder/urls.py @@ -15,15 +15,23 @@ from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns +from multivimbroker.forwarder.views import Extension from multivimbroker.forwarder.views import Forward from multivimbroker.forwarder.views import Identity +from multivimbroker.forwarder.views import Registry urlpatterns = [ url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/identity/v3$', Identity.as_view()), - url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/\ - identity/v3/auth/tokens$', Identity.as_view()), + url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/identity/v3' + r'/auth/tokens$', Identity.as_view()), + url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/registry$', + Registry.as_view()), + url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)$', + Registry.as_view()), + url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/extensions$', + Extension.as_view()), url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)', Forward.as_view()), ] diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index ed67977..edb9be1 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -39,7 +39,7 @@ class BaseServer(BaseHandler, APIView): raise NotImplementedError() -# vio proxy handler +# proxy handler class Identity(BaseServer): def get(self, request, vimid): @@ -51,6 +51,25 @@ class Identity(BaseServer): return self.send(vimid, request.get_full_path(), request.body, "POST") +class Registry(BaseServer): + + def post(self, request, vimid): + + return self.send(vimid, request.get_full_path(), request.body, "POST") + + def delete(self, request, vimid): + + return self.send(vimid, request.get_full_path(), request.body, + "DELETE") + + +class Extension(BaseServer): + + def get(self, request, vimid): + + return self.send(vimid, request.get_full_path(), request.body, "GET") + + # forward handler class Forward(BaseServer): diff --git a/multivimbroker/multivimbroker/pub/config/config.py b/multivimbroker/multivimbroker/pub/config/config.py index 5f340ea..72932dd 100644 --- a/multivimbroker/multivimbroker/pub/config/config.py +++ b/multivimbroker/multivimbroker/pub/config/config.py @@ -15,8 +15,17 @@ import os MSB_SERVICE_IP = '127.0.0.1' MSB_SERVICE_PORT = '10080' + # [ESR] -ESR_GET_VIM_URI = "/api/extsys/v1/vims" +# ESR_GET_VIM_URI = "/api/extsys/v1/vims" + +# [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' # [IMAGE LOCAL PATH] ROOT_PATH = os.path.dirname( @@ -27,19 +36,12 @@ REDIS_HOST = '127.0.0.1' REDIS_PORT = '6379' REDIS_PASSWD = '' -# [mysql] -DB_IP = "127.0.0.1" -DB_PORT = 3306 -DB_NAME = "multivimbroker" -DB_USER = "root" -DB_PASSWD = "password" - # [register] -REG_TO_MSB_WHEN_START = True +REG_TO_MSB_WHEN_START = False REG_TO_MSB_REG_URL = "/api/microservices/v1/services" REG_TO_MSB_REG_PARAM = { - "serviceName": "multivim", - "version": "v1", + "serviceName": "multicloud", + "version": "v0", "url": "/api/multicloud/v0", "protocol": "REST", "visualRange": "1", diff --git a/multivimbroker/multivimbroker/pub/msapi/extsys.py b/multivimbroker/multivimbroker/pub/msapi/extsys.py index 75959a4..2058801 100644 --- a/multivimbroker/multivimbroker/pub/msapi/extsys.py +++ b/multivimbroker/multivimbroker/pub/msapi/extsys.py @@ -13,26 +13,29 @@ import json import logging from multivimbroker.pub.exceptions import VimBrokerException -from multivimbroker.pub.utils.restcall import req_by_msb -from multivimbroker.pub.config.config import ESR_GET_VIM_URI +from multivimbroker.pub.utils.restcall import get_res_from_aai logger = logging.getLogger(__name__) -def get_vims(): - ret = req_by_msb(ESR_GET_VIM_URI, "GET") - if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) - raise VimBrokerException( - status_code=404, content="Failed to query VIMs from extsys.") - return json.JSONDecoder().decode(ret[1]) +def split_vim_to_owner_region(vim_id): + split_vim = vim_id.split('_') + cloud_owner = split_vim[0] + cloud_region = "".join(split_vim[1:]) + return cloud_owner, cloud_region def get_vim_by_id(vim_id): - ret = req_by_msb("%s/%s" % (ESR_GET_VIM_URI, vim_id), "GET") + cloud_owner, cloud_region = split_vim_to_owner_region(vim_id) + ret = get_res_from_aai("/cloud-infrastructure/cloud-regions/cloud-region" + "/%s/%s" % (cloud_owner, cloud_region)) if ret[0] != 0: - logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + logger.error("Status code is %s, detail is %s." % (ret[2], ret[1])) raise VimBrokerException( status_code=404, content="Failed to query VIM with id (%s) from extsys." % vim_id) - return json.JSONDecoder().decode(ret[1]) + ret = json.JSONDecoder().decode(ret[1]) + ret['type'] = ret['cloud-type'] + ret['version'] = ret['cloud-region-version'] + ret['vimId'] = vim_id + return ret diff --git a/multivimbroker/multivimbroker/pub/utils/restcall.py b/multivimbroker/multivimbroker/pub/utils/restcall.py index b25b389..ccdbada 100644 --- a/multivimbroker/multivimbroker/pub/utils/restcall.py +++ b/multivimbroker/multivimbroker/pub/utils/restcall.py @@ -16,7 +16,10 @@ import urllib2 import uuid import httplib2 - +from multivimbroker.pub.config.config import AAI_SCHEMA_VERSION +from multivimbroker.pub.config.config import AAI_SERVICE_URL +from multivimbroker.pub.config.config import AAI_USERNAME +from multivimbroker.pub.config.config import AAI_PASSWORD from multivimbroker.pub.config.config import MSB_SERVICE_IP, MSB_SERVICE_PORT rest_no_auth, rest_oneway_auth, rest_bothway_auth = 0, 1, 2 @@ -100,6 +103,18 @@ def req_by_msb(resource, method, content='', headers=None): rest_no_auth, resource, method, content, headers) +def get_res_from_aai(resource, content=''): + headers = { + 'X-FromAppId': 'MultiCloud', + 'X-TransactionId': '9001', + 'content-type': 'application/json', + 'accept': 'application/json' + } + base_url = "%s/%s" % (AAI_SERVICE_URL, AAI_SCHEMA_VERSION) + return call_req(base_url, AAI_USERNAME, AAI_PASSWORD, rest_no_auth, + resource, "GET", content, headers) + + def combine_url(base_url, resource): full_url = None if base_url.endswith('/') and resource.startswith('/'): diff --git a/multivimbroker/multivimbroker/pub/utils/syscomm.py b/multivimbroker/multivimbroker/pub/utils/syscomm.py index 0d0419a..cdc6480 100644 --- a/multivimbroker/multivimbroker/pub/utils/syscomm.py +++ b/multivimbroker/multivimbroker/pub/utils/syscomm.py @@ -37,25 +37,21 @@ def findMultivimDriver(vim=None): if vim and vim["type"] == "openstack": if vim["version"] == "kilo": - multivimdriver = "multivim-kilo" + multivimdriver = "multicloud-kilo" elif vim["version"] == "newton": - multivimdriver = "multivim-newton" + multivimdriver = "multicloud-newton" else: # if vim type is openstack, use latest "newton" version as default - multivimdriver = "multivim-newton" + multivimdriver = "multicloud-newton" elif vim and vim["type"] == "vmware": - multivimdriver = "multivim-vio" + multivimdriver = "multicloud-vio" else: raise exceptions.NotFound("Not support VIM type") return multivimdriver def getMultivimDriver(vimid, full_path=""): - - multivim = "multivim" + multcloud = "multicloud" vim = get_vim_by_id(vimid) - if vim["type"] and vim["version"]: - pass - - multivimdriver = findMultivimDriver(vim=vim) - return re.sub(multivim, multivimdriver, full_path) + multclouddriver = findMultivimDriver(vim=vim) + return re.sub(multcloud, multclouddriver, full_path) diff --git a/multivimbroker/multivimbroker/swagger/multivim.identity.swagger.json b/multivimbroker/multivimbroker/swagger/multivim.identity.swagger.json index 923924e..a81b431 100644 --- a/multivimbroker/multivimbroker/swagger/multivim.identity.swagger.json +++ b/multivimbroker/multivimbroker/swagger/multivim.identity.swagger.json @@ -4,7 +4,7 @@ "version": "1.0.0", "title": "MultiVIM Service rest API" }, - "basePath": "/openoapi/multivim/v1/", + "basePath": "/api/multicloud/v0/", "tags": [ { "name": "MultiVIM services" diff --git a/multivimbroker/pom.xml b/multivimbroker/pom.xml index 57a49fc..cd80d6c 100644 --- a/multivimbroker/pom.xml +++ b/multivimbroker/pom.xml @@ -11,7 +11,9 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.onap.oparent</groupId> <artifactId>oparent</artifactId> @@ -23,28 +25,28 @@ <artifactId>multicloud-framework</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - <name>multicloud/framework</name> + <name>multicloud-framework</name> <description>multivim broker</description> <build> - <plugins> - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <appendAssemblyId>false</appendAssemblyId> - <descriptors> - <descriptor>assembly.xml</descriptor> - </descriptors> - </configuration> - <executions> - <execution> - <id>make-assembly</id> - <phase>package</phase> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> + <plugins> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <configuration> + <appendAssemblyId>false</appendAssemblyId> + <descriptors> + <descriptor>assembly.xml</descriptor> + </descriptors> + </configuration> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> </build> -</project> +</project>
\ No newline at end of file diff --git a/multivimbroker/run.sh b/multivimbroker/run.sh index 3fb6e80..48b8476 100755 --- a/multivimbroker/run.sh +++ b/multivimbroker/run.sh @@ -1,13 +1,17 @@ #!/bin/bash -# Copyright (c) 2017 Wind River Systems, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - -nohup python manage.py runserver 127.0.0.1:9001 > /dev/null & + +sed -i "s/MSB_SERVICE_IP =.*/MSB_SERVICE_IP = \"${MSB_ADDR}\"/g" multivimbroker/pub/config/config.py +sed -i "s/MSB_SERVICE_PORT =.*/MSB_SERVICE_PORT = \"${MSB_PORT}\"/g" multivimbroker/pub/config/config.py +sed -i "s/AAI_ADDR =.*/AAI_ADDR = \"${AAI_ADDR}\"/g" multivimbroker/pub/config/config.py +sed -i "s/AAI_PORT =.*/AAI_PORT = \"${AAI_PORT}\"/g" multivimbroker/pub/config/config.py +sed -i "s/AAI_SCHEMA_VERSION =.*/AAI_SCHEMA_VERSION = \"${AAI_SCHEMA_VERSION}\"/g" multivimbroker/pub/config/config.py +sed -i "s/AAI_USERNAME =.*/AAI_USERNAME = \"${AAI_USERNAME}\"/g" multivimbroker/pub/config/config.py +sed -i "s/AAI_PASSWORD =.*/AAI_PASSWORD = \"${AAI_PASSWORD}\"/g" multivimbroker/pub/config/config.py + +nohup python manage.py runserver 0.0.0.0:9001 2>&1 & + +while [ ! -f logs/runtime_multivimbroker.log ]; do + sleep 1 +done + +tail -F logs/runtime_multivimbroker.log |