이 콘텐츠는 선택한 언어로 제공되지 않습니다.

A.4. Python SDK Example: Volumes


Create Volume
When a volume is created, the volume object needs a Red Hat Gluster Storage volume name, volume type and the bricks to be associated with the volume. Before creating a volume, you need to build a corresponding cluster object and associate that cluster with brick objects.
try:
    api = API(url=URL,
              username=USERNAME,
              password=PASSWORD,
              insecure=True)

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

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

    bricksParam = params.GlusterBricks()
    bricksParam.add_brick(brick1)
    bricksParam.add_brick(brick2)

    volume1 = params.GlusterVolume(
        name="music",
        cluster=api.clusters.get(name="Gluster"),
        volume_type="distribute",
        bricks=bricksParam)

    api.clusters.get("Gluster").glustervolumes.add(volume1)
    api.disconnect()

except Exception as e:
    print "Unexpected error: %s" % e
Copy to Clipboard Toggle word wrap
You can retrieve the server ID using the api.host collection.
glusterVolume Delete
def glusterVolumeDelete(clusterName, volumeName):
    try:
        API.clusters.get(clusterName).glustervolumes.get(volumeName).delete()
        return True
    except:
        return False
Copy to Clipboard Toggle word wrap
glusterVolumeStart
To start a volume, you need to pass the cluster name with which the Red Hat Gluster Storage volume is associated and the corresponding volume name to the glusterVolumeStart() function.
def glusterVolumeStart(clusterName, volumeName):
    try:
        API.clusters.get(clusterName).glustervolumes.get(volumeName).start()
        return True
    except:
        return False
Copy to Clipboard Toggle word wrap
glusterVolumeStop
To stop a volume, you need to pass the cluster name with which the Red Hat Gluster Storage volume is associated and the corresponding volume name to the glusterVolumeStart() function.
def glusterVolumeStop(clusterName, volumeName):
    try:
        API.clusters.get(clusterName).glustervolumes.get(volumeName).stop()
        return True
    except:
        return False
Copy to Clipboard Toggle word wrap
Rebalance operations: startRebalance, stopRebalance, and rebalanceStatus
To rebalance data among the servers, you need to pass the cluster name and the volume name to the startRebalance and stopRebalance functions and the jobID to the rebalanceStatus function.
import ovirtsdk
from ovirtsdk.api import API
from ovirtsdk.xml import params

# This function returns a stop rebalance task instance. Using this
# we can reterive the status of the stop rebalance.
# ex. volume = stopRebalance(clusterName, volumeName)
#     print volume.status.state

def stopRebalance(clusterName, volumeName):
    volume = api.clusters.get(clusterName).glustervolumes.get(volumeName)
    try:
        return volume.stoprebalance()
    except ovirtsdk.infrastructure.errors.RequestError, e:
        print "Error"

def startRebalance(clusterName, volumeName):
    volume = api.clusters.get(clusterName).glustervolumes.get(volumeName)
    return volume.rebalance()

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

clusterName="Default"   # name of the cluser
volumeName="music"      # name of the volume which belongs
                        # to the purticular cluster
try:
    api = API (url="https://HOST",
               username="USER",
               password="PASS",
               ca_file="ca.crt")

    status = startRebalance(clusterName, volumeName)
    jobId = status.job.get_id()
    # jobId return by startRebalance can be stored somewhere
    # for later use. With out the jobId it would be very
    # difficult to find out the actual status of this task.
    print jobId
    privStatus = None
    while True:
        status = rebalanceStatus(jobId)
        jobStatus = status.get_status().get_state()
        if jobStatus != privStatus:
            print "Description: ", status.get_description()
            print "Status:      ", jobStatus
        if "FINISHED" == jobStatus:
            break
        privStatus = jobStatus

    api.disconnect()
except Exception as ex:
    print "Unexpected error: %s" % ex
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat