|
20 | 20 | "-u", |
21 | 21 | "--upload", |
22 | 22 | help="Upload created valid preconfigs to Orchestrator", |
23 | | - type=bool, |
24 | | - default=False, |
| 23 | + action=argparse.BooleanOptionalAction, |
25 | 24 | ) |
26 | 25 | parser.add_argument( |
27 | 26 | "-aa", |
28 | 27 | "--autoapply", |
29 | 28 | help="Mark preconfigs for auto-approve", |
30 | | - type=bool, |
31 | | - default=False, |
| 29 | + action=argparse.BooleanOptionalAction, |
32 | 30 | ) |
33 | 31 | parser.add_argument( |
34 | 32 | "-j", |
|
171 | 169 | auto_apply=auto_apply, |
172 | 170 | ) |
173 | 171 |
|
174 | | - # If the validate function passes on Orchestrator write |
175 | | - # preconfig to local file and check if uploading to Orchestrator |
176 | | - if validate.status_code == 200: |
| 172 | + # Write local YAML file to see resulting YAML file locally |
| 173 | + # whether validate passes or fails |
| 174 | + yaml_filename = f'{row["hostname"]}_preconfig.yml' |
| 175 | + with open(output_directory + yaml_filename, "w") as preconfig_file: |
| 176 | + write_data = preconfig_file.write(yaml_preconfig) |
177 | 177 |
|
178 | | - # Write local YAML file |
179 | | - yaml_filename = "{}_preconfig.yml".format(row["hostname"]) |
180 | | - with open(output_directory + yaml_filename, "w") as preconfig_file: |
181 | | - write_data = preconfig_file.write(yaml_preconfig) |
| 178 | + # If the validate function passes on Orchestrator, move on |
| 179 | + # to check if uploading to Orchestrator option selected |
| 180 | + if validate.status_code == 200: |
182 | 181 |
|
183 | 182 | # If upload option was chosen, upload preconfig to |
184 | 183 | # Orchestrator with selected auto-apply settings |
|
191 | 190 | # against a discovered appliance |
192 | 191 | # Additionally a comment is added with the current |
193 | 192 | # date |
| 193 | + comment_timestamp = datetime.date.today().strftime("%d %B %Y") |
194 | 194 | orch.create_preconfig( |
195 | 195 | preconfig_name=row["hostname"], |
196 | 196 | yaml_preconfig=yaml_preconfig, |
197 | 197 | auto_apply=auto_apply, |
198 | 198 | tag=row["hostname"], |
199 | | - comment="Created/Uploaded @ {}".format( |
200 | | - datetime.date.today().strftime("%d %B %Y") |
201 | | - ), |
| 199 | + comment=f"Created/Uploaded @ {comment_timestamp}", |
202 | 200 | ) |
203 | | - print("Posted EC Preconfig {}".format(row["hostname"])) |
| 201 | + print(f'Posted EC Preconfig {row["hostname"]}') |
204 | 202 | else: |
205 | 203 | pass |
206 | 204 | else: |
207 | 205 | print( |
208 | | - "Preconfig for {} failed validation | error: {}".format( |
209 | | - row["hostname"], validate.text |
210 | | - ) |
| 206 | + f'Preconfig for {row["hostname"]}' |
| 207 | + f" failed validation | error: {validate.text}" |
211 | 208 | ) |
212 | 209 | # Write local YAML file of failed config for reference |
213 | | - yaml_filename = "{}_preconfig-FAILED.yml".format(row["hostname"]) |
| 210 | + yaml_filename = f'{row["hostname"]}_preconfig-FAILED.yml' |
214 | 211 | with open(output_directory + yaml_filename, "w") as preconfig_file: |
215 | 212 | write_data = preconfig_file.write(yaml_preconfig) |
216 | 213 |
|
|
0 commit comments