blob: 4b4b2e45f26b56b65041be2154d480f77416ebd9 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2import datetime
3from django.db import models
4from plstackapi.core.models import PlCoreBase
Tony Mackfd24d0d2013-04-14 00:59:17 -04005from plstackapi.openstack.driver import OpenStackDriver
Siobhan Tully4bc09f22013-04-10 21:15:21 -04006
7# Create your models here.
8
9class Role(PlCoreBase):
10
Tony Mackfd24d0d2013-04-14 00:59:17 -040011 #ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
Tony Mackcdec0902013-04-15 00:38:49 -040012 role_id = models.CharField(max_length=256, unique=True)
Tony Mackfd24d0d2013-04-14 00:59:17 -040013 role_type = models.CharField(max_length=80, unique=True)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040014
15 def __unicode__(self): return u'%s' % (self.role_type)
16
Tony Mackfd24d0d2013-04-14 00:59:17 -040017
18 def save(self, *args, **kwds):
Tony Mackfd24d0d2013-04-14 00:59:17 -040019 driver = OpenStackDriver()
20 if not self.role_id:
21 keystone_role = driver.create_role(name=self.role_type)
22 self.role_id = keystone_role.id
23
24 super(Role, self).save(*args, **kwds)
25
26 def delete(self, *args, **kwds):
27 driver = OpenStackDriver()
28 if self.role_id:
29 driver.delete_role({'id': self.role_id})
30
31 super(Role, self).delete(*args, **kwds)
32