updated Role admin
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index 36c1bf9..3dbf99c 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -97,6 +97,23 @@
list_display = ('name', 'site', 'deploymentNetwork')
list_filter = ('deploymentNetwork',)
+
+
+class IgnoredField(forms.Field):
+ def validate(self, value):
+ return
+
+
+
+class RoleForm(forms.ModelForm):
+ role_id = IgnoredField()
+ role_type = forms.CharField()
+
+
+class RoleAdmin(admin.ModelAdmin):
+ form = RoleForm
+ list_display = ('role_type',)
+
admin.site.register(Site, SiteAdmin)
admin.site.register(SitePrivilege)
admin.site.register(Slice, SliceAdmin)
@@ -107,7 +124,7 @@
admin.site.register(Sliver)
admin.site.register(Flavor)
admin.site.register(Key)
-admin.site.register(Role)
+admin.site.register(Role, RoleAdmin)
admin.site.register(User)
admin.site.register(DeploymentNetwork, DeploymentNetworkAdmin)
diff --git a/plstackapi/core/models/role.py b/plstackapi/core/models/role.py
index 12743ef..3efa7a1 100644
--- a/plstackapi/core/models/role.py
+++ b/plstackapi/core/models/role.py
@@ -2,14 +2,32 @@
import datetime
from django.db import models
from plstackapi.core.models import PlCoreBase
+from plstackapi.openstack.driver import OpenStackDriver
# Create your models here.
class Role(PlCoreBase):
- ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
- role_id = models.CharField(max_length=256, unique=True)
- role_type = models.CharField(max_length=80, unique=True, choices=ROLE_CHOICES)
+ #ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
+ role_id = models.CharField(max_length=256, unique=True, blank=True)
+ role_type = models.CharField(max_length=80, unique=True)
def __unicode__(self): return u'%s' % (self.role_type)
+
+ def save(self, *args, **kwds):
+
+ driver = OpenStackDriver()
+ if not self.role_id:
+ keystone_role = driver.create_role(name=self.role_type)
+ self.role_id = keystone_role.id
+
+ super(Role, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ driver = OpenStackDriver()
+ if self.role_id:
+ driver.delete_role({'id': self.role_id})
+
+ super(Role, self).delete(*args, **kwds)
+
diff --git a/plstackapi/core/serializers.py b/plstackapi/core/serializers.py
index 3692d1d..6317803 100644
--- a/plstackapi/core/serializers.py
+++ b/plstackapi/core/serializers.py
@@ -6,7 +6,6 @@
class RoleSerializer(serializers.HyperlinkedModelSerializer):
# HyperlinkedModelSerializer doesn't include the id by default
id = serializers.Field()
-
class Meta:
model = Role
fields = ('id',