|
1 | 1 | #!/usr/bin/env python3 |
2 | | - |
| 2 | +import shutil |
3 | 3 | import sys |
4 | 4 | import os |
5 | 5 | import argparse |
|
12 | 12 | from openstack.config import loader |
13 | 13 |
|
14 | 14 | from .entities import WorkloadGeneratorDomain |
15 | | -from .entities.helpers import setup_logging, cloud_checker, item_checker, Config |
| 15 | +from .entities.helpers import setup_logging, cloud_checker, item_checker, Config, iso_timestamp, deep_merge_dict |
| 16 | + |
16 | 17 |
|
17 | 18 | LOGGER = logging.getLogger() |
18 | 19 |
|
@@ -180,10 +181,26 @@ def establish_connection(): |
180 | 181 | machine_obj.delete_machine() |
181 | 182 | if args.generate_clouds_yaml: |
182 | 183 | LOGGER.info(f"Creating a a clouds yaml : {args.generate_clouds_yaml}") |
183 | | - clouds_yaml_data = {"clouds": clouds_yaml_data} |
| 184 | + |
| 185 | + clouds_yaml_data_new = {"clouds": clouds_yaml_data} |
| 186 | + if os.path.exists(args.generate_clouds_yaml): |
| 187 | + with open(args.generate_clouds_yaml, "r") as file: |
| 188 | + existing_data = yaml.safe_load(file) |
| 189 | + backup_file = f"{args.generate_clouds_yaml}_{iso_timestamp()}" |
| 190 | + logging.warning( |
| 191 | + f"File {args.generate_clouds_yaml}, making an backup to {backup_file} and adding the new values" |
| 192 | + ) |
| 193 | + shutil.copy2( |
| 194 | + args.generate_clouds_yaml, |
| 195 | + f"{args.generate_clouds_yaml}_{iso_timestamp()}", |
| 196 | + ) |
| 197 | + clouds_yaml_data_new = deep_merge_dict( |
| 198 | + existing_data, clouds_yaml_data_new |
| 199 | + ) |
| 200 | + |
184 | 201 | with open(args.generate_clouds_yaml, "w") as file: |
185 | 202 | yaml.dump( |
186 | | - clouds_yaml_data, |
| 203 | + clouds_yaml_data_new, |
187 | 204 | file, |
188 | 205 | default_flow_style=False, |
189 | 206 | explicit_start=True, |
|
0 commit comments