Merge "Add --environment-directory to the prepare command" into stable/pike

This commit is contained in:
Zuul 2017-11-10 13:25:07 +00:00 committed by Gerrit Code Review
commit 4198fe6dc0
4 changed files with 45 additions and 17 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
Add '--environment-directory' option to the `openstack overcloud container
image prepare` command.

View File

@ -16,6 +16,7 @@
from __future__ import print_function
import csv
import datetime
import glob
import hashlib
import json
import logging
@ -768,3 +769,20 @@ def relative_link_replacement(link_replacement, current_dir):
return {k: os.path.relpath(v, current_dir)
for k, v in six.iteritems(link_replacement)}
def load_environment_directories(directories):
log = logging.getLogger(__name__ + ".load_environment_directories")
if os.environ.get('TRIPLEO_ENVIRONMENT_DIRECTORY'):
directories.append(os.environ.get('TRIPLEO_ENVIRONMENT_DIRECTORY'))
environments = []
for d in directories:
if os.path.exists(d) and d != '.':
log.debug("Environment directory: %s" % d)
for f in sorted(glob.glob(os.path.join(d, '*.yaml'))):
log.debug("Environment directory file: %s" % f)
if os.path.isfile(f):
environments.append(f)
return environments

View File

@ -32,6 +32,7 @@ from tripleo_common.image import image_uploader
from tripleo_common.image import kolla_builder
from tripleoclient import constants
from tripleoclient import utils
class UploadImage(command.Command):
@ -273,6 +274,17 @@ class PrepareImageFiles(command.Command):
'images used by containerized services. (Can be specified '
'more than once.)')
)
parser.add_argument(
'--environment-directory', metavar='<HEAT ENVIRONMENT DIRECTORY>',
action='append', dest='environment_directories',
default=[os.path.join(os.environ.get('HOME', ''), '.tripleo',
'environments')],
help=_('Environment file directories that are automatically '
'added to the update command. Entries will be filtered '
'to only contain images used by containerized services. '
'Can be specified more than once. Files in directories are '
'loaded in ascending sort order.')
)
parser.add_argument(
"--env-file",
dest="output_env_file",
@ -382,8 +394,16 @@ class PrepareImageFiles(command.Command):
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
env_files = []
if parsed_args.environment_directories:
env_files.extend(utils.load_environment_directories(
parsed_args.environment_directories))
if parsed_args.environment_files:
env_files.extend(parsed_args.environment_files)
service_filter = self.build_service_filter(
parsed_args.environment_files, parsed_args.roles_file)
env_files, parsed_args.roles_file)
neutron_driver = None
if service_filter:

View File

@ -15,7 +15,6 @@
from __future__ import print_function
import argparse
import glob
import logging
import os
import os.path
@ -239,20 +238,6 @@ class DeployOvercloud(command.Command):
run_validations=run_validations,
skip_deploy_identifier=skip_deploy_identifier)
def _load_environment_directories(self, directories):
if os.environ.get('TRIPLEO_ENVIRONMENT_DIRECTORY'):
directories.append(os.environ.get('TRIPLEO_ENVIRONMENT_DIRECTORY'))
environments = []
for d in directories:
if os.path.exists(d) and d != '.':
self.log.debug("Environment directory: %s" % d)
for f in sorted(glob.glob(os.path.join(d, '*.yaml'))):
self.log.debug("Environment directory file: %s" % f)
if os.path.isfile(f):
environments.append(f)
return environments
def _process_and_upload_environment(self, container_name,
env, moved_files, tht_root):
"""Process the environment and upload to Swift
@ -419,7 +404,7 @@ class DeployOvercloud(command.Command):
created_env_files = []
if parsed_args.environment_directories:
created_env_files.extend(self._load_environment_directories(
created_env_files.extend(utils.load_environment_directories(
parsed_args.environment_directories))
env.update(self._create_parameters_env(parameters))