diff options
author | Hong Hui Xiao <honghui_xiao@yeah.net> | 2018-03-08 14:19:54 +0800 |
---|---|---|
committer | Hong Hui Xiao <honghui_xiao@yeah.net> | 2018-03-23 10:42:55 +0800 |
commit | a137643d7f753d1b26f0d7863912264e7c49a2fe (patch) | |
tree | 1e1f46c002b6a551bf78d500941d31d4ddb91aa0 /multivimbroker | |
parent | 7850f681fb63a7dca983accd42433926334fd287 (diff) |
Migrate get vim_types to new framework
A simple comparison between new framework and old framework can
be found at [1]. In a high concurrent situation, new framwork
is 24 times faster than old one. Since get vim_types is less
overhead, result in [1] is more convincing to just compare frameworks.
[1] https://paste.ubuntu.com/p/Nc5WTgsKNP/
Change-Id: I0bd3ada0684cb20319895ced77d10d8593873eee
Issue-ID: MULTICLOUD-150
Signed-off-by: Hong Hui Xiao <honghui_xiao@yeah.net>
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/api_v2/api_router/v0_controller.py | 6 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/views.py | 15 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/pub/utils/syscomm.py | 16 |
3 files changed, 23 insertions, 14 deletions
diff --git a/multivimbroker/multivimbroker/api_v2/api_router/v0_controller.py b/multivimbroker/multivimbroker/api_v2/api_router/v0_controller.py index 83b4260..99c1b08 100644 --- a/multivimbroker/multivimbroker/api_v2/api_router/v0_controller.py +++ b/multivimbroker/multivimbroker/api_v2/api_router/v0_controller.py @@ -13,10 +13,10 @@ import logging import pecan -from multivimbroker.swagger import utils from multivimbroker.pub import exceptions from multivimbroker.pub.utils import restcall from multivimbroker.pub.utils import syscomm +from multivimbroker.swagger import utils logger = logging.getLogger(__name__) @@ -30,6 +30,10 @@ IDENTITY_AUTH_URI = "identity/v3/auth/tokens" class V0_Controller(object): + @pecan.expose('json') + def vim_types(self): + return syscomm.getVIMTypes() + @pecan.expose('json', route="swagger.json") def swagger_json(self): return utils.get_swagger_json_data() diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index 83d3172..d1763c2 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os import json from rest_framework.views import APIView @@ -21,6 +20,7 @@ from rest_framework.views import Response from rest_framework.views import status from multivimbroker.forwarder.base import BaseHandler from multivimbroker.pub.utils.syscomm import originHeaders +from multivimbroker.pub.utils import syscomm class BaseServer(BaseHandler, APIView): @@ -85,18 +85,7 @@ class Extension(BaseServer): class VIMTypes(BaseServer): def get(self, request): - # Fix here unless we have plugin registry - json_file = os.path.join(os.path.dirname(__file__), - '../pub/config/provider-plugin.json') - with open(json_file, "r") as f: - plugins = json.load(f) - ret = [] - for k, v in plugins.items(): - item = {} - item["vim_type"] = v.get("vim_type") - item["versions"] = [k for k in v.get('versions', {})] - ret.append(item) - return Response(data=ret, status=status.HTTP_200_OK) + return Response(data=syscomm.getVIMTypes(), status=status.HTTP_200_OK) class CheckCapacity(BaseServer): diff --git a/multivimbroker/multivimbroker/pub/utils/syscomm.py b/multivimbroker/multivimbroker/pub/utils/syscomm.py index bd4bbb5..337a1bd 100644 --- a/multivimbroker/multivimbroker/pub/utils/syscomm.py +++ b/multivimbroker/multivimbroker/pub/utils/syscomm.py @@ -62,3 +62,19 @@ def getMultivimDriver(vimid, full_path=""): vim = get_vim_by_id(vimid) multclouddriver = findMultivimDriver(vim=vim) return re.sub(multcloud, multclouddriver, full_path) + + +def getVIMTypes(): + # Fix here unless we have plugin registry + json_file = os.path.join(os.path.dirname(__file__), + '../config/provider-plugin.json') + with open(json_file, "r") as f: + plugins = json.load(f) + ret = [] + for k, v in plugins.items(): + item = {} + item["vim_type"] = v.get("vim_type") + item["versions"] = [k for k in v.get('versions', {})] + ret.append(item) + + return ret |