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
Exemplo n.º 2
0
def set_volume_options(volume_name, hostname, options):
    """options should be of following form

    [

      {"option2": "Value2"},

      {"option3": "Value3"},

      {"option1": "Value1"},

    ]
    """
    recipe = []
    option_key_list = []
    option_value_list = []
    for option in options:
        option_key_list.append(option.keys()[0])
        option_value_list.append(option.values()[0])
    host_vol = hostname + ":" + volume_name
    recipe.append(
        gf.get_volume(
            host_vol,
            "set",
            option_keys=option_key_list,
            option_values=option_value_list
        )
    )

    config_str = cook_gdeploy_config(recipe)

    out, err, rc = invoke_gdeploy(config_str)

    return out, err, rc
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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 volume_quota_config(volume_name, hostname, action, dir_details={}):
    """dir_details should be of following form

    [

      {"dir2": "size2"},

      {"dir1": "size1"},

      {"dir3": "size3"},

    ]
    action: ["limit-usage"|"limit-objects"]
    """
    # TODO (team) quota currently has only 2 actions namely limit-usage and
    # limit-objects. However gdeploy provides quite a few actions, this needs
    # to be enhanced

    recipe = []
    host_vol = hostname + ":" + volume_name
    if dir_details:
        dir_list = []
        size_list = []
        for directory in dir_details:
            dir_list.append(directory.keys()[0])
            size_list.append(directory.values()[0])
        recipe.append(
            gf.get_quota(
                host_vol,
                action,
                path=dir_list,
                size=size_list
            )
        )
    else:
        recipe.append(
            gf.get_quota(
                host_vol,
                action
            )
        )

    config_str = cook_gdeploy_config(recipe)

    out, err, rc = invoke_gdeploy(config_str)

    return out, err, rc
Exemplo n.º 6
0
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 test_invoke_gdeploy(self, monkeypatch):
        monkeypatch.setattr(gw, "GDEPLOY_CONFIG_PATH", "/tmp/config_")

        def mock_uuid():
            return "87edcddd-f61b-4699-951f-187e6e022dc9"
        monkeypatch.setattr(uuid, 'uuid4', mock_uuid)

        def mock_subprocess_popen(args=None, stdout=None, stderr=None,
                                  close_fds=None):
            assert args == [
                "gdeploy",
                "-c",
                "/tmp/config_87edcddd-f61b-4699-951f-187e6e022dc9.conf"
            ]
            assert stdout == subprocess.PIPE
            assert stderr == subprocess.PIPE
            return process()
        monkeypatch.setattr(subprocess, "Popen", mock_subprocess_popen)

        out, err, rc = gw.invoke_gdeploy("")
        assert out == "dummy output string"
        assert err == "dummy err string"
        assert rc == 0
Exemplo n.º 9
0
def volume_snapshot_config(volume_name, hostname, action, snapname=""):
    """

    action: [create|delete|clone]

    """
    # TODO (team) currently only snapshot create, delete and clone is
    # supported. However gdeploy provides many other snapshot related
    # actions. These have to be added as and when requirement arises.
    recipe = []
    host_vol = hostname + ":" + volume_name
    recipe.append(
        gf.get_snapshot(
            host_vol,
            action,
            snapname
        )
    )

    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
Exemplo n.º 11
0
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
Exemplo n.º 12
0
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