create OSModelAdmin. Update some Admin definitions to subclass OSModelAdmin
diff --git a/plstackapi/core/models/role.py b/plstackapi/core/models/role.py
index 4b4b2e4..b9f3e2f 100644
--- a/plstackapi/core/models/role.py
+++ b/plstackapi/core/models/role.py
@@ -2,9 +2,6 @@
import datetime
from django.db import models
from plstackapi.core.models import PlCoreBase
-from plstackapi.openstack.driver import OpenStackDriver
-
-# Create your models here.
class Role(PlCoreBase):
@@ -16,17 +13,13 @@
def save(self, *args, **kwds):
- driver = OpenStackDriver()
if not self.role_id:
- keystone_role = driver.create_role(name=self.role_type)
+ keystone_role = self.driver.create_role(name=self.role_type)
self.role_id = keystone_role.id
-
super(Role, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- driver = OpenStackDriver()
if self.role_id:
- driver.delete_role({'id': self.role_id})
-
+ self.driver.delete_role({'id': self.role_id})
super(Role, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/site.py b/plstackapi/core/models/site.py
index 1e1cbe4..67b3e52 100644
--- a/plstackapi/core/models/site.py
+++ b/plstackapi/core/models/site.py
@@ -2,9 +2,6 @@
from django.db import models
from plstackapi.core.models import PlCoreBase
from plstackapi.core.models import DeploymentNetwork
-from plstackapi.openstack.driver import OpenStackDriver
-
-# Create your models here.
class Site(PlCoreBase):
@@ -24,26 +21,24 @@
def __unicode__(self): return u'%s' % (self.name)
def save(self, *args, **kwds):
- driver = OpenStackDriver()
if not self.tenant_id:
- tenant = driver.create_tenant(tenant_name=self.login_base,
- description=self.name,
- enabled=self.enabled)
+ tenant = self.driver.create_tenant(tenant_name=self.login_base,
+ description=self.name,
+ enabled=self.enabled)
self.tenant_id = tenant.id
# update the record
if self.id:
- driver.update_tenant(self.tenant_id,
- name=self.login_base,
- description=self.name,
- enabled=self.enabled)
+ self.driver.update_tenant(self.tenant_id,
+ name=self.login_base,
+ description=self.name,
+ enabled=self.enabled)
super(Site, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- driver = OpenStackDriver()
if self.tenant_id:
- driver.delete_tenant(self.tenant_id)
+ self.driver.delete_tenant(self.tenant_id)
super(Site, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/slice.py b/plstackapi/core/models/slice.py
index 27184dc..d174b2e 100644
--- a/plstackapi/core/models/slice.py
+++ b/plstackapi/core/models/slice.py
@@ -5,7 +5,6 @@
from plstackapi.core.models import PLUser
from plstackapi.core.models import Role
from plstackapi.core.models import DeploymentNetwork
-from plstackapi.openstack.driver import OpenStackDriver
# Create your models here.
@@ -25,31 +24,28 @@
def __unicode__(self): return u'%s' % (self.name)
def save(self, *args, **kwds):
-
- driver = OpenStackDriver()
if not self.tenant_id:
nova_fields = {'tenant_name': self.name,
'description': self.description,
'enabled': self.enabled}
- tenant = driver.create_tenant(**nova_fields)
+ tenant = self.driver.create_tenant(**nova_fields)
self.tenant_id = tenant.id
# create network
- network = driver.create_network(self.name)
+ network = self.driver.create_network(self.name)
self.network_id = network['id']
# create router
- router = driver.create_router(self.name)
+ router = self.driver.create_router(self.name)
self.router_id = router['id']
super(Slice, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- driver = OpenStackDriver()
if self.tenant_id:
- driver.delete_router(self.router_id)
- driver.delete_network(self.network_id)
- driver.delete_tenant(self.tenant_id)
+ self.driver.delete_router(self.router_id)
+ self.driver.delete_network(self.network_id)
+ self.driver.delete_tenant(self.tenant_id)
super(Slice, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/sliver.py b/plstackapi/core/models/sliver.py
index 27b9ab1..13f94b2 100644
--- a/plstackapi/core/models/sliver.py
+++ b/plstackapi/core/models/sliver.py
@@ -9,7 +9,6 @@
from plstackapi.core.models import Node
from plstackapi.core.models import Site
from plstackapi.core.models import DeploymentNetwork
-from plstackapi.openstack.driver import OpenStackDriver
# Create your models here.
class Sliver(PlCoreBase):
@@ -30,8 +29,7 @@
raise exceptions.ValidationError, "Slice %s has no subnet" % self.slice.name
if not self.instance_id:
- driver = OpenStackDriver()
- instance = driver.spawn_instance(name=self.name,
+ instance = self.driver.spawn_instance(name=self.name,
key_name = self.key.name,
flavor_id = self.flavor.flavor_id,
image_id = self.image.image_id,
@@ -41,8 +39,7 @@
super(Sliver, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- driver = OpenStackDriver()
if self.instance_id:
- driver.destroy_instance(self.instance_id)
+ self.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 2e10ae1..c9ea1ef 100644
--- a/plstackapi/core/models/subnet.py
+++ b/plstackapi/core/models/subnet.py
@@ -3,7 +3,6 @@
from django.db import models
from plstackapi.core.models import PlCoreBase
from plstackapi.core.models import Slice
-from plstackapi.openstack.driver import OpenStackDriver
# Create your models here.
@@ -18,10 +17,8 @@
def __unicode__(self): return u'%s' % (self.slice.name)
def save(self, *args, **kwds):
-
- driver = OpenStackDriver()
if not self.subnet_id:
- quantum_subnet = driver.create_subnet(name= self.slice.name,
+ quantum_subnet = self.driver.create_subnet(name= self.slice.name,
network_id=self.slice.network_id,
cidr_ip = self.cidr,
ip_version=self.ip_version,
@@ -29,17 +26,16 @@
end = self.end)
self.subnet_id = quantum_subnet['id']
# add subnet as interface to slice's router
- driver.add_router_interface(self.slice.router_id, self.subnet_id)
+ self.driver.add_router_interface(self.slice.router_id, self.subnet_id)
#add_route = 'route add -net %s dev br-ex gw 10.100.0.5' % self.cidr
#commands.getstatusoutput(add_route)
super(Subnet, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- driver = OpenStackDriver()
if self.subnet_id:
- driver.delete_router_interface(self.slice.router_id, self.subnet_id)
- driver.delete_subnet(self.subnet_id)
+ self.driver.delete_router_interface(self.slice.router_id, self.subnet_id)
+ self.driver.delete_subnet(self.subnet_id)
#del_route = 'route del -net %s' % self.cidr
#commands.getstatusoutput(del_route)
super(Subnet, self).delete(*args, **kwds)