Merge "swift-ring-builder --yes option"
This commit is contained in:
commit
c40de1cbc8
@ -97,6 +97,11 @@ Nerd explanation:
|
||||
.PD
|
||||
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.I "\-y, \-\-yes"
|
||||
Assume a yes response to all questions
|
||||
|
||||
.SH COMMANDS
|
||||
|
||||
.PD 0
|
||||
|
@ -181,7 +181,7 @@ def _parse_add_values(argvish):
|
||||
return parsed_devs
|
||||
|
||||
|
||||
def _set_weight_values(devs, weight):
|
||||
def _set_weight_values(devs, weight, opts):
|
||||
if not devs:
|
||||
print('Search value matched 0 devices.\n'
|
||||
'The on-disk ring builder is unchanged.')
|
||||
@ -191,8 +191,9 @@ def _set_weight_values(devs, weight):
|
||||
print('Matched more than one device:')
|
||||
for dev in devs:
|
||||
print(' %s' % format_device(dev))
|
||||
if input('Are you sure you want to update the weight for '
|
||||
'these %s devices? (y/N) ' % len(devs)) != 'y':
|
||||
if not opts.yes and \
|
||||
input('Are you sure you want to update the weight for '
|
||||
'these %s devices? (y/N) ' % len(devs)) != 'y':
|
||||
print('Aborting device modifications')
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
@ -222,7 +223,7 @@ def _parse_set_weight_values(argvish):
|
||||
devs.extend(builder.search_devs(
|
||||
parse_search_value(devstr)) or [])
|
||||
weight = float(weightstr)
|
||||
_set_weight_values(devs, weight)
|
||||
_set_weight_values(devs, weight, opts)
|
||||
else:
|
||||
if len(args) != 1:
|
||||
print(Commands.set_weight.__doc__.strip())
|
||||
@ -231,13 +232,13 @@ def _parse_set_weight_values(argvish):
|
||||
devs.extend(builder.search_devs(
|
||||
parse_search_values_from_opts(opts)) or [])
|
||||
weight = float(args[0])
|
||||
_set_weight_values(devs, weight)
|
||||
_set_weight_values(devs, weight, opts)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
|
||||
def _set_info_values(devs, change):
|
||||
def _set_info_values(devs, change, opts):
|
||||
|
||||
if not devs:
|
||||
print("Search value matched 0 devices.\n"
|
||||
@ -248,8 +249,9 @@ def _set_info_values(devs, change):
|
||||
print('Matched more than one device:')
|
||||
for dev in devs:
|
||||
print(' %s' % format_device(dev))
|
||||
if input('Are you sure you want to update the info for '
|
||||
'these %s devices? (y/N) ' % len(devs)) != 'y':
|
||||
if not opts.yes and \
|
||||
input('Are you sure you want to update the info for '
|
||||
'these %s devices? (y/N) ' % len(devs)) != 'y':
|
||||
print('Aborting device modifications')
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
@ -354,11 +356,11 @@ def _parse_set_info_values(argvish):
|
||||
if change_value or not change:
|
||||
raise ValueError('Invalid set info change value: %s' %
|
||||
repr(argvish[1]))
|
||||
_set_info_values(devs, change)
|
||||
_set_info_values(devs, change, opts)
|
||||
else:
|
||||
devs = builder.search_devs(parse_search_values_from_opts(opts))
|
||||
change = parse_change_values_from_opts(opts)
|
||||
_set_info_values(devs, change)
|
||||
_set_info_values(devs, change, opts)
|
||||
|
||||
|
||||
def _parse_remove_values(argvish):
|
||||
@ -382,7 +384,7 @@ def _parse_remove_values(argvish):
|
||||
devs.extend(builder.search_devs(
|
||||
parse_search_values_from_opts(opts)))
|
||||
|
||||
return devs
|
||||
return (devs, opts)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
exit(EXIT_ERROR)
|
||||
@ -641,6 +643,7 @@ swift-ring-builder <builder_file> add
|
||||
"""
|
||||
swift-ring-builder <builder_file> set_weight <search-value> <weight>
|
||||
[<search-value> <weight] ...
|
||||
[--yes]
|
||||
|
||||
or
|
||||
|
||||
@ -648,6 +651,7 @@ swift-ring-builder <builder_file> set_weight
|
||||
--region <region> --zone <zone> --ip <ip or hostname> --port <port>
|
||||
--replication-ip <r_ip or r_hostname> --replication-port <r_port>
|
||||
--device <device_name> --meta <meta> --weight <weight>
|
||||
[--yes]
|
||||
|
||||
Where <r_ip>, <r_hostname> and <r_port> are replication ip, hostname
|
||||
and port.
|
||||
@ -656,6 +660,8 @@ swift-ring-builder <builder_file> set_weight
|
||||
Resets the devices' weights. No partitions will be reassigned to or from
|
||||
the device until after running 'rebalance'. This is so you can make
|
||||
multiple device changes and rebalance them all just once.
|
||||
|
||||
Option --yes assume a yes response to all questions.
|
||||
"""
|
||||
# if len(argv) < 5 or len(argv) % 2 != 1:
|
||||
if len(argv) < 5:
|
||||
@ -675,6 +681,7 @@ swift-ring-builder <builder_file> set_weight
|
||||
swift-ring-builder <builder_file> set_info
|
||||
<search-value> <ip>:<port>[R<r_ip>:<r_port>]/<device_name>_<meta>
|
||||
[<search-value> <ip>:<port>[R<r_ip>:<r_port>]/<device_name>_<meta>] ...
|
||||
[--yes]
|
||||
|
||||
or
|
||||
|
||||
@ -687,6 +694,7 @@ swift-ring-builder <builder_file> set_info
|
||||
--change-replication-port <r_port>
|
||||
--change-device <device_name>
|
||||
--change-meta <meta>
|
||||
[--yes]
|
||||
|
||||
Where <r_ip>, <r_hostname> and <r_port> are replication ip, hostname
|
||||
and port.
|
||||
@ -699,6 +707,8 @@ swift-ring-builder <builder_file> set_info
|
||||
<ip>:<port>/<device_name>_<meta> parameter; just give what you
|
||||
want to change. For instance set_info d74 _"snet: 5.6.7.8" would
|
||||
just update the meta data for device id 74.
|
||||
|
||||
Option --yes assume a yes response to all questions.
|
||||
"""
|
||||
if len(argv) < 5:
|
||||
print(Commands.set_info.__doc__.strip())
|
||||
@ -719,6 +729,7 @@ swift-ring-builder <builder_file> set_info
|
||||
def remove():
|
||||
"""
|
||||
swift-ring-builder <builder_file> remove <search-value> [search-value ...]
|
||||
[--yes]
|
||||
|
||||
or
|
||||
|
||||
@ -726,6 +737,7 @@ swift-ring-builder <builder_file> remove
|
||||
--region <region> --zone <zone> --ip <ip or hostname> --port <port>
|
||||
--replication-ip <r_ip or r_hostname> --replication-port <r_port>
|
||||
--device <device_name> --meta <meta> --weight <weight>
|
||||
[--yes]
|
||||
|
||||
Where <r_ip>, <r_hostname> and <r_port> are replication ip, hostname
|
||||
and port.
|
||||
@ -737,6 +749,8 @@ swift-ring-builder <builder_file> remove
|
||||
remove command. This will not take effect until after running 'rebalance'.
|
||||
This is so you can make multiple device changes and rebalance them all just
|
||||
once.
|
||||
|
||||
Option --yes assume a yes response to all questions.
|
||||
"""
|
||||
if len(argv) < 4:
|
||||
print(Commands.remove.__doc__.strip())
|
||||
@ -744,7 +758,7 @@ swift-ring-builder <builder_file> remove
|
||||
print(parse_search_value.__doc__.strip())
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
devs = _parse_remove_values(argv[3:])
|
||||
devs, opts = _parse_remove_values(argv[3:])
|
||||
|
||||
if not devs:
|
||||
print('Search value matched 0 devices.\n'
|
||||
@ -755,8 +769,9 @@ swift-ring-builder <builder_file> remove
|
||||
print('Matched more than one device:')
|
||||
for dev in devs:
|
||||
print(' %s' % format_device(dev))
|
||||
if input('Are you sure you want to remove these %s '
|
||||
'devices? (y/N) ' % len(devs)) != 'y':
|
||||
if not opts.yes and \
|
||||
input('Are you sure you want to remove these %s '
|
||||
'devices? (y/N) ' % len(devs)) != 'y':
|
||||
print('Aborting device removals')
|
||||
exit(EXIT_ERROR)
|
||||
|
||||
|
@ -586,6 +586,8 @@ def parse_args(argvish):
|
||||
help="Device name (e.g. md0, sdb1) for change")
|
||||
parser.add_option('-M', '--change-meta', type="string", default="",
|
||||
help="Extra device info (just a string) for change")
|
||||
parser.add_option('-y', '--yes', default=False, action="store_true",
|
||||
help="Assume a yes response to all questions")
|
||||
return parser.parse_args(argvish)
|
||||
|
||||
|
||||
|
@ -233,7 +233,7 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
|
||||
# Test no devices
|
||||
# _set_weight_values doesn't take argv-like arguments
|
||||
self.assertSystemExit(
|
||||
EXIT_ERROR, ringbuilder._set_weight_values, [], 100)
|
||||
EXIT_ERROR, ringbuilder._set_weight_values, [], 100, {})
|
||||
|
||||
def test_parse_set_weight_values_number_of_arguments(self):
|
||||
# Test Number of arguments abnormal
|
||||
@ -249,7 +249,7 @@ class TestCommands(unittest.TestCase, RunSwiftRingBuilderMixin):
|
||||
# Test no devices
|
||||
# _set_info_values doesn't take argv-like arguments
|
||||
self.assertSystemExit(
|
||||
EXIT_ERROR, ringbuilder._set_info_values, [], 100)
|
||||
EXIT_ERROR, ringbuilder._set_info_values, [], 100, {})
|
||||
|
||||
def test_parse_set_info_values_number_of_arguments(self):
|
||||
# Test Number of arguments abnormal
|
||||
|
Loading…
Reference in New Issue
Block a user