Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | import datetime |
| 3 | from django.db import models |
| 4 | from plstackapi.core.models import PlCoreBase |
Tony Mack | fd24d0d | 2013-04-14 00:59:17 -0400 | [diff] [blame] | 5 | from plstackapi.openstack.driver import OpenStackDriver |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 6 | |
| 7 | # Create your models here. |
| 8 | |
| 9 | class Role(PlCoreBase): |
| 10 | |
Tony Mack | fd24d0d | 2013-04-14 00:59:17 -0400 | [diff] [blame] | 11 | #ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User')) |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 12 | role_id = models.CharField(max_length=256, unique=True) |
Tony Mack | fd24d0d | 2013-04-14 00:59:17 -0400 | [diff] [blame] | 13 | role_type = models.CharField(max_length=80, unique=True) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 14 | |
| 15 | def __unicode__(self): return u'%s' % (self.role_type) |
| 16 | |
Tony Mack | fd24d0d | 2013-04-14 00:59:17 -0400 | [diff] [blame] | 17 | |
| 18 | def save(self, *args, **kwds): |
Tony Mack | fd24d0d | 2013-04-14 00:59:17 -0400 | [diff] [blame] | 19 | 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 | |