Revision 59b4eeef lib/rapi/rlib2.py
b/lib/rapi/rlib2.py | ||
---|---|---|
23 | 23 |
|
24 | 24 |
""" |
25 | 25 |
|
26 |
import ganeti.opcodes
|
|
26 |
from ganeti import opcodes
|
|
27 | 27 |
from ganeti import http |
28 |
from ganeti import luxi |
|
29 | 28 |
from ganeti import constants |
29 |
from ganeti import cli |
|
30 | 30 |
from ganeti.rapi import baserlib |
31 | 31 |
|
32 | 32 |
|
33 |
|
|
33 | 34 |
I_FIELDS = ["name", "admin_state", "os", |
34 | 35 |
"pnode", "snodes", |
35 | 36 |
"disk_template", |
... | ... | |
105 | 106 |
} |
106 | 107 |
|
107 | 108 |
""" |
108 |
client = luxi.Client()
|
|
109 |
client = baserlib.GetClient()
|
|
109 | 110 |
return client.QueryClusterInfo() |
110 | 111 |
|
111 | 112 |
|
... | ... | |
123 | 124 |
Example: ["debian-etch"] |
124 | 125 |
|
125 | 126 |
""" |
126 |
op = ganeti.opcodes.OpDiagnoseOS(output_fields=["name", "valid"], |
|
127 |
names=[]) |
|
128 |
diagnose_data = ganeti.cli.SubmitOpCode(op) |
|
127 |
cl = baserlib.GetClient() |
|
128 |
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[]) |
|
129 |
job_id = baserlib.SubmitJob([op], cl) |
|
130 |
# we use custom feedback function, instead of print we log the status |
|
131 |
result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn) |
|
132 |
diagnose_data = result[0] |
|
129 | 133 |
|
130 | 134 |
if not isinstance(diagnose_data, list): |
131 |
raise http.HttpInternalServerError(message="Can't get OS list")
|
|
135 |
raise http.HttpBadGateway(message="Can't get OS list")
|
|
132 | 136 |
|
133 | 137 |
return [row[0] for row in diagnose_data if row[1]] |
134 | 138 |
|
... | ... | |
146 | 150 |
|
147 | 151 |
""" |
148 | 152 |
fields = ["id"] |
153 |
cl = baserlib.GetClient() |
|
149 | 154 |
# Convert the list of lists to the list of ids |
150 |
result = [job_id for [job_id] in luxi.Client().QueryJobs(None, fields)]
|
|
155 |
result = [job_id for [job_id] in cl.QueryJobs(None, fields)]
|
|
151 | 156 |
return baserlib.BuildUriList(result, "/2/jobs/%s", |
152 | 157 |
uri_fields=("id", "uri")) |
153 | 158 |
|
... | ... | |
176 | 181 |
"received_ts", "start_ts", "end_ts", |
177 | 182 |
] |
178 | 183 |
job_id = self.items[0] |
179 |
result = luxi.Client().QueryJobs([job_id, ], fields)[0]
|
|
184 |
result = baserlib.GetClient().QueryJobs([job_id, ], fields)[0]
|
|
180 | 185 |
if result is None: |
181 | 186 |
raise http.HttpNotFound() |
182 | 187 |
return baserlib.MapFields(fields, result) |
... | ... | |
186 | 191 |
|
187 | 192 |
""" |
188 | 193 |
job_id = self.items[0] |
189 |
result = luxi.Client().CancelJob(job_id)
|
|
194 |
result = baserlib.GetClient().CancelJob(job_id)
|
|
190 | 195 |
return result |
191 | 196 |
|
192 | 197 |
|
... | ... | |
237 | 242 |
@return: a dictionary with 'name' and 'uri' keys for each of them |
238 | 243 |
|
239 | 244 |
""" |
240 |
client = luxi.Client()
|
|
245 |
client = baserlib.GetClient()
|
|
241 | 246 |
|
242 | 247 |
if self.useBulk(): |
243 | 248 |
bulkdata = client.QueryNodes([], N_FIELDS, False) |
... | ... | |
260 | 265 |
|
261 | 266 |
""" |
262 | 267 |
node_name = self.items[0] |
263 |
client = luxi.Client()
|
|
268 |
client = baserlib.GetClient()
|
|
264 | 269 |
result = client.QueryNodes(names=[node_name], fields=N_FIELDS, |
265 | 270 |
use_locking=self.useLocking()) |
266 | 271 |
|
... | ... | |
326 | 331 |
@return: a dictionary with 'name' and 'uri' keys for each of them. |
327 | 332 |
|
328 | 333 |
""" |
329 |
client = luxi.Client()
|
|
334 |
client = baserlib.GetClient()
|
|
330 | 335 |
|
331 | 336 |
use_locking = self.useLocking() |
332 | 337 |
if self.useBulk(): |
... | ... | |
368 | 373 |
"ip": fn("ip", None), |
369 | 374 |
"bridge": fn("bridge", None)}] |
370 | 375 |
|
371 |
op = ganeti.opcodes.OpCreateInstance( |
|
372 |
mode=constants.INSTANCE_CREATE, |
|
373 |
instance_name=fn('name'), |
|
374 |
disks=disks, |
|
375 |
disk_template=fn('disk_template'), |
|
376 |
os_type=fn('os'), |
|
377 |
pnode=fn('pnode', None), |
|
378 |
snode=fn('snode', None), |
|
379 |
iallocator=fn('iallocator', None), |
|
380 |
nics=nics, |
|
381 |
start=fn('start', True), |
|
382 |
ip_check=fn('ip_check', True), |
|
383 |
wait_for_sync=True, |
|
384 |
hypervisor=fn('hypervisor', None), |
|
385 |
hvparams=hvparams, |
|
386 |
beparams=beparams, |
|
387 |
file_storage_dir=fn('file_storage_dir', None), |
|
388 |
file_driver=fn('file_driver', 'loop'), |
|
389 |
) |
|
390 |
|
|
391 |
job_id = ganeti.cli.SendJob([op]) |
|
392 |
return job_id |
|
376 |
op = opcodes.OpCreateInstance( |
|
377 |
mode=constants.INSTANCE_CREATE, |
|
378 |
instance_name=fn('name'), |
|
379 |
disks=disks, |
|
380 |
disk_template=fn('disk_template'), |
|
381 |
os_type=fn('os'), |
|
382 |
pnode=fn('pnode', None), |
|
383 |
snode=fn('snode', None), |
|
384 |
iallocator=fn('iallocator', None), |
|
385 |
nics=nics, |
|
386 |
start=fn('start', True), |
|
387 |
ip_check=fn('ip_check', True), |
|
388 |
wait_for_sync=True, |
|
389 |
hypervisor=fn('hypervisor', None), |
|
390 |
hvparams=hvparams, |
|
391 |
beparams=beparams, |
|
392 |
file_storage_dir=fn('file_storage_dir', None), |
|
393 |
file_driver=fn('file_driver', 'loop'), |
|
394 |
) |
|
395 |
|
|
396 |
return baserlib.SubmitJob([op]) |
|
393 | 397 |
|
394 | 398 |
|
395 | 399 |
class R_2_instances_name(baserlib.R_Generic): |
... | ... | |
402 | 406 |
"""Send information about an instance. |
403 | 407 |
|
404 | 408 |
""" |
405 |
client = luxi.Client()
|
|
409 |
client = baserlib.GetClient()
|
|
406 | 410 |
instance_name = self.items[0] |
407 | 411 |
result = client.QueryInstances(names=[instance_name], fields=I_FIELDS, |
408 | 412 |
use_locking=self.useLocking()) |
... | ... | |
413 | 417 |
"""Delete an instance. |
414 | 418 |
|
415 | 419 |
""" |
416 |
op = ganeti.opcodes.OpRemoveInstance(instance_name=self.items[0], |
|
417 |
ignore_failures=False) |
|
418 |
job_id = ganeti.cli.SendJob([op]) |
|
419 |
return job_id |
|
420 |
op = opcodes.OpRemoveInstance(instance_name=self.items[0], |
|
421 |
ignore_failures=False) |
|
422 |
return baserlib.SubmitJob([op]) |
|
420 | 423 |
|
421 | 424 |
|
422 | 425 |
class R_2_instances_name_reboot(baserlib.R_Generic): |
... | ... | |
440 | 443 |
[constants.INSTANCE_REBOOT_HARD])[0] |
441 | 444 |
ignore_secondaries = bool(self.queryargs.get('ignore_secondaries', |
442 | 445 |
[False])[0]) |
443 |
op = ganeti.opcodes.OpRebootInstance( |
|
444 |
instance_name=instance_name, |
|
445 |
reboot_type=reboot_type, |
|
446 |
ignore_secondaries=ignore_secondaries) |
|
447 |
|
|
448 |
job_id = ganeti.cli.SendJob([op]) |
|
446 |
op = opcodes.OpRebootInstance(instance_name=instance_name, |
|
447 |
reboot_type=reboot_type, |
|
448 |
ignore_secondaries=ignore_secondaries) |
|
449 | 449 |
|
450 |
return job_id
|
|
450 |
return baserlib.SubmitJob([op])
|
|
451 | 451 |
|
452 | 452 |
|
453 | 453 |
class R_2_instances_name_startup(baserlib.R_Generic): |
... | ... | |
468 | 468 |
""" |
469 | 469 |
instance_name = self.items[0] |
470 | 470 |
force_startup = bool(self.queryargs.get('force', [False])[0]) |
471 |
op = ganeti.opcodes.OpStartupInstance(instance_name=instance_name,
|
|
472 |
force=force_startup)
|
|
471 |
op = opcodes.OpStartupInstance(instance_name=instance_name, |
|
472 |
force=force_startup) |
|
473 | 473 |
|
474 |
job_id = ganeti.cli.SendJob([op]) |
|
475 |
|
|
476 |
return job_id |
|
474 |
return baserlib.SubmitJob([op]) |
|
477 | 475 |
|
478 | 476 |
|
479 | 477 |
class R_2_instances_name_shutdown(baserlib.R_Generic): |
... | ... | |
490 | 488 |
|
491 | 489 |
""" |
492 | 490 |
instance_name = self.items[0] |
493 |
op = ganeti.opcodes.OpShutdownInstance(instance_name=instance_name) |
|
494 |
|
|
495 |
job_id = ganeti.cli.SendJob([op]) |
|
491 |
op = opcodes.OpShutdownInstance(instance_name=instance_name) |
|
496 | 492 |
|
497 |
return job_id
|
|
493 |
return baserlib.SubmitJob([op])
|
|
498 | 494 |
|
499 | 495 |
|
500 | 496 |
class _R_Tags(baserlib.R_Generic): |
Also available in: Unified diff