diff options
-rw-r--r-- | vio/vio/pub/utils/fileutil.py | 2 | ||||
-rw-r--r-- | vio/vio/pub/utils/restcall.py | 4 | ||||
-rw-r--r-- | vio/vio/swagger/urls.py | 29 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py | 656 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/heat/__init__.py | 0 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/heat/views.py | 99 | ||||
-rw-r--r-- | vio/vio/swagger/views/fakeplugin/identity/views.py | 39 | ||||
-rw-r--r-- | vio/vio/swagger/views/proxyplugin/identity/views.py | 141 |
8 files changed, 962 insertions, 8 deletions
diff --git a/vio/vio/pub/utils/fileutil.py b/vio/vio/pub/utils/fileutil.py index 07b5124..dabf198 100644 --- a/vio/vio/pub/utils/fileutil.py +++ b/vio/vio/pub/utils/fileutil.py @@ -44,7 +44,7 @@ def download_file_from_http(url, local_dir, file_name): save_file.close() req.close() is_download_ok = True - except: + except Exception: logger.error(traceback.format_exc()) logger.error("Failed to download %s to %s.", url, local_file_name) return is_download_ok, local_file_name diff --git a/vio/vio/pub/utils/restcall.py b/vio/vio/pub/utils/restcall.py index 15dd90b..ee84447 100644 --- a/vio/vio/pub/utils/restcall.py +++ b/vio/vio/pub/utils/restcall.py @@ -93,10 +93,6 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content='', res_info = ("The URL[%s] request failed or is not responding." % full_url) ret = [3, res_info, resp_status, resp] - except: - logger.error(traceback.format_exc()) - ret = [4, str(sys.exc_info()), resp_status, resp] - # logger.debug("[%s]ret=%s" % (callid, str(ret))) return ret diff --git a/vio/vio/swagger/urls.py b/vio/vio/swagger/urls.py index 43b5a7f..5bf474f 100644 --- a/vio/vio/swagger/urls.py +++ b/vio/vio/swagger/urls.py @@ -31,6 +31,7 @@ from vio.swagger.views.port.views import CreatePortView, DeletePortView # proxy from vio.swagger.views.proxyplugin.identity.views import TokenView +from vio.swagger.views.proxyplugin.identity.views import TokenV2View from vio.swagger.views.proxyplugin.identity.views import IdentityServer from vio.swagger.views.proxyplugin.nova.views import ComputeServer from vio.swagger.views.proxyplugin.image.views import ImageServer @@ -48,6 +49,7 @@ 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 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 FakeImageDetail from vio.swagger.views.fakeplugin.image.views import FakeImageSchema @@ -61,6 +63,9 @@ from vio.swagger.views.fakeplugin.nova.views import FakeFlavorDetail from vio.swagger.views.fakeplugin.neutron.views import FakeNeutron from vio.swagger.views.fakeplugin.neutron.views import FakeNeutronDetail from vio.swagger.views.fakeplugin.neutron.views import FakeNeutronNetwork +from vio.swagger.views.fakeplugin.heat.views import FakeHeatResources +from vio.swagger.views.fakeplugin.heat.views import FakeHeatService +from vio.swagger.views.fakeplugin.heat.views import FakeHeatServicePreview urlpatterns = [ @@ -134,6 +139,8 @@ urlpatterns = [ # fake urls url(r'^api/multicloud-vio/v0/vmware_fake/identity/v3', FakeToken.as_view()), + url(r'api/multicloud-vio/v0/vmware_fake/identity/v2.0', + FakeTokenV2.as_view()), url(r'^api/multicloud-vio/v0/vmware_fake/identity/projects$', FakeProjects.as_view()), url(r'^api/multicloud-vio/v0/vmware_fake/identity/projects/' @@ -186,6 +193,26 @@ urlpatterns = [ FakeImage.as_view()), url(r'^api/multicloud-vio/v0/vmware_fake/neutron$', FakeNeutron.as_view()), + url(r'api/multicloud-vio/v0/vmware_fake/heat/' + r'(?P<tenantid>[0-9a-z-A-Z\-\_]+)' + r'/stacks/(?P<stack_id>[0-9a-z-A-Z\-\_]+)/resources$', + FakeHeatResources.as_view()), + url(r'api/multicloud-vio/v0/vmware_fake/heat/' + r'(?P<tenantid>[0-9a-z-A-Z\-\_]+)' + r'/stacks$', FakeHeatService.as_view()), + url(r'api/multicloud-vio/v0/vmware_fake/heat/' + r'(?P<tenantid>[0-9a-z-A-Z\-\_]+)' + r'/stacks/preview$', FakeHeatServicePreview.as_view()), + + url(r'api/multicloud-vio/v0/vmware_fake/heat/' + r'(?P<tenantid>[0-9a-z-A-Z\-\_]+)' + r'/stacks/(?P<stackName>[0-9a-z-A-Z\-\_]+)', + FakeHeatService.as_view()), + + url(r'api/multicloud-vio/v0/vmware_fake/heat/' + r'(?P<tenantid>[0-9a-z-A-Z\-\_]+)' + r'/stacks/(?P<stackName>[0-9a-z-A-Z\-\_]+)' + r'/(?P<stackID>[0-9a-z-A-Z\-\_]+)$', FakeHeatService.as_view()), # Registry url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/registry$', @@ -196,6 +223,8 @@ 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', + TokenV2View.as_view()), url(r'^api/multicloud-vio/v0/(?P<vimid>[0-9a-z-A-Z\-\_]+)/identity$', IdentityServer.as_view()), diff --git a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py index 7daf102..c0ca1dc 100644 --- a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py +++ b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py @@ -67,6 +67,39 @@ def keystone_version(): return data +def keystone_version2(): + + data = { + "version": { + "status": "deprecated", + "updated": "2016-08-04T00:00:00Z", + "media-types": [ + { + "base": "application/json", + "type": "application/" + "vnd.openstack.identity-v2.0+json" + } + ], + "id": "v2.0", + "links": [ + { + "href": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/identity/v2.0", + "rel": "self" + }, + { + "href": "https://docs.openstack.org/", + "type": "text/html", + "rel": "describedby" + } + ] + } + } + + return data + + def keystone_token(teanatid=None): data = { @@ -335,6 +368,294 @@ def keystone_token(teanatid=None): return data +def keystone_tokenV2(): + + data = \ + { + "access": { + "token": { + "issued_at": "2017-10-24T06:47:51.000000Z", + "expires": "2017-10-24T08:47:51.000000Z", + "id": Token, + "tenant": { + "enabled": true, + "description": "Bootstrap " + "project for " + "initializing the cloud.", + "name": "admin", + "id": Tenantid + }, + "audit_ids": [ + "_KKMw5S3RUCl8SNKwmiDcA" + ] + }, + "serviceCatalog": [ + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": + "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/nova/" + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/nova/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/nova/" + + Tenantid, + "id": "10fd2ceacc994090a96ab3b8541e066e" + } + ], + "type": "compute", + "name": "nova" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/neutron", + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/neutron", + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/neutron", + "id": "1bf876c18fd64e4f89cfa3c8a9624864" + } + ], + "type": "network", + "name": "neutron" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinderv2/" + + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinderv2/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinderv2/" + + Tenantid, + "id": "70ed007f3aae44288e1851d5ade542ef" + } + ], + "type": "volumev2", + "name": "cinderv2" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinderv3/" + + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinderv3/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinderv3/" + + Tenantid, + "id": "2090cf622a904c1bbc0f500c2f1b1c78" + } + ], + "type": "volumev3", + "name": "cinderv3" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/glance", + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmare_fake/glance", + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/glance", + "id": "25404699d5fc4e1989f421243c0006d1" + } + ], + "type": "image", + "name": "glance" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/nova_legacy/" + + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/nova_legacy/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/" + "nova_legacy/" + + Tenantid, + "id": "303b4193e0784d0391a2bc318ff27229" + } + ], + "type": "compute_legacy", + "name": "nova_legacy" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/heat-cfn", + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/heat-cfn", + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/heat-cfn", + "id": "1152aa50dd1a4a99be272aa84f910ef6" + } + ], + "type": "cloudformation", + "name": "heat-cfn" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinder/" + + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinder/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/cinder/" + + Tenantid, + "id": "1cdfe5803856412f9daa3bed79f6e9ac" + } + ], + "type": "volume", + "name": "cinder" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/heat/" + + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/heat/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/heat/" + + Tenantid, + "id": "7eb9b5633c8f431da405192665782392" + } + ], + "type": "orchestration", + "name": "heat" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/placement/" + + Tenantid, + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/placement/" + + Tenantid, + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/placement/" + + Tenantid, + "id": "9b509d9d5db54f51bbd27d9991586250" + } + ], + "type": "placement", + "name": "placement" + }, + { + "endpoints_links": [], + "endpoints": [ + { + "adminURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/identity", + "region": "nova", + "publicURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/identity", + "internalURL": "http://" + MSB_SERVER + + "/api/multicloud-vio/" + "v0/vmware_fake/identity", + "id": "62a158d5b28d4fdbb485e8cf6ae5cc92" + } + ], + "type": "identity", + "name": "keystone" + } + ], + "user": { + "username": "admin", + "roles_links": [], + "id": "08a03743532f4c64b5e283b15646fd10", + "roles": [ + { + "name": "admin" + } + ], + "name": "admin" + }, + "metadata": { + "is_admin": 0, + "roles": [ + "cd1ffa75112d47f9ac64a758fa75d688" + ] + } + } + } + + return data + + def list_projects(token=None): if token != Token: @@ -1816,3 +2137,338 @@ def image_schema(): } return data + + +# heat stack +STACK_ID = "3095aefc-09fb-4bc7-b1f0-f21a304e864c" +STACK_NAME = "simple_stack" + + +def getAllStacks(token): + if token != Token: + return {"error": {"message": "unauthorization", "code": 401}} + + data = \ + { + "stacks": [ + { + "creation_time": "2014-06-03T20:59:46Z", + "deletion_time": null, + "description": "sample stack", + "id": STACK_ID, + "links": [ + { + "href": "http://127.0.0.1:8004/v1/" + Tenantid + + "/stacks/" + STACK_NAME + "/" + STACK_ID, + "rel": "self" + } + ], + "parent": null, + "stack_name": STACK_NAME, + "stack_owner": null, + "stack_status": "CREATE_COMPLETE", + "stack_status_reason": + "Stack CREATE completed successfully", + "stack_user_project_id": Tenantid, + "tags": null, + "updated_time": null + } + ] + } + + return data + + +def createStack(stack_name, token): + + if token != Token: + return {"error": {"message": "unauthorization", "code": 401}} + + global STACK_NAME + STACK_NAME = stack_name + + data = { + "stack": { + "id": STACK_ID, + "links": [ + { + "href": "http://127.0.0.1:8004/v1/" + + Tenantid + "/stacks/" + + stack_name + "/" + STACK_ID, + "rel": "self" + } + ] + } + } + + return data + + +def createStackPreview(stack_name, token): + + if token != Token: + return {"error": {"message": "unauthorization", "code": 401}} + + global STACK_NAME + STACK_NAME = stack_name + + data = \ + { + "stack": { + "capabilities": [], + "creation_time": "2017-10-31T15:12:36Z", + "deletion_time": null, + "description": "HOT template for Nova Server resource.\n", + "disable_rollback": true, + "id": "None", + "links": [ + { + "href": "http://127.0.0.1:8004/v1/" + + Tenantid + "/stacks/" + + STACK_NAME + "/None", + "rel": "self" + } + ], + "notification_topics": [], + "outputs": [], + "parameters": { + "OS::project_id": "6e18cc2bdbeb48a5basad2dc499f6804", + "OS::stack_id": "None", + "OS::stack_name": "teststack", + "admin_user": "cloud-user", + "flavor": "m1.small", + "image": "F20-cfg", + "key_name": "heat_key", + "server_name": "MyServer" + }, + "parent": null, + "resources": [ + { + "attributes": {}, + "description": "", + "metadata": {}, + "physical_resource_id": "", + "properties": { + "description": "Ping and SSH", + "name": "the_sg", + "rules": [ + { + "direction": "ingress", + "ethertype": "IPv4", + "port_range_max": null, + "port_range_min": null, + "protocol": "icmp", + "remote_group_id": null, + "remote_ip_prefix": null, + "remote_mode": "remote_ip_prefix" + }, + { + "direction": "ingress", + "ethertype": "IPv4", + "port_range_max": 65535, + "port_range_min": 1, + "protocol": "tcp", + "remote_group_id": null, + "remote_ip_prefix": null, + "remote_mode": "remote_ip_prefix" + }, + { + "direction": "ingress", + "ethertype": "IPv4", + "port_range_max": 65535, + "port_range_min": 1, + "protocol": "udp", + "remote_group_id": null, + "remote_ip_prefix": null, + "remote_mode": "remote_ip_prefix" + } + ] + }, + "required_by": [ + "server1" + ], + "resource_action": "INIT", + "resource_identity": { + "path": "/resources/the_sg_res", + "stack_id": "None", + "stack_name": "teststack", + "tenant": "6e18cc2bdbeb48a5b3cad2dc499f6804" + }, + "resource_name": "the_sg_res", + "resource_status": "COMPLETE", + "resource_status_reason": "", + "resource_type": "OS::Neutron::SecurityGroup", + "stack_identity": { + "path": "", + "stack_id": "None", + "stack_name": "teststack", + "tenant": "6e18cc2bdbeb48a5b3cad2dc499f6804" + }, + "stack_name": STACK_NAME, + "updated_time": "2017-10-31T15:12:36Z" + }, + { + "attributes": { + "accessIPv4": "", + "accessIPv6": "", + "addresses": "", + "console_urls": "", + "first_address": "", + "instance_name": "", + "name": "MyServer", + "networks": "", + "show": "" + }, + "description": "", + "metadata": {}, + "physical_resource_id": "", + "properties": { + "admin_pass": null, + "admin_user": "cloud-user", + "availability_zone": null, + "block_device_mapping": null, + "config_drive": null, + "diskConfig": null, + "flavor": "m1.small", + "flavor_update_policy": "RESIZE", + "image": "F20-cfg", + "image_update_policy": "REPLACE", + "key_name": "heat_key", + "metadata": { + "ha_stack": "None" + }, + "name": "MyServer", + "networks": [ + { + "fixed_ip": null, + "network": "private", + "port": null, + "uuid": null + } + ], + "personality": {}, + "reservation_id": null, + "scheduler_hints": null, + "security_groups": [ + "None" + ], + "software_config_transport": "POLL_SERVER_CFN", + "user_data": "", + "user_data_format": "HEAT_CFNTOOLS" + }, + "required_by": [], + "resource_action": "INIT", + "resource_identity": { + "path": "/resources/hello_world", + "stack_id": "None", + "stack_name": "teststack", + "tenant": "6e18cc2bdbeb48a3433cad2dc499sdf32234" + }, + "resource_name": "hello_world", + "resource_status": "COMPLETE", + "resource_status_reason": "", + "resource_type": "OS::Nova::Server", + "stack_identity": { + "path": "", + "stack_id": "None", + "stack_name": "teststack", + "tenant": "6e18cc2bdbeb48a3433cad2dc499sdf32234" + }, + "stack_name": "teststack", + "updated_time": "2017-10-31T15:12:36Z" + } + ], + "stack_name": "test_stack", + "stack_owner": null, + "tags": null, + "template_description": + "HOT template for Nova Server resource.\n", + "timeout_mins": null, + "updated_time": null + } + } + + return data + + +def deleteStack(stack_id, token): + + if token != Token: + return {"error": {"message": "unauthorization", "code": 401}} + + if stack_id != STACK_ID: + return {"error": {"message": "stack not found", "code": 404}} + + return "" + + +def showStack(stack_id, token): + + if token != Token: + return {"error": {"message": "unauthorization", "code": 401}} + + data = \ + { + "stack": { + "capabilities": [], + "creation_time": "2014-06-03T20:59:46Z", + "deletion_time": null, + "description": "sample stack", + "disable_rollback": true, + "id": STACK_ID, + "links": [ + { + "href": "http://127.0.0.1:8004/v1/" + "eb1c63a4f77141548385f113a28f0f52/stacks/" + "simple_stack/" + "3095aefc-09fb-4bc7-b1f0-f21a304e864c", + "rel": "self" + } + ], + "notification_topics": [], + "outputs": [], + "parameters": { + "OS::project_id": "3ab5b02f-a01f-4f95-afa1-e254afc4a435", + "OS::stack_id": STACK_ID, + "OS::stack_name": STACK_NAME + }, + "parent": null, + "stack_name": STACK_NAME, + "stack_owner": "simple_username", + "stack_status": "CREATE_COMPLETE", + "stack_status_reason": "Stack CREATE completed successfully", + "stack_user_project_id": Tenantid, + "tags": null, + "template_description": "sample stack", + "timeout_mins": null, + "updated_time": null + } + } + + return data + + +def getStackResource(stack_id, token): + + if token != Token: + return {"error": {"message": "unauthorization", "code": 401}} + + if stack_id != STACK_ID: + return {"error": {"message": "stack not found", "code": 404}} + + data = \ + { + "code": "302 Found", + "message": "The resource was found at <a " + "href=\"http://127.0.0.1:8004/" + "v1/369166a68a3a49b78b4e138531556e55" + "/stacks/s1/" + "da778f26-6d25-4634-9531-d438188e48fd\">" + "http://127.0.0.1:8004/v1/" + "369166a68a3a49b78b4e138531556e55/stacks" + "/s1/da778f26-6d25-4634-9531-d438188e48fd</a>;\n" + "you should be redirected automatically.\n\n", + "title": "Found" + } + + return data diff --git a/vio/vio/swagger/views/fakeplugin/heat/__init__.py b/vio/vio/swagger/views/fakeplugin/heat/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vio/vio/swagger/views/fakeplugin/heat/__init__.py diff --git a/vio/vio/swagger/views/fakeplugin/heat/views.py b/vio/vio/swagger/views/fakeplugin/heat/views.py new file mode 100644 index 0000000..243a33d --- /dev/null +++ b/vio/vio/swagger/views/fakeplugin/heat/views.py @@ -0,0 +1,99 @@ +import json + +from rest_framework import status +from rest_framework.views import APIView +from rest_framework.response import Response + +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import getAllStacks +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import showStack +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import createStack +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import deleteStack +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import \ + getStackResource +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import \ + createStackPreview + + +class FakeHeatResources(APIView): + + def get(self, request, tenantid, stack_id=None): + token = request.META.get("HTTP_X_AUTH_TOKEN", None) + data = getStackResource(token=token, stack_id=stack_id) + + if 'error' in data: + return Response(data=data['error']['message'], + status=data['error']['code']) + + return Response(data=data, status=status.HTTP_200_OK) + + +class FakeHeatServicePreview(APIView): + + def post(self, request, tenantid=None): + token = request.META.get("HTTP_X_AUTH_TOKEN", None) + try: + if tenantid is None: + return Response(data="bad request", + status=status.HTTP_400_BAD_REQUEST) + create_req = json.loads(request.body) + except Exception as e: + return Response(data="servers error {}".format(str(e)), + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + name = create_req['stack_name'] + data = createStackPreview(stack_name=name, + token=token) + if 'error' in data: + return Response(data=data['error']['message'], + status=data['error']['code']) + + return Response(data=data, status=status.HTTP_201_CREATED) + + +class FakeHeatService(APIView): + + def get(self, request, tenantid, stackName=None, stackID=None): + token = request.META.get("HTTP_X_AUTH_TOKEN", None) + data = "" + if stackName is None and stackID is None: + data = getAllStacks(token=token) + elif stackName or stackID: + data = showStack(stack_id=stackID, token=token) + + if 'error' in data: + return Response(data=data['error']['message'], + status=data['error']['code']) + + return Response(data=data, status=status.HTTP_200_OK) + + def post(self, request, tenantid=None): + token = request.META.get("HTTP_X_AUTH_TOKEN", None) + try: + if tenantid is None: + return Response(data="bad request", + status=status.HTTP_400_BAD_REQUEST) + create_req = json.loads(request.body) + except Exception as e: + return Response(data="servers error {}".format(str(e)), + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + name = create_req['stack_name'] + + data = createStack(stack_name=name, token=token) + if 'error' in data: + return Response(data=data['error']['message'], + status=data['error']['code']) + + return Response(data=data, status=status.HTTP_201_CREATED) + + def put(self, request, vimid): + pass + + def delete(self, request, tenantid, stackName=None, stackID=None): + + token = request.META.get("HTTP_X_AUTH_TOKEN", None) + data = deleteStack(stack_id=stackID, token=token) + + if 'error' in data: + return Response(data=data['error']['message'], + status=data['error']['code']) + + return Response(data=data, status=status.HTTP_204_NO_CONTENT) diff --git a/vio/vio/swagger/views/fakeplugin/identity/views.py b/vio/vio/swagger/views/fakeplugin/identity/views.py index d291b2e..0ef35d7 100644 --- a/vio/vio/swagger/views/fakeplugin/identity/views.py +++ b/vio/vio/swagger/views/fakeplugin/identity/views.py @@ -4,8 +4,14 @@ from rest_framework import status from rest_framework.views import APIView from rest_framework.response import Response -from vio.swagger.views.fakeplugin.fakeData.fakeResponse import keystone_token -from vio.swagger.views.fakeplugin.fakeData.fakeResponse import keystone_version +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import \ + keystone_token +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import \ + keystone_tokenV2 +from vio.swagger.views.fakeplugin.fakeData.fakeResponse import \ + keystone_version +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 @@ -42,7 +48,7 @@ class FakeToken(APIView): except Exception as e: return Response( data={'error': 'Invalidate request body %s.' % e}, - status=status.HTTP_500_INTERNAL_SERVER_ERROR) + status=status.HTTP_400_BAD_REQUEST) url_path = request.get_full_path() @@ -55,3 +61,30 @@ class FakeToken(APIView): res = Response(data=tokeninfo, status=status.HTTP_201_CREATED) res['X-Subject-Token'] = tokeninfo['token']['value'] return res + + +class FakeTokenV2(APIView): + + def get(self, request): + + return Response(data=keystone_version2(), + status=status.HTTP_200_OK) + + def post(self, request): + + try: + json.loads(request.body) + except Exception as e: + return Response( + data={'error': 'Invalidate request body %s.' % e}, + status=status.HTTP_400_BAD_REQUEST) + + url_path = request.get_full_path() + + if url_path[url_path.rfind("identity"):] != \ + "identity/v2.0/tokens": + return Response(data={"error": "method not allowed"}, + status=status.HTTP_405_METHOD_NOT_ALLOWED) + + tokeninfo = keystone_tokenV2() + return Response(data=tokeninfo, 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 fe4a5d3..1791c71 100644 --- a/vio/vio/swagger/views/proxyplugin/identity/views.py +++ b/vio/vio/swagger/views/proxyplugin/identity/views.py @@ -319,3 +319,144 @@ class TokenView(BaseClient): catalog.storeEndpoint(vimid=vimid, endpoints=vimEndpoints) Res = Response(data=tokenInfo, status=status.HTTP_200_OK) return Res + + +class TokenV2View(BaseClient): + + serverType = "identity" + + def get(self, request, vimid): + + url_path = request.get_full_path() + if url_path[url_path.rfind("identity"):] != "identity/v2.0": + return Response(data={"error": "method not allowed"}, + status=status.HTTP_405_METHOD_NOT_ALLOWED) + + try: + vim_info = extsys.get_vim_by_id(vim_id=vimid) + except VimDriverVioException as e: + return Response(data={"error": str(e)}, status=e.status_code) + except Exception as e: + logging.exception("error %s" % e) + return Response(data={"error": str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + keystoneURL = vim_info['url'] + # replace to v2.0 + url = keystoneURL.split('/') + url[-1] = 'v2.0' + url = "/".join(url) + + logger.info("vimid(%(vimid)s) get keystoneV2 url %(url)s ", + {"vimid": vimid, "url": url}) + try: + res = requests.get(url=url, verify=False) + if res.status_code not in [status.HTTP_200_OK, + status.HTTP_201_CREATED, + status.HTTP_202_ACCEPTED]: + return Response(data={"error": res.content}, + status=res.status_code) + res = res.json() + res['version']['links'][0]['href'] = \ + "http://" + MSB_ADDRESS + "/multicloud-vio/v0/" \ + + vimid + "/identity/v2.0" + + except Exception as e: + logging.exception("error %s" % e) + return Response(data={"error": str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + return Response(data=res, status=status.HTTP_200_OK) + + def post(self, request, vimid): + + try: + create_req = json.loads(request.body) + except Exception as e: + return Response( + data={'error': 'Fail to decode request body %s.' % e}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + url_path = request.get_full_path() + + try: + vim_info = extsys.get_vim_by_id(vimid) + except VimDriverVioException as e: + return Response(data={'error': str(e)}, status=e.status_code) + except Exception as e: + logging.exception("error %s" % e) + return Response(data={"error": str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + if url_path[url_path.rfind("identity"):] != "identity/v2.0/tokens": + return Response(data={"error": "method not allowed"}, + status=status.HTTP_405_METHOD_NOT_ALLOWED) + # replace to v2.0 + url = vim_info['url'].split('/') + url[-1] = 'v2.0' + url = "/".join(url) + url += "/tokens" + headers = {"Content-Type": "application/json"} + logger.info("vimid(%(vimid)s) request V2 token url %(url)s ", + {"vimid": vimid, "url": url}) + + try: + res = requests.post(url=url, data=json.dumps(create_req), + headers=headers, verify=False) + if res.status_code not in [status.HTTP_200_OK, + status.HTTP_201_CREATED, + status.HTTP_202_ACCEPTED]: + return Response(data={"error": res.content}, + status=res.status_code) + tokenInfo = res.json() + except Exception as e: + logging.exception("error %s" % e) + return Response(data={'error': str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + try: + tenantid = tokenInfo['access']['token']['tenant']['id'] + vimEndpoints = defaultdict(dict) + for cal in tokenInfo['access']['serviceCatalog']: + # endpoint urls + item = cal['endpoints'][0] + adminurl = deepcopy(item['adminURL']).split('/') + internalurl = deepcopy(item['internalURL']).split('/') + publicurl = deepcopy(item['publicURL']).split('/') + adminurl = adminurl[0] + "//" + adminurl[2] + ( + "/" + adminurl[3] if len(adminurl) > 3 else "") + internalurl = internalurl[0] + "//" + internalurl[2] + ( + "/" + internalurl[3] if len(internalurl) > 3 else "") + publicurl = publicurl[0] + "//" + publicurl[2] + ( + "/" + publicurl[3] if len(publicurl) > 3 else "") + + for (key, urlname) in zip(('admin', 'internal', 'public'), + (adminurl, internalurl, + publicurl)): + vimEndpoints[cal['name']][key] = urlname + + if cal['type'] in ['image', 'network', + 'cloudformation', 'identity']: + name = cal['name'] if cal['type'] != 'identity' \ + else cal['type'] + for i in ("adminURL", "internalURL", "publicURL"): + item[i] = "http://" + MSB_ADDRESS + \ + "/multicloud-vio/v0/" + vimid + "/" + name + else: + for i in ("adminURL", "internalURL", "publicURL"): + item[i] = "http://" + MSB_ADDRESS + \ + "/multicloud-vio/v0/" + vimid + \ + "/" + cal["name"] + "/" + tenantid + + except Exception as e: + logging.exception("error %s" % e) + return Response(data={'error': str(e)}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + logger.info("vimid(%(vimid)s) service enpoints %(endpoint)s ", { + "vimid": vimid, "endpoint": vimEndpoints}) + + catalog.storeEndpoint(vimid=vimid, endpoints=vimEndpoints) + Res = Response(data=tokenInfo, status=status.HTTP_200_OK) + + return Res |