Commit 16c13387 authored by Theo Van Dinter's avatar Theo Van Dinter Committed by Iustin Pop
Browse files

Add a helper function to the RAPI client

This adds a new method WaitForJobCompletion that can be used for
client who are not interested in the entire job log, just in its
completion status.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarIustin Pop <>
Reviewed-by: default avatarRené Nussbaumer <>
parent 92902e91
# Copyright (C) 2010 Google Inc.
# Copyright (C) 2010, 2011 Google Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -39,6 +39,7 @@ import socket
import urllib
import threading
import pycurl
import time
from cStringIO import StringIO
......@@ -1161,6 +1162,36 @@ class GanetiRapiClient(object): # pylint: disable-msg=R0904
"/%s/jobs/%s" % (GANETI_RAPI_VERSION, job_id),
None, None)
def WaitForJobCompletion(self, job_id, period=5, retries=-1):
"""Polls cluster for job status until completion.
Completion is defined as any of the following states:
"error", "canceled", or "success"
@type job_id: int
@param job_id: job id to watch
@type period: int
@param period: how often to poll for status (optional, default 5s)
@type retries: int
@param retries: how many time to poll before giving up
(optional, default -1 means unlimited)
@rtype: bool
@return: True if job succeeded or False if failed/status timeout
while retries != 0:
job_result = self.GetJobStatus(job_id)
if not job_result or job_result["status"] in ("error", "canceled"):
return False
if job_result["status"] == "success":
return True
if retries > 0:
retries -= 1
return False
def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial):
"""Waits for job changes.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment