key is now just an attribute of the user model. Added 'creator' field to sliver model
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index d54387f..1dbe0d7 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -32,7 +32,7 @@
class SliverInline(admin.TabularInline):
model = Sliver
- fields = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'key', 'node', 'deploymentNetwork']
+ fields = ['ip', 'instance_name', 'slice', 'numberCores', 'image', 'node', 'deploymentNetwork']
extra = 0
#readonly_fields = ['ip', 'instance_name', 'image']
readonly_fields = ['ip', 'instance_name']
@@ -333,6 +333,7 @@
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
yield inline.get_formset(request, obj)
def get_queryset(self, request):
@@ -469,6 +470,7 @@
auth = request.session.get('auth', {})
auth['tenant'] = obj.slice.name
obj.os_manager = OpenStackManager(auth=auth, caller=request.user)
+ obj.creator = request.user
obj.save()
def delete_model(self, request, obj):
@@ -486,7 +488,7 @@
class Meta:
model = User
- fields = ('email', 'firstname', 'lastname', 'phone', 'key', 'site')
+ fields = ('email', 'firstname', 'lastname', 'phone', 'public_key', 'site')
def clean_password2(self):
# Check that the two password entries match
@@ -539,13 +541,13 @@
inlines = [SitePrivilegeInline, SliceMembershipInline]
fieldsets = (
(None, {'fields': ('email', 'password', 'site', 'is_admin', 'timezone')}),
- ('Personal info', {'fields': ('firstname','lastname','phone', 'key')}),
+ ('Personal info', {'fields': ('firstname','lastname','phone', 'public_key')}),
#('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
- 'fields': ('email', 'firstname', 'lastname', 'phone', 'site', 'key','password1', 'password2', 'is_admin')}
+ 'fields': ('email', 'firstname', 'lastname', 'phone', 'site', 'public_key','password1', 'password2', 'is_admin')}
),
)
search_fields = ('email',)
diff --git a/planetstack/core/models/plcorebase.py b/planetstack/core/models/plcorebase.py
index ed7c3ff..709fdc6 100644
--- a/planetstack/core/models/plcorebase.py
+++ b/planetstack/core/models/plcorebase.py
@@ -6,6 +6,7 @@
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
+ enacted = models.DateTimeField(null=True, default=None)
class Meta:
abstract = True
diff --git a/planetstack/core/models/sliver.py b/planetstack/core/models/sliver.py
index 03fa1d8..72ad66d 100644
--- a/planetstack/core/models/sliver.py
+++ b/planetstack/core/models/sliver.py
@@ -3,11 +3,11 @@
from django.core import exceptions
from core.models import PlCoreBase
from core.models import Image
-from core.models import Key
from core.models import Slice
from core.models import Node
from core.models import Site
from core.models import Deployment
+from core.models import User
# Create your models here.
class Sliver(PlCoreBase):
@@ -16,7 +16,8 @@
instance_name = models.CharField(blank=True, null=True, max_length=200, help_text="OpenStack generated name")
ip = models.GenericIPAddressField(help_text="Sliver ip address", blank=True, null=True)
image = models.ForeignKey(Image, related_name='slivers')
- key = models.ForeignKey(Key, related_name='slivers')
+ #key = models.ForeignKey(Key, related_name='slivers')
+ creator = models.ForeignKey(User, related_name='slivers', blank=True, null=True)
slice = models.ForeignKey(Slice, related_name='slivers')
node = models.ForeignKey(Node, related_name='slivers')
deploymentNetwork = models.ForeignKey(Deployment, verbose_name='deployment', related_name='sliver_deploymentNetwork')
diff --git a/planetstack/core/models/user.py b/planetstack/core/models/user.py
index 055b6cd..d494ede 100644
--- a/planetstack/core/models/user.py
+++ b/planetstack/core/models/user.py
@@ -63,7 +63,8 @@
phone = models.CharField(null=True, blank=True, help_text="phone number contact", max_length=100)
user_url = models.URLField(null=True, blank=True)
site = models.ForeignKey(Site, related_name='users', verbose_name="Site this user will be homed too", null=True)
- key = models.ForeignKey(Key, related_name='user', null=True, blank=True)
+ #key = models.ForeignKey(Key, related_name='user', null=True, blank=True)
+ public_key = models.CharField(null=True, blank=True, max_length=1024, help_text="Public key string")
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=True)
@@ -84,6 +85,10 @@
# The user is identified by their email address
return self.email
+ @property
+ def keyname(self):
+ return self.email[:self.email.find('@')]
+
def __unicode__(self):
return self.email
diff --git a/planetstack/core/serializers.py b/planetstack/core/serializers.py
index 447bac4..fd0c6c6 100644
--- a/planetstack/core/serializers.py
+++ b/planetstack/core/serializers.py
@@ -28,8 +28,9 @@
'firstname',
'lastname',
'email',
- 'password',
- 'phone',
+ 'password',
+ 'phone',
+ 'public_key',
'user_url',
'is_admin',
'site',
diff --git a/planetstack/openstack/client.py b/planetstack/openstack/client.py
index f3abbb2..b21c341 100644
--- a/planetstack/openstack/client.py
+++ b/planetstack/openstack/client.py
@@ -3,6 +3,8 @@
from glance import client as glance_client
from novaclient.v1_1 import client as nova_client
from quantumclient.v2_0 import client as quantum_client
+ from nova.db.sqlalchemy import api as nova_db_api
+ from nova.context import get_admin_context
has_openstack = True
except:
has_openstack = False
@@ -110,6 +112,23 @@
def __getattr__(self, name):
return getattr(self.client, name)
+class NovaDB(Client):
+ def __init__(self, *args, **kwds):
+ Client.__init__(self, *args, **kwds)
+ if has_openstack:
+ self.ctx = get_admin_context()
+ api.FLAGS(default_config_files=['/etc/nova/nova.conf'])
+ self.client = nova_db_api
+
+
+ @require_enabled
+ def connect(self, *args, **kwds):
+ self.__init__(*args, **kwds)
+
+ @require_enabled
+ def __getattr__(self, name):
+ return getattr(self.client, name)
+
class QuantumClient(Client):
def __init__(self, *args, **kwds):
Client.__init__(self, *args, **kwds)
@@ -137,6 +156,7 @@
self.keystone = KeystoneClient(*args, **kwds)
self.glance = GlanceClient(*args, **kwds)
self.nova = NovaClient(*args, **kwds)
+ self.nova_db = NovaDB(*args, **kwds)
self.quantum = QuantumClient(*args, **kwds)
@require_enabled
diff --git a/planetstack/openstack/driver.py b/planetstack/openstack/driver.py
index f84fbb8..a38b0a1 100644
--- a/planetstack/openstack/driver.py
+++ b/planetstack/openstack/driver.py
@@ -278,12 +278,16 @@
return 1
- def create_keypair(self, name, key):
+ def create_keypair(self, name, public_key):
keys = self.shell.nova.keypairs.findall(name=name)
if keys:
key = keys[0]
+ # update key
+ if key.public_key != public_key:
+ self.delete_keypair(key.id)
+ key = self.shell.nova.keypairs.create(name=name, public_key=public_key)
else:
- key = self.shell.nova.keypairs.create(name=name, public_key=key)
+ key = self.shell.nova.keypairs.create(name=name, public_key=public_key)
return key
def delete_keypair(self, id):
diff --git a/planetstack/openstack/manager.py b/planetstack/openstack/manager.py
index 83dd954..3c77952 100644
--- a/planetstack/openstack/manager.py
+++ b/planetstack/openstack/manager.py
@@ -6,11 +6,11 @@
from netaddr import IPAddress, IPNetwork
from planetstack import settings
from django.core import management
+from core.models import *
from planetstack.config import Config
try:
from openstack.client import OpenStackClient
from openstack.driver import OpenStackDriver
- from core.models import *
has_openstack = True
except:
has_openstack = False
@@ -79,12 +79,10 @@
self.driver.delete_role({'id': role.role})
@require_enabled
- def save_key(self, key):
- if not key.nkey_id:
- key_fields = {'name': random_string(8),
- 'key': key.key}
- nova_key = self.driver.create_keypair(**key_fields)
- key.nkey_id = nova_key.id
+ def save_key(self, key, name):
+ key_fields = {'name': name,
+ 'public_key': key}
+ nova_key = self.driver.create_keypair(**key_fields)
@require_enabled
def delete_key(self, key):
@@ -101,6 +99,10 @@
'enabled': True}
keystone_user = self.driver.create_user(**user_fields)
user.kuser_id = keystone_user.id
+
+ if user.public_key:
+ self.save_key(user.public_key, user.keyname)
+
if user.site:
self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'user')
if user.is_admin:
@@ -243,7 +245,7 @@
def save_sliver(self, sliver):
if not sliver.instance_id:
instance = self.driver.spawn_instance(name=sliver.name,
- key_name = sliver.key.nkey_id,
+ key_name = sliver.creator.keyname,
image_id = sliver.image.image_id,
hostname = sliver.node.name )
sliver.instance_id = instance.id
@@ -286,7 +288,7 @@
site = sites[i]
node = Node(name=compute_nodes_dict[name].hypervisor_hostname,
site=site,
- deploymentNetwork=deployment)
+ deployment=deployment)
node.save()
i+=1