Merge "Refactoring format_device function"
This commit is contained in:
commit
59f6779603
@ -40,12 +40,11 @@ def format_device(dev):
|
|||||||
"""
|
"""
|
||||||
Format a device for display.
|
Format a device for display.
|
||||||
"""
|
"""
|
||||||
if ':' in dev['ip']:
|
copy_dev = dev.copy()
|
||||||
return ('d%(id)sr%(region)sz%(zone)s-'
|
if ':' in copy_dev['ip']:
|
||||||
'[%(ip)s]:%(port)s/%(device)s_"%(meta)s"') % dev
|
copy_dev['ip'] = '[' + copy_dev['ip'] + ']'
|
||||||
else:
|
return ('d%(id)sr%(region)sz%(zone)s-%(ip)s:%(port)s/%(device)s_'
|
||||||
return ('d%(id)sr%(region)sz%(zone)s-'
|
'"%(meta)s"' % copy_dev)
|
||||||
'%(ip)s:%(port)s/%(device)s_"%(meta)s"') % dev
|
|
||||||
|
|
||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
@ -299,16 +298,9 @@ swift-ring-builder <builder_file> add
|
|||||||
'weight': weight, 'meta': meta})
|
'weight': weight, 'meta': meta})
|
||||||
new_dev = builder.search_devs(
|
new_dev = builder.search_devs(
|
||||||
'r%dz%d-%s:%s/%s' %
|
'r%dz%d-%s:%s/%s' %
|
||||||
(region, zone, ip, port, device_name))[0]['id']
|
(region, zone, ip, port, device_name))[0]
|
||||||
if ':' in ip:
|
print('Device %s with %s weight got id %s' %
|
||||||
print(
|
(format_device(new_dev), weight, new_dev['id']))
|
||||||
'Device r%dz%d-[%s]:%s/%s_"%s" with %s weight got id %s' %
|
|
||||||
(region, zone, ip, port,
|
|
||||||
device_name, meta, weight, new_dev))
|
|
||||||
else:
|
|
||||||
print('Device r%dz%d-%s:%s/%s_"%s" with %s weight got id %s' %
|
|
||||||
(region, zone, ip, port,
|
|
||||||
device_name, meta, weight, new_dev))
|
|
||||||
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
|
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
|
||||||
exit(EXIT_SUCCESS)
|
exit(EXIT_SUCCESS)
|
||||||
|
|
||||||
@ -340,16 +332,15 @@ swift-ring-builder <builder_file> set_weight <search-value> <weight>
|
|||||||
if len(devs) > 1:
|
if len(devs) > 1:
|
||||||
print 'Matched more than one device:'
|
print 'Matched more than one device:'
|
||||||
for dev in devs:
|
for dev in devs:
|
||||||
print ' d%(id)sz%(zone)s-%(ip)s:%(port)s/%(device)s_' \
|
print ' %s' % format_device(dev)
|
||||||
'"%(meta)s"' % dev
|
|
||||||
if raw_input('Are you sure you want to update the weight for '
|
if raw_input('Are you sure you want to update the weight for '
|
||||||
'these %s devices? (y/N) ' % len(devs)) != 'y':
|
'these %s devices? (y/N) ' % len(devs)) != 'y':
|
||||||
print 'Aborting device modifications'
|
print 'Aborting device modifications'
|
||||||
exit(EXIT_ERROR)
|
exit(EXIT_ERROR)
|
||||||
for dev in devs:
|
for dev in devs:
|
||||||
builder.set_dev_weight(dev['id'], weight)
|
builder.set_dev_weight(dev['id'], weight)
|
||||||
print 'd%(id)sz%(zone)s-%(ip)s:%(port)s/%(device)s_' \
|
print '%s weight set to %s' % (format_device(dev),
|
||||||
'"%(meta)s" weight set to %(weight)s' % dev
|
dev['weight'])
|
||||||
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
|
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
|
||||||
exit(EXIT_SUCCESS)
|
exit(EXIT_SUCCESS)
|
||||||
|
|
||||||
@ -471,8 +462,7 @@ swift-ring-builder <builder_file> remove <search-value> [search-value ...]
|
|||||||
if len(devs) > 1:
|
if len(devs) > 1:
|
||||||
print 'Matched more than one device:'
|
print 'Matched more than one device:'
|
||||||
for dev in devs:
|
for dev in devs:
|
||||||
print ' d%(id)sr%(region)sz%(zone)s-%(ip)s:%(port)s/' \
|
print ' %s' % format_device(dev)
|
||||||
'%(device)s_"%(meta)s"' % dev
|
|
||||||
if raw_input('Are you sure you want to remove these %s '
|
if raw_input('Are you sure you want to remove these %s '
|
||||||
'devices? (y/N) ' % len(devs)) != 'y':
|
'devices? (y/N) ' % len(devs)) != 'y':
|
||||||
print 'Aborting device removals'
|
print 'Aborting device removals'
|
||||||
@ -494,9 +484,8 @@ swift-ring-builder <builder_file> remove <search-value> [search-value ...]
|
|||||||
print '-' * 79
|
print '-' * 79
|
||||||
exit(EXIT_ERROR)
|
exit(EXIT_ERROR)
|
||||||
|
|
||||||
print 'd%(id)sr%(region)sz%(zone)s-%(ip)s:%(port)s/' \
|
print '%s marked for removal and will ' \
|
||||||
'%(device)s_"%(meta)s" marked for removal and will ' \
|
'be removed next rebalance.' % format_device(dev)
|
||||||
'be removed next rebalance.' % dev
|
|
||||||
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
|
pickle.dump(builder.to_dict(), open(argv[1], 'wb'), protocol=2)
|
||||||
exit(EXIT_SUCCESS)
|
exit(EXIT_SUCCESS)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user