Add --json-output option to tripleo-build-images

Updates the tripleo-build-images script and tripleo_common.image module
to support a --json-output option. The option will output the image
definitions after the yaml formats have been merged, allowing for
programmatic usage by external tools. JSON is used so that jq can be
used.

This change also updates the image-yaml definitions to be inline with
what's currently being used in python-tripleoclient. I can split this
out into a separate change if folks feel strongly about that.

Change-Id: I37330c6d068de4d9e717ec073fc3ddb758d65cb9
This commit is contained in:
James Slagle 2016-06-09 13:07:22 -04:00
parent 6ae90c80e6
commit 5ea3166880
5 changed files with 19 additions and 5 deletions

View File

@ -5,12 +5,12 @@ disk_images:
type: qcow2
distro: centos7
elements:
- selinux-permissive delorean-repo centos-cloud-repo epel
- selinux-permissive delorean-repo epel
-
imagename: ramdisk_agent
arch: amd64
type: qcow2
distro: centos7
elements:
- selinux-permissive delorean-repo centos-cloud-repo epel
- selinux-permissive delorean-repo epel

View File

@ -4,7 +4,7 @@ disk_images:
arch: amd64
type: qcow2
elements:
- sysctl hosts baremetal dhcp-all-interfaces os-collect-config overcloud-full overcloud-controller overcloud-compute overcloud-ceph-storage heat-config-puppet heat-config-script puppet-modules hiera os-net-config stable-interface-names grub2 element-manifest network-gateway dynamic-login undercloud-package-install pip-and-virtualenv-override
- sysctl hosts baremetal dhcp-all-interfaces os-collect-config overcloud-full overcloud-controller overcloud-compute overcloud-ceph-storage heat-config-puppet heat-config-script puppet-modules hiera os-net-config stable-interface-names grub2 element-manifest network-gateway dynamic-login enable-packages-install pip-and-virtualenv-override
packages:
- python-psutil
- python-debtcollector
@ -23,7 +23,7 @@ disk_images:
arch: amd64
type: qcow2
elements:
- ironic-agent dynamic-login element-manifest network-gateway epel undercloud-package-install pip-and-virtualenv-override
- ironic-agent dynamic-login element-manifest network-gateway epel enable-packages-install pip-and-virtualenv-override
packages:
- python-hardware-detect
options:

View File

@ -50,6 +50,10 @@ _opts = [
default=False,
help="""Skip build if cached image exists."""
),
cfg.BoolOpt('json-output',
default=False,
help="""Skip build and only output the configuration in a """
"""structured JSON format.""")
]
CONF.register_group(image_opt_group)
CONF.register_cli_opts(_opts, group=image_opt_group)
@ -62,7 +66,10 @@ def main(argv=sys.argv):
manager = ImageBuildManager(CONF.image.config_file,
output_directory=CONF.image.output_directory,
skip=CONF.image.skip)
manager.build()
if CONF.image.json_output:
manager.json_output()
else:
manager.build()
if __name__ == '__main__':
sys.exit(main(sys.argv))

View File

@ -28,6 +28,7 @@ scripts =
data_files =
lib/heat/undercloud_heat_plugins = undercloud_heat_plugins/*
share/tripleo-common/image-yaml = image-yaml/*
[build_sphinx]
source-dir = doc/source

View File

@ -15,6 +15,7 @@
import six
import json
import os
import yaml
@ -74,3 +75,8 @@ class BaseImageManager(object):
self.logger.error('No config file exists at: %s' % config_file)
raise IOError('No config file exists at: %s' % config_file)
return [x for x in config_data.values()]
def json_output(self):
self.logger.info('Using config files: %s' % self.config_files)
disk_images = self.load_config_files(self.CONFIG_SECTIONS[0])
print(json.dumps(disk_images))