enable users
diff --git a/plstackapi/planetstack/admin.py b/plstackapi/planetstack/admin.py
index 7b03c62..a42c7d6 100644
--- a/plstackapi/planetstack/admin.py
+++ b/plstackapi/planetstack/admin.py
@@ -11,4 +11,6 @@
 admin.site.register(DeploymentNetwork)
 admin.site.register(SiteDeploymentNetwork)
 admin.site.register(Sliver)
+admin.site.register(Image)
+admin.site.register(Flavor)
 
diff --git a/plstackapi/planetstack/api/users.py b/plstackapi/planetstack/api/users.py
new file mode 100644
index 0000000..13b83d8
--- /dev/null
+++ b/plstackapi/planetstack/api/users.py
@@ -0,0 +1,52 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.planetstack.api.auth import auth_check
+from plstackapi.planetstack.models import User
+ 
+
+def add_user(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    user = User(**fields)
+    nova_fields = {'name': user.email[:self.email.find('@')],
+                   'email': user.email, 
+                   'password': user.name,
+                   'enabled': user.enabled}    
+    tenant = driver.create_user(**nova_fields)
+    user.user_id=user.id
+    user.save()
+    return user
+
+def update_user(auth, id, **fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    users = User.objects.filter(id=id)
+    if not users:
+        return
+
+    user = users[0]
+    nova_fields = {}
+    if 'email' in fields:
+        nova_fields['name'] = fields['email'][:self.email.find('@')]
+        nova_fields['email'] = fields['email']
+    if 'password' in fields:
+        nova_fields['password'] = fields['password']
+    if 'enabled' in fields:
+        nova_fields['enabled'] = fields['enabled']
+    driver.update_user(user.user_id, **nova_fields)
+    user.update(**fields)
+    return user 
+
+def delete_user(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    users = Users.objects.filter(**filter)
+    for user in users:
+        driver.delete_user(id=user.user_id) 
+        user.delete()
+    return 1
+
+def get_users(auth, filter={}):
+    client = auth_check(auth)
+    users = User.objects.filter(**filter)
+    return users             
+        
+
+    
diff --git a/plstackapi/planetstack/models.py b/plstackapi/planetstack/models.py
index cdbf16c..e796614 100644
--- a/plstackapi/planetstack/models.py
+++ b/plstackapi/planetstack/models.py
@@ -59,25 +59,9 @@
 
     def __unicode__(self):  return u'%s' % (self.email)
 
-    def save(self, *args, **kwds):
-        driver  = OpenStackDriver()
-        name = self.email[:self.email.find('@')]
-        fields = {'name': name, 'email': self.email, 'password': self.password,
-                  'enabled': self.enabled}
-        if not self.id:
-            user = driver.create_user(**fields) 
-        else:
-            driver.update_user(self.user_id, **fields)
-        super(User, self).save(*args, **kwds)
-
-    def delete(self, *args, **kwds):
-        driver = OpenStackDriver()
-        driver.delete_user(self.user_id)
-        super(User, self).delete(*args, **kwds)
-
 class SitePrivilege(PlCoreBase):
 
-    user = models.ForeignKey('User')
+    user = models.ForeignKey('User', related_name='site_privileges')
     site = models.ForeignKey('Site', related_name='site_privileges')
     role = models.ForeignKey('Role')
 
@@ -160,8 +144,8 @@
         super(Slice, self).delete(*args, **kwds)
 
 class SliceMembership(PlCoreBase):
-    user = models.ForeignKey('User')
-    slice = models.ForeignKey('Slice')
+    user = models.ForeignKey('User', related_name='slice_memberships')
+    slice = models.ForeignKey('Slice', related_name='slice_memberships')
     role = models.ForeignKey('Role')
 
     def __unicode__(self):  return u'%s %s %s' % (self.slice, self.user, self.role)
@@ -243,7 +227,7 @@
     key = models.CharField(max_length=512)
     type = models.CharField(max_length=256)
     blacklisted = models.BooleanField()
-    user = models.ForeignKey(User)
+    user = models.ForeignKey(User, related_name='keys')
 
     def __unicode__(self):  return u'%s' % (self.name)
 
diff --git a/plstackapi/planetstack/serializers.py b/plstackapi/planetstack/serializers.py
index a0a502e..d4bbc94 100644
--- a/plstackapi/planetstack/serializers.py
+++ b/plstackapi/planetstack/serializers.py
@@ -11,6 +11,27 @@
                   'role_id',
                   'role_type')
 
+
+class UserSerializer(serializers.HyperlinkedModelSerializer):
+    site = serializers.HyperlinkedRelatedField(view_name='site-detail')
+    slice_memberships = serializers.HyperlinkedRelatedField(view_name='slice-membership-detail')
+    site_privileges = serializers.HyperlinkedRelatedField(view_name='site-privilege-detail')
+    class Meta:
+        model = User
+        fields = ('id',
+                  'user_id', 
+                  'firstname', 
+                  'lastname',
+                  'email', 
+                  'phone', 
+                  'user_url',
+                  'is_admin',
+                  'site',
+                  'slice_memberships',
+                  'site_privileges')
+                    
+ 
+
 class SliceSerializer(serializers.HyperlinkedModelSerializer):
 
     site = serializers.HyperlinkedRelatedField(view_name='site-detail')
diff --git a/plstackapi/planetstack/urls.py b/plstackapi/planetstack/urls.py
index ed11b87..dd333e8 100644
--- a/plstackapi/planetstack/urls.py
+++ b/plstackapi/planetstack/urls.py
@@ -4,6 +4,7 @@
 from django.contrib import admin
 from plstackapi.planetstack.views.roles import RoleListCreate, RoleRetrieveUpdateDestroy
 from plstackapi.planetstack.views.sites import SiteListCreate, SiteRetrieveUpdateDestroy
+from plstackapi.planetstack.views.users import UserListCreate, UserRetrieveUpdateDestroy
 from plstackapi.planetstack.views.deployment_networks import DeploymentNetworkListCreate, DeploymentNetworkRetrieveUpdateDestroy
 from plstackapi.planetstack.views.images import ImageListCreate, ImageRetrieveUpdateDestroy
 from plstackapi.planetstack.views.flavors import FlavorListCreate, FlavorRetrieveUpdateDestroy
@@ -29,6 +30,9 @@
     url(r'^plstackapi/roles/$', RoleListCreate.as_view(), name='role-list'),
     url(r'^plstackapi/roles/(?P<pk>[a-zA-Z0-9]+)/$', RoleRetrieveUpdateDestroy.as_view(), name='role-detail'),
 
+    url(r'^plstackapi/users/$', UserListCreate.as_view(), name='user-list'),
+    url(r'^plstackapi/users/(?P<pk>[a-zA-Z0-9]+)/$', UserRetrieveUpdateDestroy.as_view(), name='user-detail'),
+
     url(r'^plstackapi/sites/$', SiteListCreate.as_view(), name='site-list'),
     url(r'^plstackapi/sites/(?P<pk>[a-zA-Z0-9_]+)/$', SiteRetrieveUpdateDestroy.as_view(), name='site-detail'),
 
diff --git a/plstackapi/planetstack/views/api_root.py b/plstackapi/planetstack/views/api_root.py
index d2489c2..560d9eb 100644
--- a/plstackapi/planetstack/views/api_root.py
+++ b/plstackapi/planetstack/views/api_root.py
@@ -6,6 +6,7 @@
 def api_root(request, format=None):
     return Response({
         'roles': reverse('role-list', request=request, format=format),
+        'users': reverse('user-list', request=request, format=format),
         #'nodes': reverse('node-list', request=request, format=format),
         'sites': reverse('site-list', request=request, format=format),
         'deploymentNetworks': reverse('deploymentnetwork-list', request=request, format=format),
diff --git a/plstackapi/planetstack/views/sites.py b/plstackapi/planetstack/views/sites.py
index f40c0fa..8bbd30c 100644
--- a/plstackapi/planetstack/views/sites.py
+++ b/plstackapi/planetstack/views/sites.py
@@ -52,7 +52,7 @@
             return Response(status=status.HTTP_400_BAD_REQUEST)
 
         site = update_site(pk, data['site'])
-        serializer = SiteSerializer(data=site)
+        serializer = SiteSerializer(site)
         return Response(serializer.data) 
 
     def delete(self, request, pk, format=None):
diff --git a/plstackapi/planetstack/views/users.py b/plstackapi/planetstack/views/users.py
new file mode 100644
index 0000000..35f2e48
--- /dev/null
+++ b/plstackapi/planetstack/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 plstackapi.planetstack.api.user import add_user, delete_user, get_users, update_user
+from plstackapi.planetstack.serializers import UserSerializer
+from plstackapi.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) 
+            
+            
+