Add --set argument to prepare command
This new argument will allow special ceph variables to be added to the template file overcloud_containers.yaml.j2. For example if the following existed in the template file: {% set ceph_namespace=ceph_namespace or "ceph" %} {% set ceph_daemon=ceph_daemon or "daemon" %} {% set ceph_tag=ceph_tag or "tag-build-master-jewel-centos-7" %} - imagename: "{{ ceph_namespace }}/{{ ceph_daemon }}:{{ ceph_tag }}" Then the --set argument will allow making substitutions on these values, for example: openstack overcloud container image prepare \ --namespace tripleoupstream \ --tag latest \ --images-file overcloud_containers.yaml \ --set ceph_namespace=myceph \ --set ceph_tag=latest \ --env-file $HOME/docker_registry.yaml Change-Id: Ie12dbab0f4d7f20d14a764abb9095fd8b326c700
This commit is contained in:
parent
66c902a2b6
commit
b1df493d43
@ -120,6 +120,12 @@ class TestContainerImagePrepare(TestPluginV1):
|
||||
images_file,
|
||||
'--env-file',
|
||||
env_file,
|
||||
'--set',
|
||||
'ceph_namespace=myceph',
|
||||
'--set',
|
||||
'ceph_image=mydaemon',
|
||||
'--set',
|
||||
'ceph_tag=mytag',
|
||||
]
|
||||
self.cmd.app.command_options = arglist
|
||||
verifylist = []
|
||||
@ -144,7 +150,10 @@ class TestContainerImagePrepare(TestPluginV1):
|
||||
name_prefix='os-',
|
||||
name_suffix='foo',
|
||||
namespace='tripleo',
|
||||
tag='passed-ci'
|
||||
tag='passed-ci',
|
||||
ceph_image='mydaemon',
|
||||
ceph_namespace='myceph',
|
||||
ceph_tag='mytag'
|
||||
)
|
||||
ci_data = {
|
||||
'container_images': [{
|
||||
|
@ -22,6 +22,7 @@ import sys
|
||||
import tempfile
|
||||
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions as oscexc
|
||||
from osc_lib.i18n import _
|
||||
import yaml
|
||||
|
||||
@ -218,6 +219,13 @@ class PrepareImageFiles(command.Command):
|
||||
help=_("Override the default name suffix substitution.\n"
|
||||
"Default is empty."),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--set',
|
||||
metavar='<variable=value>',
|
||||
action='append',
|
||||
help=_('Set the value of a variable in the template, even if it '
|
||||
'has no dedicated argument such as "--suffix".')
|
||||
)
|
||||
parser.add_argument(
|
||||
"--exclude",
|
||||
dest="excludes",
|
||||
@ -244,6 +252,18 @@ class PrepareImageFiles(command.Command):
|
||||
)
|
||||
return parser
|
||||
|
||||
def parse_set_values(self, subs, set_values):
|
||||
if not set_values:
|
||||
return
|
||||
for s in set_values:
|
||||
try:
|
||||
(n, v) = s.split(('='), 1)
|
||||
subs[n] = v
|
||||
except ValueError:
|
||||
msg = _('Malformed --set(%s). '
|
||||
'Use the variable=value format.') % s
|
||||
raise oscexc.CommandError(msg)
|
||||
|
||||
def write_env_file(self, params, env_file):
|
||||
|
||||
with os.fdopen(os.open(env_file,
|
||||
@ -265,6 +285,7 @@ class PrepareImageFiles(command.Command):
|
||||
'name_prefix': parsed_args.prefix,
|
||||
'name_suffix': parsed_args.suffix,
|
||||
}
|
||||
self.parse_set_values(subs, parsed_args.set)
|
||||
|
||||
def ffunc(entry):
|
||||
imagename = entry.get('imagename', '')
|
||||
|
Loading…
Reference in New Issue
Block a user