update Sliver admin
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index c195a37..7b6827a 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -125,6 +125,12 @@
]
list_display = ('role_type',)
+class SliverAdmin(admin.ModelAdmin):
+ fieldsets = [
+ ('Sliver', {'fields': ['name', 'slice', 'flavor', 'image', 'key', 'node', 'deploymentNetwork']})
+ ]
+ list_display = ['name', 'slice', 'flavor', 'image', 'key', 'node', 'deploymentNetwork']
+
admin.site.register(Site, SiteAdmin)
admin.site.register(SitePrivilege)
admin.site.register(Slice, SliceAdmin)
@@ -132,7 +138,7 @@
admin.site.register(Subnet, SubnetAdmin)
admin.site.register(Image, ImageAdmin)
admin.site.register(Node, NodeAdmin)
-admin.site.register(Sliver)
+admin.site.register(Sliver, SliverAdmin)
admin.site.register(Flavor)
admin.site.register(Key, KeyAdmin)
admin.site.register(Role, RoleAdmin)
diff --git a/plstackapi/core/models/key.py b/plstackapi/core/models/key.py
index 080f211..5174ebb 100644
--- a/plstackapi/core/models/key.py
+++ b/plstackapi/core/models/key.py
@@ -8,7 +8,7 @@
class Key(PlCoreBase):
name = models.CharField(max_length=256, unique=True)
- key_id = models.CharField(max_length=256, unique=True, blank=True)
+ key_id = models.CharField(max_length=256, unique=True)
key = models.CharField(max_length=512)
type = models.CharField(max_length=256)
blacklisted = models.BooleanField(default=False)
diff --git a/plstackapi/core/models/role.py b/plstackapi/core/models/role.py
index 3efa7a1..4b4b2e4 100644
--- a/plstackapi/core/models/role.py
+++ b/plstackapi/core/models/role.py
@@ -9,14 +9,13 @@
class Role(PlCoreBase):
#ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
- role_id = models.CharField(max_length=256, unique=True, blank=True)
+ role_id = models.CharField(max_length=256, unique=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)
diff --git a/plstackapi/core/models/site.py b/plstackapi/core/models/site.py
index 2148e48..67257af 100644
--- a/plstackapi/core/models/site.py
+++ b/plstackapi/core/models/site.py
@@ -9,7 +9,7 @@
class Site(PlCoreBase):
- tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id", blank=True)
+ tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
name = models.CharField(max_length=200, help_text="Name for this Site")
site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page")
enabled = models.BooleanField(default=True, help_text="Status for this Site")
diff --git a/plstackapi/core/models/slice.py b/plstackapi/core/models/slice.py
index b080924..fe16402 100644
--- a/plstackapi/core/models/slice.py
+++ b/plstackapi/core/models/slice.py
@@ -10,7 +10,7 @@
# Create your models here.
class Slice(PlCoreBase):
- tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id", blank=True)
+ tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
name = models.CharField(unique=True, help_text="The Name of the Slice", max_length=80)
enabled = models.BooleanField(default=True, help_text="Status for this Slice")
SLICE_CHOICES = (('plc', 'PLC'), ('delegated', 'Delegated'), ('controller','Controller'), ('none','None'))
diff --git a/plstackapi/core/models/sliver.py b/plstackapi/core/models/sliver.py
index 1c4065f..27dda65 100644
--- a/plstackapi/core/models/sliver.py
+++ b/plstackapi/core/models/sliver.py
@@ -19,8 +19,26 @@
key = models.ForeignKey(Key, related_name='slivers')
slice = models.ForeignKey(Slice, related_name='slivers')
node = models.ForeignKey(Node, related_name='slivers')
- site = models.ForeignKey(Site, related_name='slivers')
+ #site = models.ForeignKey(Site, related_name='slivers')
deploymentNetwork = models.ForeignKey(DeploymentNetwork, related_name='sliver_deploymentNetwork')
def __unicode__(self): return u'%s::%s' % (self.slice, self.deploymentNetwork)
+ def save(self, *args, **kwds):
+ driver = OpenStackDriver()
+ if not self.instance_id:
+ instance = driver.spawn_instance(name=self.name,
+ key_name = self.key.name,
+ flavor_id = self.flavor.flavor_id,
+ image_id = self.image.image_id,
+ hostname = self.node.name )
+ self.instance_id = instance.id
+
+ super(Sliver, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ driver = OpenStackDriver()
+ if self.instance_id:
+ driver.destroy_instance(self.instance_id)
+
+ super(Sliver, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/subnet.py b/plstackapi/core/models/subnet.py
index ae25b63..93a7ba5 100644
--- a/plstackapi/core/models/subnet.py
+++ b/plstackapi/core/models/subnet.py
@@ -8,7 +8,7 @@
# Create your models here.
class Subnet(PlCoreBase):
- subnet_id = models.CharField(max_length=256, unique=True, blank=True)
+ subnet_id = models.CharField(max_length=256, unique=True)
cidr = models.CharField(max_length=20)
ip_version = models.IntegerField()
start = models.IPAddressField()
diff --git a/plstackapi/core/models/user.py b/plstackapi/core/models/user.py
index c21601c..30bd2a9 100644
--- a/plstackapi/core/models/user.py
+++ b/plstackapi/core/models/user.py
@@ -9,7 +9,7 @@
# Create your models here.
class User(PlCoreBase):
- user_id = models.CharField(max_length=256, unique=True, blank=True)
+ user_id = models.CharField(max_length=256, unique=True)
firstname = models.CharField(help_text="person's given name", max_length=200)
lastname = models.CharField(help_text="person's surname", max_length=200)
email = models.EmailField(help_text="e-mail address", null=True)
diff --git a/plstackapi/openstack/driver.py b/plstackapi/openstack/driver.py
index 876d089..67b5280 100644
--- a/plstackapi/openstack/driver.py
+++ b/plstackapi/openstack/driver.py
@@ -208,12 +208,7 @@
scheduler_hints=hints)
return server
- def destroy_instance(self, name, id=None):
- args = {'name': name}
- if id:
- args['id'] = id
- servers = self.shell.nova.servers.findall(**args)
+ def destroy_instance(self, id):
+ servers = self.shell.nova.servers.findall(id=id)
for server in servers:
- if name == server.name:
- if not id or id == server.id:
- self.shell.nova.servers.delete(server)
+ self.shell.nova.servers.delete(server)