support passing metadata during spawn. automatically add syscyl tags to metadata
diff --git a/planetstack/openstack/driver.py b/planetstack/openstack/driver.py
index 0e5fbf0..ce0b883 100644
--- a/planetstack/openstack/driver.py
+++ b/planetstack/openstack/driver.py
@@ -358,18 +358,18 @@
return (subnet_id, subnet)
- def spawn_instance(self, name, key_name=None, hostname=None, image_id=None, security_group=None, pubkeys=[], nics=None):
+ def spawn_instance(self, name, key_name=None, hostname=None, image_id=None, security_group=None, pubkeys=[], nics=None, metadata=None):
flavor_name = self.config.nova_default_flavor
flavor = self.shell.nova.flavors.find(name=flavor_name)
#if not image:
# image = self.config.nova_default_imave
if not security_group:
- security_group = self.config.nova_default_security_group
+ security_group = self.config.nova_default_security_group
files = {}
- if pubkeys:
+ if pubkeys:
files['/root/.ssh/authorized_keys'] = "\n".join(pubkeys)
-
+
hints = {}
availability_zone = None
if hostname:
@@ -383,7 +383,8 @@
files=files,
scheduler_hints=hints,
availability_zone=availability_zone,
- nics=nics)
+ nics=nics,
+ meta=metadata)
return server
def destroy_instance(self, id):
diff --git a/planetstack/openstack/manager.py b/planetstack/openstack/manager.py
index 2fb4ff8..9ede33f 100644
--- a/planetstack/openstack/manager.py
+++ b/planetstack/openstack/manager.py
@@ -315,9 +315,22 @@
@require_enabled
def save_sliver(self, sliver):
+ metadata_update = {}
+ if ("numberCores" in sliver.changed_fields):
+ metadata_update["cpu_cores"] = str(sliver.numberCores)
+
+ for tag in sliver.slice.tags.all():
+ if tag.name.startswith("sysctl-"):
+ metadata_update[tag.name] = tag.value
+
if not sliver.instance_id:
nics = self.get_requested_networks(sliver.slice)
- file("/tmp/scott-manager","a").write("slice: %s\nreq: %s\n" % (str(sliver.slice.name), str(nics)))
+ for nic in nics:
+ # If a network hasn't been instantiated yet, then we'll fail
+ # during slice creation. Defer saving the sliver for now.
+ if not nic.get("net-id", None):
+ sliver.save() # in case it hasn't been saved yet
+ return
slice_memberships = SliceMembership.objects.filter(slice=sliver.slice)
pubkeys = [sm.user.public_key for sm in slice_memberships if sm.user.public_key]
pubkeys.append(sliver.creator.public_key)
@@ -326,12 +339,13 @@
image_id = sliver.image.image_id,
hostname = sliver.node.name,
pubkeys = pubkeys,
- nics = nics )
+ nics = nics,
+ metadata = metadata_update )
sliver.instance_id = instance.id
sliver.instance_name = getattr(instance, 'OS-EXT-SRV-ATTR:instance_name')
-
- if sliver.instance_id and ("numberCores" in sliver.changed_fields):
- self.driver.update_instance_metadata(sliver.instance_id, {"cpu_cores": str(sliver.numberCores)})
+ else:
+ if metadata_update:
+ self.driver.update_instance_metadata(sliver.instance_id, metadata_update)
sliver.save()
sliver.enacted = datetime.now()