save() and delete() uses caller's credentials to init openstackdriver client
diff --git a/plstackapi/core/admin.py b/plstackapi/core/admin.py
index dae2256..82cf613 100644
--- a/plstackapi/core/admin.py
+++ b/plstackapi/core/admin.py
@@ -1,8 +1,10 @@
from plstackapi.core.models import Site
from plstackapi.core.models import *
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.openstack.client import OpenStackClient
+
from django.contrib import admin
from django.contrib.auth.models import Group
-
from django import forms
from django.utils.safestring import mark_safe
from django.contrib.auth.admin import UserAdmin
@@ -62,7 +64,6 @@
def save(self, commit=True):
deploymentNetwork = super(DeploymentNetworkAdminForm, self).save(commit=False)
-
if commit:
deploymentNetwork.save()
@@ -93,6 +94,17 @@
]
list_display = ['name', 'key', 'type', 'blacklisted', 'user']
+ def save_model(self, request, obj, form, change):
+ # attach the caller's openstack clien connection to the object
+ client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {}))
+ obj.driver = OpenStackDriver(client=client)
+ obj.save()
+
+ def delete_model(self, request, obj):
+ client = OpenStackClient(tenant=request.user.site.login_base, **request.session.get('auth', {}))
+ obj.driver = OpenStackDriver(client=client)
+ obj.delete()
+
class SliceAdmin(PlanetStackBaseAdmin):
fields = ['name', 'site', 'instantiation', 'description', 'slice_url']
list_display = ('name', 'site','slice_url', 'instantiation')
diff --git a/plstackapi/core/models/key.py b/plstackapi/core/models/key.py
index 9d4b139..3e4f56f 100644
--- a/plstackapi/core/models/key.py
+++ b/plstackapi/core/models/key.py
@@ -2,7 +2,6 @@
from django.db import models
from plstackapi.core.models import PlCoreBase
from plstackapi.core.models import PLUser
-from plstackapi.openstack.driver import OpenStackDriver
# Create your models here.
@@ -17,17 +16,15 @@
def __unicode__(self): return u'%s' % (self.name)
def save(self, *args, **kwds):
- driver = OpenStackDriver()
if not self.key_id:
key_fields = {'name': self.name,
'key': self.key}
- nova_key = driver.create_keypair(**key_fields)
+ nova_key = self.driver.create_keypair(**key_fields)
self.key_id = nova_key.id
super(Key, self).save(*args, **kwds)
def delete(self, *args, **kwds):
- driver = OpenStackDriver()
if self.key_id:
- driver.delete_keypair(self.key_id)
+ self.driver.delete_keypair(self.key_id)
super(Key, self).delete(*args, **kwds)