Merge pick up, tweaked role/site/plcore_base or os_manager path when OpenStack not present
diff --git a/planetstack/core/api/deployment_networks.py b/planetstack/core/api/deployment_networks.py
index 51fa03e..fcd2145 100644
--- a/planetstack/core/api/deployment_networks.py
+++ b/planetstack/core/api/deployment_networks.py
@@ -1,8 +1,6 @@
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
+from django.contrib.auth import authenticate
def _get_deployment_networks(filter):
if isinstance(filter, StringTypes) and filter.isdigit():
@@ -18,20 +16,23 @@
return deployment_networks
def add_deployment_network(auth, name):
- auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
deployment = DeploymentNetwork(name=name)
deployment.save()
return deployment
def delete_deployment_network(auth, filter={}):
- auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
deployments = _get_deployment_networks(filter)
for deployment in deployments:
deployment.delete()
return 1
def get_deployment_networks(auth, filter={}):
- auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
deployments = _get_deployment_networks(filter)
return deployments
diff --git a/planetstack/core/api/images.py b/planetstack/core/api/images.py
index c080a55..933216f 100644
--- a/planetstack/core/api/images.py
+++ b/planetstack/core/api/images.py
@@ -1,7 +1,5 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
from core.models import Image
def _get_images(filter):
@@ -26,7 +24,8 @@
return 1
def get_images(auth, filter={}):
- auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
images = _get_images(filter)
return images
diff --git a/planetstack/core/api/keys.py b/planetstack/core/api/keys.py
index e653690..3528cd3 100644
--- a/planetstack/core/api/keys.py
+++ b/planetstack/core/api/keys.py
@@ -1,8 +1,7 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
+from django.contrib.auth import authenticate
+from openstack.manager import OpenStackManager
from core.models import Key
-from core.api.auth import auth_check
from core.api.users import _get_users
@@ -20,14 +19,17 @@
return keys
def add_key(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+ manager = OpenStackManager(auth=auth, caller = user)
+
+ # look up user object
users = _get_users(fields.get('user'))
if users: fields['user'] = users[0]
+ # save
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.os_manager = manager
key.save()
return key
@@ -35,15 +37,20 @@
return
def delete_key(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+ manager = OpenStackManager(auth=auth, caller = user)
+
keys = _get_keys(filter)
for key in keys:
- driver.delete_keypair(id=key.nkey_id)
+ key.os_manager = manager
key.delete()
return 1
def get_keys(auth, filter={}):
- client = auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
keys = _get_keys(filter)
return keys
diff --git a/planetstack/core/api/nodes.py b/planetstack/core/api/nodes.py
index 6514e54..4f7ceeb 100644
--- a/planetstack/core/api/nodes.py
+++ b/planetstack/core/api/nodes.py
@@ -1,7 +1,5 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
from core.models import Node
def _get_nodes(filter):
@@ -29,7 +27,8 @@
return
def get_nodes(auth, filter={}):
- auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
nodes = _get_nodes(filter)
return nodes
diff --git a/planetstack/core/api/roles.py b/planetstack/core/api/roles.py
index a799c01..4ea05c9 100644
--- a/planetstack/core/api/roles.py
+++ b/planetstack/core/api/roles.py
@@ -1,7 +1,6 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
+from openstack.manager import OpenStackManager
from core.models import Role
@@ -19,21 +18,27 @@
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)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
+ role = Role(role_type=name)
+ role.os_manager = OpenStackManager(auth=auth, caller = user)
role.save()
return role
def delete_role(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
roles = _get_roles(filter)
for role in roles:
- driver.delete_role({'id': role.role_id})
+ auth['tenant'] = user.site.login_base
+ role.os_manager = OpenStackManager(auth=auth, caller = user)
role.delete()
return 1
def get_roles(auth, filter={}):
- client = auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
return _get_roles(filter)
diff --git a/planetstack/core/api/site_privileges.py b/planetstack/core/api/site_privileges.py
index 85a8a83..6d79701 100644
--- a/planetstack/core/api/site_privileges.py
+++ b/planetstack/core/api/site_privileges.py
@@ -1,8 +1,7 @@
from types import StringTypes
import re
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
+from openstack.manager import OpenStackManager
from core.models import SitePrivilege
from core.api.users import _get_users
from core.api.sites import _get_sites
@@ -23,7 +22,9 @@
return site_privileges
def add_site_privilege(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+
users = _get_user(fields.get('user'))
sites = _get_slice(fields.get('site'))
roles = _get_role(fields.get('role'))
@@ -32,13 +33,9 @@
if slices: fields['site'] = sites[0]
if roles: fields['role'] = roles[0]
+ auth['tenant'] = sites[0].login_base
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.os_manager = OpenStackManager(auth=auth, caller = user)
site_privilege.save()
return site_privilege
@@ -46,17 +43,21 @@
return
def delete_site_privilege(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+ manager = OpenStackManager(auth=auth, caller = user)
+
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)
+ auth['tenant'] = user.site.login_base
+ site_privilege.os_manager = OpenStackManager(auth=auth, caller = user)
site_privilege.delete()
return 1
def get_site_privileges(auth, filter={}):
- client = auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
users = _get_users(filter.get('user'))
sites = _get_slices(filter.get('site'))
roles = _get_roles(filter.get('role'))
diff --git a/planetstack/core/api/sites.py b/planetstack/core/api/sites.py
index cfca6cf..123f139 100644
--- a/planetstack/core/api/sites.py
+++ b/planetstack/core/api/sites.py
@@ -1,10 +1,8 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
+from openstack.manager import OpenStackManager
from core.models import Site
-
def _get_sites(filter):
if isinstance(filter, StringTypes) and filter.isdigit():
filter = int(filter)
@@ -19,42 +17,42 @@
return sites
def add_site(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
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.os_manager = OpenStackManager(auth=auth, caller = user)
site.save()
return site
def update_site(auth, id, **fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
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.os_manager = OpenStackManager(auth=auth, caller = user)
site.update(**fields)
return site
def delete_site(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
sites = _get_sites(id)
for site in sites:
- driver.delete_tenant(id=site.tenant_id)
+ site.os_manager = OpenStackManager(auth=auth, caller = user)
site.delete()
return 1
def get_sites(auth, filter={}):
- client = auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
sites = _get_sites(filter)
return sites
diff --git a/planetstack/core/api/slice_memberships.py b/planetstack/core/api/slice_memberships.py
index 77d79bf..3e25ae7 100644
--- a/planetstack/core/api/slice_memberships.py
+++ b/planetstack/core/api/slice_memberships.py
@@ -1,7 +1,6 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
+from openstack.manager import OpenStackManager
from core.models import SliceMembership
from core.api.users import _get_users
from core.api.slices import _get_slices
@@ -22,7 +21,9 @@
def add_slice_membership(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+
users = _get_users(fields.get('user'))
slices = _get_slices(fields.get('slice'))
roles = _get_roles(fields.get('role'))
@@ -32,12 +33,8 @@
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)
-
+ auth['tenant'] = sites[0].login_base
+ slice_membership.os_manager = OpenStackManager(auth=auth, caller = user)
slice_membership.save()
return slice_membership
@@ -45,17 +42,19 @@
return
def delete_slice_membership(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
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.os_manager = OpenStackManager(auth=auth, caller = user)
slice_membership.delete()
return 1
def get_slice_memberships(auth, filter={}):
- client = auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
users = _get_users(fields.get('user'))
slices = _get_slices(fields.get('slice'))
roles = _get_roles(fields.get('role'))
diff --git a/planetstack/core/api/slices.py b/planetstack/core/api/slices.py
index f03dd6f..c9e94a2 100644
--- a/planetstack/core/api/slices.py
+++ b/planetstack/core/api/slices.py
@@ -1,9 +1,7 @@
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 openstack.manager import OpenStackManager
from core.models import Slice
from core.api.sites import _get_sites
@@ -22,61 +20,44 @@
def add_slice(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
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.os_manager = OpenStackManager(auth=auth, caller = user)
slice.save()
return slice
def update_slice(auth, id, **fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
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)
+
+ slice.os_manager = OpenStackManager(auth=auth, caller = user)
+ for (k,v) in fields.items():
+ setattr(slice, k, v)
+ slice.save()
return slice
def delete_slice(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
- slices = _get_slices(id)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+ slices = _get_slices(filter)
for slice in slices:
- driver.delete_network(slice.network_id)
- driver.delete_router(slice.router_id)
- driver.delete_slice(id=slice.tenant_id)
+ slice.os_manager = OpenStackManager(auth=auth, caller = user)
slice.delete()
return 1
diff --git a/planetstack/core/api/slivers.py b/planetstack/core/api/slivers.py
index e3244a4..16a7e0b 100644
--- a/planetstack/core/api/slivers.py
+++ b/planetstack/core/api/slivers.py
@@ -1,15 +1,12 @@
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 openstack.manager import OpenStackManager
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():
@@ -25,21 +22,23 @@
return slivers
def add_sliver(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
-
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+
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 images: fields['image'] = images[0]
+ if keys: fields['key'] = keys[0]
+ if slices: fields['slice'] = slices[0]
+ if deployment_networks: fields['deploymentNetwork'] = deployment_networks[0]
if nodes: fields['node'] = nodes[0]
+
sliver = Sliver(**fields)
- sliver.driver = driver
+ auth['tenant'] = sliver.slice.name
+ sliver.os_manager = OpenStackManager(auth=auth, caller = user)
sliver.save()
return sliver
@@ -47,10 +46,12 @@
return
def delete_sliver(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
slivers = _get_slivers(filter)
for sliver in slivers:
- sliver.driver = driver
+ auth['tenant'] = sliver.slice.name
+ slice.os_manager = OpenStackManager(auth=auth, caller = user)
sliver.delete()
return 1
diff --git a/planetstack/core/api/users.py b/planetstack/core/api/users.py
index 3b157ac..08e851c 100644
--- a/planetstack/core/api/users.py
+++ b/planetstack/core/api/users.py
@@ -1,7 +1,6 @@
from types import StringTypes
-from openstack.client import OpenStackClient
-from openstack.driver import OpenStackDriver
-from core.api.auth import auth_check
+from django.contrib.auth import authenticate
+from openstack.manager import OpenStackManager
from core.models import User, Site
from core.api.sites import _get_sites
@@ -19,22 +18,22 @@
return users
def add_user(auth, fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
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.os_manager = OpenStackManager(auth=auth, caller = user)
user.save()
return user
def update_user(auth, id, **fields):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
+
users = User.objects.filter(id=id)
if not users:
return
@@ -48,22 +47,27 @@
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)
+ user.os_manager = OpenStackManager(auth=auth, caller = user)
+ for (k,v) in fields.items():
+ setattr(user, k, v)
+ user.save()
return user
def delete_user(auth, filter={}):
- driver = OpenStackDriver(client = auth_check(auth))
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
+ auth['tenant'] = user.site.login_base
users = _get_users(filter)
for user in users:
- driver.delete_user(id=user.kuser_id)
+ user.os_manager = OpenStackManager(auth=auth, caller = user)
user.delete()
return 1
def get_users(auth, filter={}):
- client = auth_check(auth)
+ user = authenticate(username=auth.get('username'),
+ password=auth.get('password'))
users = _get_users(filter)
return users