|
13 | 13 | import yaml |
14 | 14 | import logging |
15 | 15 | import traceback |
| 16 | +import os |
16 | 17 | log = logging.getLogger() |
17 | 18 |
|
18 | 19 |
|
@@ -118,22 +119,42 @@ def generate_topology_config_file(output_file: str, input_file: str, block_sizes |
118 | 119 | log.info("Finished.") |
119 | 120 |
|
120 | 121 |
|
| 122 | +def cleanup_topology_config_file(file_path): |
| 123 | + """Cleanup topology.conf file.""" |
| 124 | + try: |
| 125 | + if os.path.exists(file_path): |
| 126 | + log.info("Cleaning up %s", file_path) |
| 127 | + os.remove(file_path) |
| 128 | + except Exception as err: |
| 129 | + log.warning("Unable to delete %s due to %s", file_path, err) |
| 130 | + |
| 131 | + |
121 | 132 | def main(): |
122 | 133 | try: |
123 | 134 | logging.basicConfig( |
124 | 135 | level=logging.INFO, format="%(asctime)s - [%(name)s:%(funcName)s] - %(levelname)s - %(message)s" |
125 | 136 | ) |
126 | 137 | log.info("Running ParallelCluster Topology Config Generator") |
127 | 138 | parser = argparse.ArgumentParser(description="Take in Topology configuration generator related parameters") |
| 139 | + cleanup_or_generate_exclusive_group = parser.add_mutually_exclusive_group(required=True) |
128 | 140 | parser.add_argument("--output-file", help="The output file for generated topology.conf", required=True) |
129 | 141 | parser.add_argument( |
130 | 142 | "--input-file", |
131 | 143 | help="Yaml file containing pcluster CLI configuration file with default values", |
132 | 144 | required=True, |
133 | 145 | ) |
134 | | - parser.add_argument("--block-sizes", help="Block Size of topology.conf", required=True) |
| 146 | + cleanup_or_generate_exclusive_group.add_argument("--block-sizes", help="Block Sizes of topology.conf") |
| 147 | + cleanup_or_generate_exclusive_group.add_argument( |
| 148 | + "--cleanup", |
| 149 | + action="store_true", |
| 150 | + help="Cleanup topology.conf", |
| 151 | + ) |
135 | 152 | args = parser.parse_args() |
136 | | - generate_topology_config_file(args.output_file, args.input_file, args.block_sizes) |
| 153 | + if args.cleanup: |
| 154 | + cleanup_topology_config_file(args.output_file) |
| 155 | + else: |
| 156 | + generate_topology_config_file(args.output_file, args.input_file, args.block_sizes) |
| 157 | + log.info("Completed Execution of ParallelCluster Topology Config Generator") |
137 | 158 | except Exception as e: |
138 | 159 | log.exception("Failed to generate Topology.conf, exception: %s", e) |
139 | 160 | raise |
|
0 commit comments