36 |
36 |
from ganeti.rapi import httperror
|
37 |
37 |
|
38 |
38 |
|
|
39 |
I_FIELDS = ["name", "os", "pnode", "snodes",
|
|
40 |
"admin_state", "admin_ram",
|
|
41 |
"disk_template", "ip", "mac", "bridge",
|
|
42 |
"sda_size", "sdb_size", "vcpus",
|
|
43 |
"oper_state", "status", "tags"]
|
|
44 |
|
|
45 |
N_FIELDS = ["name","dtotal", "dfree",
|
|
46 |
"mtotal", "mnode", "mfree",
|
|
47 |
"pinst_cnt", "sinst_cnt", "tags"]
|
|
48 |
|
|
49 |
|
39 |
50 |
class R_version(baserlib.R_Generic):
|
40 |
51 |
"""/version resource.
|
41 |
52 |
|
... | ... | |
103 |
114 |
|
104 |
115 |
"""
|
105 |
116 |
DOC_URI = "/nodes"
|
106 |
|
|
107 |
|
def _GetDetails(self, nodeslist):
|
108 |
|
"""Returns detailed instance data for bulk output.
|
109 |
|
|
110 |
|
Args:
|
111 |
|
instance: A list of nodes names.
|
112 |
|
|
113 |
|
Returns:
|
114 |
|
A list of nodes properties
|
115 |
|
|
116 |
|
"""
|
117 |
|
fields = ["name","dtotal", "dfree",
|
118 |
|
"mtotal", "mnode", "mfree",
|
119 |
|
"pinst_cnt", "sinst_cnt", "tags"]
|
120 |
|
|
121 |
|
op = ganeti.opcodes.OpQueryNodes(output_fields=fields,
|
122 |
|
names=nodeslist)
|
123 |
|
result = ganeti.cli.SubmitOpCode(op)
|
124 |
|
|
125 |
|
nodes_details = []
|
126 |
|
for node in result:
|
127 |
|
mapped = baserlib.MapFields(fields, node)
|
128 |
|
nodes_details.append(mapped)
|
129 |
|
return nodes_details
|
130 |
117 |
|
131 |
118 |
def GET(self):
|
132 |
119 |
"""Returns a list of all nodes.
|
... | ... | |
168 |
155 |
nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
|
169 |
156 |
|
170 |
157 |
if 'bulk' in self.queryargs:
|
171 |
|
return self._GetDetails(nodeslist)
|
|
158 |
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
|
|
159 |
names=nodeslist)
|
|
160 |
result = ganeti.cli.SubmitOpCode(op)
|
|
161 |
return baserlib.MapBulkFields(result, N_FIELDS)
|
172 |
162 |
|
173 |
163 |
return baserlib.BuildUriList(nodeslist, "/nodes/%s")
|
174 |
164 |
|
... | ... | |
184 |
174 |
|
185 |
175 |
"""
|
186 |
176 |
node_name = self.items[0]
|
187 |
|
fields = ["name","dtotal", "dfree",
|
188 |
|
"mtotal", "mnode", "mfree",
|
189 |
|
"pinst_cnt", "sinst_cnt", "tags"]
|
190 |
|
|
191 |
|
op = ganeti.opcodes.OpQueryNodes(output_fields=fields,
|
|
177 |
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS,
|
192 |
178 |
names=[node_name])
|
193 |
179 |
result = ganeti.cli.SubmitOpCode(op)
|
194 |
180 |
|
195 |
|
return baserlib.MapFields(fields, result[0])
|
|
181 |
return baserlib.MapFields(N_FIELDS, result[0])
|
196 |
182 |
|
197 |
183 |
|
198 |
184 |
class R_nodes_name_tags(baserlib.R_Generic):
|
... | ... | |
218 |
204 |
"""
|
219 |
205 |
DOC_URI = "/instances"
|
220 |
206 |
|
221 |
|
def _GetDetails(self, instanceslist):
|
222 |
|
"""Returns detailed instance data for bulk output.
|
223 |
|
|
224 |
|
Args:
|
225 |
|
instance: A list of instances names.
|
226 |
|
|
227 |
|
Returns:
|
228 |
|
A list with instances properties.
|
229 |
|
|
230 |
|
"""
|
231 |
|
fields = ["name", "os", "pnode", "snodes",
|
232 |
|
"admin_state", "admin_ram",
|
233 |
|
"disk_template", "ip", "mac", "bridge",
|
234 |
|
"sda_size", "sdb_size", "vcpus",
|
235 |
|
"oper_state", "status", "tags"]
|
236 |
|
|
237 |
|
op = ganeti.opcodes.OpQueryInstances(output_fields=fields,
|
238 |
|
names=instanceslist)
|
239 |
|
result = ganeti.cli.SubmitOpCode(op)
|
240 |
207 |
|
241 |
|
instances_details = []
|
242 |
|
for instance in result:
|
243 |
|
mapped = baserlib.MapFields(fields, instance)
|
244 |
|
instances_details.append(mapped)
|
245 |
|
return instances_details
|
246 |
|
|
247 |
208 |
def GET(self):
|
248 |
209 |
"""Returns a list of all available instances.
|
249 |
210 |
|
... | ... | |
291 |
252 |
instanceslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
|
292 |
253 |
|
293 |
254 |
if 'bulk' in self.queryargs:
|
294 |
|
return self._GetDetails(instanceslist)
|
|
255 |
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
|
|
256 |
names=instanceslist)
|
|
257 |
result = ganeti.cli.SubmitOpCode(op)
|
|
258 |
return baserlib.MapBulkFields(result, I_FIELDS)
|
|
259 |
|
295 |
260 |
|
296 |
261 |
else:
|
297 |
262 |
return baserlib.BuildUriList(instanceslist, "/instances/%s")
|
... | ... | |
308 |
273 |
|
309 |
274 |
"""
|
310 |
275 |
instance_name = self.items[0]
|
311 |
|
fields = ["name", "os", "pnode", "snodes",
|
312 |
|
"admin_state", "admin_ram",
|
313 |
|
"disk_template", "ip", "mac", "bridge",
|
314 |
|
"sda_size", "sdb_size", "vcpus",
|
315 |
|
"oper_state", "status", "tags"]
|
316 |
|
|
317 |
|
op = ganeti.opcodes.OpQueryInstances(output_fields=fields,
|
|
276 |
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS,
|
318 |
277 |
names=[instance_name])
|
319 |
278 |
result = ganeti.cli.SubmitOpCode(op)
|
320 |
279 |
|
321 |
|
return baserlib.MapFields(fields, result[0])
|
|
280 |
return baserlib.MapFields(I_FIELDS, result[0])
|
322 |
281 |
|
323 |
282 |
|
324 |
283 |
class R_instances_name_tags(baserlib.R_Generic):
|