diff options
| author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2018-06-19 10:56:37 -0400 | 
|---|---|---|
| committer | Amar Tumballi <amarts@redhat.com> | 2018-06-21 05:45:08 +0000 | 
| commit | fe9b72485697a035b3dbb11b83048dd31de5863e (patch) | |
| tree | 8b265ee06edbe83c762d0124efd76cdcecebe1cf /extras/rebalance.py | |
| parent | 2bab841316025c402b97c877ccc4ee9188c929e0 (diff) | |
core/various: python3 compat, prepare for python2 -> python3
see https://review.gluster.org/#/c/19788/,
    https://review.gluster.org/#/c/19871/,
    https://review.gluster.org/#/c/19952/,
    https://review.gluster.org/#/c/20104/,
    https://review.gluster.org/#/c/20162/,
    https://review.gluster.org/#/c/20185/,
    https://review.gluster.org/#/c/20207/,
    https://review.gluster.org/#/c/20227/, and
    https://review.gluster.org/#/c/20307/
This patch fixes more selected comma white space (ws_comma) as suggested
by the 2to3 utility.
Note: Fedora packaging guidelines and SUSE rpmlint require explicit
shebangs, so popular practices like #!/usr/bin/env python and
or #!/usr/bin/python3
Note: Selected small fixes from 2to3 utility. Specifically apply,
basestring, funcattrs, has_key, idioms, map, numliterals, raise,
set_literal, types, urllib, and zip have already been applied. Also
version agnostic imports for urllib, cpickle, socketserver, _thread,
queue, etc., suggested by Aravinda in https://review.gluster.org/#/c/19767/1
Note: these 2to3 fixes report no changes are necessary: asserts, buffer,
exec, execfile, exitfunc, filter, getcwdu, imports2, input, intern,
itertools, metaclass, methodattrs, ne, next, nonzero, operator, paren,
raw_input, reduce, reload, renames, repr, standarderror, sys_exc, throw,
tuple_params, xreadlines.
Change-Id: I60932030813484803f73733a9b2b7b23c7a843fd
updates: #411
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'extras/rebalance.py')
| -rwxr-xr-x | extras/rebalance.py | 38 | 
1 files changed, 19 insertions, 19 deletions
diff --git a/extras/rebalance.py b/extras/rebalance.py index 871b06682d5..32ca067b32d 100755 --- a/extras/rebalance.py +++ b/extras/rebalance.py @@ -39,13 +39,13 @@ class Brick:  def get_bricks (host, vol):          t = pipes.Template() -        t.prepend("gluster --remote-host=%s system getspec %s"%(host,vol),".-") -        return t.open(None,"r") +        t.prepend("gluster --remote-host=%s system getspec %s"%(host, vol), ".-") +        return t.open(None, "r")  def generate_stanza (vf, all_xlators, cur_subvol):          sv_list = []          for sv in cur_subvol.subvols: -                generate_stanza(vf,all_xlators,sv) +                generate_stanza(vf, all_xlators, sv)                  sv_list.append(sv.name)          vf.write("volume %s\n"%cur_subvol.name)          vf.write("  type %s\n"%cur_subvol.type) @@ -60,14 +60,14 @@ def mount_brick (localpath, all_xlators, dht_subvol):          # Generate a volfile.          vf_name = localpath + ".vol" -        vf = open(vf_name,"w") -        generate_stanza(vf,all_xlators,dht_subvol) +        vf = open(vf_name, "w") +        generate_stanza(vf, all_xlators, dht_subvol)          vf.flush()          vf.close()          # Create a brick directory and mount the brick there.          os.mkdir(localpath) -        subprocess.call(["glusterfs","-f",vf_name,localpath]) +        subprocess.call(["glusterfs", "-f", vf_name, localpath])  # We use the command-line tools because there's no getxattr support in the  # Python standard library (which is ridiculous IMO).  Adding the xattr package @@ -81,16 +81,16 @@ def mount_brick (localpath, all_xlators, dht_subvol):  def get_range (brick):          t = pipes.Template()          cmd = "getfattr -e hex -n trusted.glusterfs.dht %s 2> /dev/null" -        t.prepend(cmd%brick,".-") -        t.append("grep ^trusted.glusterfs.dht=","--") -        f = t.open(None,"r") +        t.prepend(cmd%brick, ".-") +        t.append("grep ^trusted.glusterfs.dht=", "--") +        f = t.open(None, "r")          try:                  value = f.readline().rstrip().split('=')[1][2:]          except:                  print("could not get layout for %s (might be OK)" % brick)                  return None -        v_start = int("0x"+value[16:24],16) -        v_end = int("0x"+value[24:32],16) +        v_start = int("0x"+value[16:24], 16) +        v_end = int("0x"+value[24:32], 16)          return (v_start, v_end)  def calc_sizes (bricks, total): @@ -186,7 +186,7 @@ if __name__ == "__main__":                  if options.verbose:                          print("Cleaning up %s" % work_dir)                  for b in bricks: -                        subprocess.call(["umount",b.path]) +                        subprocess.call(["umount", b.path])                  shutil.rmtree(work_dir)          if not options.leave_mounted:                  atexit.register(cleanup_workdir) @@ -196,7 +196,7 @@ if __name__ == "__main__":          if options.verbose:                  print("Mounting subvolumes...")          index = 0 -        volfile_pipe = get_bricks(hostname,volname) +        volfile_pipe = get_bricks(hostname, volname)          all_xlators, last_xlator = volfilter.load(volfile_pipe)          for dht_vol in all_xlators.itervalues():                  if dht_vol.type == "cluster/distribute": @@ -208,8 +208,8 @@ if __name__ == "__main__":                  #print "found subvol %s" % sv.name                  lpath = "%s/brick%s" % (work_dir, index)                  index += 1 -                mount_brick(lpath,all_xlators,sv) -                bricks.append(Brick(lpath,sv.name)) +                mount_brick(lpath, all_xlators, sv) +                bricks.append(Brick(lpath, sv.name))          if index == 0:                  print("no bricks")                  sys.exit(1) @@ -251,11 +251,11 @@ if __name__ == "__main__":                          if rs > re:                                  print("%s has backwards hash range" % b.path)                                  sys.exit(1) -                        b.set_range(hash_range[0],hash_range[1]) +                        b.set_range(hash_range[0], hash_range[1])          if options.verbose:                  print("Calculating new layouts...") -        calc_sizes(bricks,total) +        calc_sizes(bricks, total)          bricks, used = normalize(bricks)          # We can't afford O(n!) here, but O(n^2) should be OK and the result @@ -266,7 +266,7 @@ if __name__ == "__main__":                  for i in range(used):                          new_bricks = bricks[:]                          del new_bricks[used] -                        new_bricks.insert(i,bricks[used]) +                        new_bricks.insert(i, bricks[used])                          new_score = get_score(new_bricks)                          if new_score > best_score:                                  best_place = i @@ -274,7 +274,7 @@ if __name__ == "__main__":                  if best_place != used:                          nb = bricks[used]                          del bricks[used] -                        bricks.insert(best_place,nb) +                        bricks.insert(best_place, nb)                  used += 1          # Finalize whatever we decided on.  | 
