blob: b9f3e2f76c6e52663c3b512680ff00661e8d1500 [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
Siobhan Tully4bc09f22013-04-10 21:15:21 -04005
6class Role(PlCoreBase):
7
Tony Mackfd24d0d2013-04-14 00:59:17 -04008 #ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
Tony Mackcdec0902013-04-15 00:38:49 -04009 role_id = models.CharField(max_length=256, unique=True)
Tony Mackfd24d0d2013-04-14 00:59:17 -040010 role_type = models.CharField(max_length=80, unique=True)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040011
12 def __unicode__(self): return u'%s' % (self.role_type)
13
Tony Mackfd24d0d2013-04-14 00:59:17 -040014
15 def save(self, *args, **kwds):
Tony Mackfd24d0d2013-04-14 00:59:17 -040016 if not self.role_id:
Tony Mackfdd4d802013-04-27 13:02:33 -040017 keystone_role = self.driver.create_role(name=self.role_type)
Tony Mackfd24d0d2013-04-14 00:59:17 -040018 self.role_id = keystone_role.id
Tony Mackfd24d0d2013-04-14 00:59:17 -040019 super(Role, self).save(*args, **kwds)
20
21 def delete(self, *args, **kwds):
Tony Mackfd24d0d2013-04-14 00:59:17 -040022 if self.role_id:
Tony Mackfdd4d802013-04-27 13:02:33 -040023 self.driver.delete_role({'id': self.role_id})
Tony Mackfd24d0d2013-04-14 00:59:17 -040024 super(Role, self).delete(*args, **kwds)
25