diff --git a/doc/source/operation.rst b/doc/source/operation.rst index 911a5b7e0..0a55d40a5 100644 --- a/doc/source/operation.rst +++ b/doc/source/operation.rst @@ -22,6 +22,29 @@ This way if you find that a newly created image is problematic, you may simply delete it and Nodepool will revert to using the previous image. +Metadata +-------- + +When nodepool creates instances, it will assign the following nova +metadata: + + groups + A json-encoded list containing the name of the image and the name + of the provider. This may be used by the Ansible OpenStack + inventory plugin. + + nodepool + A json-encoded dictionary with the following entries: + + image_name + The name of the image as a string. + + provider_name + The name of the provider as a string. + + node_id + The nodepool id of the node as an integer. + Command Line Tools ================== diff --git a/nodepool/nodepool.py b/nodepool/nodepool.py index c7681fb10..e3cc1fe61 100644 --- a/nodepool/nodepool.py +++ b/nodepool/nodepool.py @@ -425,7 +425,7 @@ class NodeLauncher(threading.Thread): server_id = self.manager.createServer( hostname, self.image.min_ram, snap_image.external_id, name_filter=self.image.name_filter, az=self.node.az, - config_drive=self.image.config_drive) + config_drive=self.image.config_drive, node_id=self.node_id) self.node.external_id = server_id session.commit() @@ -704,7 +704,7 @@ class SubNodeLauncher(threading.Thread): server_id = self.manager.createServer( hostname, self.image.min_ram, snap_image.external_id, name_filter=self.image.name_filter, az=self.node_az, - config_drive=self.image.config_drive) + config_drive=self.image.config_drive, node_id=self.node_id) self.subnode.external_id = server_id session.commit() diff --git a/nodepool/provider_manager.py b/nodepool/provider_manager.py index 2c4ff3faf..b14f28d3d 100644 --- a/nodepool/provider_manager.py +++ b/nodepool/provider_manager.py @@ -16,6 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import logging import paramiko @@ -360,7 +361,7 @@ class ProviderManager(TaskManager): def createServer(self, name, min_ram, image_id=None, image_name=None, az=None, key_name=None, name_filter=None, - config_drive=None): + config_drive=None, node_id=None): if image_name: image_id = self.findImage(image_name)['id'] flavor = self.findFlavor(min_ram, name_filter) @@ -381,6 +382,23 @@ class ProviderManager(TaskManager): else: raise Exception("Invalid 'networks' configuration.") create_args['nics'] = nics + # Put provider.name and image_name in as groups so that ansible + # inventory can auto-create groups for us based on each of those + # qualities + # Also list each of those values directly so that non-ansible + # consumption programs don't need to play a game of knowing that + # groups[0] is the image name or anything silly like that. + nodepool_meta = dict(provider_name=self.provider.name) + groups_meta = [self.provider.name] + if node_id: + nodepool_meta['node_id'] = node_id + if image_name: + nodepool_meta['image_name'] = image_name + groups_meta.append(image_name) + create_args['meta'] = dict( + groups=json.dumps(groups_meta), + nodepool=json.dumps(nodepool_meta) + ) return self.submitTask(CreateServerTask(**create_args))