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',
diff --git a/plstackapi/openstack/driver.py b/plstackapi/openstack/driver.py
index 03d4ed6..21f3422 100644
--- a/plstackapi/openstack/driver.py
+++ b/plstackapi/openstack/driver.py
@@ -43,8 +43,10 @@
return self.shell.keystone.tenants.update(id, **kwds)
def delete_tenant(self, id):
- tenant = self.shell.keystone.tenants.find(id=id)
- return self.shell.keystone.tenants.delete(tenant)
+ tenants = self.shell.keystone.tenants.findall(id=id)
+ for tenant in tenants:
+ self.shell.keystone.tenants.delete(tenant)
+ return 1
def create_user(self, name, email, password, enabled):
users = self.shell.keystone.users.findall(email=email)
@@ -56,6 +58,12 @@
user = users[0]
return user
+ def delete_user(self, id):
+ users = self.shell.keystone.users.findall(id=id)
+ for user in users:
+ self.shell.keystone.users.delete(user)
+ return 1
+
def add_user_role(self, user_id, tenant_id, role_name):
user = self.shell.keystone.users.find(id=user_id)
tenant = self.shell.keystone.tenants.find(id=tenant_id)
@@ -71,10 +79,6 @@
def update_user(self, id, **kwds):
return self.shell.keystone.users.update(id, **kwds)
- def delete_user(self, id):
- user = self.shell.keystone.users.find(id=id)
- return self.shell.keystone.users.delete(user)
-
def create_router(self, name, set_gateway=True):
routers = self.shell.quantum.list_routers(name=name)['routers']
if routers:
@@ -123,6 +127,7 @@
for subnet_id in net['subnets']:
self.delete_subnet(subnet_id)
self.shell.quantum.delete_network(net['id'])
+ return 1
def create_subnet(self, name, network_id, cidr_ip, ip_version, start, end):
#nets = self.shell.quantum.list_networks(name=network_name)['networks']
@@ -154,7 +159,13 @@
return self.shell.quantum.update_subnet(id, fields)
def delete_subnet(self, id):
- return self.shell.quantum.delete_subnet(id=id)
+ #return self.shell.quantum.delete_subnet(id=id)
+ # inefficient but fault tolerant
+ subnets = self.shell.quantum.list_subnets()['subnets']
+ for subnet in subnets:
+ if subnet['id'] == id:
+ self.shell.quantum.delete_subnet(id=id)
+ return
def create_keypair(self, name, key):
@@ -169,6 +180,7 @@
keys = self.shell.nova.keypairs.findall(name=name)
for key in keys:
self.shell.nova.keypairs.delete(key)
+ return 1
def spawn_instance(self, name, key_name=None, hostname=None, flavor_id=None, image_id=None, security_group=None, pubkeys=[]):
#if not flavor_id: