Package ganeti :: Package client :: Module base
[hide private]
[frames] | no frames]

Source Code for Module ganeti.client.base

 1  # 
 2  # 
 3   
 4  # Copyright (C) 2014 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  """Utils for CLI commands""" 
32   
33  from ganeti import cli 
34  from ganeti import constants 
35  from ganeti import ht 
36   
37   
38 -def GetResult(cl, opts, result):
39 """Waits for jobs and returns whether they have succeeded 40 41 Some OpCodes return of list of jobs. This function can be used 42 after issueing a given OpCode to look at the OpCode's result and, if 43 it is of type L{ht.TJobIdListOnly}, then it will wait for the jobs 44 to complete, otherwise just return L{constants.EXIT_SUCCESS}. 45 46 @type cl: L{ganeti.luxi.Client} 47 @param cl: client that was used to submit the OpCode, which will 48 also be used to poll the jobs 49 50 @param opts: CLI options 51 52 @param result: result of the opcode which might contain job 53 information, in which case the jobs will be polled, or simply 54 the result of the opcode 55 56 @rtype: int 57 @return: L{constants.EXIT_SUCCESS} if all jobs completed 58 successfully, L{constants.EXIT_FAILURE} otherwise 59 60 """ 61 if not ht.TJobIdListOnly(result): 62 return constants.EXIT_SUCCESS 63 64 jex = cli.JobExecutor(cl=cl, opts=opts) 65 66 for (status, job_id) in result[constants.JOB_IDS_KEY]: 67 jex.AddJobId(None, status, job_id) 68 69 bad_jobs = [job_result 70 for success, job_result in jex.GetResults() 71 if not success] 72 73 if len(bad_jobs) > 0: 74 for job in bad_jobs: 75 cli.ToStdout("Job failed, result is '%s'.", job) 76 cli.ToStdout("%s job(s) failed.", bad_jobs) 77 return constants.EXIT_FAILURE 78 else: 79 return constants.EXIT_SUCCESS
80