add mechanism for general purpose parameter passing to Image Factory

We originally added semi-generic parameter passing for OVA support and
then overloaded it for Vagrant support, before breaking that back out
as specific image types.

This change adds a fairly generic mechanism for parameter passthrough
to plugins and the base builder that does not require patching the
builder and CLI each time a new class of parameter is added to Factory.

The immediate reason for doing this is to expose the Docker plugin's
ability to set custom labels, environments and commands, but it is
likely to be useful for other things in the future.
This commit is contained in:
Ian McLeod 2015-10-27 22:30:58 -05:00 committed by Mike McLean
parent 262ec7a7da
commit 66fdccd1b3
2 changed files with 48 additions and 6 deletions

View file

@ -5306,6 +5306,11 @@ def handle_image_build(options, session, args):
parser.add_option("--ova-option", action="append",
help=_("Override a value in the OVA description XML. Provide a value " +
"in a name=value format, such as 'ovf_memory_mb=6144'"))
parser.add_option("--factory-parameter", nargs=2, action="append",
help=_("Pass a parameter to Image Factory. The results are highly specific " +
"to the image format being created. This is a two argument parameter " +
"that can be specified an arbitrary number of times. For example: "
"--factory-parameter docker_cmd '[ \"/bin/echo Hello World\" ]'"))
parser.add_option("--release", help=_("Forcibly set the release field"))
parser.add_option("--repo", action="append",
help=_("Specify a repo that will override the repo used to install " +
@ -5355,6 +5360,14 @@ def handle_image_build(options, session, args):
for k, v in config.items(section):
task_options.ova_option.append('%s=%s' % (k, v))
# as do factory-parameters
section = 'factory-parameters'
if config.has_section(section):
task_options.factory_parameter = [ ]
for k, v in config.items(section):
# We do this, rather than a dict, to match what argparse spits out
task_options.factory_parameter.append( (k, v) )
else:
if len(args) < 5:
parser.error(_("At least five arguments are required: a name, " +
@ -5483,7 +5496,7 @@ def _build_image_oz(options, task_opts, session, args):
hub_opts = {}
for opt in ('ksurl', 'ksversion', 'kickstart', 'scratch', 'repo',
'release', 'skip_tag', 'specfile', 'distro', 'format',
'disk_size', 'ova_option'):
'disk_size', 'ova_option', 'factory_parameter'):
val = getattr(task_opts, opt, None)
if val is not None:
hub_opts[opt] = val