4 # Copyright (C) 2006, 2007, 2008 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Remote API version 2 baserlib.library.
30 from ganeti import constants
31 from ganeti import luxi
33 from ganeti.rapi import baserlib
36 class R_2_jobs(baserlib.R_Generic):
43 """Returns a dictionary of jobs.
46 A dictionary with jobs id and uri.
50 # Convert the list of lists to the list of ids
51 result = [job_id for [job_id] in luxi.Client().QueryJobs(None, fields)]
52 return baserlib.BuildUriList(result, "/2/jobs/%s", uri_fields=("id", "uri"))
55 class R_2_jobs_id(baserlib.R_Generic):
56 """/2/jobs/[job_id] resource.
59 DOC_URI = "/2/jobs/[job_id]"
62 """Returns a job status.
65 A dictionary with job parameters.
68 id - job ID as a number
69 status - current job status as a string
70 ops - involved OpCodes as a list of dictionaries for each opcodes in
72 opstatus - OpCodes status as a list
73 opresult - OpCodes results as a list of lists
76 fields = ["id", "ops", "status", "opstatus", "opresult"]
77 job_id = self.items[0]
78 result = luxi.Client().QueryJobs([job_id,], fields)[0]
79 return baserlib.MapFields(fields, result)
82 class R_2_nodes(baserlib.R_Generic):
88 def _GetDetails(self, nodeslist):
89 """Returns detailed instance data for bulk output.
92 instance: A list of nodes names.
95 A list of nodes properties
98 fields = ["name","dtotal", "dfree",
99 "mtotal", "mnode", "mfree",
100 "pinst_cnt", "sinst_cnt", "tags"]
102 op = ganeti.opcodes.OpQueryNodes(output_fields=fields,
104 result = ganeti.cli.SubmitOpCode(op)
108 mapped = baserlib.MapFields(fields, node)
109 nodes_details.append(mapped)
113 """Returns a list of all nodes.
116 A dictionary with 'name' and 'uri' keys for each of them.
120 "id": "node1.example.com",
121 "uri": "\/instances\/node1.example.com"
124 "id": "node2.example.com",
125 "uri": "\/instances\/node2.example.com"
128 If the optional 'bulk' argument is provided and set to 'true'
129 value (i.e '?bulk=1'), the output contains detailed
130 information about nodes as a list.
137 "name": "www.example.com",
148 op = ganeti.opcodes.OpQueryNodes(output_fields=["name"], names=[])
149 nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
151 if 'bulk' in self.queryargs:
152 return self._GetDetails(nodeslist)
154 return baserlib.BuildUriList(nodeslist, "/nodes/%s", uri_fields=("id", "uri"))