def create_volume(volname, mnode=None, dist=1, rep=1, stripe=1, trans='tcp', servers=None, disp=1, dispd=1, red=1): """Create the gluster volume specified configuration volname and distribute count are mandatory argument Args: volname(str): volume name that has to be created Kwargs: mnode(str): server on which command has to be execeuted, defaults to tc.servers[0] dist(int): distribute count, defaults to 1 rep(int): replica count, defaults to 1 stripe(int): stripe count, defaults to 1 trans(str): transport type, defaults to tcp servers(list): servers on which volume has to be created, defaults to number of servers in pool list, if that is None, then takes tc.servers disp(int): disperse count, defaults to 1 dispd(int): disperse-data count, defaults to 1 red(int): rdundancy count, defaults to 1 Returns: tuple: Tuple containing three elements (ret, out, err). The first element 'ret' is of type 'int' and is the return value of command execution. The second element 'out' is of type 'str' and is the stdout value of the command execution. The third element 'err' is of type 'str' and is the stderr value of the command execution. (-1, '', ''): If not enough bricks are available to create volume. (ret, out, err): As returned by volume create command execution. Example: create_volume(volname) """ if servers is None: servers = nodes_from_pool_list() if not servers: servers = tc.servers[:] if mnode is None: mnode = tc.servers[0] dist = int(dist) rep = int(rep) stripe = int(stripe) disp = int(disp) dispd = int(dispd) red = int(red) dispc = 1 if disp != 1 and dispd != 1: tc.logger.error("volume can't have both disperse and disperse-data") return (-1, None, None) if disp != 1: dispc = int(disp) elif dispd != 1: dispc = int(dispd) + int(red) number_of_bricks = dist * rep * stripe * dispc replica = stripec = disperse = disperse_data = redundancy = '' from distaflibs.gluster.lib_utils import form_bricks_path bricks_path = form_bricks_path(number_of_bricks, servers[:], mnode, volname) if bricks_path is None: tc.logger.error("number of bricks required are greater than " "unused bricks") return (-1, '', '') if rep != 1: replica = "replica %d" % rep if stripe != 1: stripec = "stripe %d" % stripe ttype = "transport %s" % trans if disp != 1: disperse = "disperse %d" % disp redundancy = "redundancy %d" % red elif dispd != 1: disperse_data = "disperse-data %d" % dispd redundancy = "redundancy %d" % red ret = tc.run(mnode, "gluster volume create %s %s %s %s %s %s %s %s " "--mode=script" % (volname, replica, stripec, disperse, disperse_data, redundancy, ttype, bricks_path)) return ret
def tier_attach(volname, num_bricks_to_add, peers, replica=1, force=False, mnode=None): """Attaches tier to the volume Args: volname (str): volume name num_bricks_to_add (str): number of bricks to be added as hot tier peers (list): from these servers, hot tier will be added to volume Kwargs: replica (str): replica count of the hot tier force (bool): If this option is set to True, then attach tier will get executed with force option. If it is set to False, then attach tier will get executed without force option mnode (str): Node on which cmd has to be executed. If None, defaults to servers[0]. Returns: tuple: Tuple containing three elements (ret, out, err). The first element 'ret' is of type 'int' and is the return value of command execution. The second element 'out' is of type 'str' and is the stdout value of the command execution. The third element 'err' is of type 'str' and is the stderr value of the command execution. Example: tier_attach(testvol, '2', ['peer_node1','peer_node2']) """ if mnode is None: mnode = tc.servers[0] replica = int(replica) repc = '' if replica != 1: repc = "replica %d" % replica frce = '' if force: frce = 'force' num_bricks_to_add = int(num_bricks_to_add) from distaflibs.gluster.lib_utils import form_bricks_path bricks_path = form_bricks_path(num_bricks_to_add, peers[:], mnode, volname) if bricks_path is None: tc.logger.error("number of bricks required are greater than " "unused bricks") return (-1, '', '') bricks_path = [ re.sub(r"(.*\/\S+\_)brick(\d+)", r"\1tier\2", item) for item in bricks_path.split() if item ] tier_bricks_path = " ".join(bricks_path) cmd = ("gluster volume tier %s attach %s %s %s --mode=script" % (volname, repc, tier_bricks_path, frce)) return tc.run(mnode, cmd)
def tier_attach(volname, num_bricks_to_add, peers, replica=1, force=False, mnode=None): """Attaches tier to the volume Args: volname (str): volume name num_bricks_to_add (str): number of bricks to be added as hot tier peers (list): from these servers, hot tier will be added to volume Kwargs: replica (str): replica count of the hot tier force (bool): If this option is set to True, then attach tier will get executed with force option. If it is set to False, then attach tier will get executed without force option mnode (str): Node on which cmd has to be executed. If None, defaults to servers[0]. Returns: tuple: Tuple containing three elements (ret, out, err). The first element 'ret' is of type 'int' and is the return value of command execution. The second element 'out' is of type 'str' and is the stdout value of the command execution. The third element 'err' is of type 'str' and is the stderr value of the command execution. Example: tier_attach(testvol, '2', ['peer_node1','peer_node2']) """ if mnode is None: mnode = tc.servers[0] replica = int(replica) repc = '' if replica != 1: repc = "replica %d" % replica frce = '' if force: frce = 'force' num_bricks_to_add = int(num_bricks_to_add) from distaflibs.gluster.lib_utils import form_bricks_path bricks_path = form_bricks_path(num_bricks_to_add, peers[:], mnode, volname) if bricks_path is None: tc.logger.error("number of bricks required are greater than " "unused bricks") return (-1, '', '') bricks_path = [re.sub(r"(.*\/\S+\_)brick(\d+)", r"\1tier\2", item) for item in bricks_path.split() if item] tier_bricks_path = " ".join(bricks_path) cmd = ("gluster volume tier %s attach %s %s %s --mode=script" % (volname, repc, tier_bricks_path, frce)) return tc.run(mnode, cmd)