Questo contenuto non è disponibile nella lingua selezionata.

A.8. Python SDK Example: Hooks


Hook operations: getGlusterHook, enableHook, disableHook, resolveHook,glusterHookDetails, and glusterHookList
import pprint
import ovirtsdk
from ovirtsdk.api import API
from ovirtsdk.xml import params

api = None
clusterName = "Default"   # name of the cluser

def getGlusterHook(clusterName, hookName):
     for hook in api.clusters.get(clusterName).glusterhooks.list():
          if hookName == hook.name:
               return hook

def enableHook(clusterName, hookName):
     """ Returns enable hook status """
     hook = getGlusterHook(clusterName, hookName)
     if hook:
          return hook.enable()
     return None

def disableHook(clusterName, hookName):
     """ Returns disable hook status """
     hook = getGlusterHook(clusterName, hookName)
     if hook:
          return hook.disable()
     return None

def resolveHook(clusterName, hookName):
     """ Returns resolve hook status """
     hook = getGlusterHook(clusterName, hookName)
     if hook:
          return hook.resolve()
     return None

def glusterHookDetails(clusterName):
     # Returns hook content """
     hooks=[]
     for hook in api.clusters.get(clusterName).glusterhooks.list():
        hooks.append({"hookName": hook.name,
                      "glusterCommand": hook.get_gluster_command(),
                      "level": hook.get_stage(),#indicates whether this is a post gluster command hook or pre gluster command hook.
                      "state": hook.get_status().state,
                      "md5sum": hook.get_checksum(),
                      "content": hook.get_content()})
     return hooks

def glusterHookList(clusterName):
     # Returns list of hook names """
     hookList=[]
     for hook in api.clusters.get(clusterName).glusterhooks.list():
        hookList.append(hook.name)
     return hookList

try:
     api = API (url="https://10.70.43.95",
                username="admin@internal",
                password="redhat",
                insecure=True)
               #ca_file="ca.crt")
     hookList = glusterHookList(clusterName)
     print hookList
     print disableHook(clusterName, hookList[-1])
     pprint.pprint(glusterHookDetails(clusterName))
     print enableHook(clusterName, hookList[-1])
     api.disconnect()
except Exception as ex:
     print "Unexpected error: %s" % ex

Note

The status of enable hook, disable hook, and resolve hook can be retrieved using get_status().state. And it will raise an ovirtsdk.infrastructure.errors.RequestError when there is a failure.
22632%2C+Console+Developer+Guide-322-09-2014+17%3A11%3A35Report a bug
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2026 Red Hat
Torna in cima