Red Hat Training

A Red Hat training course is available for Red Hat Gluster Storage

A.5. Python SDK Example: Bricks

add_Brick
brick3 = params.GlusterBrick(
        brick_dir='/exports/music_3',
        server_id='0f5a7016-bb36-4f2b-a226-3b16c3eeca0c')

    brick4 = params.GlusterBrick(
        brick_dir='/exports/music_4',
        server_id='0f5a7016-bb36-4f2b-a226-3b16c3eeca0c')

    bricksParam = params.GlusterBricks()
    bricksParam.add_brick(brick3)
    bricksParam.add_brick(brick4)
remove_Brick
try:

    for volume in api.clusters.get(
            CLUSTERNAME).glustervolumes.list():
        for brick in volume.bricks.list():
            if brick.name == BRICKNAME:
                brick.delete()

    api.disconnect()

except Exception as e:
    print "Unexpected error: %s" % e
Remove brick operations: startRemoveBrick and removeBrickStatus
You can start a remove brick operation and query the brick status using the code snippet below:
import ovirtsdk
from ovirtsdk.api import API
from ovirtsdk.xml import params

api = None
clusterName = "Default"   # name of the cluster
volumeName = "music"      # name of the volume which belongs #to the particular cluster
brickName = "10.70.42.164:/home/music_b1"
# brick name. We can get the brick details which are associated to the #volume using getGlusterVolumeBrickDetails(..)

def startRemoveBrick(clusterName, volumeName, brickName):
    volume = api.clusters.get(clusterName).glustervolumes.get(volumeName)
    bricks = volume.get_bricks()
    if not bricks:
        return None
    brick = bricks.get(brickName)
    if not brick:
        return None
    try:
        return brick.delete()
    except ovirtsdk.infrastructure.errors.RequestError as e:
        print e

def removeBrickStatus(jobId):
    # jobs.get accepts job name and job id as an optional
    # parameters to provide the job details.
    return api.jobs.get(None, jobId)

try:
    api = API (url="https://HOST",
          username="USER@domain",
          password="PASS",
          ca_file="ca.crt")

    status = startRemoveBrick(clusterName, volumeName, brickName)
    if status:
        jobId = status.job.get_id()
        privStatus = None
        while True:
            status = removeBrickStatus(jobId)
            jobStatus = status.get_status().get_state()
            if jobStatus != privStatus:
                print "Description: ", status.get_description()
                print "Status:      ", jobStatus
            if "FINISHED" == jobStatus:
                break
            privStatus = jobStatus
    else:
        print "Unable to retrieve the brick details"

    api.disconnect()
except Exception as ex:
    print "Unexpected error: %s" % ex

Note

Commit is not an action that can be performed on a brick. Commit happens as part of the delete action. If a remove brick action is in finished state, it commits the changes else it perform a force delete operation.

Important

The code snippet above forcefully remove the brick without migrating the data on the brick.
22632%2C+Console+Developer+Guide-322-09-2014+17%3A11%3A35Report a bug