Trees | Indices | Help |
|
---|
|
1 # 2 # 3 4 # Copyright (C) 2010 Google Inc. 5 # All rights reserved. 6 # 7 # Redistribution and use in source and binary forms, with or without 8 # modification, are permitted provided that the following conditions are 9 # met: 10 # 11 # 1. Redistributions of source code must retain the above copyright notice, 12 # this list of conditions and the following disclaimer. 13 # 14 # 2. Redistributions in binary form must reproduce the above copyright 15 # notice, this list of conditions and the following disclaimer in the 16 # documentation and/or other materials provided with the distribution. 17 # 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 19 # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 26 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 31 """RAPI client utilities. 32 33 """ 34 35 from ganeti import constants 36 from ganeti import cli 37 38 from ganeti.rapi import client 39 40 # Local constant to avoid importing ganeti.http 41 HTTP_NOT_FOUND = 404 42 43102 10346 """Initializes this class. 47 48 @param cl: RAPI client instance 49 50 """ 51 cli.JobPollCbBase.__init__(self) 52 53 self.cl = cl5455 - def WaitForJobChangeOnce(self, job_id, fields, 56 prev_job_info, prev_log_serial, 57 timeout=constants.DEFAULT_WFJC_TIMEOUT):58 """Waits for changes on a job. 59 60 """ 61 try: 62 result = self.cl.WaitForJobChange(job_id, fields, 63 prev_job_info, prev_log_serial) 64 except client.GanetiApiError, err: 65 if err.code == HTTP_NOT_FOUND: 66 return None 67 68 raise 69 70 if result is None: 71 return constants.JOB_NOTCHANGED 72 73 return (result["job_info"], result["log_entries"])7476 """Returns the given fields for the selected job IDs. 77 78 @type job_ids: list of numbers 79 @param job_ids: Job IDs 80 @type fields: list of strings 81 @param fields: Fields 82 83 """ 84 if len(job_ids) != 1: 85 raise NotImplementedError("Only one job supported at this time") 86 87 try: 88 result = self.cl.GetJobStatus(job_ids[0]) 89 except client.GanetiApiError, err: 90 if err.code == HTTP_NOT_FOUND: 91 return [None] 92 93 raise 94 95 return [[result[name] for name in fields], ]96105 """Function to poll for the result of a job. 106 107 @param rapi_client: RAPI client instance 108 @type job_id: number 109 @param job_id: Job ID 110 @type reporter: L{cli.JobPollReportCbBase} 111 @param reporter: PollJob reporter instance 112 113 @return: The opresult of the job 114 @raise errors.JobLost: If job can't be found 115 @raise errors.OpExecError: if job didn't succeed 116 117 @see: L{ganeti.cli.GenericPollJob} 118 119 """ 120 return cli.GenericPollJob(job_id, RapiJobPollCb(rapi_client), reporter)121
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Aug 22 11:13:44 2016 | http://epydoc.sourceforge.net |