Refactor to /opt/planetstack, final tweaks to make sure planetstack can run in non-openstack mode, adjustments to GUI for model focus changes
diff --git a/planetstack/core/views/__init__.py b/planetstack/core/views/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/planetstack/core/views/__init__.py
diff --git a/planetstack/core/views/deployment_networks.py b/planetstack/core/views/deployment_networks.py
new file mode 100644
index 0000000..63220a4
--- /dev/null
+++ b/planetstack/core/views/deployment_networks.py
@@ -0,0 +1,59 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from core.api.deployment_networks import add_deployment_network, delete_deployment_network, get_deployment_networks
+from core.serializers import DeploymentNetworkSerializer
+from util.request import parse_request
+
+
+class DeploymentNetworkListCreate(APIView):
+ """
+ List all deployment networks or create a new role.
+ """
+
+ 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 'deploymentNetwork' in data:
+
+ deployment = add_deployment_network(data['auth'], data['deploymentNetwork'].get('name'))
+ serializer = DeploymentNetworkSerializer(deployment)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ deployment_networks = get_deployment_networks(data['auth'])
+ serializer = DeploymentNetworkSerializer(deployment_networks, many=True)
+ return Response(serializer.data)
+
+
+class DeploymentNetworkRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a deployment network
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a deployment network"""
+ 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'], pk)
+ if not deployment_networks:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = DeploymentNetworkSerializer(deployment_networks[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """deployment network update not implemnted"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+
+ 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_deployment_network(data['auth'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/planetstack/core/views/images.py b/planetstack/core/views/images.py
new file mode 100644
index 0000000..7e0ab59
--- /dev/null
+++ b/planetstack/core/views/images.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 core.api.images import add_image, delete_image, get_images
+from core.serializers import ImageSerializer
+from util.request import parse_request
+
+
+class ImageListCreate(APIView):
+ """
+ List all images or create a new image.
+ """
+
+ 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 'image' in data:
+ """Not Implemented"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ else:
+ images = get_images(data['auth'])
+ serializer = ImageSerializer(images, many=True)
+ return Response(serializer.data)
+
+
+class ImageRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete an image
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve an image """
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ images = get_images(data['auth'], pk)
+ if not images:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = ImageSerializer(images[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update image not implemnted"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+
+ def delete(self, request, pk, format=None):
+ """delete image not implemnted"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+
+
+
+
diff --git a/planetstack/core/views/keys.py b/planetstack/core/views/keys.py
new file mode 100644
index 0000000..a5d0995
--- /dev/null
+++ b/planetstack/core/views/keys.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 core.api.keys import add_key, delete_key, get_keys, update_key
+from core.serializers import KeySerializer
+from util.request import parse_request
+
+
+class KeyListCreate(APIView):
+ """
+ List all users or create a new key.
+ """
+
+ 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 'key' in data:
+ key = add_key(data['auth'], data['key'])
+ serializer = KeySerializer(key)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ keys = get_keys(data['auth'])
+ serializer = KeySerializer(keys, many=True)
+ return Response(serializer.data)
+
+
+class KeyRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a key
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a key"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ keys = get_keys(data['auth'], pk)
+ if not keys:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = KeySerializer(keys[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a key"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'key' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ key = update_key(pk, data['key'])
+ serializer = KeySerializer(key)
+ 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_key(data['auth'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/planetstack/core/views/nodes.py b/planetstack/core/views/nodes.py
new file mode 100644
index 0000000..0f1977e
--- /dev/null
+++ b/planetstack/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 core.api.nodes import add_node, delete_node, get_nodes, update_node
+from core.serializers import NodeSerializer
+from 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/planetstack/core/views/roles.py b/planetstack/core/views/roles.py
new file mode 100644
index 0000000..37bb149
--- /dev/null
+++ b/planetstack/core/views/roles.py
@@ -0,0 +1,58 @@
+from django.http import Http404
+from rest_framework.views import APIView
+from rest_framework.response import Response
+from rest_framework import status
+
+from core.api.roles import add_role, delete_role, get_roles
+from core.serializers import RoleSerializer
+from util.request import parse_request
+
+
+class RoleListCreate(APIView):
+ """
+ List all roles or create a new role.
+ """
+
+ 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 'role' in data:
+ role = add_role(data['auth'], data['role']['role_type'])
+ serializer = RoleSerializer(data=role)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ roles = get_roles(data['auth'])
+ serializer = RoleSerializer(roles, many=True)
+ return Response(serializer.data)
+
+
+class RoleRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a role
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a role"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ roles = get_roles(data['auth'], pk)
+ if not roles:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = RoleSerializer(roles[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """role update not implemnted"""
+ return Response(status=status.HTTP_404_NOT_FOUND)
+
+ 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_role(data['auth'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/planetstack/core/views/site_privileges.py b/planetstack/core/views/site_privileges.py
new file mode 100644
index 0000000..37fc371
--- /dev/null
+++ b/planetstack/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 core.api.site_privileges import add_site_privilege, delete_site_privilege, get_site_privileges, update_site_privilege
+from core.serializers import SitePrivilegeSerializer
+from 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/planetstack/core/views/sites.py b/planetstack/core/views/sites.py
new file mode 100644
index 0000000..6449b67
--- /dev/null
+++ b/planetstack/core/views/sites.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 core.api.sites import add_site, delete_site, get_sites
+from core.serializers import SiteSerializer
+from util.request import parse_request
+
+
+class SiteListCreate(APIView):
+ """
+ List all sites or create a new site.
+ """
+
+ 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' in data:
+ site = add_site(data['auth'], data['site'])
+ serializer = SiteSerializer(site)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ sites = get_sites(data['auth'])
+ serializer = SiteSerializer(sites, many=True)
+ return Response(serializer.data)
+
+
+class SiteRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a site
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a site"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ sites = get_sites(data['auth'], {'id': pk})
+ if not sites:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = SiteSerializer(sites[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a site"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'site' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ site = update_site(pk, data['site'])
+ serializer = SiteSerializer(site)
+ 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(data['auth'], {'id': pk})
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/planetstack/core/views/slice_memberships.py b/planetstack/core/views/slice_memberships.py
new file mode 100644
index 0000000..4bb581c
--- /dev/null
+++ b/planetstack/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 core.api.slice_memberships import add_slice_membership, delete_slice_membership, get_slice_memberships, update_slice_membership
+from core.serializers import SliceMembershipSerializer
+from 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/planetstack/core/views/slices.py b/planetstack/core/views/slices.py
new file mode 100644
index 0000000..5954d0c
--- /dev/null
+++ b/planetstack/core/views/slices.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 core.api.slices import add_slice, delete_slice, get_slices, update_slice
+from core.serializers import SliceSerializer
+from util.request import parse_request
+
+
+class SliceListCreate(APIView):
+ """
+ List all slices or create a new slice.
+ """
+
+ 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' in data:
+ slice = add_slice(data['auth'], data['slice'])
+ serializer = SliceSerializer(slice)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ slices = get_slices(data['auth'])
+ serializer = SliceSerializer(slices, many=True)
+ return Response(serializer.data)
+
+
+class SliceRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a slice
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a slice"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ slices = get_slices(data['auth'], pk)
+ if not slices:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = SliceSerializer(slices[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a slice"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'slice' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ slice = update_slice(pk, data['slice'])
+ serializer = SliceSerializer(slice)
+ 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(data['auth'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/planetstack/core/views/slivers.py b/planetstack/core/views/slivers.py
new file mode 100644
index 0000000..3741cce
--- /dev/null
+++ b/planetstack/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 core.api.slivers import add_sliver, delete_sliver, get_slivers, update_sliver
+from core.serializers import SliverSerializer
+from 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'], 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'], pk)
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+
diff --git a/planetstack/core/views/subnets.py b/planetstack/core/views/subnets.py
new file mode 100644
index 0000000..881f615
--- /dev/null
+++ b/planetstack/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 core.api.subnets import add_subnet, delete_subnet, get_subnets, update_subnet
+from core.serializers import SubnetSerializer
+from 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)
+
+
+
diff --git a/planetstack/core/views/users.py b/planetstack/core/views/users.py
new file mode 100644
index 0000000..8b27928
--- /dev/null
+++ b/planetstack/core/views/users.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 core.api.users import add_user, delete_user, get_users, update_user
+from core.serializers import UserSerializer
+from util.request import parse_request
+
+
+class UserListCreate(APIView):
+ """
+ List all users or create a new user.
+ """
+
+ 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 'user' in data:
+ user = add_user(data['auth'], data['user'])
+ serializer = UserSerializer(user)
+ return Response(serializer.data, status=status.HTTP_201_CREATED)
+ else:
+ users = get_users(data['auth'])
+ serializer = UserSerializer(users, many=True)
+ return Response(serializer.data)
+
+
+class UserRetrieveUpdateDestroy(APIView):
+ """
+ Retrieve, update or delete a user
+ """
+
+ def post(self, request, pk, format=None):
+ """Retrieve a user"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ users = get_users(data['auth'], {'id': pk})
+ if not users:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ serializer = UserSerializer(users[0])
+ return Response(serializer.data)
+
+ def put(self, request, pk, format=None):
+ """update a user"""
+ data = parse_request(request.DATA)
+ if 'auth' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+ elif 'user' not in data:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ user = update_user(pk, data['user'])
+ serializer = UserSerializer(user)
+ 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_user(data['auth'], {'id': pk})
+ return Response(status=status.HTTP_204_NO_CONTENT)
+
+
+