예제 #1
0
def jbod_storage_config():

    _target_node = getattr(sys.modules[__name__], '__grains__')['id']
    _data_field = "cluster/{0}/storage/data_devices".format(_target_node)
    _metadata_field = "cluster/{0}/storage/metadata_devices".format(_target_node)

    _cmd = "multipath -ll | grep mpath | sort -k2.2 | awk '{ print $1 }'"
    _device_list = run_subprocess_cmd([_cmd], check=False, shell=True).stdout.splitlines()  # nosec

    metadata_devices = ["/dev/disk/by-id/dm-name-{0}".format(_device_list[0])]
    data_device = ["/dev/disk/by-id/dm-name-{0}".format(device) for device in _device_list[1:]]

    provisioner.pillar_set(_metadata_field, metadata_devices)
    provisioner.pillar_set(_data_field, data_device)
    return True
예제 #2
0
def nw_roaming_ip():

    for node in __pillar__["cluster"]["node_list"]:
        pvt_nw = __pillar__['cluster']['pvt_data_nw_addr']
        field = "cluster/{0}/network/data_nw/roaming_ip".format(node)
        roaming_ip = ("{0}.{1}").format('.'.join(pvt_nw.split('.')[:3]),
                                        int(node.split('-')[1]) + 2)
        if None == __pillar__["cluster"][node]["network"]["data_nw"][
                "roaming_ip"]:
            provisioner.pillar_set(field, roaming_ip)
        else:
            # Honour user override
            return True

    return True
예제 #3
0
def jbod_storage_config():
    _target_node = __grains__['id']
    _data_field = "cluster/{0}/storage/data_devices".format(_target_node)
    _metadata_field = "cluster/{0}/storage/metadata_device".format(
        _target_node)

    _cmd = "multipath -ll | grep mpath | sort -k2.2 | awk '{ print $1 }'"
    _device_list = subprocess.Popen(
        [_cmd], shell=True,
        stdout=subprocess.PIPE).stdout.read().decode("utf-8").splitlines()

    metadata_device = ["/dev/disk/by-id/dm-name-{0}".format(_device_list[0])]
    data_device = [
        "/dev/disk/by-id/dm-name-{0}".format(device)
        for device in _device_list[1:]
    ]

    provisioner.pillar_set(_metadata_field, metadata_device)
    provisioner.pillar_set(_data_field, data_device)
    return True
예제 #4
0
def _update(data, path, cluster_id, new_passwd, cipher, cipher_key, decrypt):

    for key, val in data.items():
        logger.debug(f"Updating pillar {key}::{val}")
        if isinstance(val, dict):
            data[key] = _update(val, path + '/' + key, cluster_id, new_passwd,
                                cipher, cipher_key, decrypt)
        else:
            if (("secret" in key) or ("password" in key)):
                if not val:
                    val = new_passwd

                try:
                    temp = cipher.Cipher.decrypt(
                        cipher_key, val.encode("utf-8")).decode("utf-8")
                    if decrypt:
                        provisioner.pillar_set(path + '/' + key, temp)
                except cipher.CipherInvalidToken:
                    val = val.strip('\"')
                    val = val.strip("\'")
                    if decrypt:
                        provisioner.pillar_set(path + '/' + key, val)
                    else:
                        logger.debug(
                            f"Setting pillar {path + '/' + key} to {val}")
                        provisioner.pillar_set(
                            path + '/' + key,
                            str(
                                cipher.Cipher.encrypt(cipher_key,
                                                      bytes(val, 'utf8')),
                                'utf-8'))
    return True
예제 #5
0
def storage_device_config():

    server_nodes = [
        node for node in provisioner.pillar_get("cluster").keys()
        if "srvnode-" in node
    ]
    for node in server_nodes:
        cluster_dict = provisioner.pillar_get(f"cluster/{node}/roles", targets=node)

        if "primary" in cluster_dict[node][f"cluster/{node}/roles"]:
            cmd = ("multipath -ll | grep prio=50 -B2 |"
                  " grep mpath|sort -k2.2 | awk '{ print $1 }'")
        else:
            cmd = ("multipath -ll | grep prio=10 -B2 |"
                  " grep mpath|sort -k2.2 | awk '{ print $1 }'")

        device_list = []
        _timeout = 60
        _count = 0
        _sleep_time = 5
        while device_list == []:
            if ( _count == 0 ):
                logger.info(f"[ INFO ] Attempt {_count} "
                       "Waiting for multipath device to come up...")

            if ( _count > _timeout ):
                msg = ("[ ERROR ] multipath devices don't exist. "
                        f"Giving up after {_timeout} second.")
                raise Exception(msg)
                # break
                # return False
            else:
                time.sleep(_sleep_time)

                logger.info(f"Command to populate multipath devices: {cmd}")
                device_list = run_subprocess_cmd([cmd], check=False, shell=True).stdout.splitlines()  # nosec

                if ( len(device_list) > 0 ):
                    logger.info("[ INFO ] Found multipath devices...")
                else:
                    print(".")
                _count = _count + _sleep_time

        if device_list == []:
            raise Exception("[ ERROR ] multipath devices don't exist.")
            # return False

        metadata_devices = list()
        metadata_devices.append(f"/dev/disk/by-id/dm-name-{device_list[0]}")
        metadata_field = f"cluster/{node}/storage/metadata_devices".format(node)
        provisioner.pillar_set(metadata_field, metadata_devices)

        data_device = [f"/dev/disk/by-id/dm-name-{device}" for device in device_list[1:]]
        data_field = f"cluster/{node}/storage/data_devices"
        provisioner.pillar_set(data_field, data_device)

    if (len(provisioner.pillar_get("cluster/srvnode-1/storage/data_devices"))
        != len(provisioner.pillar_get("cluster/srvnode-2/storage/data_devices"))):
        msg = ("[ ERROR ] multipath devices don't match for the 2 nodes. "
                "Can't proceed exiting...")
        raise Exception(msg)
        # return False

    return True