此内容没有您所选择的语言版本。

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)
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap

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.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat