Add generic methods to upload files to plan

Either by local filename or by content directly. These will come in
handy for preserving content on plan update.

Change-Id: I5dea8c71b86bd35883cbe417e7aba01d69c9ab26
Partial-Bug: #1749700
(cherry picked from commit ef23c77ee8)
This commit is contained in:
Jiri Stransky 2018-02-13 12:21:15 +01:00 committed by mandreou
parent 7c4c3943a5
commit 6335326ebb
1 changed files with 18 additions and 14 deletions

View File

@ -39,29 +39,23 @@ def _upload_templates(swift_client, container_name, tht_root, roles_file=None,
tarball.tarball_extract_to_swift_container(
swift_client, tmp_tarball.name, container_name)
# Allow optional override of the roles_data.yaml file
# Optional override of the roles_data.yaml file
if roles_file:
with open(roles_file) as rf:
swift_client.put_object(container_name,
constants.OVERCLOUD_ROLES_FILE,
rf)
_upload_file(swift_client, container_name,
constants.OVERCLOUD_ROLES_FILE, roles_file)
# Allow optional override of the network_data.yaml file
# Optional override of the network_data.yaml file
if networks_file:
with open(networks_file) as rf:
swift_client.put_object(container_name,
constants.OVERCLOUD_NETWORKS_FILE,
rf)
_upload_file(swift_client, container_name,
constants.OVERCLOUD_NETWORKS_FILE, networks_file)
# Optional override of the plan-environment.yaml file
if plan_env_file:
# TODO(jpalanis): Instead of overriding default file,
# merging the user override plan-environment with default
# plan-environment file will avoid explict merging issues.
with open(plan_env_file) as pf:
swift_client.put_object(container_name,
constants.PLAN_ENVIRONMENT,
pf)
_upload_file(swift_client, container_name,
constants.PLAN_ENVIRONMENT, plan_env_file)
def _create_update_deployment_plan(clients, workflow, **workflow_input):
@ -204,6 +198,16 @@ def update_plan_from_templates(clients, name, tht_root, roles_file=None,
source_url=None, plan_environment=env)
def _upload_file(swift_client, container, filename, local_filename):
with open(local_filename) as file_content:
swift_client.put_object(container, filename, file_content)
# short function, just alias for interface parity with _upload_plan_file
def _upload_file_content(swift_client, container, filename, content):
swift_client.put_object(container, filename, content)
def _update_user_environment(swift_client, name, user_params, filename):
if user_params:
try: