remove references to OpenStackDriver and OpenStackClient outside of OpenStackManager
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index 039ac17..86b48a2 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -1,8 +1,6 @@
from plstackapi.core.models import Site
from plstackapi.core.models import *
from plstackapi.openstack.manager import OpenStackManager
-from plstackapi.openstack.driver import OpenStackDriver
-from plstackapi.openstack.client import OpenStackClient
from django.contrib import admin
from django.contrib.auth.models import Group
@@ -122,9 +120,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 SiteAdmin(OSModelAdmin):
diff --git a/plstackapi/openstack/manager.py b/plstackapi/openstack/manager.py
index e48acc0..c55e752 100644
--- a/plstackapi/openstack/manager.py
+++ b/plstackapi/openstack/manager.py
@@ -32,6 +32,9 @@
self.enabled = manager_enabled
self.driver = OpenStackDriver(client=self.client)
self.caller=caller
+ if not self.caller:
+ self.caller = self.driver.admin_user
+ self.caller.user_id = self.caller.id
@require_enabled
def save_role(self, role):
@@ -76,7 +79,7 @@
@require_enabled
- def save_site(self, site):
+ def save_site(self, site, add_role=True):
if not site.tenant_id:
tenant = self.driver.create_tenant(tenant_name=site.login_base,
description=site.name,
diff --git a/plstackapi/openstack/siteagent.py b/plstackapi/openstack/siteagent.py
index 98fedae..dab9e8a 100644
--- a/plstackapi/openstack/siteagent.py
+++ b/plstackapi/openstack/siteagent.py
@@ -1,20 +1,21 @@
import os
+import sys
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "plstackapi.planetstack.settings")
import time
from plstackapi.core.models.site import Site
-from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.openstack.manager import OpenStackManager
class SiteAgent:
def run(self):
- driver = OpenStackDriver()
- # fill in null tenant ids
- sites = Site.objects.filter(tenant_id__in=[None, ''])
- for site in sites:
- # calling save() on the model should force the tenant_id to be set
- site.driver = driver
- site.caller = driver.admin_user
- site.caller.user_id = site.caller.id
- site.save()
+ manager = OpenStackManager()
+ # exit if openstack is disable or unavailable
+ if manager.enabled and manager.has_openstack:
+ # fill in null tenant ids
+ sites = Site.objects.filter(tenant_id__in=[None, ''])
+ for site in sites:
+ # calling save() on the model should force the tenant_id to be set
+ site.os_manager = manager
+ site.save()
if __name__ == '__main__':
SiteAgent().run()