Revision 4e5a68f8 lib/rapi/rlib2.py
b/lib/rapi/rlib2.py | ||
---|---|---|
29 | 29 |
from ganeti import constants |
30 | 30 |
from ganeti.rapi import baserlib |
31 | 31 |
|
32 |
from ganeti.rapi.rlib1 import I_FIELDS, N_FIELDS |
|
32 |
|
|
33 |
I_FIELDS = ["name", "os", "pnode", "snodes", "admin_state", "disk_template", |
|
34 |
"ip", "mac", "bridge", "sda_size", "sdb_size", "beparams", |
|
35 |
"oper_state", "status", "tags"] |
|
36 |
|
|
37 |
N_FIELDS = ["name", "dtotal", "dfree", |
|
38 |
"mtotal", "mnode", "mfree", |
|
39 |
"pinst_cnt", "sinst_cnt", "tags"] |
|
40 |
|
|
41 |
|
|
42 |
class R_version(baserlib.R_Generic): |
|
43 |
"""/version resource. |
|
44 |
|
|
45 |
This resource should be used to determine the remote API version and |
|
46 |
to adapt clients accordingly. |
|
47 |
|
|
48 |
""" |
|
49 |
DOC_URI = "/version" |
|
50 |
|
|
51 |
def GET(self): |
|
52 |
"""Returns the remote API version. |
|
53 |
|
|
54 |
""" |
|
55 |
return constants.RAPI_VERSION |
|
56 |
|
|
57 |
|
|
58 |
class R_2_info(baserlib.R_Generic): |
|
59 |
"""Cluster info. |
|
60 |
|
|
61 |
""" |
|
62 |
DOC_URI = "/2/info" |
|
63 |
|
|
64 |
def GET(self): |
|
65 |
"""Returns cluster information. |
|
66 |
|
|
67 |
Example:: |
|
68 |
|
|
69 |
{ |
|
70 |
"config_version": 3, |
|
71 |
"name": "cluster1.example.com", |
|
72 |
"software_version": "1.2.4", |
|
73 |
"os_api_version": 5, |
|
74 |
"export_version": 0, |
|
75 |
"master": "node1.example.com", |
|
76 |
"architecture": [ |
|
77 |
"64bit", |
|
78 |
"x86_64" |
|
79 |
], |
|
80 |
"hypervisor_type": "xen-pvm", |
|
81 |
"protocol_version": 12 |
|
82 |
} |
|
83 |
|
|
84 |
""" |
|
85 |
op = ganeti.opcodes.OpQueryClusterInfo() |
|
86 |
return ganeti.cli.SubmitOpCode(op) |
|
87 |
|
|
88 |
|
|
89 |
class R_2_tags(baserlib.R_Generic): |
|
90 |
"""/2/tags resource. |
|
91 |
|
|
92 |
Manages cluster tags. |
|
93 |
|
|
94 |
""" |
|
95 |
DOC_URI = "/2/tags" |
|
96 |
|
|
97 |
def GET(self): |
|
98 |
"""Returns a list of all cluster tags. |
|
99 |
|
|
100 |
Example: ["tag1", "tag2", "tag3"] |
|
101 |
|
|
102 |
""" |
|
103 |
return baserlib._Tags_GET(constants.TAG_CLUSTER) |
|
104 |
|
|
105 |
|
|
106 |
class R_2_os(baserlib.R_Generic): |
|
107 |
"""/2/os resource. |
|
108 |
|
|
109 |
""" |
|
110 |
DOC_URI = "/2/os" |
|
111 |
|
|
112 |
def GET(self): |
|
113 |
"""Return a list of all OSes. |
|
114 |
|
|
115 |
Can return error 500 in case of a problem. |
|
116 |
|
|
117 |
Example: ["debian-etch"] |
|
118 |
|
|
119 |
""" |
|
120 |
op = ganeti.opcodes.OpDiagnoseOS(output_fields=["name", "valid"], |
|
121 |
names=[]) |
|
122 |
diagnose_data = ganeti.cli.SubmitOpCode(op) |
|
123 |
|
|
124 |
if not isinstance(diagnose_data, list): |
|
125 |
raise http.HttpInternalServerError(message="Can't get OS list") |
|
126 |
|
|
127 |
return [row[0] for row in diagnose_data if row[1]] |
|
33 | 128 |
|
34 | 129 |
|
35 | 130 |
class R_2_jobs(baserlib.R_Generic): |
... | ... | |
141 | 236 |
uri_fields=("id", "uri")) |
142 | 237 |
|
143 | 238 |
|
144 |
class R_nodes(R_2_nodes):
|
|
145 |
"""/nodes resource
|
|
239 |
class R_2_nodes_name(baserlib.R_Generic):
|
|
240 |
"""/2/nodes/[node_name] resources.
|
|
146 | 241 |
|
147 | 242 |
""" |
148 |
# TODO: Temporary resource will be deprecated |
|
149 |
DOC_URI = "/nodes" |
|
243 |
DOC_URI = "/nodes/[node_name]" |
|
244 |
|
|
245 |
def GET(self): |
|
246 |
"""Send information about a node. |
|
247 |
|
|
248 |
""" |
|
249 |
node_name = self.items[0] |
|
250 |
op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS, |
|
251 |
names=[node_name]) |
|
252 |
result = ganeti.cli.SubmitOpCode(op) |
|
253 |
|
|
254 |
return baserlib.MapFields(N_FIELDS, result[0]) |
|
150 | 255 |
|
151 | 256 |
|
152 | 257 |
class R_2_instances(baserlib.R_Generic): |
... | ... | |
254 | 359 |
return job_id |
255 | 360 |
|
256 | 361 |
|
257 |
class R_instances(R_2_instances):
|
|
258 |
"""/instances resource.
|
|
362 |
class R_2_instances_name(baserlib.R_Generic):
|
|
363 |
"""/2/instances/[instance_name] resources.
|
|
259 | 364 |
|
260 | 365 |
""" |
261 |
# TODO: Temporary resource will be deprecated |
|
262 |
DOC_URI = "/instances" |
|
366 |
DOC_URI = "/2/instances/[instance_name]" |
|
367 |
|
|
368 |
def GET(self): |
|
369 |
"""Send information about an instance. |
|
370 |
|
|
371 |
""" |
|
372 |
instance_name = self.items[0] |
|
373 |
op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS, |
|
374 |
names=[instance_name]) |
|
375 |
result = ganeti.cli.SubmitOpCode(op) |
|
376 |
|
|
377 |
return baserlib.MapFields(I_FIELDS, result[0]) |
|
263 | 378 |
|
264 | 379 |
|
265 | 380 |
class R_2_instances_name_reboot(baserlib.R_Generic): |
Also available in: Unified diff