From d507bd9f186c45b51d635e26070aef7280b6c175 Mon Sep 17 00:00:00 2001 From: Michael Still Date: Sun, 5 Aug 2012 21:35:28 +1000 Subject: Config drive v2 This is the first cut of config drive v2. Some points to note: - implements a helper to create new-style config drives. These config drives can be VFAT or ISO9660, this is controlled by a flag. The current default is ISO9660. - the config drives contain all the injected files, as well as everything returned from the ec2 style metadata service. Only the most recent version of the ec2 metadata is used, but future versions will appear as well. - the v1 functionality of specifying an image from glance to have the files injected into is dropped. - the location for file injection is now a directory named openstack/files, not the root level of the filesystem. Filename mapping is in the openstack metadata files. - the default format for the config drive is iso9660, although the previous vfat is available with a flag change. - includes the first version of an openstack metadata format. - there are some simple unit tests which probably need more done to them. Partially implements bp config-drive-v2. Change-Id: I210fa4dd7d8d6be398a46b30a0d46b960e22d6b0 --- nova/api/metadata/base.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'nova/api') diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index 61bc9cad0..78ebdd821 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -19,6 +19,7 @@ """Instance Metadata information.""" import base64 +import json import os from nova.api.ec2 import ec2utils @@ -27,9 +28,21 @@ from nova import context from nova import db from nova import flags from nova import network +from nova.openstack.common import cfg + + +metadata_opts = [ + cfg.StrOpt('config_drive_skip_versions', + default=('1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 ' + '2007-12-15 2008-02-01 2008-09-01'), + help=('List of metadata versions to skip placing into the ' + 'config drive')), + ] FLAGS = flags.FLAGS flags.DECLARE('dhcp_domain', 'nova.network.manager') +FLAGS.register_opts(metadata_opts) + _DEFAULT_MAPPINGS = {'ami': 'sda1', 'ephemeral0': 'sda2', @@ -205,6 +218,39 @@ class InstanceMetadata(): return data + def metadata_for_config_drive(self, injected_files): + """Yields (path, value) tuples for metadata elements.""" + # EC2 style metadata + for version in VERSIONS: + if version in FLAGS.config_drive_skip_versions.split(' '): + continue + + data = self.get_ec2_metadata(version) + if 'user-data' in data: + filepath = os.path.join('ec2', version, 'userdata.raw') + yield (filepath, data['user-data']) + del data['user-data'] + + try: + del data['public-keys']['0']['_name'] + except KeyError: + pass + + filepath = os.path.join('ec2', version, 'metadata.json') + yield (filepath, json.dumps(data['meta-data'])) + + filepath = os.path.join('ec2', 'latest', 'metadata.json') + yield (filepath, json.dumps(data['meta-data'])) + + # Openstack style metadata + # TODO(mikal): refactor this later + files = [] + for path in injected_files: + files.append({'path': path, + 'content': injected_files[path]}) + yield ('openstack/2012-08-10/files.json', json.dumps(files)) + yield ('openstack/latest/files.json', json.dumps(files)) + def get_metadata_by_address(address): ctxt = context.get_admin_context() -- cgit