diff options
author | liangke <lokyse@163.com> | 2017-10-31 17:52:24 +0800 |
---|---|---|
committer | liangke <lokyse@163.com> | 2017-10-31 18:01:47 +0800 |
commit | 6b4a98c714abf92c01ade2334304529fca57d4c4 (patch) | |
tree | 76f03b12980ab7f6c2c61794e204a30ff047f219 /vio | |
parent | 39dab7d05abf06f2199b6062cd71748d42a4018f (diff) |
Add some functions of fake_cloud
1 Add tenant api in keystonev2
2 Add image version api
3 Change identiy endpoint to v2 if using keystoneV2
4 Fix a issue that it should
update endpoint of vimid if vimid's endpoint was added before.
Change-Id: I408fc55941c5b3e73d67cb0cf9ba732ec5f3a4ee
issue-Id: MULTICLOUD-79
Signed-off-by: liangke <lokyse@163.com>
Diffstat (limited to 'vio')
-rw-r--r-- | vio/vio/pub/utils/syscomm.py | 5 | ||||
-rw-r--r-- | vio/vio/swagger/urls.py | 13 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py | 118 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/identity/views.py | 9 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/image/views.py | 9 | ||||
-rw-r--r-- | vio/vio/swagger/views/proxyplugin/identity/views.py | 14 |
6 files changed, 163 insertions, 5 deletions
diff --git a/vio/vio/pub/utils/syscomm.py b/vio/vio/pub/utils/syscomm.py index 451548d..f1db022 100644 --- a/vio/vio/pub/utils/syscomm.py +++ b/vio/vio/pub/utils/syscomm.py @@ -47,7 +47,10 @@ class Catalogs(object): self.ct = defaultdict(dict) def storeEndpoint(self, vimid, endpoints): - self.ct.setdefault(vimid, endpoints) + if vimid in self.ct: + self.ct[vimid].update(endpoints) + else: + self.ct.setdefault(vimid, endpoints) def getEndpointBy(self, vimid, serverType, interface='public'): diff --git a/vio/vio/swagger/urls.py b/vio/vio/swagger/urls.py index 5bf474f..fc1b02e 100644 --- a/vio/vio/swagger/urls.py +++ b/vio/vio/swagger/urls.py @@ -48,9 +48,11 @@ from vio.swagger.views.extensions.views import Extensions # fake from vio.swagger.views.fakeplugin.identity.views import FakeProjects +from vio.swagger.views.fakeplugin.identity.views import FakeTenants from vio.swagger.views.fakeplugin.identity.views import FakeToken from vio.swagger.views.fakeplugin.identity.views import FakeTokenV2 from vio.swagger.views.fakeplugin.image.views import FakeImage +from vio.swagger.views.fakeplugin.image.views import FakeImageVersion from vio.swagger.views.fakeplugin.image.views import FakeImageDetail from vio.swagger.views.fakeplugin.image.views import FakeImageSchema from vio.swagger.views.fakeplugin.nova.views import FakeNovaServer @@ -146,6 +148,8 @@ urlpatterns = [ url(r'^api/multicloud-vio/v0/vmware_fake/identity/projects/' r'(?P<projectid>[0-9a-z-A-Z]+)$', FakeProjects.as_view()), + url(r'api/multicloud-vio/v0/vmware_fake/identity/tenants', + FakeTenants.as_view()), url(r'^api/multicloud-vio/v0/vmware_fake/nova/' r'(?P<tenantid>[0-9a-z-A-Z\-\_]+)' r'/os-hypervisors/detail$', @@ -190,7 +194,7 @@ urlpatterns = [ url(r'^api/multicloud-vio/v0/vmware_fake/glance/v2/images', FakeImage.as_view()), url(r'^api/multicloud-vio/v0/vmware_fake/glance/version', - FakeImage.as_view()), + FakeImageVersion.as_view()), url(r'^api/multicloud-vio/v0/vmware_fake/neutron$', FakeNeutron.as_view()), url(r'api/multicloud-vio/v0/vmware_fake/heat/' @@ -223,11 +227,14 @@ urlpatterns = [ # proxy url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/identity/v3', TokenView.as_view()), - url(r'api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/identity/v2.0', + url(r'api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/identity/v2.0$', + TokenV2View.as_view()), + url(r'api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)' + r'/identity/v2.0/tokens$', TokenV2View.as_view()), - url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/identity$', IdentityServer.as_view()), + # handler the rest of identity requests url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/' r'identity/(?P<other>(.*))$', IdentityServer.as_view()), diff --git a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py index c0ca1dc..16d33ac 100644 --- a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py +++ b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py @@ -737,6 +737,25 @@ def show_project(token, projectid=""): return data +# used for keystonev2 +def get_tenants(): + + data = \ + { + "tenants": [ + { + "id": Tenantid, + "name": "admin", + "description": "A description ...", + "enabled": true + } + ], + "tenants_links": [] + } + + return data + + def get_serverdetail(token): data = {"servers": []} @@ -1869,6 +1888,105 @@ def list_image(): return data +def image_version(): + + data = { + "versions": [ + { + "id": "v2.6", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "EXPERIMENTAL" + }, + { + "id": "v2.5", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "CURRENT" + }, + { + "id": "v2.4", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "SUPPORTED" + }, + { + "id": "v2.3", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "SUPPORTED" + }, + { + "id": "v2.2", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "SUPPORTED" + }, + { + "id": "v2.1", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "SUPPORTED" + }, + { + "id": "v2.0", + "links": [ + { + "href": "http://glance.openstack.example.org/v2/", + "rel": "self" + } + ], + "status": "SUPPORTED" + }, + { + "id": "v1.1", + "links": [ + { + "href": "http://glance.openstack.example.org/v1/", + "rel": "self" + } + ], + "status": "DEPRECATED" + }, + { + "id": "v1.0", + "links": [ + { + "href": "http://glance.openstack.example.org/v1/", + "rel": "self" + } + ], + "status": "DEPRECATED" + } + ] + } + return data + + def image_schema(): data = { diff --git a/vio/vio/swagger/views/fakeplugin/identity/views.py b/vio/vio/swagger/views/fakeplugin/identity/views.py index 0ef35d7..73f189f 100644 --- a/vio/vio/swagger/views/fakeplugin/identity/views.py +++ b/vio/vio/swagger/views/fakeplugin/identity/views.py @@ -14,6 +14,7 @@ from vio.swagger.views.fakeplugin.fakeData.fakeResponse import \ keystone_version2 from vio.swagger.views.fakeplugin.fakeData.fakeResponse import list_projects from vio.swagger.views.fakeplugin.fakeData.fakeResponse import show_project +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import get_tenants class FakeProjects(APIView): @@ -88,3 +89,11 @@ class FakeTokenV2(APIView): tokeninfo = keystone_tokenV2() return Response(data=tokeninfo, status=status.HTTP_200_OK) + + +class FakeTenants(APIView): + + def get(self, request, projectid=None): + + data = get_tenants() + return Response(data=data, status=status.HTTP_200_OK) diff --git a/vio/vio/swagger/views/fakeplugin/image/views.py b/vio/vio/swagger/views/fakeplugin/image/views.py index 560c297..6d6e242 100644 --- a/vio/vio/swagger/views/fakeplugin/image/views.py +++ b/vio/vio/swagger/views/fakeplugin/image/views.py @@ -6,6 +6,7 @@ from rest_framework.response import Response from vio.swagger.views.fakeplugin.fakeData.fakeResponse import image_detail from vio.swagger.views.fakeplugin.fakeData.fakeResponse import list_image from vio.swagger.views.fakeplugin.fakeData.fakeResponse import image_schema +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import image_version false = "false" null = "null" @@ -33,3 +34,11 @@ class FakeImageSchema(APIView): def get(self, request): data = image_schema() return Response(data=data, status=status.HTTP_200_OK) + + +class FakeImageVersion(APIView): + + def get(self, request): + + data = image_version() + return Response(data=data, status=status.HTTP_200_OK) diff --git a/vio/vio/swagger/views/proxyplugin/identity/views.py b/vio/vio/swagger/views/proxyplugin/identity/views.py index 1791c71..25c475b 100644 --- a/vio/vio/swagger/views/proxyplugin/identity/views.py +++ b/vio/vio/swagger/views/proxyplugin/identity/views.py @@ -51,7 +51,7 @@ class IdentityServer(BaseClient): try: res = self._request(url, method="GET", headers=headers) if res.status_code != status.HTTP_200_OK: - return Response(data={"error": res.content}, + return Response(data={"error": res.data}, status=res.status_code) res = res.data # replace keystone auth url with multicloud @@ -283,6 +283,12 @@ class TokenView(BaseClient): adminurl = deepcopy(item['adminURL']).split('/') internalurl = deepcopy(item['internalURL']).split('/') publicurl = deepcopy(item['publicURL']).split('/') + # VIO identity url use v3 as default even got token by v2, + # need change to v2.0 + if cal['type'] == 'identity': + adminurl[-1] = "v2.0" + publicurl[-1] = "v2.0" + internalurl[-1] = "v2.0" adminurl = adminurl[0] + "//" + adminurl[2] + ( "/" + adminurl[3] if len(adminurl) > 3 else "") internalurl = internalurl[0] + "//"+internalurl[2] + ( @@ -423,6 +429,12 @@ class TokenV2View(BaseClient): adminurl = deepcopy(item['adminURL']).split('/') internalurl = deepcopy(item['internalURL']).split('/') publicurl = deepcopy(item['publicURL']).split('/') + # VIO identity url use v3 as default even got token by v2, + # need change to v2.0 + if cal['type'] == 'identity': + adminurl[-1] = "v2.0" + publicurl[-1] = "v2.0" + internalurl[-1] = "v2.0" adminurl = adminurl[0] + "//" + adminurl[2] + ( "/" + adminurl[3] if len(adminurl) > 3 else "") internalurl = internalurl[0] + "//" + internalurl[2] + ( |