blob: 6fd7c34cbdd84a7adcb77f3383f40213930ea551 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2from django.db import models
Siobhan Tully30fd4292013-05-10 08:59:56 -04003from core.models import PlCoreBase
Siobhan Tully4bc09f22013-04-10 21:15:21 -04004
5# Create your models here.
6
7class Key(PlCoreBase):
Siobhan Tully73291342013-05-10 10:50:08 -04008 name = models.CharField(max_length=256)
9 nkey_id = models.CharField(null=True, blank=True, max_length=256, unique=True)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040010 key = models.CharField(max_length=512)
11 type = models.CharField(max_length=256)
12 blacklisted = models.BooleanField(default=False)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040013
Siobhan Tully73291342013-05-10 10:50:08 -040014 def __unicode__(self): return u'%s' % (self.key)
Tony Mack759b57a2013-04-14 21:03:31 -040015
16 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040017 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040018 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040019 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040020 self.os_manager.save_key(self)
Tony Mack759b57a2013-04-14 21:03:31 -040021 super(Key, self).save(*args, **kwds)
22
23 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040024 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040025 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040026 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040027 self.os_manager.delete_key(self)
Tony Mack759b57a2013-04-14 21:03:31 -040028 super(Key, self).delete(*args, **kwds)
29