Record interesting info into nova metadata
Sometimes one wants to run a quick command across classes of nodes. This is made really easy if there are some defining characteristics recorded in the nova metadata that things like the ansible inventory can pick up on. Add information to the meta parameter to record that information in nova. Change-Id: I3e24f5aa004c5bb8de7ffb757035d64804547f1d
This commit is contained in:
parent
3a761d8028
commit
00e39427c2
@ -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
|
||||
==================
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user