sites work when openstack is disabled or unavailable
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index 58f5f58..e332c29 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -144,9 +144,9 @@
if obj is None:
continue
# give inline object access to driver and caller
- client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {}))
- inline.model.driver = OpenStackDriver(client=client)
- inline.model.caller = request.user
+ auth = request.session.get('auth', {})
+ auth['tenant'] = request.user.site.login_base
+ inline.model.os_manager = OpenStackManager(auth=auth, caller=request.user)
yield inline.get_formset(request, obj)
class SitePrivilegeAdmin(PlanetStackBaseAdmin):
diff --git a/plstackapi/core/models/site.py b/plstackapi/core/models/site.py
index 76cc0a4..2c60e16 100644
--- a/plstackapi/core/models/site.py
+++ b/plstackapi/core/models/site.py
@@ -21,26 +21,12 @@
def __unicode__(self): return u'%s' % (self.name)
def save(self, *args, **kwds):
- if not self.tenant_id:
- tenant = self.driver.create_tenant(tenant_name=self.login_base,
- description=self.name,
- enabled=self.enabled)
- self.tenant_id = tenant.id
- # give caller an admin role at the tenant they've created
- self.driver.add_user_role(self.caller.user_id, tenant.id, 'admin')
-
- # update the record
- if self.id:
- self.driver.update_tenant(self.tenant_id,
- description=self.name,
- enabled=self.enabled)
-
+ self.os_manager.save_site(self)
super(Site, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- if self.tenant_id:
- self.driver.delete_tenant(self.tenant_id)
+ self.os_manager.delete_site(self)
super(Site, self).delete(*args, **kwds)
diff --git a/plstackapi/openstack/manager.py b/plstackapi/openstack/manager.py
index 79403a8..9cf7652 100644
--- a/plstackapi/openstack/manager.py
+++ b/plstackapi/openstack/manager.py
@@ -28,7 +28,7 @@
self.client = OpenStackClient(**auth)
self.driver = OpenStackDriver(client=self.client)
- self.caller=None
+ self.caller=caller
@require_enabled
def save_role(self, role):
@@ -70,6 +70,28 @@
if user.user_id:
self.driver.delete_user(user.user_id)
+
+
+ @require_enabled
+ def save_site(self, site):
+ if not site.tenant_id:
+ tenant = self.driver.create_tenant(tenant_name=site.login_base,
+ description=site.name,
+ enabled=site.enabled)
+ site.tenant_id = tenant.id
+ # give caller an admin role at the tenant they've created
+ self.driver.add_user_role(self.caller.user_id, tenant.id, 'admin')
+
+ # update the record
+ if site.id and site.tenant_id:
+ self.driver.update_tenant(site.tenant_id,
+ description=site.name,
+ enabled=site.enabled)
+
+ @require_enabled
+ def delete_site(self, site):
+ if site.tenant_id:
+ self.driver.delete_tenant(site.tenant_id)
def refresh_nodes(self):
# collect local nodes