python-tripleoclient/tripleoclient/workflows/roles.py
Harald Jensås 3d615ea413 Dynamic defaults for roles, networks, vips and bm
When running 'overcloud deploy' command look for dynamic
defaults file for these options:
  --roles-file, --network-file, --vip-file and
  --baremetal-deployment

When the option is set by the user, use the user provided
file and make sure a copy is created in the working
directory. If the argument is not set look in the working
directory for the file used previously and use that file.

overclod node, and overcloud network commands require the
user input. But will place a copy in the working_dir for
overcloud deploy.

The depends-on creates these "defaults" by running the
different nova-less/network-v2 export commands when
upgrading the undercloud. With this change the next
'overcloud deploy' after the undercloud upgrade will use
the correct files (unless the user set the args ...)

Conflicts:
  tripleoclient/constants.py
  tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py
  tripleoclient/utils.py
  tripleoclient/v1/overcloud_deploy.py

Depends-On: https://review.opendev.org/795773
Change-Id: I53ba631dc80428c6f1fe71c2bbfb0b5a36dd8f01
(cherry picked from commit 81cd105620)
2021-09-27 12:09:05 +00:00

60 lines
1.6 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import yaml
from tripleoclient import utils
LOG = logging.getLogger(__name__)
def get_roles_data(working_dir, stack_name):
abs_roles_file = utils.get_roles_file_path(working_dir, stack_name)
with open(abs_roles_file, 'r') as fp:
roles_data = yaml.safe_load(fp)
return roles_data
def get_roles(clients,
stack_name,
template,
files,
env_files,
working_dir,
detail=False, valid=False):
roles_data = get_roles_data(working_dir, stack_name)
if detail:
return roles_data
role_names = [role['name'] for role in roles_data]
if not valid:
return role_names
stack_data = utils.build_stack_data(
clients, stack_name, template,
files, env_files)
valid_roles = []
for name in role_names:
role_count = stack_data['heat_resource_tree'][
'parameters'].get(name + 'Count', {}).get(
'default', 0)
if role_count > 0:
valid_roles.append(name)
return valid_roles