subnets and slivers work when openstack is disable or unavailable
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index a562911..039ac17 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -233,17 +233,17 @@
list_display = ('slice','cidr', 'start', 'end', 'ip_version')
def save_model(self, request, obj, form, change):
- # update openstack connection to use this subnet's slice/tenant
- client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {}))
- obj.driver = OpenStackDriver(client=client)
- obj.caller = request.user
+ # update openstack connection to use this site/tenant
+ auth = request.session.get('auth', {})
+ auth['tenant'] = obj.slice.name
+ obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
obj.save()
def delete_model(self, request, obj):
- # update openstack connection to use this subnet's slice/tenant
- client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {}))
- obj.driver = OpenStackDriver(client=client)
- obj.caller = request.user
+ # update openstack connection to use this site/tenant
+ auth = request.session.get('auth', {})
+ auth['tenant'] = obj.slice.name
+ obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
obj.delete()
class ImageAdmin(admin.ModelAdmin):
@@ -272,19 +272,18 @@
list_display = ['ip', 'instance_name', 'name', 'slice', 'numberCores', 'image', 'key', 'node', 'deploymentNetwork']
def save_model(self, request, obj, form, change):
- # update openstack connection to use this sliver's slice/tenant
- client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {}))
- obj.driver = OpenStackDriver(client=client)
- obj.caller = request.user
+ # update openstack connection to use this site/tenant
+ auth = request.session.get('auth', {})
+ auth['tenant'] = obj.slice.name
+ obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
obj.save()
def delete_model(self, request, obj):
- # update openstack connection to use this sliver's slice/tenant
- client = OpenStackClient(tenant=obj.slice.name, **request.session.get('auth', {}))
- obj.driver = OpenStackDriver(client=client)
- obj.caller = request.user
+ # update openstack connection to use this site/tenant
+ auth = request.session.get('auth', {})
+ auth['tenant'] = obj.slice.name
+ obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
obj.delete()
-
class UserCreationForm(forms.ModelForm):
"""A form for creating new users. Includes all the required
diff --git a/plstackapi/core/models/sliver.py b/plstackapi/core/models/sliver.py
index a4bf2c0..9a3ca81 100644
--- a/plstackapi/core/models/sliver.py
+++ b/plstackapi/core/models/sliver.py
@@ -29,18 +29,9 @@
if not self.slice.subnet.exists():
raise exceptions.ValidationError, "Slice %s has no subnet" % self.slice.name
- if not self.instance_id:
- instance = self.driver.spawn_instance(name=self.name,
- key_name = self.key.name,
- image_id = self.image.image_id,
- hostname = self.node.name )
- self.instance_id = instance.id
- self.instance_name = getattr(instance, 'OS-EXT-SRV-ATTR:instance_name')
-
+ self.os_manager.save_sliver(self)
super(Sliver, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- if self.instance_id:
- self.driver.destroy_instance(self.instance_id)
-
+ self.os_manager.delete_sliver(self)
super(Sliver, self).delete(*args, **kwds)
diff --git a/plstackapi/core/models/subnet.py b/plstackapi/core/models/subnet.py
index c9ea1ef..be8c938 100644
--- a/plstackapi/core/models/subnet.py
+++ b/plstackapi/core/models/subnet.py
@@ -17,25 +17,9 @@
def __unicode__(self): return u'%s' % (self.slice.name)
def save(self, *args, **kwds):
- if not self.subnet_id:
- 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,
- start = self.start,
- end = self.end)
- self.subnet_id = quantum_subnet['id']
- # add subnet as interface to slice's router
- 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)
-
+ self.os_manager.save_subnet(self)
super(Subnet, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- if 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)
+ self.os_manager.delete_subnet(self)
super(Subnet, self).delete(*args, **kwds)