Add instance boot properties

This allows us to set parameters for server boot on various images.
This is the equivalent of the "--property" flag when using "openstack
server create".  Various tools on the booted servers can then query
the config-drive metadata to get this value.

Needed-By: https://review.openstack.org/604193/

Change-Id: I99c1980f089aa2971ba728b77adfc6f4200e0b77
This commit is contained in:
Ian Wienand 2018-09-21 12:47:37 +10:00
parent a217373948
commit 7015bd9af4
7 changed files with 51 additions and 3 deletions

View File

@ -301,60 +301,80 @@ providers:
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: debian-stretch
diskimage: debian-stretch
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: fedora-27
diskimage: fedora-27
min-ram: 1024
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: ubuntu-bionic
diskimage: ubuntu-bionic
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: ubuntu-trusty
diskimage: ubuntu-trusty
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: ubuntu-xenial
diskimage: ubuntu-xenial
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: opensuse-423
diskimage: opensuse-423
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: opensuse-150
diskimage: opensuse-150
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: opensuse-tumbleweed
diskimage: opensuse-tumbleweed
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
- name: gentoo-17-0-systemd
diskimage: gentoo-17-0-systemd
min-ram: 512
flavor-name: 'nodepool'
console-log: True
key-name: $NODEPOOL_KEY_NAME
instance-properties:
nodepool_devstack: testing
diskimages:
- name: centos-7

View File

@ -710,6 +710,12 @@ Example configuration::
In gigabytes. Default 50.
``instance-properties`` (default: None)
A dictionary of key/value properties to set when booting each
server. These properties become available via the ``meta-data``
on the active server (e.g. within
``config-drive:openstack/latest/meta_data.json``)
Static driver
^^^^^^^^^^^^^

View File

@ -86,6 +86,7 @@ class ProviderLabel(ConfigValue):
self.console_log = False
self.boot_from_volume = False
self.volume_size = None
self.instance_properties = None
# The ProviderPool object that owns this label.
self.pool = None
@ -101,7 +102,8 @@ class ProviderLabel(ConfigValue):
other.name == self.name and
other.console_log == self.console_log and
other.boot_from_volume == self.boot_from_volume and
other.volume_size == self.volume_size)
other.volume_size == self.volume_size and
other.instance_properties == self.instance_properties)
return False
def __repr__(self):
@ -302,6 +304,8 @@ class OpenStackProviderConfig(ProviderConfig):
pl.boot_from_volume = bool(label.get('boot-from-volume',
False))
pl.volume_size = label.get('volume-size', 50)
pl.instance_properties = label.get('instance-properties',
None)
top_label = config.labels[pl.name]
top_label.pools.append(pp)
@ -336,6 +340,7 @@ class OpenStackProviderConfig(ProviderConfig):
'console-log': bool,
'boot-from-volume': bool,
'volume-size': int,
'instance-properties': dict,
}
label_min_ram = v.Schema({v.Required('min-ram'): int}, extra=True)

View File

@ -136,7 +136,8 @@ class OpenStackNodeLauncher(NodeLauncher):
networks=self.pool.networks,
security_groups=self.pool.security_groups,
boot_from_volume=self.label.boot_from_volume,
volume_size=self.label.volume_size)
volume_size=self.label.volume_size,
instance_properties=self.label.instance_properties)
self.node.external_id = server.id
self.node.hostname = hostname

View File

@ -268,7 +268,8 @@ class OpenStackProvider(Provider):
nodepool_node_id=None, nodepool_node_label=None,
nodepool_image_name=None,
networks=None, security_groups=None,
boot_from_volume=False, volume_size=50):
boot_from_volume=False, volume_size=50,
instance_properties=None):
if not networks:
networks = []
if not isinstance(image, dict):
@ -313,6 +314,9 @@ class OpenStackProvider(Provider):
groups=",".join(groups_list),
nodepool_provider_name=self.provider.name,
)
# merge in any provided properties
if instance_properties:
meta = {**instance_properties, **meta}
if nodepool_node_id:
meta['nodepool_node_id'] = nodepool_node_id
if nodepool_image_name:

View File

@ -46,6 +46,9 @@ providers:
min-ram: 8192
boot-from-volume: True
volume-size: 100
instance-properties:
a_key: a_value
b_key: b_value
- name: cloud2
driver: openstack

View File

@ -50,6 +50,15 @@ function sshintonode {
FAILURE_REASON="Root partition of $name does not appear to have grown: $root_size < $expected_root_size"
RETURN=1
fi
# Check we saw metadata deployed to the config-drive
/tmp/ssh_wrapper $node \
"dd status=none if=/dev/sr0 | tr -cd '[:print:]' | grep -q nodepool_devstack"
if [[ $? -ne 0 ]]; then
echo "*** Failed to find metadata in config-drive"
FAILURE_REASON="Failed to find meta-data in config-drive for $node"
RETURN=1
fi
}
function waitforimage {