root / lib / rapi / rlib2.py @ 0e514de1
History | View | Annotate | Download (38.8 kB)
1 | 10b207d4 | Oleksiy Mishchenko | #
|
---|---|---|---|
2 | 10b207d4 | Oleksiy Mishchenko | #
|
3 | 10b207d4 | Oleksiy Mishchenko | |
4 | ab9e48d1 | Iustin Pop | # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
|
5 | 10b207d4 | Oleksiy Mishchenko | #
|
6 | 10b207d4 | Oleksiy Mishchenko | # This program is free software; you can redistribute it and/or modify
|
7 | 10b207d4 | Oleksiy Mishchenko | # it under the terms of the GNU General Public License as published by
|
8 | 10b207d4 | Oleksiy Mishchenko | # the Free Software Foundation; either version 2 of the License, or
|
9 | 10b207d4 | Oleksiy Mishchenko | # (at your option) any later version.
|
10 | 10b207d4 | Oleksiy Mishchenko | #
|
11 | 10b207d4 | Oleksiy Mishchenko | # This program is distributed in the hope that it will be useful, but
|
12 | 10b207d4 | Oleksiy Mishchenko | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 10b207d4 | Oleksiy Mishchenko | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 10b207d4 | Oleksiy Mishchenko | # General Public License for more details.
|
15 | 10b207d4 | Oleksiy Mishchenko | #
|
16 | 10b207d4 | Oleksiy Mishchenko | # You should have received a copy of the GNU General Public License
|
17 | 10b207d4 | Oleksiy Mishchenko | # along with this program; if not, write to the Free Software
|
18 | 10b207d4 | Oleksiy Mishchenko | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 10b207d4 | Oleksiy Mishchenko | # 02110-1301, USA.
|
20 | 10b207d4 | Oleksiy Mishchenko | |
21 | 10b207d4 | Oleksiy Mishchenko | |
22 | f3c1a70c | Michael Hanselmann | """Remote API resource implementations.
|
23 | 10b207d4 | Oleksiy Mishchenko |
|
24 | f3c1a70c | Michael Hanselmann | PUT or POST?
|
25 | f3c1a70c | Michael Hanselmann | ============
|
26 | 88394aa7 | René Nussbaumer |
|
27 | f3c1a70c | Michael Hanselmann | According to RFC2616 the main difference between PUT and POST is that
|
28 | f3c1a70c | Michael Hanselmann | POST can create new resources but PUT can only create the resource the
|
29 | f3c1a70c | Michael Hanselmann | URI was pointing to on the PUT request.
|
30 | 88394aa7 | René Nussbaumer |
|
31 | d91a933f | Michael Hanselmann | In the context of this module POST on ``/2/instances`` to change an existing
|
32 | f3c1a70c | Michael Hanselmann | entity is legitimate, while PUT would not be. PUT creates a new entity (e.g. a
|
33 | f3c1a70c | Michael Hanselmann | new instance) with a name specified in the request.
|
34 | 88394aa7 | René Nussbaumer |
|
35 | 140ff718 | Michael Hanselmann | Quoting from RFC2616, section 9.6::
|
36 | f3c1a70c | Michael Hanselmann |
|
37 | f3c1a70c | Michael Hanselmann | The fundamental difference between the POST and PUT requests is reflected in
|
38 | f3c1a70c | Michael Hanselmann | the different meaning of the Request-URI. The URI in a POST request
|
39 | f3c1a70c | Michael Hanselmann | identifies the resource that will handle the enclosed entity. That resource
|
40 | f3c1a70c | Michael Hanselmann | might be a data-accepting process, a gateway to some other protocol, or a
|
41 | f3c1a70c | Michael Hanselmann | separate entity that accepts annotations. In contrast, the URI in a PUT
|
42 | f3c1a70c | Michael Hanselmann | request identifies the entity enclosed with the request -- the user agent
|
43 | f3c1a70c | Michael Hanselmann | knows what URI is intended and the server MUST NOT attempt to apply the
|
44 | f3c1a70c | Michael Hanselmann | request to some other resource. If the server desires that the request be
|
45 | f3c1a70c | Michael Hanselmann | applied to a different URI, it MUST send a 301 (Moved Permanently) response;
|
46 | f3c1a70c | Michael Hanselmann | the user agent MAY then make its own decision regarding whether or not to
|
47 | f3c1a70c | Michael Hanselmann | redirect the request.
|
48 | f3c1a70c | Michael Hanselmann |
|
49 | f3c1a70c | Michael Hanselmann | So when adding new methods, if they are operating on the URI entity itself,
|
50 | f3c1a70c | Michael Hanselmann | PUT should be prefered over POST.
|
51 | 88394aa7 | René Nussbaumer |
|
52 | 10b207d4 | Oleksiy Mishchenko | """
|
53 | 10b207d4 | Oleksiy Mishchenko | |
54 | b459a848 | Andrea Spadaccini | # pylint: disable=C0103
|
55 | fe267188 | Iustin Pop | |
56 | fe267188 | Iustin Pop | # C0103: Invalid name, since the R_* names are not conforming
|
57 | fe267188 | Iustin Pop | |
58 | 59b4eeef | Iustin Pop | from ganeti import opcodes |
59 | e5ff1a47 | René Nussbaumer | from ganeti import objects |
60 | 15fd9fd5 | Oleksiy Mishchenko | from ganeti import http |
61 | 15fd9fd5 | Oleksiy Mishchenko | from ganeti import constants |
62 | 59b4eeef | Iustin Pop | from ganeti import cli |
63 | 8381fa2d | Michael Hanselmann | from ganeti import rapi |
64 | d1c172de | Michael Hanselmann | from ganeti import ht |
65 | e987f166 | Michael Hanselmann | from ganeti import compat |
66 | be1ddd09 | Michael Hanselmann | from ganeti import ssconf |
67 | 38206f3c | Iustin Pop | from ganeti.rapi import baserlib |
68 | 10b207d4 | Oleksiy Mishchenko | |
69 | 4e5a68f8 | Oleksiy Mishchenko | |
70 | 7118a0df | Iustin Pop | _COMMON_FIELDS = ["ctime", "mtime", "uuid", "serial_no", "tags"] |
71 | 9031ee8e | Iustin Pop | I_FIELDS = ["name", "admin_state", "os", |
72 | 9031ee8e | Iustin Pop | "pnode", "snodes", |
73 | 9031ee8e | Iustin Pop | "disk_template",
|
74 | 4588b4bd | Dimitris Aragiorgis | "nic.ips", "nic.macs", "nic.modes", |
75 | 4588b4bd | Dimitris Aragiorgis | "nic.links", "nic.networks", "nic.bridges", |
76 | a8b16c4e | Tim Boring | "network_port",
|
77 | 0e514de1 | Bernardo Dal Seno | "disk.sizes", "disk.spindles", "disk_usage", |
78 | a5b9d725 | Iustin Pop | "beparams", "hvparams", |
79 | 4ea3de4e | Balazs Lecz | "oper_state", "oper_ram", "oper_vcpus", "status", |
80 | 90224407 | Iustin Pop | "custom_hvparams", "custom_beparams", "custom_nicparams", |
81 | 7118a0df | Iustin Pop | ] + _COMMON_FIELDS |
82 | 9031ee8e | Iustin Pop | |
83 | 0b2454b9 | Iustin Pop | N_FIELDS = ["name", "offline", "master_candidate", "drained", |
84 | 9031ee8e | Iustin Pop | "dtotal", "dfree", |
85 | 4e5a68f8 | Oleksiy Mishchenko | "mtotal", "mnode", "mfree", |
86 | 7118a0df | Iustin Pop | "pinst_cnt", "sinst_cnt", |
87 | 0105bad3 | Iustin Pop | "ctotal", "cnodes", "csockets", |
88 | 7118a0df | Iustin Pop | "pip", "sip", "role", |
89 | 93962b80 | Iustin Pop | "pinst_list", "sinst_list", |
90 | c190e817 | Iustin Pop | "master_capable", "vm_capable", |
91 | 37e61a77 | Iustin Pop | "ndparams",
|
92 | fd254195 | Iustin Pop | "group.uuid",
|
93 | 7118a0df | Iustin Pop | ] + _COMMON_FIELDS |
94 | 4e5a68f8 | Oleksiy Mishchenko | |
95 | 4588b4bd | Dimitris Aragiorgis | NET_FIELDS = ["name", "network", "gateway", |
96 | 4588b4bd | Dimitris Aragiorgis | "network6", "gateway6", |
97 | 5cfa6c37 | Dimitris Aragiorgis | "mac_prefix",
|
98 | 4588b4bd | Dimitris Aragiorgis | "free_count", "reserved_count", |
99 | 4588b4bd | Dimitris Aragiorgis | "map", "group_list", "inst_list", |
100 | 8140e24f | Dimitris Aragiorgis | "external_reservations", "tags", |
101 | 3c286190 | Dimitris Aragiorgis | ] |
102 | 4588b4bd | Dimitris Aragiorgis | |
103 | f4e86448 | Michael Hanselmann | G_FIELDS = [ |
104 | f4e86448 | Michael Hanselmann | "alloc_policy",
|
105 | f4e86448 | Michael Hanselmann | "name",
|
106 | f4e86448 | Michael Hanselmann | "node_cnt",
|
107 | f4e86448 | Michael Hanselmann | "node_list",
|
108 | edd49f9b | Agata Murawska | "ipolicy",
|
109 | 003306f9 | Iustin Pop | "custom_ipolicy",
|
110 | 003306f9 | Iustin Pop | "diskparams",
|
111 | 003306f9 | Iustin Pop | "custom_diskparams",
|
112 | 003306f9 | Iustin Pop | "ndparams",
|
113 | 003306f9 | Iustin Pop | "custom_ndparams",
|
114 | f4e86448 | Michael Hanselmann | ] + _COMMON_FIELDS |
115 | 0897dc97 | Adeodato Simo | |
116 | bd7b2070 | Michael Hanselmann | J_FIELDS_BULK = [ |
117 | e987f166 | Michael Hanselmann | "id", "ops", "status", "summary", |
118 | bd7b2070 | Michael Hanselmann | "opstatus",
|
119 | e987f166 | Michael Hanselmann | "received_ts", "start_ts", "end_ts", |
120 | e987f166 | Michael Hanselmann | ] |
121 | e987f166 | Michael Hanselmann | |
122 | bd7b2070 | Michael Hanselmann | J_FIELDS = J_FIELDS_BULK + [ |
123 | bd7b2070 | Michael Hanselmann | "oplog",
|
124 | bd7b2070 | Michael Hanselmann | "opresult",
|
125 | bd7b2070 | Michael Hanselmann | ] |
126 | bd7b2070 | Michael Hanselmann | |
127 | 64dae8fc | Michael Hanselmann | _NR_DRAINED = "drained"
|
128 | 51cc8637 | Michael Hanselmann | _NR_MASTER_CANDIDATE = "master-candidate"
|
129 | 64dae8fc | Michael Hanselmann | _NR_MASTER = "master"
|
130 | 64dae8fc | Michael Hanselmann | _NR_OFFLINE = "offline"
|
131 | 64dae8fc | Michael Hanselmann | _NR_REGULAR = "regular"
|
132 | 64dae8fc | Michael Hanselmann | |
133 | 64dae8fc | Michael Hanselmann | _NR_MAP = { |
134 | 1e28e3b8 | Michael Hanselmann | constants.NR_MASTER: _NR_MASTER, |
135 | 51cc8637 | Michael Hanselmann | constants.NR_MCANDIDATE: _NR_MASTER_CANDIDATE, |
136 | 1e28e3b8 | Michael Hanselmann | constants.NR_DRAINED: _NR_DRAINED, |
137 | 1e28e3b8 | Michael Hanselmann | constants.NR_OFFLINE: _NR_OFFLINE, |
138 | 1e28e3b8 | Michael Hanselmann | constants.NR_REGULAR: _NR_REGULAR, |
139 | 64dae8fc | Michael Hanselmann | } |
140 | 64dae8fc | Michael Hanselmann | |
141 | 1e28e3b8 | Michael Hanselmann | assert frozenset(_NR_MAP.keys()) == constants.NR_ALL |
142 | 1e28e3b8 | Michael Hanselmann | |
143 | d975f482 | Michael Hanselmann | # Request data version field
|
144 | d975f482 | Michael Hanselmann | _REQ_DATA_VERSION = "__version__"
|
145 | d975f482 | Michael Hanselmann | |
146 | 6395cebb | Michael Hanselmann | # Feature string for instance creation request data version 1
|
147 | 6395cebb | Michael Hanselmann | _INST_CREATE_REQV1 = "instance-create-reqv1"
|
148 | 6395cebb | Michael Hanselmann | |
149 | c744425f | Michael Hanselmann | # Feature string for instance reinstall request version 1
|
150 | c744425f | Michael Hanselmann | _INST_REINSTALL_REQV1 = "instance-reinstall-reqv1"
|
151 | c744425f | Michael Hanselmann | |
152 | b7a1c816 | Michael Hanselmann | # Feature string for node migration version 1
|
153 | b7a1c816 | Michael Hanselmann | _NODE_MIGRATE_REQV1 = "node-migrate-reqv1"
|
154 | b7a1c816 | Michael Hanselmann | |
155 | de40437a | Michael Hanselmann | # Feature string for node evacuation with LU-generated jobs
|
156 | de40437a | Michael Hanselmann | _NODE_EVAC_RES1 = "node-evac-res1"
|
157 | de40437a | Michael Hanselmann | |
158 | b8028dcf | Michael Hanselmann | ALL_FEATURES = compat.UniqueFrozenset([ |
159 | b4fcee5b | Michael Hanselmann | _INST_CREATE_REQV1, |
160 | b4fcee5b | Michael Hanselmann | _INST_REINSTALL_REQV1, |
161 | b4fcee5b | Michael Hanselmann | _NODE_MIGRATE_REQV1, |
162 | b4fcee5b | Michael Hanselmann | _NODE_EVAC_RES1, |
163 | b4fcee5b | Michael Hanselmann | ]) |
164 | b4fcee5b | Michael Hanselmann | |
165 | 793a8f7c | Michael Hanselmann | # Timeout for /2/jobs/[job_id]/wait. Gives job up to 10 seconds to change.
|
166 | 793a8f7c | Michael Hanselmann | _WFJC_TIMEOUT = 10
|
167 | 793a8f7c | Michael Hanselmann | |
168 | 4e5a68f8 | Oleksiy Mishchenko | |
169 | 28a45bfc | René Nussbaumer | # FIXME: For compatibility we update the beparams/memory field. Needs to be
|
170 | 09b7b6f2 | Michele Tartara | # removed in Ganeti 2.8
|
171 | 28a45bfc | René Nussbaumer | def _UpdateBeparams(inst): |
172 | 28a45bfc | René Nussbaumer | """Updates the beparams dict of inst to support the memory field.
|
173 | 28a45bfc | René Nussbaumer |
|
174 | 28a45bfc | René Nussbaumer | @param inst: Inst dict
|
175 | 28a45bfc | René Nussbaumer | @return: Updated inst dict
|
176 | 28a45bfc | René Nussbaumer |
|
177 | 28a45bfc | René Nussbaumer | """
|
178 | 28a45bfc | René Nussbaumer | beparams = inst["beparams"]
|
179 | 28a45bfc | René Nussbaumer | beparams[constants.BE_MEMORY] = beparams[constants.BE_MAXMEM] |
180 | 28a45bfc | René Nussbaumer | |
181 | 28a45bfc | René Nussbaumer | return inst
|
182 | 28a45bfc | René Nussbaumer | |
183 | 28a45bfc | René Nussbaumer | |
184 | 26ff6ee2 | Michael Hanselmann | class R_root(baserlib.ResourceBase): |
185 | 0f945c65 | Michael Hanselmann | """/ resource.
|
186 | 0f945c65 | Michael Hanselmann |
|
187 | 0f945c65 | Michael Hanselmann | """
|
188 | 0f945c65 | Michael Hanselmann | @staticmethod
|
189 | 0f945c65 | Michael Hanselmann | def GET(): |
190 | 0f945c65 | Michael Hanselmann | """Supported for legacy reasons.
|
191 | 0f945c65 | Michael Hanselmann |
|
192 | 0f945c65 | Michael Hanselmann | """
|
193 | 0f945c65 | Michael Hanselmann | return None |
194 | 0f945c65 | Michael Hanselmann | |
195 | 0f945c65 | Michael Hanselmann | |
196 | 132cdb87 | Michael Hanselmann | class R_2(R_root): |
197 | 132cdb87 | Michael Hanselmann | """/2 resource.
|
198 | 132cdb87 | Michael Hanselmann |
|
199 | 132cdb87 | Michael Hanselmann | """
|
200 | 132cdb87 | Michael Hanselmann | |
201 | 132cdb87 | Michael Hanselmann | |
202 | 26ff6ee2 | Michael Hanselmann | class R_version(baserlib.ResourceBase): |
203 | 4e5a68f8 | Oleksiy Mishchenko | """/version resource.
|
204 | 4e5a68f8 | Oleksiy Mishchenko |
|
205 | 4e5a68f8 | Oleksiy Mishchenko | This resource should be used to determine the remote API version and
|
206 | 4e5a68f8 | Oleksiy Mishchenko | to adapt clients accordingly.
|
207 | 4e5a68f8 | Oleksiy Mishchenko |
|
208 | 4e5a68f8 | Oleksiy Mishchenko | """
|
209 | 7e950d31 | Iustin Pop | @staticmethod
|
210 | 7e950d31 | Iustin Pop | def GET(): |
211 | 4e5a68f8 | Oleksiy Mishchenko | """Returns the remote API version.
|
212 | 4e5a68f8 | Oleksiy Mishchenko |
|
213 | 4e5a68f8 | Oleksiy Mishchenko | """
|
214 | 4e5a68f8 | Oleksiy Mishchenko | return constants.RAPI_VERSION
|
215 | 4e5a68f8 | Oleksiy Mishchenko | |
216 | 4e5a68f8 | Oleksiy Mishchenko | |
217 | f6ce0ba2 | Michael Hanselmann | class R_2_info(baserlib.OpcodeResource): |
218 | b58a4d16 | Michael Hanselmann | """/2/info resource.
|
219 | 4e5a68f8 | Oleksiy Mishchenko |
|
220 | 4e5a68f8 | Oleksiy Mishchenko | """
|
221 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpClusterQuery |
222 | f6ce0ba2 | Michael Hanselmann | |
223 | be1ddd09 | Michael Hanselmann | def GET(self): |
224 | 4e5a68f8 | Oleksiy Mishchenko | """Returns cluster information.
|
225 | 4e5a68f8 | Oleksiy Mishchenko |
|
226 | 4e5a68f8 | Oleksiy Mishchenko | """
|
227 | a2160e57 | Iustin Pop | client = self.GetClient(query=True) |
228 | 9031ee8e | Iustin Pop | return client.QueryClusterInfo()
|
229 | 4e5a68f8 | Oleksiy Mishchenko | |
230 | 4e5a68f8 | Oleksiy Mishchenko | |
231 | 26ff6ee2 | Michael Hanselmann | class R_2_features(baserlib.ResourceBase): |
232 | 7eac4a4d | Michael Hanselmann | """/2/features resource.
|
233 | 7eac4a4d | Michael Hanselmann |
|
234 | 7eac4a4d | Michael Hanselmann | """
|
235 | 7eac4a4d | Michael Hanselmann | @staticmethod
|
236 | 7eac4a4d | Michael Hanselmann | def GET(): |
237 | 7eac4a4d | Michael Hanselmann | """Returns list of optional RAPI features implemented.
|
238 | 7eac4a4d | Michael Hanselmann |
|
239 | 7eac4a4d | Michael Hanselmann | """
|
240 | b4fcee5b | Michael Hanselmann | return list(ALL_FEATURES) |
241 | 7eac4a4d | Michael Hanselmann | |
242 | 7eac4a4d | Michael Hanselmann | |
243 | f6ce0ba2 | Michael Hanselmann | class R_2_os(baserlib.OpcodeResource): |
244 | 4e5a68f8 | Oleksiy Mishchenko | """/2/os resource.
|
245 | 4e5a68f8 | Oleksiy Mishchenko |
|
246 | 4e5a68f8 | Oleksiy Mishchenko | """
|
247 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpOsDiagnose |
248 | f6ce0ba2 | Michael Hanselmann | |
249 | be1ddd09 | Michael Hanselmann | def GET(self): |
250 | 4e5a68f8 | Oleksiy Mishchenko | """Return a list of all OSes.
|
251 | 4e5a68f8 | Oleksiy Mishchenko |
|
252 | 4e5a68f8 | Oleksiy Mishchenko | Can return error 500 in case of a problem.
|
253 | 4e5a68f8 | Oleksiy Mishchenko |
|
254 | 4e5a68f8 | Oleksiy Mishchenko | Example: ["debian-etch"]
|
255 | 4e5a68f8 | Oleksiy Mishchenko |
|
256 | 4e5a68f8 | Oleksiy Mishchenko | """
|
257 | be1ddd09 | Michael Hanselmann | cl = self.GetClient()
|
258 | da2d02e7 | Iustin Pop | op = opcodes.OpOsDiagnose(output_fields=["name", "variants"], names=[]) |
259 | be1ddd09 | Michael Hanselmann | job_id = self.SubmitJob([op], cl=cl)
|
260 | 59b4eeef | Iustin Pop | # we use custom feedback function, instead of print we log the status
|
261 | 59b4eeef | Iustin Pop | result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn) |
262 | 59b4eeef | Iustin Pop | diagnose_data = result[0]
|
263 | 4e5a68f8 | Oleksiy Mishchenko | |
264 | 4e5a68f8 | Oleksiy Mishchenko | if not isinstance(diagnose_data, list): |
265 | 59b4eeef | Iustin Pop | raise http.HttpBadGateway(message="Can't get OS list") |
266 | 4e5a68f8 | Oleksiy Mishchenko | |
267 | e3ac208c | Guido Trotter | os_names = [] |
268 | d22dfef7 | Iustin Pop | for (name, variants) in diagnose_data: |
269 | d22dfef7 | Iustin Pop | os_names.extend(cli.CalculateOSNames(name, variants)) |
270 | e3ac208c | Guido Trotter | |
271 | e3ac208c | Guido Trotter | return os_names
|
272 | 51ee2f49 | Oleksiy Mishchenko | |
273 | 10b207d4 | Oleksiy Mishchenko | |
274 | 8fd625fc | Michael Hanselmann | class R_2_redist_config(baserlib.OpcodeResource): |
275 | 508e9b20 | Michael Hanselmann | """/2/redistribute-config resource.
|
276 | 508e9b20 | Michael Hanselmann |
|
277 | 508e9b20 | Michael Hanselmann | """
|
278 | 8fd625fc | Michael Hanselmann | PUT_OPCODE = opcodes.OpClusterRedistConf |
279 | 508e9b20 | Michael Hanselmann | |
280 | 508e9b20 | Michael Hanselmann | |
281 | 50c7d82e | Michael Hanselmann | class R_2_cluster_modify(baserlib.OpcodeResource): |
282 | 62e999a5 | Michael Hanselmann | """/2/modify resource.
|
283 | 62e999a5 | Michael Hanselmann |
|
284 | 62e999a5 | Michael Hanselmann | """
|
285 | 50c7d82e | Michael Hanselmann | PUT_OPCODE = opcodes.OpClusterSetParams |
286 | 62e999a5 | Michael Hanselmann | |
287 | 62e999a5 | Michael Hanselmann | |
288 | 26ff6ee2 | Michael Hanselmann | class R_2_jobs(baserlib.ResourceBase): |
289 | 10b207d4 | Oleksiy Mishchenko | """/2/jobs resource.
|
290 | 10b207d4 | Oleksiy Mishchenko |
|
291 | 10b207d4 | Oleksiy Mishchenko | """
|
292 | e987f166 | Michael Hanselmann | def GET(self): |
293 | 10b207d4 | Oleksiy Mishchenko | """Returns a dictionary of jobs.
|
294 | 10b207d4 | Oleksiy Mishchenko |
|
295 | c41eea6e | Iustin Pop | @return: a dictionary with jobs id and uri.
|
296 | 38206f3c | Iustin Pop |
|
297 | 10b207d4 | Oleksiy Mishchenko | """
|
298 | d45a824b | Iustin Pop | client = self.GetClient(query=True) |
299 | e987f166 | Michael Hanselmann | |
300 | e987f166 | Michael Hanselmann | if self.useBulk(): |
301 | bd7b2070 | Michael Hanselmann | bulkdata = client.QueryJobs(None, J_FIELDS_BULK)
|
302 | bd7b2070 | Michael Hanselmann | return baserlib.MapBulkFields(bulkdata, J_FIELDS_BULK)
|
303 | e987f166 | Michael Hanselmann | else:
|
304 | e987f166 | Michael Hanselmann | jobdata = map(compat.fst, client.QueryJobs(None, ["id"])) |
305 | e987f166 | Michael Hanselmann | return baserlib.BuildUriList(jobdata, "/2/jobs/%s", |
306 | e987f166 | Michael Hanselmann | uri_fields=("id", "uri")) |
307 | 10b207d4 | Oleksiy Mishchenko | |
308 | 10b207d4 | Oleksiy Mishchenko | |
309 | 26ff6ee2 | Michael Hanselmann | class R_2_jobs_id(baserlib.ResourceBase): |
310 | 10b207d4 | Oleksiy Mishchenko | """/2/jobs/[job_id] resource.
|
311 | 10b207d4 | Oleksiy Mishchenko |
|
312 | 10b207d4 | Oleksiy Mishchenko | """
|
313 | 10b207d4 | Oleksiy Mishchenko | def GET(self): |
314 | 10b207d4 | Oleksiy Mishchenko | """Returns a job status.
|
315 | 10b207d4 | Oleksiy Mishchenko |
|
316 | c41eea6e | Iustin Pop | @return: a dictionary with job parameters.
|
317 | c41eea6e | Iustin Pop | The result includes:
|
318 | c41eea6e | Iustin Pop | - id: job ID as a number
|
319 | c41eea6e | Iustin Pop | - status: current job status as a string
|
320 | c41eea6e | Iustin Pop | - ops: involved OpCodes as a list of dictionaries for each
|
321 | c41eea6e | Iustin Pop | opcodes in the job
|
322 | c41eea6e | Iustin Pop | - opstatus: OpCodes status as a list
|
323 | c41eea6e | Iustin Pop | - opresult: OpCodes results as a list of lists
|
324 | 38206f3c | Iustin Pop |
|
325 | 10b207d4 | Oleksiy Mishchenko | """
|
326 | 10b207d4 | Oleksiy Mishchenko | job_id = self.items[0] |
327 | d45a824b | Iustin Pop | result = self.GetClient(query=True).QueryJobs([job_id, ], J_FIELDS)[0] |
328 | ee69c97f | Iustin Pop | if result is None: |
329 | ee69c97f | Iustin Pop | raise http.HttpNotFound()
|
330 | e987f166 | Michael Hanselmann | return baserlib.MapFields(J_FIELDS, result)
|
331 | 10b207d4 | Oleksiy Mishchenko | |
332 | c7f5f338 | Oleksiy Mishchenko | def DELETE(self): |
333 | c7f5f338 | Oleksiy Mishchenko | """Cancel not-yet-started job.
|
334 | c7f5f338 | Oleksiy Mishchenko |
|
335 | c7f5f338 | Oleksiy Mishchenko | """
|
336 | c7f5f338 | Oleksiy Mishchenko | job_id = self.items[0] |
337 | be1ddd09 | Michael Hanselmann | result = self.GetClient().CancelJob(job_id)
|
338 | c7f5f338 | Oleksiy Mishchenko | return result
|
339 | c7f5f338 | Oleksiy Mishchenko | |
340 | 10b207d4 | Oleksiy Mishchenko | |
341 | 26ff6ee2 | Michael Hanselmann | class R_2_jobs_id_wait(baserlib.ResourceBase): |
342 | 793a8f7c | Michael Hanselmann | """/2/jobs/[job_id]/wait resource.
|
343 | 793a8f7c | Michael Hanselmann |
|
344 | 793a8f7c | Michael Hanselmann | """
|
345 | 793a8f7c | Michael Hanselmann | # WaitForJobChange provides access to sensitive information and blocks
|
346 | 793a8f7c | Michael Hanselmann | # machine resources (it's a blocking RAPI call), hence restricting access.
|
347 | 793a8f7c | Michael Hanselmann | GET_ACCESS = [rapi.RAPI_ACCESS_WRITE] |
348 | 793a8f7c | Michael Hanselmann | |
349 | 793a8f7c | Michael Hanselmann | def GET(self): |
350 | 793a8f7c | Michael Hanselmann | """Waits for job changes.
|
351 | 793a8f7c | Michael Hanselmann |
|
352 | 793a8f7c | Michael Hanselmann | """
|
353 | 793a8f7c | Michael Hanselmann | job_id = self.items[0] |
354 | 793a8f7c | Michael Hanselmann | |
355 | 793a8f7c | Michael Hanselmann | fields = self.getBodyParameter("fields") |
356 | 793a8f7c | Michael Hanselmann | prev_job_info = self.getBodyParameter("previous_job_info", None) |
357 | 793a8f7c | Michael Hanselmann | prev_log_serial = self.getBodyParameter("previous_log_serial", None) |
358 | 793a8f7c | Michael Hanselmann | |
359 | 793a8f7c | Michael Hanselmann | if not isinstance(fields, list): |
360 | 793a8f7c | Michael Hanselmann | raise http.HttpBadRequest("The 'fields' parameter should be a list") |
361 | 793a8f7c | Michael Hanselmann | |
362 | 793a8f7c | Michael Hanselmann | if not (prev_job_info is None or isinstance(prev_job_info, list)): |
363 | 793a8f7c | Michael Hanselmann | raise http.HttpBadRequest("The 'previous_job_info' parameter should" |
364 | 793a8f7c | Michael Hanselmann | " be a list")
|
365 | 793a8f7c | Michael Hanselmann | |
366 | 793a8f7c | Michael Hanselmann | if not (prev_log_serial is None or |
367 | 793a8f7c | Michael Hanselmann | isinstance(prev_log_serial, (int, long))): |
368 | 793a8f7c | Michael Hanselmann | raise http.HttpBadRequest("The 'previous_log_serial' parameter should" |
369 | 793a8f7c | Michael Hanselmann | " be a number")
|
370 | 793a8f7c | Michael Hanselmann | |
371 | be1ddd09 | Michael Hanselmann | client = self.GetClient()
|
372 | 793a8f7c | Michael Hanselmann | result = client.WaitForJobChangeOnce(job_id, fields, |
373 | 793a8f7c | Michael Hanselmann | prev_job_info, prev_log_serial, |
374 | 793a8f7c | Michael Hanselmann | timeout=_WFJC_TIMEOUT) |
375 | 793a8f7c | Michael Hanselmann | if not result: |
376 | 793a8f7c | Michael Hanselmann | raise http.HttpNotFound()
|
377 | 793a8f7c | Michael Hanselmann | |
378 | 793a8f7c | Michael Hanselmann | if result == constants.JOB_NOTCHANGED:
|
379 | 793a8f7c | Michael Hanselmann | # No changes
|
380 | 793a8f7c | Michael Hanselmann | return None |
381 | 793a8f7c | Michael Hanselmann | |
382 | 793a8f7c | Michael Hanselmann | (job_info, log_entries) = result |
383 | 793a8f7c | Michael Hanselmann | |
384 | 793a8f7c | Michael Hanselmann | return {
|
385 | 793a8f7c | Michael Hanselmann | "job_info": job_info,
|
386 | 793a8f7c | Michael Hanselmann | "log_entries": log_entries,
|
387 | 793a8f7c | Michael Hanselmann | } |
388 | 793a8f7c | Michael Hanselmann | |
389 | 793a8f7c | Michael Hanselmann | |
390 | f6ce0ba2 | Michael Hanselmann | class R_2_nodes(baserlib.OpcodeResource): |
391 | 10b207d4 | Oleksiy Mishchenko | """/2/nodes resource.
|
392 | 10b207d4 | Oleksiy Mishchenko |
|
393 | 10b207d4 | Oleksiy Mishchenko | """
|
394 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpNodeQuery |
395 | f6ce0ba2 | Michael Hanselmann | |
396 | 10b207d4 | Oleksiy Mishchenko | def GET(self): |
397 | 10b207d4 | Oleksiy Mishchenko | """Returns a list of all nodes.
|
398 | 38206f3c | Iustin Pop |
|
399 | 10b207d4 | Oleksiy Mishchenko | """
|
400 | d9a22528 | Iustin Pop | client = self.GetClient(query=True) |
401 | 38206f3c | Iustin Pop | |
402 | 3d103742 | Iustin Pop | if self.useBulk(): |
403 | 9031ee8e | Iustin Pop | bulkdata = client.QueryNodes([], N_FIELDS, False)
|
404 | a0dcf7c2 | Oleksiy Mishchenko | return baserlib.MapBulkFields(bulkdata, N_FIELDS)
|
405 | 9031ee8e | Iustin Pop | else:
|
406 | 9031ee8e | Iustin Pop | nodesdata = client.QueryNodes([], ["name"], False) |
407 | 9031ee8e | Iustin Pop | nodeslist = [row[0] for row in nodesdata] |
408 | 9031ee8e | Iustin Pop | return baserlib.BuildUriList(nodeslist, "/2/nodes/%s", |
409 | 9031ee8e | Iustin Pop | uri_fields=("id", "uri")) |
410 | 441e7cfd | Oleksiy Mishchenko | |
411 | 441e7cfd | Oleksiy Mishchenko | |
412 | f6ce0ba2 | Michael Hanselmann | class R_2_nodes_name(baserlib.OpcodeResource): |
413 | b58a4d16 | Michael Hanselmann | """/2/nodes/[node_name] resource.
|
414 | 028c6b76 | Oleksiy Mishchenko |
|
415 | 028c6b76 | Oleksiy Mishchenko | """
|
416 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpNodeQuery |
417 | f6ce0ba2 | Michael Hanselmann | |
418 | 4e5a68f8 | Oleksiy Mishchenko | def GET(self): |
419 | 4e5a68f8 | Oleksiy Mishchenko | """Send information about a node.
|
420 | 4e5a68f8 | Oleksiy Mishchenko |
|
421 | 4e5a68f8 | Oleksiy Mishchenko | """
|
422 | 4e5a68f8 | Oleksiy Mishchenko | node_name = self.items[0] |
423 | d9a22528 | Iustin Pop | client = self.GetClient(query=True) |
424 | e8ebbd2b | Michael Hanselmann | |
425 | e8ebbd2b | Michael Hanselmann | result = baserlib.HandleItemQueryErrors(client.QueryNodes, |
426 | e8ebbd2b | Michael Hanselmann | names=[node_name], fields=N_FIELDS, |
427 | e8ebbd2b | Michael Hanselmann | use_locking=self.useLocking())
|
428 | 4e5a68f8 | Oleksiy Mishchenko | |
429 | 4e5a68f8 | Oleksiy Mishchenko | return baserlib.MapFields(N_FIELDS, result[0]) |
430 | 028c6b76 | Oleksiy Mishchenko | |
431 | 028c6b76 | Oleksiy Mishchenko | |
432 | 42d4d8b9 | Michael Hanselmann | class R_2_nodes_name_powercycle(baserlib.OpcodeResource): |
433 | 42d4d8b9 | Michael Hanselmann | """/2/nodes/[node_name]/powercycle resource.
|
434 | 42d4d8b9 | Michael Hanselmann |
|
435 | 42d4d8b9 | Michael Hanselmann | """
|
436 | 42d4d8b9 | Michael Hanselmann | POST_OPCODE = opcodes.OpNodePowercycle |
437 | 42d4d8b9 | Michael Hanselmann | |
438 | 42d4d8b9 | Michael Hanselmann | def GetPostOpInput(self): |
439 | 42d4d8b9 | Michael Hanselmann | """Tries to powercycle a node.
|
440 | 42d4d8b9 | Michael Hanselmann |
|
441 | 42d4d8b9 | Michael Hanselmann | """
|
442 | 42d4d8b9 | Michael Hanselmann | return (self.request_body, { |
443 | 42d4d8b9 | Michael Hanselmann | "node_name": self.items[0], |
444 | 42d4d8b9 | Michael Hanselmann | "force": self.useForce(), |
445 | 42d4d8b9 | Michael Hanselmann | }) |
446 | 42d4d8b9 | Michael Hanselmann | |
447 | 42d4d8b9 | Michael Hanselmann | |
448 | 51cc8637 | Michael Hanselmann | class R_2_nodes_name_role(baserlib.OpcodeResource): |
449 | 51cc8637 | Michael Hanselmann | """/2/nodes/[node_name]/role resource.
|
450 | 64dae8fc | Michael Hanselmann |
|
451 | 64dae8fc | Michael Hanselmann | """
|
452 | 51cc8637 | Michael Hanselmann | PUT_OPCODE = opcodes.OpNodeSetParams |
453 | 51cc8637 | Michael Hanselmann | |
454 | 64dae8fc | Michael Hanselmann | def GET(self): |
455 | 64dae8fc | Michael Hanselmann | """Returns the current node role.
|
456 | 64dae8fc | Michael Hanselmann |
|
457 | 64dae8fc | Michael Hanselmann | @return: Node role
|
458 | 64dae8fc | Michael Hanselmann |
|
459 | 64dae8fc | Michael Hanselmann | """
|
460 | 64dae8fc | Michael Hanselmann | node_name = self.items[0] |
461 | 9fbf0098 | Iustin Pop | client = self.GetClient(query=True) |
462 | 64dae8fc | Michael Hanselmann | result = client.QueryNodes(names=[node_name], fields=["role"],
|
463 | 64dae8fc | Michael Hanselmann | use_locking=self.useLocking())
|
464 | 64dae8fc | Michael Hanselmann | |
465 | 64dae8fc | Michael Hanselmann | return _NR_MAP[result[0][0]] |
466 | 64dae8fc | Michael Hanselmann | |
467 | 51cc8637 | Michael Hanselmann | def GetPutOpInput(self): |
468 | 64dae8fc | Michael Hanselmann | """Sets the node role.
|
469 | 64dae8fc | Michael Hanselmann |
|
470 | 64dae8fc | Michael Hanselmann | """
|
471 | 51cc8637 | Michael Hanselmann | baserlib.CheckType(self.request_body, basestring, "Body contents") |
472 | 64dae8fc | Michael Hanselmann | |
473 | 627ad739 | Michael Hanselmann | role = self.request_body
|
474 | 64dae8fc | Michael Hanselmann | |
475 | 64dae8fc | Michael Hanselmann | if role == _NR_REGULAR:
|
476 | 64dae8fc | Michael Hanselmann | candidate = False
|
477 | 64dae8fc | Michael Hanselmann | offline = False
|
478 | 64dae8fc | Michael Hanselmann | drained = False
|
479 | 64dae8fc | Michael Hanselmann | |
480 | 51cc8637 | Michael Hanselmann | elif role == _NR_MASTER_CANDIDATE:
|
481 | 64dae8fc | Michael Hanselmann | candidate = True
|
482 | 64dae8fc | Michael Hanselmann | offline = drained = None
|
483 | 64dae8fc | Michael Hanselmann | |
484 | 64dae8fc | Michael Hanselmann | elif role == _NR_DRAINED:
|
485 | 64dae8fc | Michael Hanselmann | drained = True
|
486 | 64dae8fc | Michael Hanselmann | candidate = offline = None
|
487 | 64dae8fc | Michael Hanselmann | |
488 | 64dae8fc | Michael Hanselmann | elif role == _NR_OFFLINE:
|
489 | 64dae8fc | Michael Hanselmann | offline = True
|
490 | 64dae8fc | Michael Hanselmann | candidate = drained = None
|
491 | 64dae8fc | Michael Hanselmann | |
492 | 64dae8fc | Michael Hanselmann | else:
|
493 | 64dae8fc | Michael Hanselmann | raise http.HttpBadRequest("Can't set '%s' role" % role) |
494 | 64dae8fc | Michael Hanselmann | |
495 | 51cc8637 | Michael Hanselmann | assert len(self.items) == 1 |
496 | 64dae8fc | Michael Hanselmann | |
497 | 51cc8637 | Michael Hanselmann | return ({}, {
|
498 | 51cc8637 | Michael Hanselmann | "node_name": self.items[0], |
499 | 51cc8637 | Michael Hanselmann | "master_candidate": candidate,
|
500 | 51cc8637 | Michael Hanselmann | "offline": offline,
|
501 | 51cc8637 | Michael Hanselmann | "drained": drained,
|
502 | 51cc8637 | Michael Hanselmann | "force": self.useForce(), |
503 | 682878d9 | Guido Trotter | "auto_promote": bool(self._checkIntVariable("auto-promote", default=0)), |
504 | 51cc8637 | Michael Hanselmann | }) |
505 | 64dae8fc | Michael Hanselmann | |
506 | 64dae8fc | Michael Hanselmann | |
507 | 7fa91722 | Michael Hanselmann | class R_2_nodes_name_evacuate(baserlib.OpcodeResource): |
508 | 73452f12 | Michael Hanselmann | """/2/nodes/[node_name]/evacuate resource.
|
509 | 73452f12 | Michael Hanselmann |
|
510 | 73452f12 | Michael Hanselmann | """
|
511 | 7fa91722 | Michael Hanselmann | POST_OPCODE = opcodes.OpNodeEvacuate |
512 | 7fa91722 | Michael Hanselmann | |
513 | 7fa91722 | Michael Hanselmann | def GetPostOpInput(self): |
514 | de40437a | Michael Hanselmann | """Evacuate all instances off a node.
|
515 | 73452f12 | Michael Hanselmann |
|
516 | 73452f12 | Michael Hanselmann | """
|
517 | 7fa91722 | Michael Hanselmann | return (self.request_body, { |
518 | de40437a | Michael Hanselmann | "node_name": self.items[0], |
519 | de40437a | Michael Hanselmann | "dry_run": self.dryRun(), |
520 | de40437a | Michael Hanselmann | }) |
521 | 941b9309 | Iustin Pop | |
522 | 73452f12 | Michael Hanselmann | |
523 | 55168cc7 | Michael Hanselmann | class R_2_nodes_name_migrate(baserlib.OpcodeResource): |
524 | 7a95a954 | Michael Hanselmann | """/2/nodes/[node_name]/migrate resource.
|
525 | 1c482bab | Michael Hanselmann |
|
526 | 1c482bab | Michael Hanselmann | """
|
527 | 55168cc7 | Michael Hanselmann | POST_OPCODE = opcodes.OpNodeMigrate |
528 | 55168cc7 | Michael Hanselmann | |
529 | 55168cc7 | Michael Hanselmann | def GetPostOpInput(self): |
530 | 1c482bab | Michael Hanselmann | """Migrate all primary instances from a node.
|
531 | 1c482bab | Michael Hanselmann |
|
532 | 1c482bab | Michael Hanselmann | """
|
533 | b7a1c816 | Michael Hanselmann | if self.queryargs: |
534 | b7a1c816 | Michael Hanselmann | # Support old-style requests
|
535 | b7a1c816 | Michael Hanselmann | if "live" in self.queryargs and "mode" in self.queryargs: |
536 | b7a1c816 | Michael Hanselmann | raise http.HttpBadRequest("Only one of 'live' and 'mode' should" |
537 | b7a1c816 | Michael Hanselmann | " be passed")
|
538 | b7a1c816 | Michael Hanselmann | |
539 | b7a1c816 | Michael Hanselmann | if "live" in self.queryargs: |
540 | b7a1c816 | Michael Hanselmann | if self._checkIntVariable("live", default=1): |
541 | b7a1c816 | Michael Hanselmann | mode = constants.HT_MIGRATION_LIVE |
542 | b7a1c816 | Michael Hanselmann | else:
|
543 | b7a1c816 | Michael Hanselmann | mode = constants.HT_MIGRATION_NONLIVE |
544 | 52194140 | Iustin Pop | else:
|
545 | b7a1c816 | Michael Hanselmann | mode = self._checkStringVariable("mode", default=None) |
546 | b7a1c816 | Michael Hanselmann | |
547 | b7a1c816 | Michael Hanselmann | data = { |
548 | b7a1c816 | Michael Hanselmann | "mode": mode,
|
549 | b7a1c816 | Michael Hanselmann | } |
550 | 52194140 | Iustin Pop | else:
|
551 | b7a1c816 | Michael Hanselmann | data = self.request_body
|
552 | 52194140 | Iustin Pop | |
553 | 55168cc7 | Michael Hanselmann | return (data, {
|
554 | 55168cc7 | Michael Hanselmann | "node_name": self.items[0], |
555 | b7a1c816 | Michael Hanselmann | }) |
556 | 1c482bab | Michael Hanselmann | |
557 | 1c482bab | Michael Hanselmann | |
558 | 682878d9 | Guido Trotter | class R_2_nodes_name_modify(baserlib.OpcodeResource): |
559 | 94497dd1 | Michael Hanselmann | """/2/nodes/[node_name]/modify resource.
|
560 | 94497dd1 | Michael Hanselmann |
|
561 | 94497dd1 | Michael Hanselmann | """
|
562 | 8b8f54dd | Guido Trotter | POST_OPCODE = opcodes.OpNodeSetParams |
563 | 94497dd1 | Michael Hanselmann | |
564 | 8b8f54dd | Guido Trotter | def GetPostOpInput(self): |
565 | 682878d9 | Guido Trotter | """Changes parameters of a node.
|
566 | 94497dd1 | Michael Hanselmann |
|
567 | 94497dd1 | Michael Hanselmann | """
|
568 | 682878d9 | Guido Trotter | assert len(self.items) == 1 |
569 | 94497dd1 | Michael Hanselmann | |
570 | 682878d9 | Guido Trotter | return (self.request_body, { |
571 | 370f2042 | Guido Trotter | "node_name": self.items[0], |
572 | 94497dd1 | Michael Hanselmann | }) |
573 | 94497dd1 | Michael Hanselmann | |
574 | 94497dd1 | Michael Hanselmann | |
575 | eb08e09d | Michael Hanselmann | class R_2_nodes_name_storage(baserlib.OpcodeResource): |
576 | b58a4d16 | Michael Hanselmann | """/2/nodes/[node_name]/storage resource.
|
577 | 7a95a954 | Michael Hanselmann |
|
578 | 7a95a954 | Michael Hanselmann | """
|
579 | ad8d0595 | Iustin Pop | # LUNodeQueryStorage acquires locks, hence restricting access to GET
|
580 | 7a95a954 | Michael Hanselmann | GET_ACCESS = [rapi.RAPI_ACCESS_WRITE] |
581 | eb08e09d | Michael Hanselmann | GET_OPCODE = opcodes.OpNodeQueryStorage |
582 | 7a95a954 | Michael Hanselmann | |
583 | eb08e09d | Michael Hanselmann | def GetGetOpInput(self): |
584 | eb08e09d | Michael Hanselmann | """List storage available on a node.
|
585 | 7a95a954 | Michael Hanselmann |
|
586 | eb08e09d | Michael Hanselmann | """
|
587 | 7a95a954 | Michael Hanselmann | storage_type = self._checkStringVariable("storage_type", None) |
588 | 7a95a954 | Michael Hanselmann | output_fields = self._checkStringVariable("output_fields", None) |
589 | eb08e09d | Michael Hanselmann | |
590 | 7a95a954 | Michael Hanselmann | if not output_fields: |
591 | 7a95a954 | Michael Hanselmann | raise http.HttpBadRequest("Missing the required 'output_fields'" |
592 | 7a95a954 | Michael Hanselmann | " parameter")
|
593 | 7a95a954 | Michael Hanselmann | |
594 | eb08e09d | Michael Hanselmann | return ({}, {
|
595 | eb08e09d | Michael Hanselmann | "nodes": [self.items[0]], |
596 | eb08e09d | Michael Hanselmann | "storage_type": storage_type,
|
597 | eb08e09d | Michael Hanselmann | "output_fields": output_fields.split(","), |
598 | eb08e09d | Michael Hanselmann | }) |
599 | 7a95a954 | Michael Hanselmann | |
600 | 7a95a954 | Michael Hanselmann | |
601 | 8d232068 | Michael Hanselmann | class R_2_nodes_name_storage_modify(baserlib.OpcodeResource): |
602 | b58a4d16 | Michael Hanselmann | """/2/nodes/[node_name]/storage/modify resource.
|
603 | 1e82bc80 | Michael Hanselmann |
|
604 | 1e82bc80 | Michael Hanselmann | """
|
605 | 8d232068 | Michael Hanselmann | PUT_OPCODE = opcodes.OpNodeModifyStorage |
606 | 1e82bc80 | Michael Hanselmann | |
607 | 8d232068 | Michael Hanselmann | def GetPutOpInput(self): |
608 | 8d232068 | Michael Hanselmann | """Modifies a storage volume on a node.
|
609 | 1e82bc80 | Michael Hanselmann |
|
610 | 8d232068 | Michael Hanselmann | """
|
611 | 8d232068 | Michael Hanselmann | storage_type = self._checkStringVariable("storage_type", None) |
612 | 1e82bc80 | Michael Hanselmann | name = self._checkStringVariable("name", None) |
613 | 8d232068 | Michael Hanselmann | |
614 | 1e82bc80 | Michael Hanselmann | if not name: |
615 | 1e82bc80 | Michael Hanselmann | raise http.HttpBadRequest("Missing the required 'name'" |
616 | 1e82bc80 | Michael Hanselmann | " parameter")
|
617 | 1e82bc80 | Michael Hanselmann | |
618 | 1e82bc80 | Michael Hanselmann | changes = {} |
619 | 1e82bc80 | Michael Hanselmann | |
620 | 1e82bc80 | Michael Hanselmann | if "allocatable" in self.queryargs: |
621 | 1e82bc80 | Michael Hanselmann | changes[constants.SF_ALLOCATABLE] = \ |
622 | 1e82bc80 | Michael Hanselmann | bool(self._checkIntVariable("allocatable", default=1)) |
623 | 1e82bc80 | Michael Hanselmann | |
624 | 8d232068 | Michael Hanselmann | return ({}, {
|
625 | 8d232068 | Michael Hanselmann | "node_name": self.items[0], |
626 | 8d232068 | Michael Hanselmann | "storage_type": storage_type,
|
627 | 8d232068 | Michael Hanselmann | "name": name,
|
628 | 8d232068 | Michael Hanselmann | "changes": changes,
|
629 | 8d232068 | Michael Hanselmann | }) |
630 | 1e82bc80 | Michael Hanselmann | |
631 | 1e82bc80 | Michael Hanselmann | |
632 | 98270691 | Michael Hanselmann | class R_2_nodes_name_storage_repair(baserlib.OpcodeResource): |
633 | b58a4d16 | Michael Hanselmann | """/2/nodes/[node_name]/storage/repair resource.
|
634 | 723f4565 | Michael Hanselmann |
|
635 | 723f4565 | Michael Hanselmann | """
|
636 | 98270691 | Michael Hanselmann | PUT_OPCODE = opcodes.OpRepairNodeStorage |
637 | 723f4565 | Michael Hanselmann | |
638 | 98270691 | Michael Hanselmann | def GetPutOpInput(self): |
639 | 98270691 | Michael Hanselmann | """Repairs a storage volume on a node.
|
640 | 723f4565 | Michael Hanselmann |
|
641 | 98270691 | Michael Hanselmann | """
|
642 | 98270691 | Michael Hanselmann | storage_type = self._checkStringVariable("storage_type", None) |
643 | 723f4565 | Michael Hanselmann | name = self._checkStringVariable("name", None) |
644 | 723f4565 | Michael Hanselmann | if not name: |
645 | 723f4565 | Michael Hanselmann | raise http.HttpBadRequest("Missing the required 'name'" |
646 | 723f4565 | Michael Hanselmann | " parameter")
|
647 | 723f4565 | Michael Hanselmann | |
648 | 98270691 | Michael Hanselmann | return ({}, {
|
649 | 98270691 | Michael Hanselmann | "node_name": self.items[0], |
650 | 98270691 | Michael Hanselmann | "storage_type": storage_type,
|
651 | 98270691 | Michael Hanselmann | "name": name,
|
652 | 98270691 | Michael Hanselmann | }) |
653 | 723f4565 | Michael Hanselmann | |
654 | 723f4565 | Michael Hanselmann | |
655 | 4588b4bd | Dimitris Aragiorgis | class R_2_networks(baserlib.OpcodeResource): |
656 | 4588b4bd | Dimitris Aragiorgis | """/2/networks resource.
|
657 | 4588b4bd | Dimitris Aragiorgis |
|
658 | 4588b4bd | Dimitris Aragiorgis | """
|
659 | 4588b4bd | Dimitris Aragiorgis | GET_OPCODE = opcodes.OpNetworkQuery |
660 | 4588b4bd | Dimitris Aragiorgis | POST_OPCODE = opcodes.OpNetworkAdd |
661 | 4588b4bd | Dimitris Aragiorgis | POST_RENAME = { |
662 | 4588b4bd | Dimitris Aragiorgis | "name": "network_name", |
663 | 4588b4bd | Dimitris Aragiorgis | } |
664 | 4588b4bd | Dimitris Aragiorgis | |
665 | 4588b4bd | Dimitris Aragiorgis | def GetPostOpInput(self): |
666 | 4588b4bd | Dimitris Aragiorgis | """Create a network.
|
667 | 4588b4bd | Dimitris Aragiorgis |
|
668 | 4588b4bd | Dimitris Aragiorgis | """
|
669 | 4588b4bd | Dimitris Aragiorgis | assert not self.items |
670 | 4588b4bd | Dimitris Aragiorgis | return (self.request_body, { |
671 | 4588b4bd | Dimitris Aragiorgis | "dry_run": self.dryRun(), |
672 | 4588b4bd | Dimitris Aragiorgis | }) |
673 | 4588b4bd | Dimitris Aragiorgis | |
674 | 4588b4bd | Dimitris Aragiorgis | def GET(self): |
675 | 4588b4bd | Dimitris Aragiorgis | """Returns a list of all networks.
|
676 | 4588b4bd | Dimitris Aragiorgis |
|
677 | 4588b4bd | Dimitris Aragiorgis | """
|
678 | ab9e48d1 | Iustin Pop | client = self.GetClient(query=True) |
679 | 4588b4bd | Dimitris Aragiorgis | |
680 | 4588b4bd | Dimitris Aragiorgis | if self.useBulk(): |
681 | 4588b4bd | Dimitris Aragiorgis | bulkdata = client.QueryNetworks([], NET_FIELDS, False)
|
682 | 4588b4bd | Dimitris Aragiorgis | return baserlib.MapBulkFields(bulkdata, NET_FIELDS)
|
683 | 4588b4bd | Dimitris Aragiorgis | else:
|
684 | 4588b4bd | Dimitris Aragiorgis | data = client.QueryNetworks([], ["name"], False) |
685 | 4588b4bd | Dimitris Aragiorgis | networknames = [row[0] for row in data] |
686 | 4588b4bd | Dimitris Aragiorgis | return baserlib.BuildUriList(networknames, "/2/networks/%s", |
687 | 4588b4bd | Dimitris Aragiorgis | uri_fields=("name", "uri")) |
688 | 4588b4bd | Dimitris Aragiorgis | |
689 | 4588b4bd | Dimitris Aragiorgis | |
690 | 4588b4bd | Dimitris Aragiorgis | class R_2_networks_name(baserlib.OpcodeResource): |
691 | 6e8091f9 | Dimitris Aragiorgis | """/2/networks/[network_name] resource.
|
692 | 4588b4bd | Dimitris Aragiorgis |
|
693 | 4588b4bd | Dimitris Aragiorgis | """
|
694 | 4588b4bd | Dimitris Aragiorgis | DELETE_OPCODE = opcodes.OpNetworkRemove |
695 | 4588b4bd | Dimitris Aragiorgis | |
696 | 4588b4bd | Dimitris Aragiorgis | def GET(self): |
697 | 4588b4bd | Dimitris Aragiorgis | """Send information about a network.
|
698 | 4588b4bd | Dimitris Aragiorgis |
|
699 | 4588b4bd | Dimitris Aragiorgis | """
|
700 | 4588b4bd | Dimitris Aragiorgis | network_name = self.items[0] |
701 | ab9e48d1 | Iustin Pop | client = self.GetClient(query=True) |
702 | 4588b4bd | Dimitris Aragiorgis | |
703 | 4588b4bd | Dimitris Aragiorgis | result = baserlib.HandleItemQueryErrors(client.QueryNetworks, |
704 | 4588b4bd | Dimitris Aragiorgis | names=[network_name], |
705 | 4588b4bd | Dimitris Aragiorgis | fields=NET_FIELDS, |
706 | 4588b4bd | Dimitris Aragiorgis | use_locking=self.useLocking())
|
707 | 4588b4bd | Dimitris Aragiorgis | |
708 | 4588b4bd | Dimitris Aragiorgis | return baserlib.MapFields(NET_FIELDS, result[0]) |
709 | 4588b4bd | Dimitris Aragiorgis | |
710 | 4588b4bd | Dimitris Aragiorgis | def GetDeleteOpInput(self): |
711 | 4588b4bd | Dimitris Aragiorgis | """Delete a network.
|
712 | 4588b4bd | Dimitris Aragiorgis |
|
713 | 4588b4bd | Dimitris Aragiorgis | """
|
714 | 4588b4bd | Dimitris Aragiorgis | assert len(self.items) == 1 |
715 | 4588b4bd | Dimitris Aragiorgis | return (self.request_body, { |
716 | 4588b4bd | Dimitris Aragiorgis | "network_name": self.items[0], |
717 | 4588b4bd | Dimitris Aragiorgis | "dry_run": self.dryRun(), |
718 | 4588b4bd | Dimitris Aragiorgis | }) |
719 | 4588b4bd | Dimitris Aragiorgis | |
720 | 3c286190 | Dimitris Aragiorgis | |
721 | 4588b4bd | Dimitris Aragiorgis | class R_2_networks_name_connect(baserlib.OpcodeResource): |
722 | 6e8091f9 | Dimitris Aragiorgis | """/2/networks/[network_name]/connect resource.
|
723 | 4588b4bd | Dimitris Aragiorgis |
|
724 | 4588b4bd | Dimitris Aragiorgis | """
|
725 | 4588b4bd | Dimitris Aragiorgis | PUT_OPCODE = opcodes.OpNetworkConnect |
726 | 4588b4bd | Dimitris Aragiorgis | |
727 | 4588b4bd | Dimitris Aragiorgis | def GetPutOpInput(self): |
728 | 4588b4bd | Dimitris Aragiorgis | """Changes some parameters of node group.
|
729 | 4588b4bd | Dimitris Aragiorgis |
|
730 | 4588b4bd | Dimitris Aragiorgis | """
|
731 | 4588b4bd | Dimitris Aragiorgis | assert self.items |
732 | 4588b4bd | Dimitris Aragiorgis | return (self.request_body, { |
733 | 4588b4bd | Dimitris Aragiorgis | "network_name": self.items[0], |
734 | 6e8091f9 | Dimitris Aragiorgis | "dry_run": self.dryRun(), |
735 | 4588b4bd | Dimitris Aragiorgis | }) |
736 | 4588b4bd | Dimitris Aragiorgis | |
737 | 3c286190 | Dimitris Aragiorgis | |
738 | 4588b4bd | Dimitris Aragiorgis | class R_2_networks_name_disconnect(baserlib.OpcodeResource): |
739 | 6e8091f9 | Dimitris Aragiorgis | """/2/networks/[network_name]/disconnect resource.
|
740 | 4588b4bd | Dimitris Aragiorgis |
|
741 | 4588b4bd | Dimitris Aragiorgis | """
|
742 | 4588b4bd | Dimitris Aragiorgis | PUT_OPCODE = opcodes.OpNetworkDisconnect |
743 | 4588b4bd | Dimitris Aragiorgis | |
744 | 4588b4bd | Dimitris Aragiorgis | def GetPutOpInput(self): |
745 | 4588b4bd | Dimitris Aragiorgis | """Changes some parameters of node group.
|
746 | 4588b4bd | Dimitris Aragiorgis |
|
747 | 4588b4bd | Dimitris Aragiorgis | """
|
748 | 4588b4bd | Dimitris Aragiorgis | assert self.items |
749 | 4588b4bd | Dimitris Aragiorgis | return (self.request_body, { |
750 | 4588b4bd | Dimitris Aragiorgis | "network_name": self.items[0], |
751 | 6e8091f9 | Dimitris Aragiorgis | "dry_run": self.dryRun(), |
752 | 6e8091f9 | Dimitris Aragiorgis | }) |
753 | 6e8091f9 | Dimitris Aragiorgis | |
754 | 3c286190 | Dimitris Aragiorgis | |
755 | 6e8091f9 | Dimitris Aragiorgis | class R_2_networks_name_modify(baserlib.OpcodeResource): |
756 | 6e8091f9 | Dimitris Aragiorgis | """/2/networks/[network_name]/modify resource.
|
757 | 6e8091f9 | Dimitris Aragiorgis |
|
758 | 6e8091f9 | Dimitris Aragiorgis | """
|
759 | 6e8091f9 | Dimitris Aragiorgis | PUT_OPCODE = opcodes.OpNetworkSetParams |
760 | 6e8091f9 | Dimitris Aragiorgis | |
761 | 6e8091f9 | Dimitris Aragiorgis | def GetPutOpInput(self): |
762 | 6e8091f9 | Dimitris Aragiorgis | """Changes some parameters of network.
|
763 | 6e8091f9 | Dimitris Aragiorgis |
|
764 | 6e8091f9 | Dimitris Aragiorgis | """
|
765 | 6e8091f9 | Dimitris Aragiorgis | assert self.items |
766 | 6e8091f9 | Dimitris Aragiorgis | return (self.request_body, { |
767 | 6e8091f9 | Dimitris Aragiorgis | "network_name": self.items[0], |
768 | 4588b4bd | Dimitris Aragiorgis | }) |
769 | 4588b4bd | Dimitris Aragiorgis | |
770 | 6e8091f9 | Dimitris Aragiorgis | |
771 | c91407bc | Michael Hanselmann | class R_2_groups(baserlib.OpcodeResource): |
772 | c91407bc | Michael Hanselmann | """/2/groups resource.
|
773 | 90e99856 | Adeodato Simo |
|
774 | 90e99856 | Adeodato Simo | """
|
775 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpGroupQuery |
776 | c91407bc | Michael Hanselmann | POST_OPCODE = opcodes.OpGroupAdd |
777 | c91407bc | Michael Hanselmann | POST_RENAME = { |
778 | 527fbde8 | Michael Hanselmann | "name": "group_name", |
779 | 527fbde8 | Michael Hanselmann | } |
780 | 527fbde8 | Michael Hanselmann | |
781 | c91407bc | Michael Hanselmann | def GetPostOpInput(self): |
782 | c91407bc | Michael Hanselmann | """Create a node group.
|
783 | 90e99856 | Adeodato Simo |
|
784 | 4588b4bd | Dimitris Aragiorgis |
|
785 | c91407bc | Michael Hanselmann | """
|
786 | c91407bc | Michael Hanselmann | assert not self.items |
787 | c91407bc | Michael Hanselmann | return (self.request_body, { |
788 | c91407bc | Michael Hanselmann | "dry_run": self.dryRun(), |
789 | c91407bc | Michael Hanselmann | }) |
790 | 0897dc97 | Adeodato Simo | |
791 | 0897dc97 | Adeodato Simo | def GET(self): |
792 | 0897dc97 | Adeodato Simo | """Returns a list of all node groups.
|
793 | 0897dc97 | Adeodato Simo |
|
794 | 0897dc97 | Adeodato Simo | """
|
795 | 9fbf0098 | Iustin Pop | client = self.GetClient(query=True) |
796 | 0897dc97 | Adeodato Simo | |
797 | 0897dc97 | Adeodato Simo | if self.useBulk(): |
798 | 0897dc97 | Adeodato Simo | bulkdata = client.QueryGroups([], G_FIELDS, False)
|
799 | 0897dc97 | Adeodato Simo | return baserlib.MapBulkFields(bulkdata, G_FIELDS)
|
800 | 0897dc97 | Adeodato Simo | else:
|
801 | 0897dc97 | Adeodato Simo | data = client.QueryGroups([], ["name"], False) |
802 | 0897dc97 | Adeodato Simo | groupnames = [row[0] for row in data] |
803 | 0897dc97 | Adeodato Simo | return baserlib.BuildUriList(groupnames, "/2/groups/%s", |
804 | 0897dc97 | Adeodato Simo | uri_fields=("name", "uri")) |
805 | 0897dc97 | Adeodato Simo | |
806 | 0897dc97 | Adeodato Simo | |
807 | 86f1f5d4 | Michael Hanselmann | class R_2_groups_name(baserlib.OpcodeResource): |
808 | b58a4d16 | Michael Hanselmann | """/2/groups/[group_name] resource.
|
809 | 0897dc97 | Adeodato Simo |
|
810 | 0897dc97 | Adeodato Simo | """
|
811 | 86f1f5d4 | Michael Hanselmann | DELETE_OPCODE = opcodes.OpGroupRemove |
812 | 86f1f5d4 | Michael Hanselmann | |
813 | 0897dc97 | Adeodato Simo | def GET(self): |
814 | 0897dc97 | Adeodato Simo | """Send information about a node group.
|
815 | 0897dc97 | Adeodato Simo |
|
816 | 0897dc97 | Adeodato Simo | """
|
817 | 0897dc97 | Adeodato Simo | group_name = self.items[0] |
818 | 9fbf0098 | Iustin Pop | client = self.GetClient(query=True) |
819 | 0897dc97 | Adeodato Simo | |
820 | 0897dc97 | Adeodato Simo | result = baserlib.HandleItemQueryErrors(client.QueryGroups, |
821 | 0897dc97 | Adeodato Simo | names=[group_name], fields=G_FIELDS, |
822 | 0897dc97 | Adeodato Simo | use_locking=self.useLocking())
|
823 | 0897dc97 | Adeodato Simo | |
824 | 0897dc97 | Adeodato Simo | return baserlib.MapFields(G_FIELDS, result[0]) |
825 | 0897dc97 | Adeodato Simo | |
826 | 86f1f5d4 | Michael Hanselmann | def GetDeleteOpInput(self): |
827 | 0dbaa9ca | Adeodato Simo | """Delete a node group.
|
828 | 0dbaa9ca | Adeodato Simo |
|
829 | 0dbaa9ca | Adeodato Simo | """
|
830 | 86f1f5d4 | Michael Hanselmann | assert len(self.items) == 1 |
831 | 86f1f5d4 | Michael Hanselmann | return ({}, {
|
832 | 86f1f5d4 | Michael Hanselmann | "group_name": self.items[0], |
833 | 86f1f5d4 | Michael Hanselmann | "dry_run": self.dryRun(), |
834 | 86f1f5d4 | Michael Hanselmann | }) |
835 | 0dbaa9ca | Adeodato Simo | |
836 | 0dbaa9ca | Adeodato Simo | |
837 | d5211458 | Michael Hanselmann | class R_2_groups_name_modify(baserlib.OpcodeResource): |
838 | f18fab7d | Adeodato Simo | """/2/groups/[group_name]/modify resource.
|
839 | f18fab7d | Adeodato Simo |
|
840 | f18fab7d | Adeodato Simo | """
|
841 | d5211458 | Michael Hanselmann | PUT_OPCODE = opcodes.OpGroupSetParams |
842 | f18fab7d | Adeodato Simo | |
843 | d5211458 | Michael Hanselmann | def GetPutOpInput(self): |
844 | d5211458 | Michael Hanselmann | """Changes some parameters of node group.
|
845 | f18fab7d | Adeodato Simo |
|
846 | f18fab7d | Adeodato Simo | """
|
847 | d5211458 | Michael Hanselmann | assert self.items |
848 | d5211458 | Michael Hanselmann | return (self.request_body, { |
849 | d5211458 | Michael Hanselmann | "group_name": self.items[0], |
850 | d5211458 | Michael Hanselmann | }) |
851 | f18fab7d | Adeodato Simo | |
852 | f18fab7d | Adeodato Simo | |
853 | cd0d4d5a | Michael Hanselmann | class R_2_groups_name_rename(baserlib.OpcodeResource): |
854 | b58a4d16 | Michael Hanselmann | """/2/groups/[group_name]/rename resource.
|
855 | 0dbaa9ca | Adeodato Simo |
|
856 | 0dbaa9ca | Adeodato Simo | """
|
857 | cd0d4d5a | Michael Hanselmann | PUT_OPCODE = opcodes.OpGroupRename |
858 | 0dbaa9ca | Adeodato Simo | |
859 | cd0d4d5a | Michael Hanselmann | def GetPutOpInput(self): |
860 | cd0d4d5a | Michael Hanselmann | """Changes the name of a node group.
|
861 | 0dbaa9ca | Adeodato Simo |
|
862 | 0dbaa9ca | Adeodato Simo | """
|
863 | cd0d4d5a | Michael Hanselmann | assert len(self.items) == 1 |
864 | cd0d4d5a | Michael Hanselmann | return (self.request_body, { |
865 | cd0d4d5a | Michael Hanselmann | "group_name": self.items[0], |
866 | cd0d4d5a | Michael Hanselmann | "dry_run": self.dryRun(), |
867 | cd0d4d5a | Michael Hanselmann | }) |
868 | 0897dc97 | Adeodato Simo | |
869 | 0897dc97 | Adeodato Simo | |
870 | 87fd3ec7 | Michael Hanselmann | class R_2_groups_name_assign_nodes(baserlib.OpcodeResource): |
871 | b58a4d16 | Michael Hanselmann | """/2/groups/[group_name]/assign-nodes resource.
|
872 | 4245446f | Adeodato Simo |
|
873 | 4245446f | Adeodato Simo | """
|
874 | 87fd3ec7 | Michael Hanselmann | PUT_OPCODE = opcodes.OpGroupAssignNodes |
875 | 4245446f | Adeodato Simo | |
876 | 87fd3ec7 | Michael Hanselmann | def GetPutOpInput(self): |
877 | 87fd3ec7 | Michael Hanselmann | """Assigns nodes to a group.
|
878 | 4245446f | Adeodato Simo |
|
879 | 4245446f | Adeodato Simo | """
|
880 | 87fd3ec7 | Michael Hanselmann | assert len(self.items) == 1 |
881 | 87fd3ec7 | Michael Hanselmann | return (self.request_body, { |
882 | 4245446f | Adeodato Simo | "group_name": self.items[0], |
883 | 4245446f | Adeodato Simo | "dry_run": self.dryRun(), |
884 | 4245446f | Adeodato Simo | "force": self.useForce(), |
885 | 4245446f | Adeodato Simo | }) |
886 | 4245446f | Adeodato Simo | |
887 | 4245446f | Adeodato Simo | |
888 | 09a43b39 | Michael Hanselmann | class R_2_instances(baserlib.OpcodeResource): |
889 | 09a43b39 | Michael Hanselmann | """/2/instances resource.
|
890 | 6395cebb | Michael Hanselmann |
|
891 | 6395cebb | Michael Hanselmann | """
|
892 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpInstanceQuery |
893 | 09a43b39 | Michael Hanselmann | POST_OPCODE = opcodes.OpInstanceCreate |
894 | 09a43b39 | Michael Hanselmann | POST_RENAME = { |
895 | 526a662a | Michael Hanselmann | "os": "os_type", |
896 | 526a662a | Michael Hanselmann | "name": "instance_name", |
897 | 526a662a | Michael Hanselmann | } |
898 | 526a662a | Michael Hanselmann | |
899 | 441e7cfd | Oleksiy Mishchenko | def GET(self): |
900 | 441e7cfd | Oleksiy Mishchenko | """Returns a list of all available instances.
|
901 | 441e7cfd | Oleksiy Mishchenko |
|
902 | 441e7cfd | Oleksiy Mishchenko | """
|
903 | be1ddd09 | Michael Hanselmann | client = self.GetClient()
|
904 | 441e7cfd | Oleksiy Mishchenko | |
905 | 3d103742 | Iustin Pop | use_locking = self.useLocking()
|
906 | 3d103742 | Iustin Pop | if self.useBulk(): |
907 | 3d103742 | Iustin Pop | bulkdata = client.QueryInstances([], I_FIELDS, use_locking) |
908 | 28a45bfc | René Nussbaumer | return map(_UpdateBeparams, baserlib.MapBulkFields(bulkdata, I_FIELDS)) |
909 | 441e7cfd | Oleksiy Mishchenko | else:
|
910 | 3d103742 | Iustin Pop | instancesdata = client.QueryInstances([], ["name"], use_locking)
|
911 | 9031ee8e | Iustin Pop | instanceslist = [row[0] for row in instancesdata] |
912 | 441e7cfd | Oleksiy Mishchenko | return baserlib.BuildUriList(instanceslist, "/2/instances/%s", |
913 | 441e7cfd | Oleksiy Mishchenko | uri_fields=("id", "uri")) |
914 | 441e7cfd | Oleksiy Mishchenko | |
915 | 09a43b39 | Michael Hanselmann | def GetPostOpInput(self): |
916 | d975f482 | Michael Hanselmann | """Create an instance.
|
917 | d975f482 | Michael Hanselmann |
|
918 | d975f482 | Michael Hanselmann | @return: a job id
|
919 | d975f482 | Michael Hanselmann |
|
920 | d975f482 | Michael Hanselmann | """
|
921 | 09a43b39 | Michael Hanselmann | baserlib.CheckType(self.request_body, dict, "Body contents") |
922 | d975f482 | Michael Hanselmann | |
923 | d975f482 | Michael Hanselmann | # Default to request data version 0
|
924 | d975f482 | Michael Hanselmann | data_version = self.getBodyParameter(_REQ_DATA_VERSION, 0) |
925 | d975f482 | Michael Hanselmann | |
926 | d975f482 | Michael Hanselmann | if data_version == 0: |
927 | 3fd7f652 | Michael Hanselmann | raise http.HttpBadRequest("Instance creation request version 0 is no" |
928 | 3fd7f652 | Michael Hanselmann | " longer supported")
|
929 | 09a43b39 | Michael Hanselmann | elif data_version != 1: |
930 | d975f482 | Michael Hanselmann | raise http.HttpBadRequest("Unsupported request data version %s" % |
931 | 12eff9b9 | Michael Hanselmann | data_version) |
932 | d975f482 | Michael Hanselmann | |
933 | 09a43b39 | Michael Hanselmann | data = self.request_body.copy()
|
934 | 09a43b39 | Michael Hanselmann | # Remove "__version__"
|
935 | 09a43b39 | Michael Hanselmann | data.pop(_REQ_DATA_VERSION, None)
|
936 | 09a43b39 | Michael Hanselmann | |
937 | 09a43b39 | Michael Hanselmann | return (data, {
|
938 | 09a43b39 | Michael Hanselmann | "dry_run": self.dryRun(), |
939 | 09a43b39 | Michael Hanselmann | }) |
940 | 2f7635f4 | Oleksiy Mishchenko | |
941 | 441e7cfd | Oleksiy Mishchenko | |
942 | 4ee72287 | René Nussbaumer | class R_2_instances_multi_alloc(baserlib.OpcodeResource): |
943 | 4ee72287 | René Nussbaumer | """/2/instances-multi-alloc resource.
|
944 | 4ee72287 | René Nussbaumer |
|
945 | 4ee72287 | René Nussbaumer | """
|
946 | 4ee72287 | René Nussbaumer | POST_OPCODE = opcodes.OpInstanceMultiAlloc |
947 | 4ee72287 | René Nussbaumer | |
948 | 4ee72287 | René Nussbaumer | def GetPostOpInput(self): |
949 | 4ee72287 | René Nussbaumer | """Try to allocate multiple instances.
|
950 | 4ee72287 | René Nussbaumer |
|
951 | 4ee72287 | René Nussbaumer | @return: A dict with submitted jobs, allocatable instances and failed
|
952 | 4ee72287 | René Nussbaumer | allocations
|
953 | 4ee72287 | René Nussbaumer |
|
954 | 4ee72287 | René Nussbaumer | """
|
955 | e5ff1a47 | René Nussbaumer | if "instances" not in self.request_body: |
956 | e5ff1a47 | René Nussbaumer | raise http.HttpBadRequest("Request is missing required 'instances' field" |
957 | e5ff1a47 | René Nussbaumer | " in body")
|
958 | e5ff1a47 | René Nussbaumer | |
959 | e5ff1a47 | René Nussbaumer | op_id = { |
960 | e5ff1a47 | René Nussbaumer | "OP_ID": self.POST_OPCODE.OP_ID, # pylint: disable=E1101 |
961 | e5ff1a47 | René Nussbaumer | } |
962 | e5ff1a47 | René Nussbaumer | body = objects.FillDict(self.request_body, {
|
963 | e5ff1a47 | René Nussbaumer | "instances": [objects.FillDict(inst, op_id)
|
964 | e5ff1a47 | René Nussbaumer | for inst in self.request_body["instances"]], |
965 | e5ff1a47 | René Nussbaumer | }) |
966 | e5ff1a47 | René Nussbaumer | |
967 | e5ff1a47 | René Nussbaumer | return (body, {
|
968 | 4ee72287 | René Nussbaumer | "dry_run": self.dryRun(), |
969 | 4ee72287 | René Nussbaumer | }) |
970 | 4ee72287 | René Nussbaumer | |
971 | 4ee72287 | René Nussbaumer | |
972 | a6fa7892 | Michael Hanselmann | class R_2_instances_name(baserlib.OpcodeResource): |
973 | b58a4d16 | Michael Hanselmann | """/2/instances/[instance_name] resource.
|
974 | 028c6b76 | Oleksiy Mishchenko |
|
975 | 028c6b76 | Oleksiy Mishchenko | """
|
976 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpInstanceQuery |
977 | a6fa7892 | Michael Hanselmann | DELETE_OPCODE = opcodes.OpInstanceRemove |
978 | a6fa7892 | Michael Hanselmann | |
979 | 4e5a68f8 | Oleksiy Mishchenko | def GET(self): |
980 | 4e5a68f8 | Oleksiy Mishchenko | """Send information about an instance.
|
981 | 4e5a68f8 | Oleksiy Mishchenko |
|
982 | 4e5a68f8 | Oleksiy Mishchenko | """
|
983 | be1ddd09 | Michael Hanselmann | client = self.GetClient()
|
984 | 4e5a68f8 | Oleksiy Mishchenko | instance_name = self.items[0] |
985 | e8ebbd2b | Michael Hanselmann | |
986 | e8ebbd2b | Michael Hanselmann | result = baserlib.HandleItemQueryErrors(client.QueryInstances, |
987 | e8ebbd2b | Michael Hanselmann | names=[instance_name], |
988 | e8ebbd2b | Michael Hanselmann | fields=I_FIELDS, |
989 | e8ebbd2b | Michael Hanselmann | use_locking=self.useLocking())
|
990 | 4e5a68f8 | Oleksiy Mishchenko | |
991 | 28a45bfc | René Nussbaumer | return _UpdateBeparams(baserlib.MapFields(I_FIELDS, result[0])) |
992 | 028c6b76 | Oleksiy Mishchenko | |
993 | a6fa7892 | Michael Hanselmann | def GetDeleteOpInput(self): |
994 | 6e99c5a0 | Iustin Pop | """Delete an instance.
|
995 | 6e99c5a0 | Iustin Pop |
|
996 | 6e99c5a0 | Iustin Pop | """
|
997 | a6fa7892 | Michael Hanselmann | assert len(self.items) == 1 |
998 | a6fa7892 | Michael Hanselmann | return ({}, {
|
999 | a6fa7892 | Michael Hanselmann | "instance_name": self.items[0], |
1000 | a6fa7892 | Michael Hanselmann | "ignore_failures": False, |
1001 | a6fa7892 | Michael Hanselmann | "dry_run": self.dryRun(), |
1002 | a6fa7892 | Michael Hanselmann | }) |
1003 | 6e99c5a0 | Iustin Pop | |
1004 | 028c6b76 | Oleksiy Mishchenko | |
1005 | 7b3df961 | Michael Hanselmann | class R_2_instances_name_info(baserlib.OpcodeResource): |
1006 | d8260842 | Michael Hanselmann | """/2/instances/[instance_name]/info resource.
|
1007 | d8260842 | Michael Hanselmann |
|
1008 | d8260842 | Michael Hanselmann | """
|
1009 | 7b3df961 | Michael Hanselmann | GET_OPCODE = opcodes.OpInstanceQueryData |
1010 | 7b3df961 | Michael Hanselmann | |
1011 | 7b3df961 | Michael Hanselmann | def GetGetOpInput(self): |
1012 | d8260842 | Michael Hanselmann | """Request detailed instance information.
|
1013 | d8260842 | Michael Hanselmann |
|
1014 | d8260842 | Michael Hanselmann | """
|
1015 | 7b3df961 | Michael Hanselmann | assert len(self.items) == 1 |
1016 | 7b3df961 | Michael Hanselmann | return ({}, {
|
1017 | 7b3df961 | Michael Hanselmann | "instances": [self.items[0]], |
1018 | 7b3df961 | Michael Hanselmann | "static": bool(self._checkIntVariable("static", default=0)), |
1019 | 7b3df961 | Michael Hanselmann | }) |
1020 | d8260842 | Michael Hanselmann | |
1021 | d8260842 | Michael Hanselmann | |
1022 | ac4888c1 | Michael Hanselmann | class R_2_instances_name_reboot(baserlib.OpcodeResource): |
1023 | 2276aa29 | Oleksiy Mishchenko | """/2/instances/[instance_name]/reboot resource.
|
1024 | 2276aa29 | Oleksiy Mishchenko |
|
1025 | 2276aa29 | Oleksiy Mishchenko | Implements an instance reboot.
|
1026 | 2276aa29 | Oleksiy Mishchenko |
|
1027 | 2276aa29 | Oleksiy Mishchenko | """
|
1028 | ac4888c1 | Michael Hanselmann | POST_OPCODE = opcodes.OpInstanceReboot |
1029 | ac4888c1 | Michael Hanselmann | |
1030 | ac4888c1 | Michael Hanselmann | def GetPostOpInput(self): |
1031 | 2276aa29 | Oleksiy Mishchenko | """Reboot an instance.
|
1032 | 2276aa29 | Oleksiy Mishchenko |
|
1033 | 0c55c24b | Oleksiy Mishchenko | The URI takes type=[hard|soft|full] and
|
1034 | 0c55c24b | Oleksiy Mishchenko | ignore_secondaries=[False|True] parameters.
|
1035 | 0c55c24b | Oleksiy Mishchenko |
|
1036 | 2276aa29 | Oleksiy Mishchenko | """
|
1037 | ac4888c1 | Michael Hanselmann | return ({}, {
|
1038 | ac4888c1 | Michael Hanselmann | "instance_name": self.items[0], |
1039 | ac4888c1 | Michael Hanselmann | "reboot_type":
|
1040 | ac4888c1 | Michael Hanselmann | self.queryargs.get("type", [constants.INSTANCE_REBOOT_HARD])[0], |
1041 | ac4888c1 | Michael Hanselmann | "ignore_secondaries": bool(self._checkIntVariable("ignore_secondaries")), |
1042 | ac4888c1 | Michael Hanselmann | "dry_run": self.dryRun(), |
1043 | ac4888c1 | Michael Hanselmann | }) |
1044 | 2276aa29 | Oleksiy Mishchenko | |
1045 | 2276aa29 | Oleksiy Mishchenko | |
1046 | 4717e6eb | Michael Hanselmann | class R_2_instances_name_startup(baserlib.OpcodeResource): |
1047 | 0c55c24b | Oleksiy Mishchenko | """/2/instances/[instance_name]/startup resource.
|
1048 | 0c55c24b | Oleksiy Mishchenko |
|
1049 | 0c55c24b | Oleksiy Mishchenko | Implements an instance startup.
|
1050 | 0c55c24b | Oleksiy Mishchenko |
|
1051 | 0c55c24b | Oleksiy Mishchenko | """
|
1052 | 4717e6eb | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceStartup |
1053 | 4717e6eb | Michael Hanselmann | |
1054 | 4717e6eb | Michael Hanselmann | def GetPutOpInput(self): |
1055 | 0c55c24b | Oleksiy Mishchenko | """Startup an instance.
|
1056 | 0c55c24b | Oleksiy Mishchenko |
|
1057 | c41eea6e | Iustin Pop | The URI takes force=[False|True] parameter to start the instance
|
1058 | c41eea6e | Iustin Pop | if even if secondary disks are failing.
|
1059 | 0c55c24b | Oleksiy Mishchenko |
|
1060 | 0c55c24b | Oleksiy Mishchenko | """
|
1061 | 4717e6eb | Michael Hanselmann | return ({}, {
|
1062 | 4717e6eb | Michael Hanselmann | "instance_name": self.items[0], |
1063 | 4717e6eb | Michael Hanselmann | "force": self.useForce(), |
1064 | 4717e6eb | Michael Hanselmann | "dry_run": self.dryRun(), |
1065 | 4717e6eb | Michael Hanselmann | "no_remember": bool(self._checkIntVariable("no_remember")), |
1066 | 4717e6eb | Michael Hanselmann | }) |
1067 | 0c55c24b | Oleksiy Mishchenko | |
1068 | 0c55c24b | Oleksiy Mishchenko | |
1069 | 3175ade6 | Michael Hanselmann | class R_2_instances_name_shutdown(baserlib.OpcodeResource): |
1070 | 0c55c24b | Oleksiy Mishchenko | """/2/instances/[instance_name]/shutdown resource.
|
1071 | 0c55c24b | Oleksiy Mishchenko |
|
1072 | 0c55c24b | Oleksiy Mishchenko | Implements an instance shutdown.
|
1073 | 0c55c24b | Oleksiy Mishchenko |
|
1074 | 0c55c24b | Oleksiy Mishchenko | """
|
1075 | 3175ade6 | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceShutdown |
1076 | 0c55c24b | Oleksiy Mishchenko | |
1077 | 3175ade6 | Michael Hanselmann | def GetPutOpInput(self): |
1078 | 3175ade6 | Michael Hanselmann | """Shutdown an instance.
|
1079 | 7fa310f6 | René Nussbaumer |
|
1080 | 0c55c24b | Oleksiy Mishchenko | """
|
1081 | 3175ade6 | Michael Hanselmann | return (self.request_body, { |
1082 | 3175ade6 | Michael Hanselmann | "instance_name": self.items[0], |
1083 | 3175ade6 | Michael Hanselmann | "no_remember": bool(self._checkIntVariable("no_remember")), |
1084 | 3175ade6 | Michael Hanselmann | "dry_run": self.dryRun(), |
1085 | 3175ade6 | Michael Hanselmann | }) |
1086 | 0c55c24b | Oleksiy Mishchenko | |
1087 | 0c55c24b | Oleksiy Mishchenko | |
1088 | c744425f | Michael Hanselmann | def _ParseInstanceReinstallRequest(name, data): |
1089 | c744425f | Michael Hanselmann | """Parses a request for reinstalling an instance.
|
1090 | c744425f | Michael Hanselmann |
|
1091 | c744425f | Michael Hanselmann | """
|
1092 | c744425f | Michael Hanselmann | if not isinstance(data, dict): |
1093 | c744425f | Michael Hanselmann | raise http.HttpBadRequest("Invalid body contents, not a dictionary") |
1094 | c744425f | Michael Hanselmann | |
1095 | bd0807fe | Guido Trotter | ostype = baserlib.CheckParameter(data, "os", default=None) |
1096 | c744425f | Michael Hanselmann | start = baserlib.CheckParameter(data, "start", exptype=bool, |
1097 | c744425f | Michael Hanselmann | default=True)
|
1098 | c744425f | Michael Hanselmann | osparams = baserlib.CheckParameter(data, "osparams", default=None) |
1099 | c744425f | Michael Hanselmann | |
1100 | c744425f | Michael Hanselmann | ops = [ |
1101 | ee3e37a7 | Iustin Pop | opcodes.OpInstanceShutdown(instance_name=name), |
1102 | 5073fd8f | Iustin Pop | opcodes.OpInstanceReinstall(instance_name=name, os_type=ostype, |
1103 | c744425f | Michael Hanselmann | osparams=osparams), |
1104 | c744425f | Michael Hanselmann | ] |
1105 | c744425f | Michael Hanselmann | |
1106 | c744425f | Michael Hanselmann | if start:
|
1107 | c873d91c | Iustin Pop | ops.append(opcodes.OpInstanceStartup(instance_name=name, force=False))
|
1108 | c744425f | Michael Hanselmann | |
1109 | c744425f | Michael Hanselmann | return ops
|
1110 | c744425f | Michael Hanselmann | |
1111 | c744425f | Michael Hanselmann | |
1112 | f6ce0ba2 | Michael Hanselmann | class R_2_instances_name_reinstall(baserlib.OpcodeResource): |
1113 | e5b7c4ca | Iustin Pop | """/2/instances/[instance_name]/reinstall resource.
|
1114 | e5b7c4ca | Iustin Pop |
|
1115 | e5b7c4ca | Iustin Pop | Implements an instance reinstall.
|
1116 | e5b7c4ca | Iustin Pop |
|
1117 | e5b7c4ca | Iustin Pop | """
|
1118 | f6ce0ba2 | Michael Hanselmann | POST_OPCODE = opcodes.OpInstanceReinstall |
1119 | f6ce0ba2 | Michael Hanselmann | |
1120 | e5b7c4ca | Iustin Pop | def POST(self): |
1121 | e5b7c4ca | Iustin Pop | """Reinstall an instance.
|
1122 | e5b7c4ca | Iustin Pop |
|
1123 | e5b7c4ca | Iustin Pop | The URI takes os=name and nostartup=[0|1] optional
|
1124 | e5b7c4ca | Iustin Pop | parameters. By default, the instance will be started
|
1125 | e5b7c4ca | Iustin Pop | automatically.
|
1126 | e5b7c4ca | Iustin Pop |
|
1127 | e5b7c4ca | Iustin Pop | """
|
1128 | c744425f | Michael Hanselmann | if self.request_body: |
1129 | c744425f | Michael Hanselmann | if self.queryargs: |
1130 | c744425f | Michael Hanselmann | raise http.HttpBadRequest("Can't combine query and body parameters") |
1131 | c744425f | Michael Hanselmann | |
1132 | c744425f | Michael Hanselmann | body = self.request_body
|
1133 | bd0807fe | Guido Trotter | elif self.queryargs: |
1134 | c744425f | Michael Hanselmann | # Legacy interface, do not modify/extend
|
1135 | c744425f | Michael Hanselmann | body = { |
1136 | c744425f | Michael Hanselmann | "os": self._checkStringVariable("os"), |
1137 | c744425f | Michael Hanselmann | "start": not self._checkIntVariable("nostartup"), |
1138 | c744425f | Michael Hanselmann | } |
1139 | bd0807fe | Guido Trotter | else:
|
1140 | bd0807fe | Guido Trotter | body = {} |
1141 | c744425f | Michael Hanselmann | |
1142 | c744425f | Michael Hanselmann | ops = _ParseInstanceReinstallRequest(self.items[0], body) |
1143 | c744425f | Michael Hanselmann | |
1144 | be1ddd09 | Michael Hanselmann | return self.SubmitJob(ops) |
1145 | e5b7c4ca | Iustin Pop | |
1146 | e5b7c4ca | Iustin Pop | |
1147 | 0dbc732c | Michael Hanselmann | class R_2_instances_name_replace_disks(baserlib.OpcodeResource): |
1148 | 4c98b915 | Michael Hanselmann | """/2/instances/[instance_name]/replace-disks resource.
|
1149 | 4c98b915 | Michael Hanselmann |
|
1150 | 4c98b915 | Michael Hanselmann | """
|
1151 | 0dbc732c | Michael Hanselmann | POST_OPCODE = opcodes.OpInstanceReplaceDisks |
1152 | 0dbc732c | Michael Hanselmann | |
1153 | 0dbc732c | Michael Hanselmann | def GetPostOpInput(self): |
1154 | 4c98b915 | Michael Hanselmann | """Replaces disks on an instance.
|
1155 | 4c98b915 | Michael Hanselmann |
|
1156 | 4c98b915 | Michael Hanselmann | """
|
1157 | 0dbc732c | Michael Hanselmann | static = { |
1158 | 0dbc732c | Michael Hanselmann | "instance_name": self.items[0], |
1159 | 0dbc732c | Michael Hanselmann | } |
1160 | 4c98b915 | Michael Hanselmann | |
1161 | 539d65ba | Michael Hanselmann | if self.request_body: |
1162 | 7dcf333d | Michael Hanselmann | data = self.request_body
|
1163 | 539d65ba | Michael Hanselmann | elif self.queryargs: |
1164 | 539d65ba | Michael Hanselmann | # Legacy interface, do not modify/extend
|
1165 | 7dcf333d | Michael Hanselmann | data = { |
1166 | 539d65ba | Michael Hanselmann | "remote_node": self._checkStringVariable("remote_node", default=None), |
1167 | 539d65ba | Michael Hanselmann | "mode": self._checkStringVariable("mode", default=None), |
1168 | 539d65ba | Michael Hanselmann | "disks": self._checkStringVariable("disks", default=None), |
1169 | 539d65ba | Michael Hanselmann | "iallocator": self._checkStringVariable("iallocator", default=None), |
1170 | 539d65ba | Michael Hanselmann | } |
1171 | 539d65ba | Michael Hanselmann | else:
|
1172 | 7dcf333d | Michael Hanselmann | data = {} |
1173 | 539d65ba | Michael Hanselmann | |
1174 | 0dbc732c | Michael Hanselmann | # Parse disks
|
1175 | 0dbc732c | Michael Hanselmann | try:
|
1176 | 7dcf333d | Michael Hanselmann | raw_disks = data.pop("disks")
|
1177 | 0dbc732c | Michael Hanselmann | except KeyError: |
1178 | 0dbc732c | Michael Hanselmann | pass
|
1179 | 0dbc732c | Michael Hanselmann | else:
|
1180 | 7dcf333d | Michael Hanselmann | if raw_disks:
|
1181 | 7dcf333d | Michael Hanselmann | if ht.TListOf(ht.TInt)(raw_disks): # pylint: disable=E1102 |
1182 | 7dcf333d | Michael Hanselmann | data["disks"] = raw_disks
|
1183 | 7dcf333d | Michael Hanselmann | else:
|
1184 | 7dcf333d | Michael Hanselmann | # Backwards compatibility for strings of the format "1, 2, 3"
|
1185 | 7dcf333d | Michael Hanselmann | try:
|
1186 | 7dcf333d | Michael Hanselmann | data["disks"] = [int(part) for part in raw_disks.split(",")] |
1187 | 7dcf333d | Michael Hanselmann | except (TypeError, ValueError), err: |
1188 | 7dcf333d | Michael Hanselmann | raise http.HttpBadRequest("Invalid disk index passed: %s" % err) |
1189 | 0dbc732c | Michael Hanselmann | |
1190 | 0dbc732c | Michael Hanselmann | return (data, static)
|
1191 | 4c98b915 | Michael Hanselmann | |
1192 | 4c98b915 | Michael Hanselmann | |
1193 | 1824a7a1 | Michael Hanselmann | class R_2_instances_name_activate_disks(baserlib.OpcodeResource): |
1194 | 2197b66f | René Nussbaumer | """/2/instances/[instance_name]/activate-disks resource.
|
1195 | 2197b66f | René Nussbaumer |
|
1196 | 2197b66f | René Nussbaumer | """
|
1197 | 1824a7a1 | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceActivateDisks |
1198 | 1824a7a1 | Michael Hanselmann | |
1199 | 1824a7a1 | Michael Hanselmann | def GetPutOpInput(self): |
1200 | 2197b66f | René Nussbaumer | """Activate disks for an instance.
|
1201 | 2197b66f | René Nussbaumer |
|
1202 | 2197b66f | René Nussbaumer | The URI might contain ignore_size to ignore current recorded size.
|
1203 | 2197b66f | René Nussbaumer |
|
1204 | 2197b66f | René Nussbaumer | """
|
1205 | 1824a7a1 | Michael Hanselmann | return ({}, {
|
1206 | 1824a7a1 | Michael Hanselmann | "instance_name": self.items[0], |
1207 | 1824a7a1 | Michael Hanselmann | "ignore_size": bool(self._checkIntVariable("ignore_size")), |
1208 | 1824a7a1 | Michael Hanselmann | }) |
1209 | 2197b66f | René Nussbaumer | |
1210 | 2197b66f | René Nussbaumer | |
1211 | 973ec124 | Michael Hanselmann | class R_2_instances_name_deactivate_disks(baserlib.OpcodeResource): |
1212 | 0a37de5f | René Nussbaumer | """/2/instances/[instance_name]/deactivate-disks resource.
|
1213 | 0a37de5f | René Nussbaumer |
|
1214 | 0a37de5f | René Nussbaumer | """
|
1215 | 973ec124 | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceDeactivateDisks |
1216 | 973ec124 | Michael Hanselmann | |
1217 | 973ec124 | Michael Hanselmann | def GetPutOpInput(self): |
1218 | 0a37de5f | René Nussbaumer | """Deactivate disks for an instance.
|
1219 | 0a37de5f | René Nussbaumer |
|
1220 | 0a37de5f | René Nussbaumer | """
|
1221 | 973ec124 | Michael Hanselmann | return ({}, {
|
1222 | 973ec124 | Michael Hanselmann | "instance_name": self.items[0], |
1223 | 973ec124 | Michael Hanselmann | }) |
1224 | 0a37de5f | René Nussbaumer | |
1225 | 0a37de5f | René Nussbaumer | |
1226 | a52978c7 | Michael Hanselmann | class R_2_instances_name_recreate_disks(baserlib.OpcodeResource): |
1227 | a52978c7 | Michael Hanselmann | """/2/instances/[instance_name]/recreate-disks resource.
|
1228 | a52978c7 | Michael Hanselmann |
|
1229 | a52978c7 | Michael Hanselmann | """
|
1230 | a52978c7 | Michael Hanselmann | POST_OPCODE = opcodes.OpInstanceRecreateDisks |
1231 | a52978c7 | Michael Hanselmann | |
1232 | a52978c7 | Michael Hanselmann | def GetPostOpInput(self): |
1233 | a52978c7 | Michael Hanselmann | """Recreate disks for an instance.
|
1234 | a52978c7 | Michael Hanselmann |
|
1235 | a52978c7 | Michael Hanselmann | """
|
1236 | a52978c7 | Michael Hanselmann | return ({}, {
|
1237 | a52978c7 | Michael Hanselmann | "instance_name": self.items[0], |
1238 | a52978c7 | Michael Hanselmann | }) |
1239 | a52978c7 | Michael Hanselmann | |
1240 | a52978c7 | Michael Hanselmann | |
1241 | 1c63311d | Michael Hanselmann | class R_2_instances_name_prepare_export(baserlib.OpcodeResource): |
1242 | ebeb600f | Michael Hanselmann | """/2/instances/[instance_name]/prepare-export resource.
|
1243 | ebeb600f | Michael Hanselmann |
|
1244 | ebeb600f | Michael Hanselmann | """
|
1245 | 1c63311d | Michael Hanselmann | PUT_OPCODE = opcodes.OpBackupPrepare |
1246 | ebeb600f | Michael Hanselmann | |
1247 | 1c63311d | Michael Hanselmann | def GetPutOpInput(self): |
1248 | 1c63311d | Michael Hanselmann | """Prepares an export for an instance.
|
1249 | ebeb600f | Michael Hanselmann |
|
1250 | ebeb600f | Michael Hanselmann | """
|
1251 | 1c63311d | Michael Hanselmann | return ({}, {
|
1252 | 1c63311d | Michael Hanselmann | "instance_name": self.items[0], |
1253 | 1c63311d | Michael Hanselmann | "mode": self._checkStringVariable("mode"), |
1254 | 1c63311d | Michael Hanselmann | }) |
1255 | ebeb600f | Michael Hanselmann | |
1256 | ebeb600f | Michael Hanselmann | |
1257 | 134afbe7 | Michael Hanselmann | class R_2_instances_name_export(baserlib.OpcodeResource): |
1258 | ebeb600f | Michael Hanselmann | """/2/instances/[instance_name]/export resource.
|
1259 | ebeb600f | Michael Hanselmann |
|
1260 | ebeb600f | Michael Hanselmann | """
|
1261 | 134afbe7 | Michael Hanselmann | PUT_OPCODE = opcodes.OpBackupExport |
1262 | 134afbe7 | Michael Hanselmann | PUT_RENAME = { |
1263 | 134afbe7 | Michael Hanselmann | "destination": "target_node", |
1264 | 134afbe7 | Michael Hanselmann | } |
1265 | ebeb600f | Michael Hanselmann | |
1266 | 134afbe7 | Michael Hanselmann | def GetPutOpInput(self): |
1267 | 134afbe7 | Michael Hanselmann | """Exports an instance.
|
1268 | ebeb600f | Michael Hanselmann |
|
1269 | ebeb600f | Michael Hanselmann | """
|
1270 | 134afbe7 | Michael Hanselmann | return (self.request_body, { |
1271 | 134afbe7 | Michael Hanselmann | "instance_name": self.items[0], |
1272 | 134afbe7 | Michael Hanselmann | }) |
1273 | ebeb600f | Michael Hanselmann | |
1274 | ebeb600f | Michael Hanselmann | |
1275 | 075a29be | Michael Hanselmann | class R_2_instances_name_migrate(baserlib.OpcodeResource): |
1276 | 5823e0d2 | Michael Hanselmann | """/2/instances/[instance_name]/migrate resource.
|
1277 | 5823e0d2 | Michael Hanselmann |
|
1278 | 5823e0d2 | Michael Hanselmann | """
|
1279 | 075a29be | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceMigrate |
1280 | 5823e0d2 | Michael Hanselmann | |
1281 | 075a29be | Michael Hanselmann | def GetPutOpInput(self): |
1282 | 075a29be | Michael Hanselmann | """Migrates an instance.
|
1283 | 5823e0d2 | Michael Hanselmann |
|
1284 | 5823e0d2 | Michael Hanselmann | """
|
1285 | 075a29be | Michael Hanselmann | return (self.request_body, { |
1286 | 075a29be | Michael Hanselmann | "instance_name": self.items[0], |
1287 | 075a29be | Michael Hanselmann | }) |
1288 | 5823e0d2 | Michael Hanselmann | |
1289 | 5823e0d2 | Michael Hanselmann | |
1290 | b5f2ab80 | Michael Hanselmann | class R_2_instances_name_failover(baserlib.OpcodeResource): |
1291 | c0a146a1 | Michael Hanselmann | """/2/instances/[instance_name]/failover resource.
|
1292 | c0a146a1 | Michael Hanselmann |
|
1293 | c0a146a1 | Michael Hanselmann | """
|
1294 | b5f2ab80 | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceFailover |
1295 | c0a146a1 | Michael Hanselmann | |
1296 | b5f2ab80 | Michael Hanselmann | def GetPutOpInput(self): |
1297 | b5f2ab80 | Michael Hanselmann | """Does a failover of an instance.
|
1298 | c0a146a1 | Michael Hanselmann |
|
1299 | c0a146a1 | Michael Hanselmann | """
|
1300 | b5f2ab80 | Michael Hanselmann | return (self.request_body, { |
1301 | c0a146a1 | Michael Hanselmann | "instance_name": self.items[0], |
1302 | c0a146a1 | Michael Hanselmann | }) |
1303 | c0a146a1 | Michael Hanselmann | |
1304 | c0a146a1 | Michael Hanselmann | |
1305 | d76f9b5d | Michael Hanselmann | class R_2_instances_name_rename(baserlib.OpcodeResource): |
1306 | d56e7dc7 | Michael Hanselmann | """/2/instances/[instance_name]/rename resource.
|
1307 | d56e7dc7 | Michael Hanselmann |
|
1308 | d56e7dc7 | Michael Hanselmann | """
|
1309 | d76f9b5d | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceRename |
1310 | d56e7dc7 | Michael Hanselmann | |
1311 | d76f9b5d | Michael Hanselmann | def GetPutOpInput(self): |
1312 | d76f9b5d | Michael Hanselmann | """Changes the name of an instance.
|
1313 | d56e7dc7 | Michael Hanselmann |
|
1314 | d56e7dc7 | Michael Hanselmann | """
|
1315 | d76f9b5d | Michael Hanselmann | return (self.request_body, { |
1316 | d76f9b5d | Michael Hanselmann | "instance_name": self.items[0], |
1317 | d76f9b5d | Michael Hanselmann | }) |
1318 | d56e7dc7 | Michael Hanselmann | |
1319 | d56e7dc7 | Michael Hanselmann | |
1320 | f3db88ba | Michael Hanselmann | class R_2_instances_name_modify(baserlib.OpcodeResource): |
1321 | 3882937a | Michael Hanselmann | """/2/instances/[instance_name]/modify resource.
|
1322 | 3882937a | Michael Hanselmann |
|
1323 | 3882937a | Michael Hanselmann | """
|
1324 | f3db88ba | Michael Hanselmann | PUT_OPCODE = opcodes.OpInstanceSetParams |
1325 | 3882937a | Michael Hanselmann | |
1326 | f3db88ba | Michael Hanselmann | def GetPutOpInput(self): |
1327 | f3db88ba | Michael Hanselmann | """Changes parameters of an instance.
|
1328 | 3882937a | Michael Hanselmann |
|
1329 | 3882937a | Michael Hanselmann | """
|
1330 | f3db88ba | Michael Hanselmann | return (self.request_body, { |
1331 | f3db88ba | Michael Hanselmann | "instance_name": self.items[0], |
1332 | f3db88ba | Michael Hanselmann | }) |
1333 | 3882937a | Michael Hanselmann | |
1334 | 3882937a | Michael Hanselmann | |
1335 | 335965b9 | Michael Hanselmann | class R_2_instances_name_disk_grow(baserlib.OpcodeResource): |
1336 | b58a4d16 | Michael Hanselmann | """/2/instances/[instance_name]/disk/[disk_index]/grow resource.
|
1337 | e23881ed | Michael Hanselmann |
|
1338 | e23881ed | Michael Hanselmann | """
|
1339 | 335965b9 | Michael Hanselmann | POST_OPCODE = opcodes.OpInstanceGrowDisk |
1340 | e23881ed | Michael Hanselmann | |
1341 | 335965b9 | Michael Hanselmann | def GetPostOpInput(self): |
1342 | 335965b9 | Michael Hanselmann | """Increases the size of an instance disk.
|
1343 | e23881ed | Michael Hanselmann |
|
1344 | e23881ed | Michael Hanselmann | """
|
1345 | 335965b9 | Michael Hanselmann | return (self.request_body, { |
1346 | e23881ed | Michael Hanselmann | "instance_name": self.items[0], |
1347 | e23881ed | Michael Hanselmann | "disk": int(self.items[1]), |
1348 | e23881ed | Michael Hanselmann | }) |
1349 | e23881ed | Michael Hanselmann | |
1350 | e23881ed | Michael Hanselmann | |
1351 | 26ff6ee2 | Michael Hanselmann | class R_2_instances_name_console(baserlib.ResourceBase): |
1352 | b82d4c5e | Michael Hanselmann | """/2/instances/[instance_name]/console resource.
|
1353 | b82d4c5e | Michael Hanselmann |
|
1354 | b82d4c5e | Michael Hanselmann | """
|
1355 | 5e12acfe | Michael Hanselmann | GET_ACCESS = [rapi.RAPI_ACCESS_WRITE, rapi.RAPI_ACCESS_READ] |
1356 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpInstanceConsole |
1357 | b82d4c5e | Michael Hanselmann | |
1358 | b82d4c5e | Michael Hanselmann | def GET(self): |
1359 | b82d4c5e | Michael Hanselmann | """Request information for connecting to instance's console.
|
1360 | b82d4c5e | Michael Hanselmann |
|
1361 | b82d4c5e | Michael Hanselmann | @return: Serialized instance console description, see
|
1362 | b82d4c5e | Michael Hanselmann | L{objects.InstanceConsole}
|
1363 | b82d4c5e | Michael Hanselmann |
|
1364 | b82d4c5e | Michael Hanselmann | """
|
1365 | be1ddd09 | Michael Hanselmann | client = self.GetClient()
|
1366 | b82d4c5e | Michael Hanselmann | |
1367 | b82d4c5e | Michael Hanselmann | ((console, ), ) = client.QueryInstances([self.items[0]], ["console"], False) |
1368 | b82d4c5e | Michael Hanselmann | |
1369 | b82d4c5e | Michael Hanselmann | if console is None: |
1370 | b82d4c5e | Michael Hanselmann | raise http.HttpServiceUnavailable("Instance console unavailable") |
1371 | b82d4c5e | Michael Hanselmann | |
1372 | b82d4c5e | Michael Hanselmann | assert isinstance(console, dict) |
1373 | b82d4c5e | Michael Hanselmann | return console
|
1374 | b82d4c5e | Michael Hanselmann | |
1375 | b82d4c5e | Michael Hanselmann | |
1376 | 208a6cff | Michael Hanselmann | def _GetQueryFields(args): |
1377 | 2a38e913 | Michael Hanselmann | """Tries to extract C{fields} query parameter.
|
1378 | 2a38e913 | Michael Hanselmann |
|
1379 | 2a38e913 | Michael Hanselmann | @type args: dictionary
|
1380 | 2a38e913 | Michael Hanselmann | @rtype: list of string
|
1381 | 2a38e913 | Michael Hanselmann | @raise http.HttpBadRequest: When parameter can't be found
|
1382 | 208a6cff | Michael Hanselmann |
|
1383 | 208a6cff | Michael Hanselmann | """
|
1384 | 208a6cff | Michael Hanselmann | try:
|
1385 | 208a6cff | Michael Hanselmann | fields = args["fields"]
|
1386 | 208a6cff | Michael Hanselmann | except KeyError: |
1387 | 208a6cff | Michael Hanselmann | raise http.HttpBadRequest("Missing 'fields' query argument") |
1388 | 208a6cff | Michael Hanselmann | |
1389 | 208a6cff | Michael Hanselmann | return _SplitQueryFields(fields[0]) |
1390 | 208a6cff | Michael Hanselmann | |
1391 | 208a6cff | Michael Hanselmann | |
1392 | 208a6cff | Michael Hanselmann | def _SplitQueryFields(fields): |
1393 | 2a38e913 | Michael Hanselmann | """Splits fields as given for a query request.
|
1394 | 2a38e913 | Michael Hanselmann |
|
1395 | 2a38e913 | Michael Hanselmann | @type fields: string
|
1396 | 2a38e913 | Michael Hanselmann | @rtype: list of string
|
1397 | 208a6cff | Michael Hanselmann |
|
1398 | 208a6cff | Michael Hanselmann | """
|
1399 | 208a6cff | Michael Hanselmann | return [i.strip() for i in fields.split(",")] |
1400 | 208a6cff | Michael Hanselmann | |
1401 | 208a6cff | Michael Hanselmann | |
1402 | 26ff6ee2 | Michael Hanselmann | class R_2_query(baserlib.ResourceBase): |
1403 | 208a6cff | Michael Hanselmann | """/2/query/[resource] resource.
|
1404 | 208a6cff | Michael Hanselmann |
|
1405 | 208a6cff | Michael Hanselmann | """
|
1406 | 208a6cff | Michael Hanselmann | # Results might contain sensitive information
|
1407 | 5e12acfe | Michael Hanselmann | GET_ACCESS = [rapi.RAPI_ACCESS_WRITE, rapi.RAPI_ACCESS_READ] |
1408 | 5e12acfe | Michael Hanselmann | PUT_ACCESS = GET_ACCESS |
1409 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpQuery |
1410 | f6ce0ba2 | Michael Hanselmann | PUT_OPCODE = opcodes.OpQuery |
1411 | 208a6cff | Michael Hanselmann | |
1412 | 2e5c33db | Iustin Pop | def _Query(self, fields, qfilter): |
1413 | 2e5c33db | Iustin Pop | return self.GetClient().Query(self.items[0], fields, qfilter).ToDict() |
1414 | 208a6cff | Michael Hanselmann | |
1415 | 208a6cff | Michael Hanselmann | def GET(self): |
1416 | 208a6cff | Michael Hanselmann | """Returns resource information.
|
1417 | 208a6cff | Michael Hanselmann |
|
1418 | 208a6cff | Michael Hanselmann | @return: Query result, see L{objects.QueryResponse}
|
1419 | 208a6cff | Michael Hanselmann |
|
1420 | 208a6cff | Michael Hanselmann | """
|
1421 | 208a6cff | Michael Hanselmann | return self._Query(_GetQueryFields(self.queryargs), None) |
1422 | 208a6cff | Michael Hanselmann | |
1423 | 208a6cff | Michael Hanselmann | def PUT(self): |
1424 | 208a6cff | Michael Hanselmann | """Submits job querying for resources.
|
1425 | 208a6cff | Michael Hanselmann |
|
1426 | 208a6cff | Michael Hanselmann | @return: Query result, see L{objects.QueryResponse}
|
1427 | 208a6cff | Michael Hanselmann |
|
1428 | 208a6cff | Michael Hanselmann | """
|
1429 | 208a6cff | Michael Hanselmann | body = self.request_body
|
1430 | 208a6cff | Michael Hanselmann | |
1431 | 208a6cff | Michael Hanselmann | baserlib.CheckType(body, dict, "Body contents") |
1432 | 208a6cff | Michael Hanselmann | |
1433 | 208a6cff | Michael Hanselmann | try:
|
1434 | 208a6cff | Michael Hanselmann | fields = body["fields"]
|
1435 | 208a6cff | Michael Hanselmann | except KeyError: |
1436 | 208a6cff | Michael Hanselmann | fields = _GetQueryFields(self.queryargs)
|
1437 | 208a6cff | Michael Hanselmann | |
1438 | 2e5c33db | Iustin Pop | qfilter = body.get("qfilter", None) |
1439 | 2e5c33db | Iustin Pop | # TODO: remove this after 2.7
|
1440 | 2e5c33db | Iustin Pop | if qfilter is None: |
1441 | 2e5c33db | Iustin Pop | qfilter = body.get("filter", None) |
1442 | 2e5c33db | Iustin Pop | |
1443 | 2e5c33db | Iustin Pop | return self._Query(fields, qfilter) |
1444 | 208a6cff | Michael Hanselmann | |
1445 | 208a6cff | Michael Hanselmann | |
1446 | 26ff6ee2 | Michael Hanselmann | class R_2_query_fields(baserlib.ResourceBase): |
1447 | 208a6cff | Michael Hanselmann | """/2/query/[resource]/fields resource.
|
1448 | 208a6cff | Michael Hanselmann |
|
1449 | 208a6cff | Michael Hanselmann | """
|
1450 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpQueryFields |
1451 | f6ce0ba2 | Michael Hanselmann | |
1452 | 208a6cff | Michael Hanselmann | def GET(self): |
1453 | 208a6cff | Michael Hanselmann | """Retrieves list of available fields for a resource.
|
1454 | 208a6cff | Michael Hanselmann |
|
1455 | 208a6cff | Michael Hanselmann | @return: List of serialized L{objects.QueryFieldDefinition}
|
1456 | 208a6cff | Michael Hanselmann |
|
1457 | 208a6cff | Michael Hanselmann | """
|
1458 | 208a6cff | Michael Hanselmann | try:
|
1459 | 208a6cff | Michael Hanselmann | raw_fields = self.queryargs["fields"] |
1460 | 208a6cff | Michael Hanselmann | except KeyError: |
1461 | 208a6cff | Michael Hanselmann | fields = None
|
1462 | 208a6cff | Michael Hanselmann | else:
|
1463 | 208a6cff | Michael Hanselmann | fields = _SplitQueryFields(raw_fields[0])
|
1464 | 208a6cff | Michael Hanselmann | |
1465 | be1ddd09 | Michael Hanselmann | return self.GetClient().QueryFields(self.items[0], fields).ToDict() |
1466 | 208a6cff | Michael Hanselmann | |
1467 | 208a6cff | Michael Hanselmann | |
1468 | 460ef073 | Michael Hanselmann | class _R_Tags(baserlib.OpcodeResource): |
1469 | 3bd0f3d8 | Iustin Pop | """Quasiclass for tagging resources.
|
1470 | 441e7cfd | Oleksiy Mishchenko |
|
1471 | c8e0a534 | Iustin Pop | Manages tags. When inheriting this class you must define the
|
1472 | 18cb43a2 | Oleksiy Mishchenko | TAG_LEVEL for it.
|
1473 | 441e7cfd | Oleksiy Mishchenko |
|
1474 | 441e7cfd | Oleksiy Mishchenko | """
|
1475 | 7a6b9510 | Iustin Pop | TAG_LEVEL = None
|
1476 | f6ce0ba2 | Michael Hanselmann | GET_OPCODE = opcodes.OpTagsGet |
1477 | 460ef073 | Michael Hanselmann | PUT_OPCODE = opcodes.OpTagsSet |
1478 | 460ef073 | Michael Hanselmann | DELETE_OPCODE = opcodes.OpTagsDel |
1479 | 18cb43a2 | Oleksiy Mishchenko | |
1480 | 460ef073 | Michael Hanselmann | def __init__(self, items, queryargs, req, **kwargs): |
1481 | 18cb43a2 | Oleksiy Mishchenko | """A tag resource constructor.
|
1482 | 18cb43a2 | Oleksiy Mishchenko |
|
1483 | 18cb43a2 | Oleksiy Mishchenko | We have to override the default to sort out cluster naming case.
|
1484 | 18cb43a2 | Oleksiy Mishchenko |
|
1485 | 18cb43a2 | Oleksiy Mishchenko | """
|
1486 | 460ef073 | Michael Hanselmann | baserlib.OpcodeResource.__init__(self, items, queryargs, req, **kwargs)
|
1487 | 18cb43a2 | Oleksiy Mishchenko | |
1488 | 5313eed7 | Michael Hanselmann | if self.TAG_LEVEL == constants.TAG_CLUSTER: |
1489 | 5313eed7 | Michael Hanselmann | self.name = None |
1490 | 18cb43a2 | Oleksiy Mishchenko | else:
|
1491 | 5313eed7 | Michael Hanselmann | self.name = items[0] |
1492 | 441e7cfd | Oleksiy Mishchenko | |
1493 | 441e7cfd | Oleksiy Mishchenko | def GET(self): |
1494 | 18cb43a2 | Oleksiy Mishchenko | """Returns a list of tags.
|
1495 | 441e7cfd | Oleksiy Mishchenko |
|
1496 | 441e7cfd | Oleksiy Mishchenko | Example: ["tag1", "tag2", "tag3"]
|
1497 | 441e7cfd | Oleksiy Mishchenko |
|
1498 | 441e7cfd | Oleksiy Mishchenko | """
|
1499 | f87ec53f | Michael Hanselmann | kind = self.TAG_LEVEL
|
1500 | f87ec53f | Michael Hanselmann | |
1501 | f87ec53f | Michael Hanselmann | if kind in (constants.TAG_INSTANCE, |
1502 | f87ec53f | Michael Hanselmann | constants.TAG_NODEGROUP, |
1503 | f87ec53f | Michael Hanselmann | constants.TAG_NODE): |
1504 | f87ec53f | Michael Hanselmann | if not self.name: |
1505 | f87ec53f | Michael Hanselmann | raise http.HttpBadRequest("Missing name on tag request") |
1506 | f87ec53f | Michael Hanselmann | |
1507 | f2374060 | Iustin Pop | cl = self.GetClient(query=True) |
1508 | cebd85d8 | Iustin Pop | tags = list(cl.QueryTags(kind, self.name)) |
1509 | f87ec53f | Michael Hanselmann | |
1510 | f87ec53f | Michael Hanselmann | elif kind == constants.TAG_CLUSTER:
|
1511 | f87ec53f | Michael Hanselmann | assert not self.name |
1512 | f87ec53f | Michael Hanselmann | # TODO: Use query API?
|
1513 | f87ec53f | Michael Hanselmann | ssc = ssconf.SimpleStore() |
1514 | f87ec53f | Michael Hanselmann | tags = ssc.GetClusterTags() |
1515 | f87ec53f | Michael Hanselmann | |
1516 | f87ec53f | Michael Hanselmann | return list(tags) |
1517 | 441e7cfd | Oleksiy Mishchenko | |
1518 | 460ef073 | Michael Hanselmann | def GetPutOpInput(self): |
1519 | 18cb43a2 | Oleksiy Mishchenko | """Add a set of tags.
|
1520 | 441e7cfd | Oleksiy Mishchenko |
|
1521 | c41eea6e | Iustin Pop | The request as a list of strings should be PUT to this URI. And
|
1522 | c41eea6e | Iustin Pop | you'll have back a job id.
|
1523 | 441e7cfd | Oleksiy Mishchenko |
|
1524 | 441e7cfd | Oleksiy Mishchenko | """
|
1525 | 460ef073 | Michael Hanselmann | return ({}, {
|
1526 | 460ef073 | Michael Hanselmann | "kind": self.TAG_LEVEL, |
1527 | 460ef073 | Michael Hanselmann | "name": self.name, |
1528 | 460ef073 | Michael Hanselmann | "tags": self.queryargs.get("tag", []), |
1529 | 460ef073 | Michael Hanselmann | "dry_run": self.dryRun(), |
1530 | 460ef073 | Michael Hanselmann | }) |
1531 | 15fd9fd5 | Oleksiy Mishchenko | |
1532 | 460ef073 | Michael Hanselmann | def GetDeleteOpInput(self): |
1533 | 15fd9fd5 | Oleksiy Mishchenko | """Delete a tag.
|
1534 | 15fd9fd5 | Oleksiy Mishchenko |
|
1535 | 18cb43a2 | Oleksiy Mishchenko | In order to delete a set of tags, the DELETE
|
1536 | c41eea6e | Iustin Pop | request should be addressed to URI like:
|
1537 | 18cb43a2 | Oleksiy Mishchenko | /tags?tag=[tag]&tag=[tag]
|
1538 | 15fd9fd5 | Oleksiy Mishchenko |
|
1539 | 15fd9fd5 | Oleksiy Mishchenko | """
|
1540 | 460ef073 | Michael Hanselmann | # Re-use code
|
1541 | 460ef073 | Michael Hanselmann | return self.GetPutOpInput() |
1542 | 18cb43a2 | Oleksiy Mishchenko | |
1543 | 18cb43a2 | Oleksiy Mishchenko | |
1544 | 18cb43a2 | Oleksiy Mishchenko | class R_2_instances_name_tags(_R_Tags): |
1545 | 18cb43a2 | Oleksiy Mishchenko | """ /2/instances/[instance_name]/tags resource.
|
1546 | 18cb43a2 | Oleksiy Mishchenko |
|
1547 | 18cb43a2 | Oleksiy Mishchenko | Manages per-instance tags.
|
1548 | 18cb43a2 | Oleksiy Mishchenko |
|
1549 | 18cb43a2 | Oleksiy Mishchenko | """
|
1550 | 18cb43a2 | Oleksiy Mishchenko | TAG_LEVEL = constants.TAG_INSTANCE |
1551 | 18cb43a2 | Oleksiy Mishchenko | |
1552 | 18cb43a2 | Oleksiy Mishchenko | |
1553 | 18cb43a2 | Oleksiy Mishchenko | class R_2_nodes_name_tags(_R_Tags): |
1554 | 18cb43a2 | Oleksiy Mishchenko | """ /2/nodes/[node_name]/tags resource.
|
1555 | 18cb43a2 | Oleksiy Mishchenko |
|
1556 | 18cb43a2 | Oleksiy Mishchenko | Manages per-node tags.
|
1557 | 18cb43a2 | Oleksiy Mishchenko |
|
1558 | 18cb43a2 | Oleksiy Mishchenko | """
|
1559 | 18cb43a2 | Oleksiy Mishchenko | TAG_LEVEL = constants.TAG_NODE |
1560 | 18cb43a2 | Oleksiy Mishchenko | |
1561 | 18cb43a2 | Oleksiy Mishchenko | |
1562 | 414ebaf1 | Michael Hanselmann | class R_2_groups_name_tags(_R_Tags): |
1563 | 414ebaf1 | Michael Hanselmann | """ /2/groups/[group_name]/tags resource.
|
1564 | 414ebaf1 | Michael Hanselmann |
|
1565 | 414ebaf1 | Michael Hanselmann | Manages per-nodegroup tags.
|
1566 | 414ebaf1 | Michael Hanselmann |
|
1567 | 414ebaf1 | Michael Hanselmann | """
|
1568 | 414ebaf1 | Michael Hanselmann | TAG_LEVEL = constants.TAG_NODEGROUP |
1569 | 414ebaf1 | Michael Hanselmann | |
1570 | 3c286190 | Dimitris Aragiorgis | |
1571 | 6e8091f9 | Dimitris Aragiorgis | class R_2_networks_name_tags(_R_Tags): |
1572 | 6e8091f9 | Dimitris Aragiorgis | """ /2/networks/[network_name]/tags resource.
|
1573 | 6e8091f9 | Dimitris Aragiorgis |
|
1574 | 6e8091f9 | Dimitris Aragiorgis | Manages per-network tags.
|
1575 | 6e8091f9 | Dimitris Aragiorgis |
|
1576 | 6e8091f9 | Dimitris Aragiorgis | """
|
1577 | 6e8091f9 | Dimitris Aragiorgis | TAG_LEVEL = constants.TAG_NETWORK |
1578 | 6e8091f9 | Dimitris Aragiorgis | |
1579 | 414ebaf1 | Michael Hanselmann | |
1580 | 18cb43a2 | Oleksiy Mishchenko | class R_2_tags(_R_Tags): |
1581 | b58a4d16 | Michael Hanselmann | """ /2/tags resource.
|
1582 | 18cb43a2 | Oleksiy Mishchenko |
|
1583 | 18cb43a2 | Oleksiy Mishchenko | Manages cluster tags.
|
1584 | 18cb43a2 | Oleksiy Mishchenko |
|
1585 | 18cb43a2 | Oleksiy Mishchenko | """
|
1586 | 18cb43a2 | Oleksiy Mishchenko | TAG_LEVEL = constants.TAG_CLUSTER |