root / lib / rapi / rlib1.py @ 21f04e5e
History | View | Annotate | Download (8.4 kB)
1 | 8c229cc7 | Oleksiy Mishchenko | #
|
---|---|---|---|
2 | 8c229cc7 | Oleksiy Mishchenko | #
|
3 | 8c229cc7 | Oleksiy Mishchenko | |
4 | 8c229cc7 | Oleksiy Mishchenko | # Copyright (C) 2006, 2007, 2008 Google Inc.
|
5 | 8c229cc7 | Oleksiy Mishchenko | #
|
6 | 8c229cc7 | Oleksiy Mishchenko | # This program is free software; you can redistribute it and/or modify
|
7 | 8c229cc7 | Oleksiy Mishchenko | # it under the terms of the GNU General Public License as published by
|
8 | 8c229cc7 | Oleksiy Mishchenko | # the Free Software Foundation; either version 2 of the License, or
|
9 | 8c229cc7 | Oleksiy Mishchenko | # (at your option) any later version.
|
10 | 8c229cc7 | Oleksiy Mishchenko | #
|
11 | 8c229cc7 | Oleksiy Mishchenko | # This program is distributed in the hope that it will be useful, but
|
12 | 8c229cc7 | Oleksiy Mishchenko | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 8c229cc7 | Oleksiy Mishchenko | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 8c229cc7 | Oleksiy Mishchenko | # General Public License for more details.
|
15 | 8c229cc7 | Oleksiy Mishchenko | #
|
16 | 8c229cc7 | Oleksiy Mishchenko | # You should have received a copy of the GNU General Public License
|
17 | 8c229cc7 | Oleksiy Mishchenko | # along with this program; if not, write to the Free Software
|
18 | 8c229cc7 | Oleksiy Mishchenko | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 8c229cc7 | Oleksiy Mishchenko | # 02110-1301, USA.
|
20 | 8c229cc7 | Oleksiy Mishchenko | |
21 | 8c229cc7 | Oleksiy Mishchenko | |
22 | 10b207d4 | Oleksiy Mishchenko | """Remote API version 1 resources library.
|
23 | 8c229cc7 | Oleksiy Mishchenko |
|
24 | 8c229cc7 | Oleksiy Mishchenko | """
|
25 | 8c229cc7 | Oleksiy Mishchenko | |
26 | 8c229cc7 | Oleksiy Mishchenko | import ganeti.cli |
27 | 10b207d4 | Oleksiy Mishchenko | import ganeti.errors |
28 | 10b207d4 | Oleksiy Mishchenko | import ganeti.opcodes |
29 | 8c229cc7 | Oleksiy Mishchenko | |
30 | 8c229cc7 | Oleksiy Mishchenko | from ganeti import constants |
31 | 937e4814 | Michael Hanselmann | from ganeti import http |
32 | 8c229cc7 | Oleksiy Mishchenko | |
33 | 38206f3c | Iustin Pop | from ganeti.rapi import baserlib |
34 | 8c229cc7 | Oleksiy Mishchenko | |
35 | 8c229cc7 | Oleksiy Mishchenko | |
36 | 2f7635f4 | Oleksiy Mishchenko | I_FIELDS = ["name", "os", "pnode", "snodes", "admin_state", "disk_template", |
37 | 1a05d855 | Oleksiy Mishchenko | "ip", "mac", "bridge", "sda_size", "sdb_size", "beparams", |
38 | 51ee2f49 | Oleksiy Mishchenko | "oper_state", "status", "tags"] |
39 | 51ee2f49 | Oleksiy Mishchenko | |
40 | 38206f3c | Iustin Pop | N_FIELDS = ["name", "dtotal", "dfree", |
41 | 51ee2f49 | Oleksiy Mishchenko | "mtotal", "mnode", "mfree", |
42 | 51ee2f49 | Oleksiy Mishchenko | "pinst_cnt", "sinst_cnt", "tags"] |
43 | 51ee2f49 | Oleksiy Mishchenko | |
44 | 51ee2f49 | Oleksiy Mishchenko | |
45 | 10b207d4 | Oleksiy Mishchenko | class R_version(baserlib.R_Generic): |
46 | 8c229cc7 | Oleksiy Mishchenko | """/version resource.
|
47 | 8c229cc7 | Oleksiy Mishchenko |
|
48 | 8c229cc7 | Oleksiy Mishchenko | This resource should be used to determine the remote API version and to adapt
|
49 | 8c229cc7 | Oleksiy Mishchenko | clients accordingly.
|
50 | 8c229cc7 | Oleksiy Mishchenko |
|
51 | 8c229cc7 | Oleksiy Mishchenko | """
|
52 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/version"
|
53 | 8c229cc7 | Oleksiy Mishchenko | |
54 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
55 | 8c229cc7 | Oleksiy Mishchenko | """Returns the remote API version.
|
56 | 8c229cc7 | Oleksiy Mishchenko |
|
57 | 8c229cc7 | Oleksiy Mishchenko | """
|
58 | 8c229cc7 | Oleksiy Mishchenko | return constants.RAPI_VERSION
|
59 | 8c229cc7 | Oleksiy Mishchenko | |
60 | 8c229cc7 | Oleksiy Mishchenko | |
61 | 10b207d4 | Oleksiy Mishchenko | class R_tags(baserlib.R_Generic): |
62 | 8c229cc7 | Oleksiy Mishchenko | """/tags resource.
|
63 | 8c229cc7 | Oleksiy Mishchenko |
|
64 | 8c229cc7 | Oleksiy Mishchenko | Manages cluster tags.
|
65 | 8c229cc7 | Oleksiy Mishchenko |
|
66 | 8c229cc7 | Oleksiy Mishchenko | """
|
67 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/tags"
|
68 | 8c229cc7 | Oleksiy Mishchenko | |
69 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
70 | 8c229cc7 | Oleksiy Mishchenko | """Returns a list of all cluster tags.
|
71 | 8c229cc7 | Oleksiy Mishchenko |
|
72 | 8c229cc7 | Oleksiy Mishchenko | Example: ["tag1", "tag2", "tag3"]
|
73 | 8c229cc7 | Oleksiy Mishchenko |
|
74 | 8c229cc7 | Oleksiy Mishchenko | """
|
75 | 10b207d4 | Oleksiy Mishchenko | return baserlib._Tags_GET(constants.TAG_CLUSTER)
|
76 | 8c229cc7 | Oleksiy Mishchenko | |
77 | 8c229cc7 | Oleksiy Mishchenko | |
78 | 10b207d4 | Oleksiy Mishchenko | class R_info(baserlib.R_Generic): |
79 | 8c229cc7 | Oleksiy Mishchenko | """Cluster info.
|
80 | 8c229cc7 | Oleksiy Mishchenko |
|
81 | 8c229cc7 | Oleksiy Mishchenko | """
|
82 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/info"
|
83 | 8c229cc7 | Oleksiy Mishchenko | |
84 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
85 | 8c229cc7 | Oleksiy Mishchenko | """Returns cluster information.
|
86 | 8c229cc7 | Oleksiy Mishchenko |
|
87 | 8c229cc7 | Oleksiy Mishchenko | Example: {
|
88 | 8c229cc7 | Oleksiy Mishchenko | "config_version": 3,
|
89 | 8c229cc7 | Oleksiy Mishchenko | "name": "cluster1.example.com",
|
90 | 8c229cc7 | Oleksiy Mishchenko | "software_version": "1.2.4",
|
91 | 8c229cc7 | Oleksiy Mishchenko | "os_api_version": 5,
|
92 | 8c229cc7 | Oleksiy Mishchenko | "export_version": 0,
|
93 | 8c229cc7 | Oleksiy Mishchenko | "master": "node1.example.com",
|
94 | 8c229cc7 | Oleksiy Mishchenko | "architecture": [
|
95 | 8c229cc7 | Oleksiy Mishchenko | "64bit",
|
96 | 8c229cc7 | Oleksiy Mishchenko | "x86_64"
|
97 | 8c229cc7 | Oleksiy Mishchenko | ],
|
98 | e49099a4 | Alexander Schreiber | "hypervisor_type": "xen-pvm",
|
99 | 8c229cc7 | Oleksiy Mishchenko | "protocol_version": 12
|
100 | 8c229cc7 | Oleksiy Mishchenko | }
|
101 | 8c229cc7 | Oleksiy Mishchenko |
|
102 | 8c229cc7 | Oleksiy Mishchenko | """
|
103 | 8c229cc7 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryClusterInfo() |
104 | 8c229cc7 | Oleksiy Mishchenko | return ganeti.cli.SubmitOpCode(op)
|
105 | 8c229cc7 | Oleksiy Mishchenko | |
106 | 8c229cc7 | Oleksiy Mishchenko | |
107 | 10b207d4 | Oleksiy Mishchenko | class R_nodes(baserlib.R_Generic): |
108 | 8c229cc7 | Oleksiy Mishchenko | """/nodes resource.
|
109 | 8c229cc7 | Oleksiy Mishchenko |
|
110 | 8c229cc7 | Oleksiy Mishchenko | """
|
111 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/nodes"
|
112 | 38206f3c | Iustin Pop | |
113 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
114 | 8c229cc7 | Oleksiy Mishchenko | """Returns a list of all nodes.
|
115 | 38206f3c | Iustin Pop |
|
116 | 8c229cc7 | Oleksiy Mishchenko | Returns:
|
117 | 8c229cc7 | Oleksiy Mishchenko | A dictionary with 'name' and 'uri' keys for each of them.
|
118 | 8c229cc7 | Oleksiy Mishchenko |
|
119 | 8c229cc7 | Oleksiy Mishchenko | Example: [
|
120 | 8c229cc7 | Oleksiy Mishchenko | {
|
121 | 8c229cc7 | Oleksiy Mishchenko | "name": "node1.example.com",
|
122 | 8c229cc7 | Oleksiy Mishchenko | "uri": "\/instances\/node1.example.com"
|
123 | 8c229cc7 | Oleksiy Mishchenko | },
|
124 | 8c229cc7 | Oleksiy Mishchenko | {
|
125 | 8c229cc7 | Oleksiy Mishchenko | "name": "node2.example.com",
|
126 | 8c229cc7 | Oleksiy Mishchenko | "uri": "\/instances\/node2.example.com"
|
127 | 8c229cc7 | Oleksiy Mishchenko | }]
|
128 | 8c229cc7 | Oleksiy Mishchenko |
|
129 | 38206f3c | Iustin Pop | If the optional 'bulk' argument is provided and set to 'true'
|
130 | 8c229cc7 | Oleksiy Mishchenko | value (i.e '?bulk=1'), the output contains detailed
|
131 | 8075ce7e | Oleksiy Mishchenko | information about nodes as a list.
|
132 | 8c229cc7 | Oleksiy Mishchenko |
|
133 | 8c229cc7 | Oleksiy Mishchenko | Example: [
|
134 | 8c229cc7 | Oleksiy Mishchenko | {
|
135 | 8c229cc7 | Oleksiy Mishchenko | "pinst_cnt": 1,
|
136 | 8c229cc7 | Oleksiy Mishchenko | "mfree": 31280,
|
137 | 8c229cc7 | Oleksiy Mishchenko | "mtotal": 32763,
|
138 | 8c229cc7 | Oleksiy Mishchenko | "name": "www.example.com",
|
139 | 8c229cc7 | Oleksiy Mishchenko | "tags": [],
|
140 | 8c229cc7 | Oleksiy Mishchenko | "mnode": 512,
|
141 | 8c229cc7 | Oleksiy Mishchenko | "dtotal": 5246208,
|
142 | 8c229cc7 | Oleksiy Mishchenko | "sinst_cnt": 2,
|
143 | 8c229cc7 | Oleksiy Mishchenko | "dfree": 5171712
|
144 | 8c229cc7 | Oleksiy Mishchenko | },
|
145 | 8c229cc7 | Oleksiy Mishchenko | ...
|
146 | 8c229cc7 | Oleksiy Mishchenko | ]
|
147 | 8c229cc7 | Oleksiy Mishchenko |
|
148 | 8c229cc7 | Oleksiy Mishchenko | """
|
149 | 8c229cc7 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryNodes(output_fields=["name"], names=[])
|
150 | 10b207d4 | Oleksiy Mishchenko | nodeslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
|
151 | 38206f3c | Iustin Pop | |
152 | 8c229cc7 | Oleksiy Mishchenko | if 'bulk' in self.queryargs: |
153 | 51ee2f49 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS, |
154 | 51ee2f49 | Oleksiy Mishchenko | names=nodeslist) |
155 | 51ee2f49 | Oleksiy Mishchenko | result = ganeti.cli.SubmitOpCode(op) |
156 | 51ee2f49 | Oleksiy Mishchenko | return baserlib.MapBulkFields(result, N_FIELDS)
|
157 | 8c229cc7 | Oleksiy Mishchenko | |
158 | 10b207d4 | Oleksiy Mishchenko | return baserlib.BuildUriList(nodeslist, "/nodes/%s") |
159 | 8c229cc7 | Oleksiy Mishchenko | |
160 | 8c229cc7 | Oleksiy Mishchenko | |
161 | 10b207d4 | Oleksiy Mishchenko | class R_nodes_name(baserlib.R_Generic): |
162 | 8c229cc7 | Oleksiy Mishchenko | """/nodes/[node_name] resources.
|
163 | 8c229cc7 | Oleksiy Mishchenko |
|
164 | 8c229cc7 | Oleksiy Mishchenko | """
|
165 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/nodes/[node_name]"
|
166 | 8c229cc7 | Oleksiy Mishchenko | |
167 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
168 | 38206f3c | Iustin Pop | """Send information about a node.
|
169 | 8c229cc7 | Oleksiy Mishchenko |
|
170 | 8c229cc7 | Oleksiy Mishchenko | """
|
171 | 8c229cc7 | Oleksiy Mishchenko | node_name = self.items[0] |
172 | 51ee2f49 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryNodes(output_fields=N_FIELDS, |
173 | 8c229cc7 | Oleksiy Mishchenko | names=[node_name]) |
174 | 8c229cc7 | Oleksiy Mishchenko | result = ganeti.cli.SubmitOpCode(op) |
175 | 8c229cc7 | Oleksiy Mishchenko | |
176 | 51ee2f49 | Oleksiy Mishchenko | return baserlib.MapFields(N_FIELDS, result[0]) |
177 | 8c229cc7 | Oleksiy Mishchenko | |
178 | 8c229cc7 | Oleksiy Mishchenko | |
179 | 10b207d4 | Oleksiy Mishchenko | class R_nodes_name_tags(baserlib.R_Generic): |
180 | 8c229cc7 | Oleksiy Mishchenko | """/nodes/[node_name]/tags resource.
|
181 | 8c229cc7 | Oleksiy Mishchenko |
|
182 | 8c229cc7 | Oleksiy Mishchenko | Manages per-node tags.
|
183 | 8c229cc7 | Oleksiy Mishchenko |
|
184 | 8c229cc7 | Oleksiy Mishchenko | """
|
185 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/nodes/[node_name]/tags"
|
186 | 8c229cc7 | Oleksiy Mishchenko | |
187 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
188 | 8c229cc7 | Oleksiy Mishchenko | """Returns a list of node tags.
|
189 | 8c229cc7 | Oleksiy Mishchenko |
|
190 | 8c229cc7 | Oleksiy Mishchenko | Example: ["tag1", "tag2", "tag3"]
|
191 | 8c229cc7 | Oleksiy Mishchenko |
|
192 | 8c229cc7 | Oleksiy Mishchenko | """
|
193 | 10b207d4 | Oleksiy Mishchenko | return baserlib._Tags_GET(constants.TAG_NODE, name=self.items[0]) |
194 | 8c229cc7 | Oleksiy Mishchenko | |
195 | 8c229cc7 | Oleksiy Mishchenko | |
196 | 10b207d4 | Oleksiy Mishchenko | class R_instances(baserlib.R_Generic): |
197 | 8c229cc7 | Oleksiy Mishchenko | """/instances resource.
|
198 | 8c229cc7 | Oleksiy Mishchenko |
|
199 | 8c229cc7 | Oleksiy Mishchenko | """
|
200 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/instances"
|
201 | 8c229cc7 | Oleksiy Mishchenko | |
202 | 8c229cc7 | Oleksiy Mishchenko | |
203 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
204 | 8c229cc7 | Oleksiy Mishchenko | """Returns a list of all available instances.
|
205 | 38206f3c | Iustin Pop |
|
206 | 8c229cc7 | Oleksiy Mishchenko | Returns:
|
207 | 8c229cc7 | Oleksiy Mishchenko | A dictionary with 'name' and 'uri' keys for each of them.
|
208 | 8c229cc7 | Oleksiy Mishchenko |
|
209 | 8c229cc7 | Oleksiy Mishchenko | Example: [
|
210 | 8c229cc7 | Oleksiy Mishchenko | {
|
211 | 8c229cc7 | Oleksiy Mishchenko | "name": "web.example.com",
|
212 | 8c229cc7 | Oleksiy Mishchenko | "uri": "\/instances\/web.example.com"
|
213 | 8c229cc7 | Oleksiy Mishchenko | },
|
214 | 8c229cc7 | Oleksiy Mishchenko | {
|
215 | 8c229cc7 | Oleksiy Mishchenko | "name": "mail.example.com",
|
216 | 8c229cc7 | Oleksiy Mishchenko | "uri": "\/instances\/mail.example.com"
|
217 | 8c229cc7 | Oleksiy Mishchenko | }]
|
218 | 8c229cc7 | Oleksiy Mishchenko |
|
219 | 38206f3c | Iustin Pop | If the optional 'bulk' argument is provided and set to 'true'
|
220 | 8c229cc7 | Oleksiy Mishchenko | value (i.e '?bulk=1'), the output contains detailed
|
221 | 8075ce7e | Oleksiy Mishchenko | information about instances as a list.
|
222 | 8c229cc7 | Oleksiy Mishchenko |
|
223 | 8c229cc7 | Oleksiy Mishchenko | Example: [
|
224 | 8c229cc7 | Oleksiy Mishchenko | {
|
225 | 8c229cc7 | Oleksiy Mishchenko | "status": "running",
|
226 | 8c229cc7 | Oleksiy Mishchenko | "bridge": "xen-br0",
|
227 | 8c229cc7 | Oleksiy Mishchenko | "name": "web.example.com",
|
228 | 8c229cc7 | Oleksiy Mishchenko | "tags": ["tag1", "tag2"],
|
229 | 8c229cc7 | Oleksiy Mishchenko | "admin_ram": 512,
|
230 | 8c229cc7 | Oleksiy Mishchenko | "sda_size": 20480,
|
231 | 8c229cc7 | Oleksiy Mishchenko | "pnode": "node1.example.com",
|
232 | 8c229cc7 | Oleksiy Mishchenko | "mac": "01:23:45:67:89:01",
|
233 | 8c229cc7 | Oleksiy Mishchenko | "sdb_size": 4096,
|
234 | 8c229cc7 | Oleksiy Mishchenko | "snodes": ["node2.example.com"],
|
235 | 8c229cc7 | Oleksiy Mishchenko | "disk_template": "drbd",
|
236 | 8c229cc7 | Oleksiy Mishchenko | "ip": null,
|
237 | 8c229cc7 | Oleksiy Mishchenko | "admin_state": true,
|
238 | 8c229cc7 | Oleksiy Mishchenko | "os": "debian-etch",
|
239 | 8c229cc7 | Oleksiy Mishchenko | "vcpus": 2,
|
240 | 8c229cc7 | Oleksiy Mishchenko | "oper_state": true
|
241 | 8c229cc7 | Oleksiy Mishchenko | },
|
242 | 8c229cc7 | Oleksiy Mishchenko | ...
|
243 | 8c229cc7 | Oleksiy Mishchenko | ]
|
244 | 8c229cc7 | Oleksiy Mishchenko |
|
245 | 8c229cc7 | Oleksiy Mishchenko | """
|
246 | 8c229cc7 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryInstances(output_fields=["name"], names=[])
|
247 | 10b207d4 | Oleksiy Mishchenko | instanceslist = baserlib.ExtractField(ganeti.cli.SubmitOpCode(op), 0)
|
248 | 38206f3c | Iustin Pop | |
249 | 8c229cc7 | Oleksiy Mishchenko | if 'bulk' in self.queryargs: |
250 | 51ee2f49 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS, |
251 | 51ee2f49 | Oleksiy Mishchenko | names=instanceslist) |
252 | 51ee2f49 | Oleksiy Mishchenko | result = ganeti.cli.SubmitOpCode(op) |
253 | 51ee2f49 | Oleksiy Mishchenko | return baserlib.MapBulkFields(result, I_FIELDS)
|
254 | 51ee2f49 | Oleksiy Mishchenko | |
255 | 8c229cc7 | Oleksiy Mishchenko | |
256 | 8c229cc7 | Oleksiy Mishchenko | else:
|
257 | 10b207d4 | Oleksiy Mishchenko | return baserlib.BuildUriList(instanceslist, "/instances/%s") |
258 | 8c229cc7 | Oleksiy Mishchenko | |
259 | 8c229cc7 | Oleksiy Mishchenko | |
260 | 10b207d4 | Oleksiy Mishchenko | class R_instances_name(baserlib.R_Generic): |
261 | 8c229cc7 | Oleksiy Mishchenko | """/instances/[instance_name] resources.
|
262 | 8c229cc7 | Oleksiy Mishchenko |
|
263 | 8c229cc7 | Oleksiy Mishchenko | """
|
264 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/instances/[instance_name]"
|
265 | 8c229cc7 | Oleksiy Mishchenko | |
266 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
267 | 8c229cc7 | Oleksiy Mishchenko | """Send information about an instance.
|
268 | 8c229cc7 | Oleksiy Mishchenko |
|
269 | 8c229cc7 | Oleksiy Mishchenko | """
|
270 | 8c229cc7 | Oleksiy Mishchenko | instance_name = self.items[0] |
271 | 51ee2f49 | Oleksiy Mishchenko | op = ganeti.opcodes.OpQueryInstances(output_fields=I_FIELDS, |
272 | 8c229cc7 | Oleksiy Mishchenko | names=[instance_name]) |
273 | 8c229cc7 | Oleksiy Mishchenko | result = ganeti.cli.SubmitOpCode(op) |
274 | 8c229cc7 | Oleksiy Mishchenko | |
275 | 51ee2f49 | Oleksiy Mishchenko | return baserlib.MapFields(I_FIELDS, result[0]) |
276 | 8c229cc7 | Oleksiy Mishchenko | |
277 | 2f7635f4 | Oleksiy Mishchenko | def DELETE(self): |
278 | 2f7635f4 | Oleksiy Mishchenko | """Removes an instance.
|
279 | 2f7635f4 | Oleksiy Mishchenko |
|
280 | 2f7635f4 | Oleksiy Mishchenko | """
|
281 | 2f7635f4 | Oleksiy Mishchenko | instance_name = self.items[0] |
282 | 2f7635f4 | Oleksiy Mishchenko | op = ganeti.opcodes.OpRemoveInstance(instance_name=instance_name, |
283 | 2f7635f4 | Oleksiy Mishchenko | ignore_failures=True)
|
284 | 2f7635f4 | Oleksiy Mishchenko | job_id = ganeti.cli.SendJob([op]) |
285 | 2f7635f4 | Oleksiy Mishchenko | |
286 | 2f7635f4 | Oleksiy Mishchenko | return job_id
|
287 | 2f7635f4 | Oleksiy Mishchenko | |
288 | 21f04e5e | Oleksiy Mishchenko | def PUT(self): |
289 | d50b3059 | Oleksiy Mishchenko | """Modify an instance.
|
290 | d50b3059 | Oleksiy Mishchenko |
|
291 | d50b3059 | Oleksiy Mishchenko | """
|
292 | d50b3059 | Oleksiy Mishchenko | instance_name = self.items[0] |
293 | d50b3059 | Oleksiy Mishchenko | opts = {} |
294 | d50b3059 | Oleksiy Mishchenko | |
295 | d50b3059 | Oleksiy Mishchenko | for key in self.queryargs: |
296 | d50b3059 | Oleksiy Mishchenko | opts[key] = self.queryargs[key][0] |
297 | d50b3059 | Oleksiy Mishchenko | |
298 | d50b3059 | Oleksiy Mishchenko | beparams = baserlib.MakeParamsDict(opts, constants.BES_PARAMETERS) |
299 | d50b3059 | Oleksiy Mishchenko | hvparams = baserlib.MakeParamsDict(opts, constants.HVS_PARAMETERS) |
300 | d50b3059 | Oleksiy Mishchenko | |
301 | d50b3059 | Oleksiy Mishchenko | op = ganeti.opcodes.OpSetInstanceParams( |
302 | d50b3059 | Oleksiy Mishchenko | instance_name=instance_name, |
303 | d50b3059 | Oleksiy Mishchenko | ip=opts.get('ip', None), |
304 | d50b3059 | Oleksiy Mishchenko | bridge=opts.get('bridge', None), |
305 | d50b3059 | Oleksiy Mishchenko | mac=opts.get('mac', None), |
306 | d50b3059 | Oleksiy Mishchenko | hvparams=hvparams, |
307 | d50b3059 | Oleksiy Mishchenko | beparams=beparams, |
308 | d50b3059 | Oleksiy Mishchenko | force=opts.get('force', None)) |
309 | d50b3059 | Oleksiy Mishchenko | |
310 | d50b3059 | Oleksiy Mishchenko | job_id = ganeti.cli.SendJob([op]) |
311 | d50b3059 | Oleksiy Mishchenko | |
312 | d50b3059 | Oleksiy Mishchenko | return job_id
|
313 | d50b3059 | Oleksiy Mishchenko | |
314 | 8c229cc7 | Oleksiy Mishchenko | |
315 | 10b207d4 | Oleksiy Mishchenko | class R_instances_name_tags(baserlib.R_Generic): |
316 | 8c229cc7 | Oleksiy Mishchenko | """/instances/[instance_name]/tags resource.
|
317 | 8c229cc7 | Oleksiy Mishchenko |
|
318 | 8c229cc7 | Oleksiy Mishchenko | Manages per-instance tags.
|
319 | 8c229cc7 | Oleksiy Mishchenko |
|
320 | 8c229cc7 | Oleksiy Mishchenko | """
|
321 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/instances/[instance_name]/tags"
|
322 | 8c229cc7 | Oleksiy Mishchenko | |
323 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
324 | 8c229cc7 | Oleksiy Mishchenko | """Returns a list of instance tags.
|
325 | 8c229cc7 | Oleksiy Mishchenko |
|
326 | 8c229cc7 | Oleksiy Mishchenko | Example: ["tag1", "tag2", "tag3"]
|
327 | 8c229cc7 | Oleksiy Mishchenko |
|
328 | 8c229cc7 | Oleksiy Mishchenko | """
|
329 | 10b207d4 | Oleksiy Mishchenko | return baserlib._Tags_GET(constants.TAG_INSTANCE, name=self.items[0]) |
330 | 8c229cc7 | Oleksiy Mishchenko | |
331 | 8c229cc7 | Oleksiy Mishchenko | |
332 | 10b207d4 | Oleksiy Mishchenko | class R_os(baserlib.R_Generic): |
333 | 8c229cc7 | Oleksiy Mishchenko | """/os resource.
|
334 | 8c229cc7 | Oleksiy Mishchenko |
|
335 | 8c229cc7 | Oleksiy Mishchenko | """
|
336 | 8c229cc7 | Oleksiy Mishchenko | DOC_URI = "/os"
|
337 | 8c229cc7 | Oleksiy Mishchenko | |
338 | 8c229cc7 | Oleksiy Mishchenko | def GET(self): |
339 | 8c229cc7 | Oleksiy Mishchenko | """Return a list of all OSes.
|
340 | 8c229cc7 | Oleksiy Mishchenko |
|
341 | 8c229cc7 | Oleksiy Mishchenko | Can return error 500 in case of a problem.
|
342 | 8c229cc7 | Oleksiy Mishchenko |
|
343 | 8c229cc7 | Oleksiy Mishchenko | Example: ["debian-etch"]
|
344 | 8c229cc7 | Oleksiy Mishchenko |
|
345 | 8c229cc7 | Oleksiy Mishchenko | """
|
346 | 8c229cc7 | Oleksiy Mishchenko | op = ganeti.opcodes.OpDiagnoseOS(output_fields=["name", "valid"], |
347 | 8c229cc7 | Oleksiy Mishchenko | names=[]) |
348 | 8c229cc7 | Oleksiy Mishchenko | diagnose_data = ganeti.cli.SubmitOpCode(op) |
349 | 8c229cc7 | Oleksiy Mishchenko | |
350 | 8c229cc7 | Oleksiy Mishchenko | if not isinstance(diagnose_data, list): |
351 | 937e4814 | Michael Hanselmann | raise http.HTTPInternalError(message="Can't get OS list") |
352 | 8c229cc7 | Oleksiy Mishchenko | |
353 | 8c229cc7 | Oleksiy Mishchenko | return [row[0] for row in diagnose_data if row[1]] |