updated models
diff --git a/plstackapi/core/models.py b/plstackapi/core/models.py
index 6e7dcd4..fd679df 100644
--- a/plstackapi/core/models.py
+++ b/plstackapi/core/models.py
@@ -12,6 +12,19 @@
class Meta:
abstract = True
+class Role(PlCoreBase):
+
+ ROLE_CHOICES = (('admin', 'Admin'), ('pi', 'Principle Investigator'), ('user','User'))
+ role_type = models.CharField(max_length=80, unique=True, choices=ROLE_CHOICES)
+
+ def __unicode__(self): return u'%s' % (self.role_type)
+
+ def save(self):
+ if not self.id:
+ self.created = datetime.date.today()
+ self.updated = datetime.datetime.today()
+ super(Role, self).save()
+
class Site(PlCoreBase):
tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
name = models.CharField(max_length=200, help_text="Name for this Site")
@@ -44,6 +57,37 @@
driver.delete_tenant(self.tenant_id)
super(Site, self).delete(*args, **kwargs)
+class User(PlCoreBase):
+ 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")
+ phone = models.CharField(help_text="phone number contact", max_length=100)
+ user_url = models.URLField()
+ site = models.ForeignKey(Site, related_name='site_user', verbose_name="Site this user will be homed too")
+
+ def __unicode__(self): return u'%s' % (self.email)
+
+ def save(self):
+ if not self.id:
+ self.created = datetime.date.today()
+ self.updated = datetime.datetime.today()
+ super(User, self).save()
+
+class SitePrivilege(PlCoreBase):
+
+ user = models.ForeignKey('User')
+ site = models.ForeignKey('Site')
+ role = models.ForeignKey('Role')
+
+ def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
+
+ def save(self):
+ if not self.id:
+ self.created = datetime.date.today()
+ self.updated = datetime.datetime.today()
+ super(SitePrivilege, self).save()
+
class Slice(PlCoreBase):
tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
name = models.CharField(help_text="The Name of the Slice", max_length=80)
@@ -53,7 +97,7 @@
omf_friendly = models.BooleanField()
description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024)
slice_url = models.URLField(blank=True, max_length=512)
- site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Node belongs too")
+ site = models.ForeignKey(Site, related_name='site_slice', help_text="The Site this Node belongs too")
def __unicode__(self): return u'%s' % (self.name)
@@ -66,6 +110,13 @@
description=self.description,
enabled=self.enabled)
self.tenant_id = tenant.id
+
+ # create router
+ driver.create_router(name=self.name)
+
+ # create a network
+ driver.create_network(name=self.name)
+
else:
# update record
self.driver.update_tenant(self.tenant_id, name=self.name,
@@ -78,6 +129,51 @@
driver.delete_tenant(self.tenant_id)
super(Slice, self).delete(*args, **kwds)
+class SliceMembership(PlCoreBase):
+ user = models.ForeignKey('User')
+ slice = models.ForeignKey('Slice')
+ role = models.ForeignKey('Role')
+
+ def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role)
+
+ def save(self):
+ if not self.id:
+ self.created = datetime.date.today()
+ self.updated = datetime.datetime.today()
+ super(SliceMembership, self).save()
+
+class SubNet(PlCoreBase):
+ subnet_id = models.CharField(max_length=256, unique=True)
+ cidr = models.CharField(max_length=20)
+ ip_version = models.IntegerField()
+ start = models.IPAddressField()
+ end = models.IPAddressField()
+ slice = models.ForeignKey(Slice, related_name='slice_subnet')
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+ def save(self, *args, **kwargs):
+ driver = OpenStackDriver()
+ if not self.id:
+ subnet = driver.create_subnet(network_name=self.slice.name,
+ cidr_ip = self.cidr,
+ ip_version=self.ip_version,
+ start = self.start,
+ end = self.end)
+
+ self.subnet_id = subnet.id
+
+ super(SubNet, self).save(*args, **kwargs)
+
+
+ def delete(self, *args, **kwargs):
+ # delete quantum network
+ driver = OpenStackDriver()
+ driver.delete_subnet(self.subnet_id)
+ super(SubNet, self).delete(*args, **kwargs)
+
+
+
class DeploymentNetwork(PlCoreBase):
name = models.CharField(max_length=200, unique=True, help_text="Name of the Deployment Network")
@@ -95,15 +191,61 @@
def __unicode__(self): return u'%s::%s' % (self.site, self.deploymentNetwork)
+class Node(PlCoreBase):
+ name = models.CharField(max_length=200, unique=True, help_text="Name of the Node")
+ siteDeploymentNetwork = models.ForeignKey(SiteDeploymentNetwork, help_text="The Site and Deployment Network this Node belongs too.")
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+class Image(PlCoreBase):
+ image_id = models.CharField(max_length=256, unique=True)
+ name = models.CharField(max_length=256, unique=True)
+ disk_format = models.CharField(max_length=256)
+ container_format = models.CharField(max_length=256)
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+
+class Flavor(PlCoreBase):
+ flavor_id = models.IntegerField(unique=True)
+ name = models.CharField(max_length=256, unique=True)
+ memory_mb = models.IntegerField()
+ disk_gb = models.IntegerField()
+ vcpus = models.IntegerField()
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+class Key(PlCoreBase):
+ name = models.CharField(max_length=256, unique=True)
+ key = models.CharField(max_length=512)
+ type = models.CharField(max_length=256)
+ blacklisted = models.BooleanField()
+ user = models.ForeignKey(User)
+
+ def __unicode__(self): return u'%s' % (self.name)
+
+ def save(self, *args, **kwds):
+ driver = OpenStackDriver()
+ if not self.id:
+ keypair = driver.create_keypair(name=self.name, key=self.key)
+ super(Key, self).save(*args, **kwds)
+
+ def delete(self, *args, **kwds):
+ driver = OpenStackDriver()
+ driver.delete_keypair(self.name)
+ super(Key, self).delete(*args, **kwds)
+
+
+
class Sliver(PlCoreBase):
- tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
instance_id = models.CharField(max_length=200, help_text="Nova instance id")
name = models.CharField(max_length=200, help_text="Sliver name")
- flavor = models.CharField(max_length=200, help_text="OS Flavor")
- image = models.CharField(max_length=200, help_text="Image Name")
+ flavor = models.ForeignKey(Flavor, related_name='sliver_flavor')
+ image = models.ForeignKey(Image, related_name='sliver_image')
+ key = models.ForeignKey(Key, related_name='sliver_key')
slice = models.ForeignKey(Slice, related_name='sliver_slice')
- siteDeploymentNetwork = models.ForeignKey(SiteDeploymentNetwork)
- #node = models.ForeignKey(Node, related_name='node')
+ siteDeploymentNetwork = models.ForeignKey(SiteDeploymentNetwork, related_name='sliver_deployment')
+ node = models.ForeignKey(Node, related_name='sliver_node')
def __unicode__(self): return u'%s::%s' % (self.slice, self.siteDeploymentNetwork)
@@ -112,8 +254,8 @@
instance = driver.spawn_instances(name=self.name,
keyname=self.name,
hostnames=self.node.name,
- flavor=self.flavor,
- image=self.image)
+ flavor=self.flavor.name,
+ image=self.image.name)
self.instance_id = instance.id
super(Sliver, self).save(*args, **kwds)
@@ -121,79 +263,4 @@
driver = OpenStackDriver()
driver.destroy_instance(name=self.name, id=self.instance_id)
super(Sliver, self).delete(*args, **kwds)
-
-class Node(PlCoreBase):
- name = models.CharField(max_length=200, unique=True, help_text="Name of the Node")
- siteDeploymentNetwork = models.ForeignKey(SiteDeploymentNetwork, help_text="The Site and Deployment Network this Node belongs too.")
-
- def __unicode__(self): return u'%s' % (self.name)
-
-class Network(PlCoreBase):
- slice = models.ForeignKey(Slice, related_name='network_slice')
- name = models.CharField(max_length=200, unique=True)
- quantum_id = models.CharField(max_length=200, unique=True)
-
- def __unicode__(self): return u'%s' % (self.name)
-
- def save(self, *args, **kwargs):
- os_shell = OpenStackShell()
- network_fields = {'name': self.name}
-
- if not self.id:
- # check if quantum network record exists
- networks = os_shell.quantum.list_networks(name=self.name)
- if not networks:
- network = os_shell.quantum.create_network(name=self.name,
- admin_state_up=False)
- else:
- network = networks[0]
- self.quantum_id = network.id
- super(Network, self).save(*args, **kwargs)
-
- def delete(self, *args, **kwargs):
- # delete quantum network
- os_shell = OpenStackShell()
- os_shell.quantum.delete_network(self.quantum_id)
-
- super(Network, self).delete(*args, **kwargs)
-
-class SubNet(PlCoreBase):
- network = models.ForeignKey(Network, related_name='network')
- name = models.CharField(max_length=200, unique=True)
- quantum_id = models.CharField(max_length=200, unique=True)
- cidr = models.CharField(max_length=20)
- ip_version = models.IntegerField()
- start = models.IPAddressField()
- end = models.IPAddressField()
-
- def __unicode__(self): return u'%s' % (self.name)
-
- def save(self, *args, **kwargs):
- os_shell = OpenStackShell()
- subnet_fields = {'network_id': self.network.quantum_id,
- 'name' : self.name,
- 'ip_version': self.ip_version,
- 'cidr': self.cidr,
- 'allocation_pools': {'start': self.start,
- 'end': self.end}
- }
- if not self.id:
- subnets = os_shell.quantum.list_subnets(name=self.name)
- if not subnets:
- subnet = os_shell.quantum.create_subnet(**subnet_fields)
- else:
- subnet = subnets[0]
- self.quantum_id = subnet.id
- super(SubNet, self).save(*args, **kwargs)
-
-
- def delete(self, *args, **kwargs):
- # delete quantum network
- os_shell = OpenStackShell()
- os_shell.quantum.delete_subnet(self.quantum_id)
-
- super(SubNet, self).delete(*args, **kwargs)
-
-
-