RoleAdmin and Role model work when openstack is disable
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index a814c55..904b566 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -1,5 +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
@@ -76,12 +77,24 @@
obj.caller = request.user
obj.delete()
-class RoleAdmin(OSModelAdmin):
+class RoleAdmin(PlanetStackBaseAdmin):
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(
queryset=Site.objects.all(),
diff --git a/plstackapi/core/models/role.py b/plstackapi/core/models/role.py
index b9f3e2f..41bfd62 100644
--- a/plstackapi/core/models/role.py
+++ b/plstackapi/core/models/role.py
@@ -13,13 +13,10 @@
def save(self, *args, **kwds):
- if not self.role_id:
- keystone_role = self.driver.create_role(name=self.role_type)
- self.role_id = keystone_role.id
+ self.os_manager.save_role(self)
super(Role, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- if self.role_id:
- self.driver.delete_role({'id': self.role_id})
+ self.os_manager.delete_role(self)
super(Role, self).delete(*args, **kwds)