def select_volume_bricks_to_bring_offline(mnode, volname):
    """Randomly selects bricks to bring offline without affecting the cluster
    from a non-tiered volume.

    Args:
        mnode (str): Node on which commands will be executed.
        volname (str): Name of the volume.

    Returns:
        list: On success returns list of bricks that can be brough offline.
            If volume doesn't exist or is a tiered volume returns empty list
    """
    volume_bricks_to_bring_offline = []

    # Check if volume is tiered
    if is_tiered_volume(mnode, volname):
        return volume_bricks_to_bring_offline

    # get volume type
    volume_type_info = get_volume_type_info(mnode, volname)
    volume_type = volume_type_info['volume_type_info']['typeStr']

    # get subvols
    subvols_dict = get_subvols(mnode, volname)
    volume_subvols = subvols_dict['volume_subvols']

    # select bricks from distribute volume
    if volume_type == 'Distribute':
        volume_bricks_to_bring_offline = []

    # select bricks from replicated, distributed-replicated volume
    elif (volume_type == 'Replicate'
          or volume_type == 'Distributed-Replicate'):
        # Get replica count
        volume_replica_count = (
            volume_type_info['volume_type_info']['replicaCount'])

        # Get quorum info
        quorum_info = get_client_quorum_info(mnode, volname)
        volume_quorum_info = quorum_info['volume_quorum_info']

        # Get list of bricks to bring offline
        volume_bricks_to_bring_offline = (
            get_bricks_to_bring_offline_from_replicated_volume(
                volume_subvols, volume_replica_count, volume_quorum_info))

    # select bricks from Disperse, Distribured-Disperse volume
    elif (volume_type == 'Disperse' or volume_type == 'Distributed-Disperse'):

        # Get redundancy count
        volume_redundancy_count = (
            volume_type_info['volume_type_info']['redundancyCount'])

        # Get list of bricks to bring offline
        volume_bricks_to_bring_offline = (
            get_bricks_to_bring_offline_from_disperse_volume(
                volume_subvols, volume_redundancy_count))

    return volume_bricks_to_bring_offline
def select_hot_tier_bricks_to_bring_offline(mnode, volname):
    """Randomly selects bricks to bring offline without affecting the cluster
    from a hot tier.

    Args:
        mnode (str): Node on which commands will be executed.
        volname (str): Name of the volume.

    Returns:
        list: On success returns list of bricks that can be brough offline
            from hot tier. If volume doesn't exist or is a non tiered volume
            returns empty list.
    """
    hot_tier_bricks_to_bring_offline = []

    # Check if volume is tiered
    if not is_tiered_volume(mnode, volname):
        return hot_tier_bricks_to_bring_offline

    # get volume type
    volume_type_info = get_volume_type_info(mnode, volname)
    hot_tier_type = volume_type_info['hot_tier_type_info']['hotBrickType']

    # get subvols
    subvols_dict = get_subvols(mnode, volname)
    hot_tier_subvols = subvols_dict['hot_tier_subvols']

    # select bricks from distribute volume
    if hot_tier_type == 'Distribute':
        hot_tier_bricks_to_bring_offline = []

    # select bricks from replicated, distributed-replicated volume
    if (hot_tier_type == 'Replicate'
            or hot_tier_type == 'Distributed-Replicate'):
        # Get replica count
        hot_tier_replica_count = (
            volume_type_info['hot_tier_type_info']['hotreplicaCount'])

        # Get quorum info
        quorum_info = get_client_quorum_info(mnode, volname)
        hot_tier_quorum_info = quorum_info['hot_tier_quorum_info']

        # Get list of bricks to bring offline
        hot_tier_bricks_to_bring_offline = (
            get_bricks_to_bring_offline_from_replicated_volume(
                hot_tier_subvols, hot_tier_replica_count,
                hot_tier_quorum_info))

    return hot_tier_bricks_to_bring_offline
def select_bricks_to_bring_offline(mnode, volname):
    """Randomly selects bricks to bring offline without affecting the cluster

    Args:
        mnode (str): Node on which commands will be executed.
        volname (str): Name of the volume.

    Returns:
        dict: On success returns dict. Value of each key is list of bricks to
            bring offline.
            If volume doesn't exist returns dict with value of each item
            being empty list.
            Example:
                brick_to_bring_offline = {
                    'is_tier': False,
                    'hot_tier_bricks': [],
                    'cold_tier_bricks': [],
                    'volume_bricks': []
                    }
    """
    # Defaulting the values to empty list
    bricks_to_bring_offline = {
        'is_tier': False,
        'hot_tier_bricks': [],
        'cold_tier_bricks': [],
        'volume_bricks': []
    }

    volinfo = get_volume_info(mnode, volname)
    if volinfo is None:
        g.log.error("Unable to get the volume info for volume %s", volname)
        return bricks_to_bring_offline

    if is_tiered_volume(mnode, volname):
        bricks_to_bring_offline['is_tier'] = True
        # Select bricks from tiered volume.
        bricks_to_bring_offline = (select_tier_volume_bricks_to_bring_offline(
            mnode, volname))
    else:
        # Select bricks from non-tiered volume.
        volume_bricks = select_volume_bricks_to_bring_offline(mnode, volname)
        bricks_to_bring_offline['volume_bricks'] = volume_bricks

    return bricks_to_bring_offline
Exemple #4
0
def select_tier_volume_bricks_to_bring_offline(mnode, volname):
    """Randomly selects bricks to bring offline without affecting the cluster
    from a tiered volume.

    Args:
        mnode (str): Node on which commands will be executed.
        volname (str): Name of the volume.

    Returns:
        dict: On success returns dict. Value of each key is list of bricks to
            bring offline.
            If volume doesn't exist or is not a tiered volume returns dict
            with value of each item being empty list.
            Example:
                brick_to_bring_offline = {
                    'hot_tier_bricks': [],
                    'cold_tier_bricks': [],
                    }
    """
    # Defaulting the values to empty list
    bricks_to_bring_offline = {
        'hot_tier_bricks': [],
        'cold_tier_bricks': [],
    }

    volinfo = get_volume_info(mnode, volname)
    if volinfo is None:
        g.log.error("Unable to get the volume info for volume %s", volname)
        return bricks_to_bring_offline

    if is_tiered_volume(mnode, volname):
        # Select bricks from both hot tier and cold tier.
        hot_tier_bricks = (select_hot_tier_bricks_to_bring_offline(
            mnode, volname))
        cold_tier_bricks = (select_cold_tier_bricks_to_bring_offline(
            mnode, volname))
        bricks_to_bring_offline['hot_tier_bricks'] = hot_tier_bricks
        bricks_to_bring_offline['cold_tier_bricks'] = cold_tier_bricks
        return bricks_to_bring_offline
    else:
        return bricks_to_bring_offline