Add option to override confirmation in yaml-nic-config-2-script.py

This change adds the option to override the user input confirmation
to overwrite the nic template file. This is required when the script
is used inside automated jobs.

Closes-bug: 1770296

Change-Id: Ic8275bb3a944e503c73ab06c3d5140ea3563c0a6
This commit is contained in:
Marius Cornea 2018-05-09 21:46:26 -04:00
parent 7f23133651
commit 553554ad72

View File

@ -32,6 +32,11 @@ def parse_opts(argv):
default="network/scripts/run-os-net-config.sh")
parser.add_argument('files', nargs="+", metavar='<file>',
help='List of one or more NIC config files to convert')
parser.add_argument('--yes',
action='store_true',
help=("Use --yes to skip the confirmation "
"to overwrite the original config file "),
)
opts = parser.parse_args(argv[1:])
return opts
@ -240,7 +245,7 @@ for base_path in opts.files:
print('The yaml file will be overwritten and the original saved as %s'
% backup_filename)
if not raw_input("Overwrite %s? [y/n] " % base_path).lower() == 'y':
if not (opts.yes or raw_input("Overwrite %s? [y/n] " % base_path).lower() == 'y'):
print("Skipping file %s" % base_path)
continue