multi-rhel images prepare default

New arguments:
 --enable-multi-rhel : flag to create multi-rhel prepare
 --exclude: list of containers to exclude
 --minor-override: tags to override on the minor release
 --major-override: tags to override on the mayor release
 --roles: list of the roles
 --role-file: role_data.yaml patch

Example:

openstack tripleo container image prepare default \
  --enable-multi-rhel --exclude nova-compute \
  --exclude nova-libvirt \
  --exclude ovn-controller \
  --major-override "{'tag':'other_tag'}" \
  --minor-override "{'tag':'my_tag'}" \
  --roles ComputeEL8 --roles Controller --roles Compute

openstack tripleo container image prepare default \
  --enable-multi-rhel --exclude nova-compute \
  --exclude nova-libvirt \
  --exclude ovn-controller \
  --major-override "{'tag':'other_tag'}" \
  --minor-override "{'tag':'my_tag'}" \
  --role-file /home/stack/role_data.yaml

This will generate a file like:

https://paste.opendev.org/show/b6oRQ1sTmWW4fvbbHVWG/

Change-Id: Ib834234c57ff525bb2f7a4993534515091a7138a
This commit is contained in:
Juan Badia Payno
2023-01-11 16:51:56 +01:00
parent 21d95d299f
commit 43789fb73a

View File

@@ -444,6 +444,48 @@ class TripleOImagePrepareDefault(command.Command):
'registries. Do not use this for an overcloud that '
'may not have network connectivity to a remote registry.')
)
parser.add_argument(
'--enable-multi-rhel',
dest='multi_rhel',
action='store_true',
default=False,
help=_('Use this flag to enable multi-rhel')
)
parser.add_argument(
'--exclude',
dest='exclude',
action='append',
default=[],
help=_('List of services to include/exclude')
)
parser.add_argument(
'--major-override',
dest='major',
action='store',
default='{}',
help=_('The override parameters for major release')
)
parser.add_argument(
'--minor-override',
dest='minor',
action='store',
default='{}',
help=_('The override parameters for minor release')
)
parser.add_argument(
'--roles',
dest='roles',
action='append',
default=['ComputeEL8'],
help=_('List of roles')
)
parser.add_argument(
'--role-file',
dest='rolefile',
action='store',
default='',
help=_('role_data.yaml file')
)
return parser
def take_action(self, parsed_args):
@@ -467,7 +509,47 @@ class TripleOImagePrepareDefault(command.Command):
' with ContainerImageRegistryCredentials for the '
'registries requiring authentication.')
params['ContainerImageRegistryLogin'] = True
if parsed_args.multi_rhel:
cip_exc = copy.deepcopy(cip)
cip_inc = copy.deepcopy(cip)
if parsed_args.major is not None:
major = yaml.safe_load(parsed_args.major)
if len(parsed_args.exclude) > 0:
cip_exc[0]['excludes'] = copy.deepcopy(parsed_args.exclude)
cip_inc[0]['includes'] = copy.deepcopy(parsed_args.exclude)
if parsed_args.minor is not None:
minor = yaml.safe_load(parsed_args.minor)
for key in minor.keys():
if key in cip_inc[0]['set'].keys():
cip_inc[0]['set'][key] = minor[key]
if parsed_args.major is not None:
major = yaml.safe_load(parsed_args.major)
for key in major.keys():
if key in cip_exc[0]['set'].keys():
cip_exc[0]['set'][key] = major[key]
params_set = params['ContainerImagePrepare'][0]['set']
if key in params_set.keys():
params_set[key] = major[key]
base_role = [cip_exc[0], cip_inc[0]]
if parsed_args.rolefile != '':
read_roles = []
if os.path.exists(parsed_args.rolefile):
with open(parsed_args.rolefile) as file:
roles = yaml.safe_load(file)
self.log.fatal('{} file'.format(parsed_args.rolefile))
self.log.fatal('{} roles'.format(roles))
for role in roles:
read_roles.append(role['name'])
else:
self.log.fatal('[ERROR] {} role file does'
' not exits'.format(parsed_args.rolefile))
roles = read_roles
else:
roles = parsed_args.roles
for role in roles:
params[('{}ContainerImagePrepare').format(role)] = base_role
self.app.command_options = [word.replace("\n", "")
for word in self.app.command_options]
env_data = build_env_file(params, self.app.command_options)
self.app.stdout.write(env_data)
if parsed_args.output_env_file: