keys and users work when openstack is disabled or unavailable
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index 4bb9a98..58f5f58 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -63,37 +63,26 @@
save_on_top = False
class OSModelAdmin(PlanetStackBaseAdmin):
- """Attach client connection to openstack on delete() and save()"""
+ """Attach client connection to openstack on delete() and save()"""
def save_model(self, request, obj, form, change):
- client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {}))
- obj.driver = OpenStackDriver(client=client)
- obj.caller = request.user
+ auth = request.session.get('auth', {})
+ auth['tenant'] = request.user.site.login_base
+ obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
obj.save()
def delete_model(self, request, obj):
- client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {}))
- obj.driver = OpenStackDriver(client=client)
- obj.caller = request.user
- obj.delete()
+ auth = request.session.get('auth', {})
+ auth['tenant'] = request.user.site.login_base
+ obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
+ obj.delete()
-class RoleAdmin(PlanetStackBaseAdmin):
+class RoleAdmin(OSModelAdmin):
fieldsets = [
('Role', {'fields': ['role_type']})
]
list_display = ('role_type',)
- def save_model(self, request, obj, form, change):
- auth = request.session.get('auth', {})
- auth['tenant'] = request.user.site.login_base
- obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
- obj.save()
-
- def delete_model(self, request, obj):
- auth = request.session.get('auth', {})
- auth['tenant'] = request.user.site.login_base
- obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
- obj.delete()
class DeploymentNetworkAdminForm(forms.ModelForm):
sites = forms.ModelMultipleChoiceField(
diff --git a/plstackapi/core/models/key.py b/plstackapi/core/models/key.py
index 3e4f56f..afbebff 100644
--- a/plstackapi/core/models/key.py
+++ b/plstackapi/core/models/key.py
@@ -16,15 +16,10 @@
def __unicode__(self): return u'%s' % (self.name)
def save(self, *args, **kwds):
- if not self.key_id:
- key_fields = {'name': self.name,
- 'key': self.key}
- nova_key = self.driver.create_keypair(**key_fields)
- self.key_id = nova_key.id
+ self.os_manager.save_key(self)
super(Key, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- if self.key_id:
- self.driver.delete_keypair(self.key_id)
+ self.os_manager.delete_key(self)
super(Key, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/pluser.py b/plstackapi/core/models/pluser.py
index f914662..474f044 100644
--- a/plstackapi/core/models/pluser.py
+++ b/plstackapi/core/models/pluser.py
@@ -3,7 +3,7 @@
from django.db import models
from plstackapi.core.models import PlCoreBase
from plstackapi.core.models import Site
-from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.openstack.manager import OpenStackManager
from django.contrib.auth.models import User, AbstractBaseUser, UserManager, BaseUserManager
# Create your models here.
@@ -101,22 +101,16 @@
def save(self, *args, **kwds):
- if not self.user_id:
- if not self.driver:
- setattr(self, 'driver', OpenStackDriver())
- name = self.email[:self.email.find('@')]
- user_fields = {'name': name,
- 'email': self.email,
- 'password': self.password,
- 'enabled': True}
- keystone_user = self.driver.create_user(**user_fields)
- self.user_id = keystone_user.id
+ if not hasattr(self, 'os_manager'):
+ setattr(self, 'os_manager', OpenStackManager())
+
+ self.os_manager.save_user(self)
self.set_password(self.password)
super(PLUser, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- if self.user_id:
- if not getattr(self, 'driver'):
- setattr(self, 'driver', OpenStackDriver())
- self.driver.delete_user(self.user_id)
+ if not hasattr(self, 'os_manager'):
+ setattr(self, 'os_manager', OpenStackManager())
+
+ self.os_manager.delete_user(self)
super(PLUser, self).delete(*args, **kwds)