-
Language:
English
-
Language:
English
Red Hat Training
A Red Hat training course is available for Red Hat Gluster Storage
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