~notmyname/swift/deslogging

« back to all changes in this revision

Viewing changes to bin/swift-ring-builder

  • Committer: Tarmac
  • Author(s): gholt
  • Date: 2011-05-23 20:22:23 UTC
  • mfrom: (288.2.7 atriskparts)
  • Revision ID: tarmac-20110523202223-cfc3dm24yrz2a1ro
swift-ring-builder: Added list_parts command which shows common partitions for a given list of devices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# limitations under the License.
16
16
 
17
17
import cPickle as pickle
 
18
from array import array
18
19
from errno import EEXIST
19
20
from gzip import GzipFile
20
21
from os import mkdir
49
50
        _shiny           Matches devices with shiny in the meta data
50
51
        _"snet: 5.6.7.8" Matches devices with snet: 5.6.7.8 in the meta data
51
52
        [::1]            Matches devices in any zone with the ip ::1
52
 
        z1-[::1]:5678    Matches devices in zone 1 with the ip ::1 and port 5678
 
53
        z1-[::1]:5678    Matches devices in zone 1 with ip ::1 and port 5678
53
54
    Most specific example:
54
55
        d74z1-1.2.3.4:5678/sdb1_"snet: 5.6.7.8"
55
56
    Nerd explanation:
229
230
                 dev['meta'])
230
231
        exit(EXIT_RING_UNCHANGED)
231
232
 
 
233
    def list_parts():
 
234
        """
 
235
swift-ring-builder <builder_file> list_parts <search-value> [<search-value>] ..
 
236
    Returns a 2 column list of all the partitions that are assigned to any of
 
237
    the devices matching the search values given. The first column is the
 
238
    assigned partition number and the second column is the number of device
 
239
    matches for that partition. The list is ordered from most number of matches
 
240
    to least. If there are a lot of devices to match against, this command
 
241
    could take a while to run.
 
242
        """
 
243
        if len(argv) < 4:
 
244
            print Commands.list_parts.__doc__.strip()
 
245
            print
 
246
            print search_devs.__doc__.strip()
 
247
            exit(EXIT_RING_UNCHANGED)
 
248
        devs = []
 
249
        for arg in argv[3:]:
 
250
            devs.extend(search_devs(builder, arg) or [])
 
251
        if not devs:
 
252
            print 'No matching devices found'
 
253
            exit(EXIT_ERROR)
 
254
        devs = [d['id'] for d in devs]
 
255
        matches = [array('i') for x in xrange(builder.replicas)]
 
256
        for part in xrange(builder.parts):
 
257
            count = len([d for d in builder.get_part_devices(part)
 
258
                         if d['id'] in devs])
 
259
            if count:
 
260
                matches[builder.replicas - count].append(part)
 
261
        print 'Partition   Matches'
 
262
        for index, parts in enumerate(matches):
 
263
            for part in parts:
 
264
                print '%9d   %7d' % (part, builder.replicas - index)
 
265
        exit(EXIT_RING_UNCHANGED)
 
266
 
232
267
    def add():
233
268
        """
234
269
swift-ring-builder <builder_file> add z<zone>-<ip>:<port>/<device_name>_<meta>