def test_get_hosts(self): host_list = ["12.34.45.56", "23.56.78.43", "45,67,43,12"] host = gf.get_hosts(host_list) expected_host_dict = { "hosts": ["12.34.45.56", "23.56.78.43", "45,67,43,12"] } assert host == expected_host_dict
def install_gluster_packages(host_list, glusterfs_packages=None, glusterfs_repo=None, gpgcheck=None): """sample host list: ["12.34.45.65","34.23.67.34", "12.76.77.88"] """ recipe = [] recipe.append(gf.get_hosts(host_list)) recipe.append( gf.get_yum( "install", glusterfs_packages if glusterfs_packages else GLUSTERFS_PACKAGES, glusterfs_repo if glusterfs_repo else get_glusterfs_repo(), gpgcheck if gpgcheck else "no")) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def delete_volume(volume_name, host=None, force=None): recipe = [] if host: host_list = [host] recipe.append(gf.get_hosts(host_list)) force = "yes" if force else "no" recipe.append(gf.get_volume(volume_name, action="delete", force=force)) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def create_cluster(host_list): """sample host list: ["12.34.45.65","34.23.67.34", "12.76.77.88"] """ recipe = [] recipe.append(gf.get_hosts(host_list)) recipe.append(gf.get_peer("probe")) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def remove_host(host_list, force=False): """sample host list: ["12.34.45.65","34.23.67.34", "12.76.77.88"] """ recipe = [] recipe.append(gf.get_hosts(host_list)) force = "yes" if force else "no" recipe.append(gf.get_peer("detach", force)) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def configure_gluster_service(host_list): """sample host list: ["12.34.45.65","34.23.67.34", "12.76.77.88"] """ recipe = [] recipe.append(gf.get_hosts(host_list)) recipe.append(gf.get_service("enable", "glusterd")) recipe.append(gf.get_service("start", "glusterd")) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def configure_gluster_firewall(host_list): """sample host list: ["12.34.45.65","34.23.67.34", "12.76.77.88"] """ recipe = [] recipe.append(gf.get_hosts(host_list)) glusterfs_ports = [ "111/tcp", "2049/tcp", "54321/tcp", "5900/tcp", "5900-6923/tcp", "5666/tcp", "16514/tcp" ] recipe.append( gf.get_firewall("add", glusterfs_ports, "glusterfs", permanent="true")) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def expand_volume(volume_name, brick_details, replica_count=None, disperse_count=None, force=False, increase_replica_count=False): """Brick details should be of following form, its a list of list where each sublist is a collection of bricks which forms a replica set(in case of replicated volume) or a subvolume(in case of a distributed dispersed volume) [ [ {"hostname1": "brick1"}, {"hostname2": "brick1"}, {"hostname3": "brick1"}, {"hostname4": "brick1"} ], [ {"hostname1": "brick2"}, {"hostname2": "brick2"}, {"hostname3": "brick2"}, {"hostname4": "brick2"} ], [ {"hostname1": "brick3"}, {"hostname2": "brick3"}, {"hostname4": "brick3"}, {"hostname3": "brick3"} ], ] """ recipe = [] brick_list = [] host_list = set() if replica_count and not increase_replica_count: if len(brick_details[0]) != int(replica_count): out = "insufficient brick sets for replica count" + \ ": %s. Brick set count %s" % ( replica_count, len(brick_details[0]) ) err = out rc = 1 return out, err, rc if disperse_count: if len(brick_details[0]) != ( int(disperse_count)): out = "insufficient nos bricks for disperse count" + \ ": %s. Brick count: %s" % ( disperse_count, len(brick_details[0]) ) err = out rc = 1 return out, err, rc set_length = len(brick_details[0]) for replica_set in brick_details: if len(replica_set) != set_length: out = "number of bricks in different sets are not same" + \ "Bricks passed: %s" % ( str(brick_details) ) err = out rc = 1 return out, err, rc for el in replica_set: host_list.add(el.keys()[0]) brick_list.append(el.keys()[0] + ":" + el.values()[0]) recipe.append(gf.get_hosts(list(host_list))) arg_dict = {} force = "yes" if force else "no" arg_dict.update({"force": force}) if increase_replica_count: arg_dict.update({"replica_count": replica_count}) arg_dict.update({"state": "force"}) args = [volume_name, "add-brick", brick_list] recipe.append( gf.get_volume(*args, **arg_dict) ) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc
def provision_disks(disk_dictionary, disk_type=None, disk_count=None, stripe_size=None): """Structure of disk dictionary {"host_name_0": { "diks_name_0": { "mount_path": <actual-mountpath>, "brick_path": <actual-brick-path>, "vg": <vg-name>, "lv": <lv-name>, "pv": <pv-name>, "pool": <pool-name>, }, "diks_name_1": { "mount_path": <actual-mountpath>, "brick_path": <actual-brick-path>, "vg": <vg-name>, "lv": <lv-name>, "pv": <pv-name>, "pool": <pool-name>, }, "diks_name_2": { "mount_path": <actual-mountpath>, "brick_path": <actual-brick-path>, "vg": <vg-name>, "lv": <lv-name>, "pv": <pv-name>, "pool": <pool-name>, } }, "host_name_2": { "diks_name_0": { "mount_path": <actual-mountpath>, "brick_path": <actual-brick-path>, "vg": <vg-name>, "lv": <lv-name>, "pv": <pv-name>, "pool": <pool-name>, }, "diks_name_1": { "mount_path": <actual-mountpath>, "brick_path": <actual-brick-path>, "vg": <vg-name>, "lv": <lv-name>, "pv": <pv-name>, "pool": <pool-name>, }, "diks_name_2": { "mount_path": <actual-mountpath>, "brick_path": <actual-brick-path>, "vg": <vg-name>, "lv": <lv-name>, "pv": <pv-name>, "pool": <pool-name>, }, } } disk_type = [RAID10|RAID6|JBOD] disk_count = is nos of data disks in case of RAID device stripe_size = stripe size in KB in case of RAID device """ recipe = [] recipe.append(gf.get_hosts(disk_dictionary.keys())) for host, disks in disk_dictionary.iteritems(): device_list = [] mount_point_list = [] brick_path_list = [] vg_list = [] pool_list = [] lv_list = [] pv_list = [] for disk, detail in disks.iteritems(): device_list.append(disk) mount_point_list.append(detail["mount_path"]) brick_path_list.append(detail["brick_path"]) lv_list.append(detail["lv"]) pool_list.append(detail["pool"]) vg_list.append(detail["vg"]) pv_list.append(detail["pv"]) recipe.append( gf.get_backend_setup(device_list, mount_points=mount_point_list, brick_dirs=brick_path_list, target_host=host, lvs=lv_list, pools=pool_list, vgs=vg_list, pvs=pv_list)) if disk_type: recipe.append(gf.get_disktype(disk_type)) if disk_type in ["RAID6", "RAID10"]: if not stripe_size or not disk_count: raise ValueError("Stripe size and disk count is mandatory" + "for disk of type: %s" % (disk_type)) else: recipe.append(gf.get_diskcount(disk_count)) recipe.append(gf.get_stripesize(stripe_size)) config_str = cook_gdeploy_config(recipe) out, err, rc = invoke_gdeploy(config_str) return out, err, rc