several bug fixes
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index 0c90b9a..aafa6e5 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -88,6 +88,7 @@
class SliceMembershipInline(admin.TabularInline):
model = SliceMembership
extra = 0
+ fields = ('user', 'role')
def formfield_for_foreignkey(self, db_field, request, **kwargs):
if db_field.name == 'slice':
@@ -204,6 +205,17 @@
# hide MyInline in the add view
if obj is None:
continue
+ if isinstance(inline, SliceInline):
+ inline.model.caller = request.user
+ yield inline.get_formset(request, obj)
+
+ def get_formsets(self, request, obj=None):
+ for inline in self.get_inline_instances(request, obj):
+ # hide MyInline in the add view
+ if obj is None:
+ continue
+ if isinstance(inline, SliverInline):
+ inline.model.caller = request.user
yield inline.get_formset(request, obj)
class SitePrivilegeAdmin(PlanetStackBaseAdmin):
@@ -247,7 +259,7 @@
qs = qs.filter(site__in=sites)
return qs
-class SliceAdmin(OSModelAdmin):
+class SliceAdmin(PlanetStackBaseAdmin):
fields = ['name', 'site', 'serviceClass', 'description', 'slice_url']
list_display = ('name', 'site','serviceClass', 'slice_url')
inlines = [SliverInline, SliceMembershipInline, SliceTagInline]
@@ -280,11 +292,8 @@
# hide MyInline in the add view
if obj is None:
continue
- # give inline object access to driver and caller
- auth = request.session.get('auth', {})
- auth['tenant'] = obj.name # meed to connect using slice's tenant
- inline.model.os_manager = OpenStackManager(auth=auth, caller=request.user)
- inline.model.creator = request.user
+ if isinstance(inline, SliverInline):
+ inline.model.caller = request.user
yield inline.get_formset(request, obj)
def get_queryset(self, request):
@@ -292,7 +301,12 @@
if request.user.is_superuser:
return qs
# users can only see slices at their site
- return qs.filter(site=request.user.site)
+ return qs.filter(site=request.user.site)
+
+ def save_model(self, request, obj, form, change):
+ # update openstack connection to use this site/tenant
+ obj.caller = request.user
+ obj.save()
class SliceMembershipAdmin(PlanetStackBaseAdmin):
fieldsets = [
@@ -476,7 +490,7 @@
return self.initial["password"]
-class UserAdmin(UserAdmin, OSModelAdmin):
+class UserAdmin(UserAdmin):
class Meta:
app_label = "core"
diff --git a/planetstack/core/api/slivers.py b/planetstack/core/api/slivers.py
index 16a7e0b..2ce24c7 100644
--- a/planetstack/core/api/slivers.py
+++ b/planetstack/core/api/slivers.py
@@ -3,7 +3,6 @@
from openstack.manager import OpenStackManager
from core.models import Sliver, Slice
from core.api.images import _get_images
-from core.api.keys import _get_keys
from core.api.slices import _get_slices
from core.api.deployment_networks import _get_deployment_networks
from core.api.nodes import _get_nodes
@@ -26,12 +25,10 @@
password=auth.get('password'))
images = _get_images(fields.get('image'))
- keys = _get_keys(fields.get('key'))
slices = _get_slices(fields.get('slice'))
deployment_networks = _get_deployment_networks(fields.get('deploymentNetwork'))
nodes = _get_nodes(fields.get('node'))
if images: fields['image'] = images[0]
- if keys: fields['key'] = keys[0]
if slices: fields['slice'] = slices[0]
if deployment_networks: fields['deploymentNetwork'] = deployment_networks[0]
if nodes: fields['node'] = nodes[0]
diff --git a/planetstack/core/models/slice.py b/planetstack/core/models/slice.py
index d6908a7..da9379d 100644
--- a/planetstack/core/models/slice.py
+++ b/planetstack/core/models/slice.py
@@ -22,6 +22,7 @@
subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id")
serviceClass = models.ForeignKey(ServiceClass, related_name = "slices", null=True, default=ServiceClass.get_default)
+ creator = models.ForeignKey(User, related_name='slices', blank=True, null=True)
def __unicode__(self): return u'%s' % (self.name)
@@ -31,6 +32,8 @@
# will fail unless it is allowed. But, we we really don't want it to
# ever save None, so fix it up here.
self.serviceClass = ServiceClass.get_default()
+ if not self.creator and hasattr(self, 'caller'):
+ self.creator = self.caller
super(Slice, self).save(*args, **kwds)
class SliceMembership(PlCoreBase):
diff --git a/planetstack/core/models/sliver.py b/planetstack/core/models/sliver.py
index 72ad66d..13eb353 100644
--- a/planetstack/core/models/sliver.py
+++ b/planetstack/core/models/sliver.py
@@ -29,15 +29,6 @@
def save(self, *args, **kwds):
if not self.name:
self.name = self.slice.name
- if not hasattr(self, 'os_manager'):
- from openstack.manager import OpenStackManager
- setattr(self, 'os_manager', OpenStackManager())
- self.os_manager.save_sliver(self)
+ if not self.creator and hasattr(self, 'caller'):
+ self.creator = self.caller
super(Sliver, self).save(*args, **kwds)
-
- def delete(self, *args, **kwds):
- if not hasattr(self, 'os_manager'):
- from openstack.manager import OpenStackManager
- setattr(self, 'os_manager', OpenStackManager())
- self.os_manager.delete_sliver(self)
- super(Sliver, self).delete(*args, **kwds)
diff --git a/planetstack/openstack/manager.py b/planetstack/openstack/manager.py
index f912270..ed2769d 100644
--- a/planetstack/openstack/manager.py
+++ b/planetstack/openstack/manager.py
@@ -253,7 +253,8 @@
def save_sliver(self, sliver):
if not sliver.instance_id:
slice_memberships = SliceMembership.objects.filter(slice=sliver.slice)
- pubkeys = [sm.user.public_key for sm in slice_memberships if sm.user.public_key != null]
+ pubkeys = [sm.user.public_key for sm in slice_memberships if sm.user.public_key != null]
+ pubkeys.append(sliver.creator.public_key)
instance = self.driver.spawn_instance(name=sliver.name,
key_name = sliver.creator.keyname,
image_id = sliver.image.image_id,
diff --git a/planetstack/openstack/observer.py b/planetstack/openstack/observer.py
index c0291ab..872cf58 100644
--- a/planetstack/openstack/observer.py
+++ b/planetstack/openstack/observer.py
@@ -20,7 +20,7 @@
self.sync_tenants()
self.sync_users()
#self.sync_user_tenant_roles()
- #self.sync_slivers()
+ self.sync_slivers()
time.sleep(7)
except:
traceback.print_exc()
@@ -58,13 +58,16 @@
pending_sites = Site.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
for site in pending_sites:
self.manager.save_site(site)
+ site.save()
site.enacted = datetime.now()
site.save(update_fields=['enacted'])
# get all slices that need to be synced (enacted < updated or enacted is None)
pending_slices = Slice.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
for slice in pending_slices:
+ self.manager.init_caller(slice.creator, slice.creator.site.login_base)
self.manager.save_slice(slice)
+ slice.save()
slice.enacted = datetime.now()
slice.save(update_fields=['enacted'])
@@ -102,6 +105,7 @@
pending_users = User.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
for user in pending_users:
self.manager.save_user(user)
+ user.save()
user.enacted = datetime.now()
user.save(update_fields=['enacted'])
@@ -130,10 +134,11 @@
# get all users that need to be synced (enacted < updated or enacted is None)
pending_slivers = Sliver.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
for sliver in pending_slivers:
- if sliver.creator:
+ if not sliver.instance_id and sliver.creator:
# update manager context
- self.manager.init_caller(sliver.creator)
+ self.manager.init_caller(sliver.creator, sliver.slice.name)
self.manager.save_sliver(sliver)
+ sliver.save()
sliver.enacted = datetime.now()
sliver.save(update_fields=['enacted'])