summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxinhuili <lxinhui@vmware.com>2017-10-24 06:08:18 +0000
committerGerrit Code Review <gerrit@onap.org>2017-10-24 06:08:18 +0000
commit065857adf40a6dbb27b7603cf33ee8efc2d2f3c3 (patch)
treeeb7d3d01c45056275d936466964d240572344de9
parent65f7f6367cbab0765b32e1a0cf6b78cadcef18b7 (diff)
parent61ee6c379878269e7e3655e4a2cbe58825d921ce (diff)
Merge "Add fake heat response data"
-rw-r--r--vio/vio/swagger/urls.py17
-rw-r--r--vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py338
-rw-r--r--vio/vio/swagger/views/fakeplugin/heat/__init__.py0
-rw-r--r--vio/vio/swagger/views/fakeplugin/heat/views.py99
4 files changed, 454 insertions, 0 deletions
diff --git a/vio/vio/swagger/urls.py b/vio/vio/swagger/urls.py
index 43b5a7f..e40bc77 100644
--- a/vio/vio/swagger/urls.py
+++ b/vio/vio/swagger/urls.py
@@ -61,6 +61,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 = [
@@ -186,6 +189,20 @@ 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\-\_]+)'
+ 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$',
diff --git a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py
index 7daf102..1508e3f 100644
--- a/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py
+++ b/vio/vio/swagger/views/fakeplugin/fakeData/fakeResponse.py
@@ -1816,3 +1816,341 @@ 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}}
+
+ if stack_id != STACK_ID:
+ return {"error": {"message": "stack not found", "code": 404}}
+
+ 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..c520ef4
--- /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 and 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)