merge latest code
diff --git a/plstackapi/core/views/deployment_networks.py b/plstackapi/core/views/deployment_networks.py
index 60e8030..60e8b14 100644
--- a/plstackapi/core/views/deployment_networks.py
+++ b/plstackapi/core/views/deployment_networks.py
@@ -37,7 +37,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- deployment_networks = get_deployment_networks(data['auth'], {'name': pk})
+ deployment_networks = get_deployment_networks(data['auth'], pk)
if not deployment_networks:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = DeploymentNetworkSerializer(deployment_networks[0])
@@ -51,7 +51,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_deployment_network(data['auth'], {'name': pk})
+ delete_deployment_network(data['auth'], pk)
return Response(status=status.HTTP_204_NO_CONTENT)
diff --git a/plstackapi/core/views/flavors.py b/plstackapi/core/views/flavors.py
index ef48499..0e06c8e 100644
--- a/plstackapi/core/views/flavors.py
+++ b/plstackapi/core/views/flavors.py
@@ -36,7 +36,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- flavors = get_flavors(data['auth'], {'id': pk})
+ flavors = get_flavors(data['auth'], pk)
if not flavors:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = FlavorSerializer(flavors[0])
diff --git a/plstackapi/core/views/images.py b/plstackapi/core/views/images.py
index f48cb71..4a548ac 100644
--- a/plstackapi/core/views/images.py
+++ b/plstackapi/core/views/images.py
@@ -36,7 +36,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- images = get_images(data['auth'], {'id': pk})
+ images = get_images(data['auth'], pk)
if not images:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = ImageSerializer(images[0])
diff --git a/plstackapi/core/views/keys.py b/plstackapi/core/views/keys.py
index 6b52b8e..80a378d 100644
--- a/plstackapi/core/views/keys.py
+++ b/plstackapi/core/views/keys.py
@@ -37,7 +37,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- keys = get_keys(data['auth'], {'id': pk})
+ keys = get_keys(data['auth'], pk)
if not keys:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = KeySerializer(keys[0])
@@ -59,7 +59,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_key(data['auth'], {'id': pk})
+ delete_key(data['auth'], pk)
return Response(status=status.HTTP_204_NO_CONTENT)
diff --git a/plstackapi/core/views/nodes.py b/plstackapi/core/views/nodes.py
new file mode 100644
index 0000000..baa9f17
--- /dev/null
+++ b/plstackapi/core/views/nodes.py
@@ -0,0 +1,55 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from plstackapi.core.api.nodes import add_node, delete_node, get_nodes, update_node
+from plstackapi.core.serializers import NodeSerializer
+from plstackapi.util.request import parse_request
+
+
+class NodeListCreate(APIView):
+ """
+ List all nodes or create a new node.
+ """
+
+ def post(self, request, format = None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'node' in data:
+ """Not Implemented"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ else:
+ nodes = get_nodes(data['auth'])
+ serializer = NodeSerializer(nodes, many=True)
+ return Response(serializer.data)
+
+
+class NodeRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete an node
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve an node """
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ nodes = get_nodes(data['auth'], pk)
+ if not nodes:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = NodeSerializer(nodes[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update node not implemnted"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+
+ def delete(self, request, pk, format=None):
+ """delete node not implemnted"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+
+
+
+
diff --git a/plstackapi/core/views/roles.py b/plstackapi/core/views/roles.py
index 05eb77e..74fe789 100644
--- a/plstackapi/core/views/roles.py
+++ b/plstackapi/core/views/roles.py
@@ -37,7 +37,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- roles = get_roles(data['auth'], {'role_id': pk})
+ roles = get_roles(data['auth'], pk)
if not roles:
return Response(status=status.HTTP_404_NOT_FOUND)
serializer = RoleSerializer(roles[0])
@@ -51,7 +51,7 @@
data = parse_request(request.DATA)
if 'auth' not in data:
return Response(status=status.HTTP_400_BAD_REQUEST)
- delete_role(data['auth'], {'role_id': pk})
+ delete_role(data['auth'], pk)
return Response(status=status.HTTP_204_NO_CONTENT)
diff --git a/plstackapi/core/views/site_privileges.py b/plstackapi/core/views/site_privileges.py
new file mode 100644
index 0000000..b104fa7
--- /dev/null
+++ b/plstackapi/core/views/site_privileges.py
@@ -0,0 +1,66 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from plstackapi.core.api.site_privileges import add_site_privilege, delete_site_privilege, get_site_privileges, update_site_privilege
+from plstackapi.core.serializers import SitePrivilegeSerializer
+from plstackapi.util.request import parse_request
+
+
+class SitePrivilegeListCreate(APIView):
+ """
+ List all site_privileges or create a new site_privilege.
+ """
+
+ def post(self, request, format = None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'site_privilege' in data:
+ site_privilege = add_site_privilege(data['auth'], data['site_privilege'])
+ serializer = SitePrivilegeSerializer(site_privilege)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ site_privileges = get_site_privileges(data['auth'])
+ serializer = SitePrivilegeSerializer(site_privileges, many=True)
+ return Response(serializer.data)
+
+
+class SitePrivilegeRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a site_privilege
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a site_privilege"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ site_privileges = get_site_privileges(data['auth'], pk)
+ if not site_privileges:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = SitePrivilegeSerializer(site_privileges[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a site_privilege"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'site_privilege' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ site_privilege = update_site_privilege(pk, data['site_privilege'])
+ serializer = SitePrivilegeSerializer(site_privilege)
+ return Response(serializer.data)
+
+ def delete(self, request, pk, format=None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ delete_site_privilege(data['auth'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/plstackapi/core/views/slice_memberships.py b/plstackapi/core/views/slice_memberships.py
new file mode 100644
index 0000000..a4f6848
--- /dev/null
+++ b/plstackapi/core/views/slice_memberships.py
@@ -0,0 +1,66 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from plstackapi.core.api.slice_memberships import add_slice_membership, delete_slice_membership, get_slice_memberships, update_slice_membership
+from plstackapi.core.serializers import SliceMembershipSerializer
+from plstackapi.util.request import parse_request
+
+
+class SliceMembershipListCreate(APIView):
+ """
+ List all slice_memberships or create a new slice_membership.
+ """
+
+ def post(self, request, format = None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'slice_membership' in data:
+ slice_membership = add_slice_membership(data['auth'], data['slice_membership'])
+ serializer = SliceMembershipSerializer(slice_membership)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ slice_memberships = get_slice_memberships(data['auth'])
+ serializer = SliceMembershipSerializer(slice_memberships, many=True)
+ return Response(serializer.data)
+
+
+class SliceMembershipRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a slice_membership
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a slice_membership"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ slice_memberships = get_slice_memberships(data['auth'], pk)
+ if not slice_memberships:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = SliceMembershipSerializer(slice_memberships[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a slice_membership"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'slice_membership' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ slice_membership = update_slice_membership(pk, data['slice_membership'])
+ serializer = SliceMembershipSerializer(slice_membership)
+ return Response(serializer.data)
+
+ def delete(self, request, pk, format=None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ delete_slice_membership(data['auth'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/plstackapi/core/views/slices.py b/plstackapi/core/views/slices.py
index 6015f4d..01415bb 100644
--- a/plstackapi/core/views/slices.py
+++ b/plstackapi/core/views/slices.py
@@ -40,7 +40,7 @@
slices = get_slices(data['auth'], {'id': pk})
if not slices:
return Response(status=status.HTTP_404_NOT_FOUND)
- serializer = UserSerializer(slices[0])
+ serializer = SliceSerializer(slices[0])
return Response(serializer.data)
def put(self, request, pk, format=None):
@@ -52,7 +52,7 @@
return Response(status=status.HTTP_400_BAD_REQUEST)
slice = update_slice(pk, data['slice'])
- serializer = UserSerializer(slice)
+ serializer = SliceSerializer(slice)
return Response(serializer.data)
def delete(self, request, pk, format=None):
diff --git a/plstackapi/core/views/slivers.py b/plstackapi/core/views/slivers.py
new file mode 100644
index 0000000..4063419
--- /dev/null
+++ b/plstackapi/core/views/slivers.py
@@ -0,0 +1,66 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from plstackapi.core.api.slivers import add_sliver, delete_sliver, get_slivers, update_sliver
+from plstackapi.core.serializers import SliverSerializer
+from plstackapi.util.request import parse_request
+
+
+class SliverListCreate(APIView):
+ """
+ List all slivers or create a new sliver.
+ """
+
+ def post(self, request, format = None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'sliver' in data:
+ sliver = add_sliver(data['auth'], data['sliver'])
+ serializer = SliverSerializer(sliver)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ slivers = get_slivers(data['auth'])
+ serializer = SliverSerializer(slivers, many=True)
+ return Response(serializer.data)
+
+
+class SliverRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a sliver
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a sliver"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ slivers = get_slivers(data['auth'], {'id': pk})
+ if not slivers:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = SliverSerializer(slivers[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a sliver"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'sliver' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ sliver = update_sliver(pk, data['sliver'])
+ serializer = SliverSerializer(sliver)
+ return Response(serializer.data)
+
+ def delete(self, request, pk, format=None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ delete_sliver(data['auth'], {'id': pk})
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/plstackapi/core/views/subnets.py b/plstackapi/core/views/subnets.py
new file mode 100644
index 0000000..d96d048
--- /dev/null
+++ b/plstackapi/core/views/subnets.py
@@ -0,0 +1,66 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from plstackapi.core.api.subnets import add_subnet, delete_subnet, get_subnets, update_subnet
+from plstackapi.core.serializers import SubnetSerializer
+from plstackapi.util.request import parse_request
+
+
+class SubnetListCreate(APIView):
+ """
+ List all subnets or create a new subnet.
+ """
+
+ def post(self, request, format = None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'subnet' in data:
+ subnet = add_subnet(data['auth'], data['subnet'])
+ serializer = SubnetSerializer(subnet)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ subnets = get_subnets(data['auth'])
+ serializer = SubnetSerializer(subnets, many=True)
+ return Response(serializer.data)
+
+
+class SubnetRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a subnet
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a subnet"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ subnets = get_subnets(data['auth'], {'id': pk})
+ if not subnets:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = SubnetSerializer(subnets[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a subnet"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'subnet' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ subnet = update_subnet(pk, data['subnet'])
+ serializer = SubnetSerializer(subnet)
+ return Response(serializer.data)
+
+ def delete(self, request, pk, format=None):
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ delete_subnet(data['auth'], {'id': pk})
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+