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/api/__init__.py b/planetstack/core/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/planetstack/core/api/__init__.py
diff --git a/planetstack/core/api/auth.py b/planetstack/core/api/auth.py
new file mode 100644
index 0000000..8796f14
--- /dev/null
+++ b/planetstack/core/api/auth.py
@@ -0,0 +1,8 @@
+from openstack.client import OpenStackClient
+
+def auth_check(username, password, tenant):
+    client = OpenStackClient(username=username,
+                             password=password,
+                             tenant=tenant)
+    client.authenticate()
+    return client
diff --git a/planetstack/core/api/deployment_networks.py b/planetstack/core/api/deployment_networks.py
new file mode 100644
index 0000000..51fa03e
--- /dev/null
+++ b/planetstack/core/api/deployment_networks.py
@@ -0,0 +1,39 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import DeploymentNetwork
+
+def _get_deployment_networks(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        deployment_networks = DeploymentNetwork.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        deployment_networks = DeploymentNetwork.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        deployment_networks = DeploymentNetwork.objects.filter(**filter)
+    else:
+        deployment_networks = []
+    return deployment_networks 
+
+def add_deployment_network(auth, name):
+    auth_check(auth)    
+    deployment = DeploymentNetwork(name=name)
+    deployment.save()
+    return deployment
+
+def delete_deployment_network(auth, filter={}):
+    auth_check(auth)   
+    deployments = _get_deployment_networks(filter)
+    for deployment in deployments:
+        deployment.delete()
+    return 1
+
+def get_deployment_networks(auth, filter={}):
+    auth_check(auth)   
+    deployments = _get_deployment_networks(filter)
+    return deployments             
+        
+
+    
diff --git a/planetstack/core/api/images.py b/planetstack/core/api/images.py
new file mode 100644
index 0000000..c080a55
--- /dev/null
+++ b/planetstack/core/api/images.py
@@ -0,0 +1,34 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Image
+ 
+def _get_images(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        images = Image.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        images = Image.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        images = Image.objects.filter(**filter)
+    else:
+        images = []
+    return images
+
+def add_image(auth, fields={}):
+    """not implemented"""
+    return 
+
+def delete_image(auth, filter={}):
+    """not implemented"""
+    return 1
+
+def get_images(auth, filter={}):
+    auth_check(auth)   
+    images = _get_images(filter)
+    return images             
+        
+
+    
diff --git a/planetstack/core/api/keys.py b/planetstack/core/api/keys.py
new file mode 100644
index 0000000..e653690
--- /dev/null
+++ b/planetstack/core/api/keys.py
@@ -0,0 +1,51 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.models import Key
+from core.api.auth import auth_check
+from core.api.users import _get_users
+
+
+def _get_keys(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        keys = Key.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        keys = Key.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        keys = Key.objects.filter(**filter)
+    else:
+        keys = []
+    return keys 
+
+def add_key(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    users = _get_users(fields.get('user')) 
+    if users: fields['user'] = users[0]    
+    key = Key(**fields)
+    nova_fields = {'name': key.name,
+                   'key': key.key} 
+    nova_key = driver.create_keypair(**nova_fields)
+    key.nkey_id = nova_key.id
+    key.save()
+    return key
+
+def update_key(auth, id, **fields):
+    return  
+
+def delete_key(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    keys = _get_keys(filter)
+    for key in keys:
+        driver.delete_keypair(id=key.nkey_id) 
+        key.delete()
+    return 1
+
+def get_keys(auth, filter={}):
+    client = auth_check(auth)
+    keys = _get_keys(filter)
+    return keys             
+        
+
+    
diff --git a/planetstack/core/api/nodes.py b/planetstack/core/api/nodes.py
new file mode 100644
index 0000000..6514e54
--- /dev/null
+++ b/planetstack/core/api/nodes.py
@@ -0,0 +1,37 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Node
+ 
+def _get_nodes(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        nodes = Node.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        nodes = Node.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        nodes = Node.objects.filter(**filter)
+    else:
+        nodes = []
+    return nodes
+
+def add_node(auth, fields={}):
+    """not implemented"""
+    return 
+
+def delete_node(auth, filter={}):
+    """not implemented"""
+    return 1
+
+def update_node(auth, id, fields={}):
+    return 
+
+def get_nodes(auth, filter={}):
+    auth_check(auth)   
+    nodes = _get_nodes(filter)
+    return nodes             
+        
+
+    
diff --git a/planetstack/core/api/roles.py b/planetstack/core/api/roles.py
new file mode 100644
index 0000000..a799c01
--- /dev/null
+++ b/planetstack/core/api/roles.py
@@ -0,0 +1,39 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Role
+ 
+
+def _get_roles(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        roles = Role.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        roles = Role.objects.filter(role_type=filter)
+    elif isinstance(filter, dict):
+        roles = Role.objects.filter(**filter)
+    else:
+        roles = []
+    return roles
+
+def add_role(auth, name):
+    driver = OpenStackDriver(client = auth_check(auth))    
+    keystone_role = driver.create_role(name=name)
+    role = Role(role_type=name, role_id=keystone_role.id)
+    role.save()
+    return role
+
+def delete_role(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    roles = _get_roles(filter) 
+    for role in roles:
+        driver.delete_role({'id': role.role_id}) 
+        role.delete()
+    return 1
+
+def get_roles(auth, filter={}):
+    client = auth_check(auth)
+    return _get_roles(filter)             
+        
diff --git a/planetstack/core/api/site_privileges.py b/planetstack/core/api/site_privileges.py
new file mode 100644
index 0000000..85a8a83
--- /dev/null
+++ b/planetstack/core/api/site_privileges.py
@@ -0,0 +1,72 @@
+from types import StringTypes
+import re
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import SitePrivilege
+from core.api.users import _get_users
+from core.api.sites import _get_sites
+from core.api.roles import _get_roles
+
+
+def _get_site_privileges(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        site_privileges = SitePrivilege.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        site_privileges = SitePrivilege.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        site_privileges = SitePrivilege.objects.filter(**filter)
+    else:
+        site_privileges = []
+    return site_privileges
+ 
+def add_site_privilege(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    users = _get_user(fields.get('user')) 
+    sites = _get_slice(fields.get('site')) 
+    roles = _get_role(fields.get('role'))
+    
+    if users: fields['user'] = users[0]     
+    if slices: fields['site'] = sites[0] 
+    if roles: fields['role'] = roles[0]
+ 
+    site_privilege = SitePrivilege(**fields)
+
+    # update nova role
+    driver.add_user_role(site_privilege.user.kuser_id, 
+                         site_privilege.site.tenant_id, 
+                         site_privilege.role.name)
+    
+    site_privilege.save()
+    return site_privilege
+
+def update_site_privilege(auth, id, **fields):
+    return  
+
+def delete_site_privilege(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    site_privileges = _get_site_privileges(filter)
+    for site_privilege in site_privileges:
+        driver.delete_user_role(kuser_id=site_privilege.user.id,
+                                tenant_id = site_privilege.site.tenant_id,
+                                role_name = site_privilege.role.name) 
+        site_privilege.delete()
+    return 1
+
+def get_site_privileges(auth, filter={}):
+    client = auth_check(auth)
+    users = _get_users(filter.get('user'))
+    sites = _get_slices(filter.get('site'))
+    roles = _get_roles(filter.get('role'))
+
+    if users: filter['user'] = users[0]
+    if sites: filter['site'] = sites[0]
+    if roles: filter['role'] = roles[0]
+    
+    site_privileges = _get_site_privileges(filter)
+    return site_privileges             
+        
+
+    
diff --git a/planetstack/core/api/sites.py b/planetstack/core/api/sites.py
new file mode 100644
index 0000000..cfca6cf
--- /dev/null
+++ b/planetstack/core/api/sites.py
@@ -0,0 +1,62 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Site
+
+
+def _get_sites(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        sites = Site.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        sites = Site.objects.filter(login_base=filter)
+    elif isinstance(filter, dict):
+        sites = Site.objects.filter(**filter)
+    else:
+        sites = []
+    return sites 
+
+def add_site(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    site = Site(**fields)
+    nova_fields = {'tenant_name': site.login_base,
+                   'description': site.name,
+                   'enabled': site.enabled}    
+    tenant = driver.create_tenant(**nova_fields)
+    site.tenant_id=tenant.id
+    site.save()
+    return site
+
+def update_site(auth, id, **fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    sites = _get_sites(id)
+    if not sites:
+        return
+
+    site = Site[0]
+    nova_fields = {}
+    if 'description' in fields:
+        nova_fields['description'] = fields['name']
+    if 'enabled' in fields:
+        nova_fields['enabled'] = fields['enabled']
+    driver.update_tenant(site.tenant_id, **nova_fields)
+    site.update(**fields)
+    return site 
+
+def delete_site(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    sites = _get_sites(id)
+    for site in sites:
+        driver.delete_tenant(id=site.tenant_id) 
+        site.delete()
+    return 1
+
+def get_sites(auth, filter={}):
+    client = auth_check(auth)
+    sites = _get_sites(filter)
+    return sites             
+        
+
+    
diff --git a/planetstack/core/api/slice_memberships.py b/planetstack/core/api/slice_memberships.py
new file mode 100644
index 0000000..77d79bf
--- /dev/null
+++ b/planetstack/core/api/slice_memberships.py
@@ -0,0 +1,71 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import SliceMembership
+from core.api.users import _get_users
+from core.api.slices import _get_slices
+from core.api.roles import _get_roles
+
+def _get_slice_memberships(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        slice_memberships = SitePrivilege.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        slice_memberships = SitePrivilege.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        slice_memberships = SitePrivilege.objects.filter(**filter)
+    else:
+        slice_memberships = []
+    return slice_memberships
+
+ 
+def add_slice_membership(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    users = _get_users(fields.get('user')) 
+    slices = _get_slices(fields.get('slice')) 
+    roles = _get_roles(fields.get('role'))
+    
+    if users: fields['user'] = users[0]     
+    if slices: fields['slice'] = slices[0] 
+    if roles: fields['role'] = roles[0]
+ 
+    slice_membership = SliceMembership(**fields)
+
+    # update nova role
+    driver.add_user_role(slice_membership.user.user_id, 
+                         slice_membership.slice.tenant_id, 
+                         slice_membership.role.name)
+    
+    slice_membership.save()
+    return slice_membership
+
+def update_slice_membership(auth, id, **fields):
+    return  
+
+def delete_slice_membership(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    slice_memberships = _get_slice_memberships(filter)
+    for slice_membership in slice_memberships:
+        driver.delete_user_role(kuser_id=slice_membership.user.id,
+                                tenant_id = slice_membership.slice.tenant_id,
+                                role_name = slice_membership.role.name) 
+        slice_membership.delete()
+    return 1
+
+def get_slice_memberships(auth, filter={}):
+    client = auth_check(auth)
+    users = _get_users(fields.get('user'))
+    slices = _get_slices(fields.get('slice'))
+    roles = _get_roles(fields.get('role'))
+
+    if users: fields['user'] = users[0]
+    if slices: fields['slice'] = slices[0]
+    if roles: fields['role'] = roles[0]
+
+    slice_memberships = _get_slice_memberships(filter)
+    return slice_memberships             
+        
+
+    
diff --git a/planetstack/core/api/slices.py b/planetstack/core/api/slices.py
new file mode 100644
index 0000000..f03dd6f
--- /dev/null
+++ b/planetstack/core/api/slices.py
@@ -0,0 +1,93 @@
+import re
+from types import StringTypes
+from django.contrib.auth import authenticate
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Slice
+from core.api.sites import _get_sites
+
+def _get_slices(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        slices = Slice.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        slices = Slice.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        slices = Slice.objects.filter(**filter)
+    else:
+        slices = []
+    return slices
+    
+ 
+def add_slice(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    login_base = fields['name'][:fields['name'].find('_')]
+    sites = _get_sites(login_base) 
+    if sites: fields['site'] = sites[0]     
+    slice = Slice(**fields)
+   
+    # create tenant
+    nova_fields = {'tenant_name': slice.name,
+                   'description': slice.description,
+                   'enabled': slice.enabled}
+    tenant = driver.create_tenant(**nova_fields)
+    slice.tenant_id=tenant.id
+    
+    # create network
+    network = driver.create_network(slice.name)
+    slice.network_id = network['id']
+
+    # create router
+    router = driver.create_router(slice.name)
+    slice.router_id = router['id']    
+
+    slice.save()
+    return slice
+
+def update_slice(auth, id, **fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    slices = _get_slices(id)
+    if not slices:
+        return
+
+    # update tenant
+    slice = slices[0]
+    nova_fields = {}
+    if 'name' in fields:
+        nova_fields['tenant_name'] = fields['name']
+    if 'description' in fields:
+        nova_fields['description'] = fields['description']
+    if 'enabled' in fields:
+        nova_fields['enabled'] = fields['enabled']
+    driver.update_tenant(slice.tenant_id, **nova_fields)
+
+    # update db record 
+    sites = _get_sites(fields.get('site'))
+    if sites: fields['site'] = sites[0]
+    slice.update(**fields)
+
+    return slice 
+
+def delete_slice(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    slices = _get_slices(id)
+    for slice in slices:
+        driver.delete_network(slice.network_id)
+        driver.delete_router(slice.router_id)
+        driver.delete_slice(id=slice.tenant_id) 
+        slice.delete()
+    return 1
+
+def get_slices(auth, filter={}):
+    user = authenticate(username=auth.get('username'),
+                        password=auth.get('password'))
+    if 'site' in filter:
+        sites = _get_sites(filter.get('site'))
+        if sites: filter['site'] = sites[0]
+    slices = _get_slices(filter)
+    return slices             
+        
+
+    
diff --git a/planetstack/core/api/slivers.py b/planetstack/core/api/slivers.py
new file mode 100644
index 0000000..e3244a4
--- /dev/null
+++ b/planetstack/core/api/slivers.py
@@ -0,0 +1,67 @@
+from types import StringTypes
+from django.contrib.auth import authenticate
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Sliver, Slice
+from core.api.images import _get_images
+from core.api.keys import _get_keys
+from core.api.slices import _get_slices
+from core.api.deployment_networks import _get_deployment_networks
+from core.api.nodes import _get_nodes
+ 
+
+def _get_slivers(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        slivers = Sliver.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        slivers = Sliver.objects.filter(name=filter)
+    elif isinstance(filter, dict):
+        slivers = Sliver.objects.filter(**filter)
+    else:
+        slivers = []
+    return slivers
+ 
+def add_sliver(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+        
+    images = _get_images(fields.get('image'))
+    if images: fields['image'] = images[0]     
+    keys = _get_keys(fields.get('key'))
+    if keys: fields['key'] = keys[0]     
+    slices = _get_slices(fields.get('slice'))
+    if slices: 
+        fields['slice'] = slices[0]     
+    deployment_networks = _get_deployment_networks(fields.get('deploymentNetwork'))
+    if deployment_networks: fields['deploymentNetwork'] = deployment_networks[0]     
+    nodes = _get_nodes(fields.get('node'))
+    if nodes: fields['node'] = nodes[0]     
+    sliver = Sliver(**fields)
+    sliver.driver = driver    
+    sliver.save()
+    return sliver
+
+def update_sliver(auth, sliver, **fields):
+    return  
+
+def delete_sliver(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    slivers = _get_slivers(filter)
+    for sliver in slivers:
+        sliver.driver = driver
+        sliver.delete()
+    return 1
+
+def get_slivers(auth, filter={}):
+    user = authenticate(username=auth.get('username'),
+                        password=auth.get('password'))
+    if 'slice' in filter:
+        slices = _get_slices(filter.get('slice'))
+        if slices: filter['slice'] = slices[0]
+    slivers = _get_slivers(filter)
+    return slivers             
+        
+
+    
diff --git a/planetstack/core/api/subnets.py b/planetstack/core/api/subnets.py
new file mode 100644
index 0000000..d618eda
--- /dev/null
+++ b/planetstack/core/api/subnets.py
@@ -0,0 +1,74 @@
+import commands
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import Subnet
+from core.api.slices import _get_slices
+
+
+def _get_subnets(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        subnets = Subnet.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        # the name is the subnet's slice's name
+        slices = _get_slices(filter)
+        slice = None
+        if slices: slice=slices[0]
+        subnets = Subnet.objects.filter(slice=slice)
+    elif isinstance(filter, dict):
+        subnets = Subnet.objects.filter(**filter)
+    else:
+        subnets = []
+    return subnets
+
+def add_subnet(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    slices = _get_slices(fields.get('slice')) 
+    if slices: fields['slice'] = slices[0]     
+    subnet = Subnet(**fields)
+    # create quantum subnet
+    quantum_subnet = driver.create_subnet(name= subnet.slice.name,
+                                          network_id=subnet.slice.network_id,
+                                          cidr_ip = subnet.cidr,
+                                          ip_version=subnet.ip_version,
+                                          start = subnet.start,
+                                          end = subnet.end)
+    subnet.subnet_id=quantum_subnet['id']
+    ## set dns servers
+    #driver.update_subnet(subnet.id, {'dns_nameservers': ['8.8.8.8', '8.8.4.4']})
+
+    # add subnet as interface to slice's router
+    try: driver.add_router_interface(subnet.slice.router_id, subnet.subnet_id)
+    except: pass         
+    #add_route = 'route add -net %s dev br-ex gw 10.100.0.5' % self.cidr
+    commands.getstatusoutput(add_route)    
+    subnet.save()
+    return subnet
+
+def update_subnet(auth, subnet, **fields):
+    return  
+
+def delete_subnet(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    subnets = Subnet.objects.filter(**filter)
+    for subnet in subnets:
+        driver.delete_router_interface(subnet.slice.router_id, subnet.subnet_id)
+        driver.delete_subnet(subnet.subnet_id) 
+        subnet.delete()
+        #del_route = 'route del -net %s' % subnet.cidr
+    commands.getstatusoutput(del_route)
+    return 1
+
+def get_subnets(auth, filter={}):
+    client = auth_check(auth)
+    if 'slice' in filter:
+        slice = _get_slice(filter.get('slice'))
+        if slice: filter['slice'] = slice
+    subnets = Subnet.objects.filter(**filter)
+    return subnets             
+        
+
+    
diff --git a/planetstack/core/api/users.py b/planetstack/core/api/users.py
new file mode 100644
index 0000000..3b157ac
--- /dev/null
+++ b/planetstack/core/api/users.py
@@ -0,0 +1,71 @@
+from types import StringTypes
+from openstack.client import OpenStackClient
+from openstack.driver import OpenStackDriver
+from core.api.auth import auth_check
+from core.models import User, Site
+from core.api.sites import _get_sites
+
+def _get_users(filter):
+    if isinstance(filter, StringTypes) and filter.isdigit():
+        filter = int(filter)
+    if isinstance(filter, int):
+        users = User.objects.filter(id=filter)
+    elif isinstance(filter, StringTypes):
+        users = User.objects.filter(email=filter)
+    elif isinstance(filter, dict):
+        users = User.objects.filter(**filter)
+    else:
+        users = []
+    return users 
+
+def add_user(auth, fields):
+    driver = OpenStackDriver(client = auth_check(auth))
+    sites = _get_sites(fields.get('site')) 
+    if sites: fields['site'] = sites[0]     
+    user = User(**fields)
+    nova_fields = {'name': user.email[:user.email.find('@')],
+                   'email': user.email, 
+                   'password': fields.get('password'),
+                   'enabled': user.enabled}    
+    nova_user = driver.create_user(**nova_fields)
+    #driver.add_user_user(user.id, user.site.tenant_id, 'user')
+    user.kuser_id=nova_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.kuser_id, **nova_fields)
+    sites = _get_sites(fields.get('site'))
+    if sites: fields['site'] = sites[0]
+    user.update(**fields)
+    return user 
+
+def delete_user(auth, filter={}):
+    driver = OpenStackDriver(client = auth_check(auth))   
+    users = _get_users(filter)
+    for user in users:
+        driver.delete_user(id=user.kuser_id) 
+        user.delete()
+    return 1
+
+def get_users(auth, filter={}):
+    client = auth_check(auth)
+    users = _get_users(filter)
+    return users             
+        
+
+