root / daemons / ganeti-noded @ ab221ddf
History | View | Annotate | Download (22.1 kB)
1 | a8083063 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | a8083063 | Iustin Pop | # |
3 | a8083063 | Iustin Pop | |
4 | a8083063 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc. |
5 | a8083063 | Iustin Pop | # |
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify |
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by |
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or |
9 | a8083063 | Iustin Pop | # (at your option) any later version. |
10 | a8083063 | Iustin Pop | # |
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but |
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | a8083063 | Iustin Pop | # General Public License for more details. |
15 | a8083063 | Iustin Pop | # |
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License |
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software |
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | a8083063 | Iustin Pop | # 02110-1301, USA. |
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | """Ganeti node daemon""" |
23 | a8083063 | Iustin Pop | |
24 | 7260cfbe | Iustin Pop | # pylint: disable-msg=C0103,W0142 |
25 | 7260cfbe | Iustin Pop | |
26 | 7260cfbe | Iustin Pop | # C0103: Functions in this module need to have a given name structure, |
27 | 7260cfbe | Iustin Pop | # and the name of the daemon doesn't match |
28 | 7260cfbe | Iustin Pop | |
29 | 7260cfbe | Iustin Pop | # W0142: Used * or ** magic, since we do use it extensively in this |
30 | 7260cfbe | Iustin Pop | # module |
31 | 3ecf6786 | Iustin Pop | |
32 | a8083063 | Iustin Pop | import os |
33 | a8083063 | Iustin Pop | import sys |
34 | c89189b1 | Iustin Pop | import logging |
35 | 84b58db2 | Michael Hanselmann | import signal |
36 | a8083063 | Iustin Pop | |
37 | a8083063 | Iustin Pop | from optparse import OptionParser |
38 | a8083063 | Iustin Pop | |
39 | a8083063 | Iustin Pop | from ganeti import backend |
40 | a8083063 | Iustin Pop | from ganeti import constants |
41 | a8083063 | Iustin Pop | from ganeti import objects |
42 | a8083063 | Iustin Pop | from ganeti import errors |
43 | 25d6d12a | Michael Hanselmann | from ganeti import jstore |
44 | cc28af80 | Michael Hanselmann | from ganeti import daemon |
45 | 1df6506c | Michael Hanselmann | from ganeti import http |
46 | 16abfbc2 | Alexander Schreiber | from ganeti import utils |
47 | e337de97 | Michael Hanselmann | from ganeti import storage |
48 | ab221ddf | Michael Hanselmann | from ganeti import serializer |
49 | a8083063 | Iustin Pop | |
50 | 30e4e741 | Iustin Pop | import ganeti.http.server # pylint: disable-msg=W0611 |
51 | 19205c39 | Michael Hanselmann | |
52 | a8083063 | Iustin Pop | |
53 | 25d6d12a | Michael Hanselmann | queue_lock = None |
54 | 25d6d12a | Michael Hanselmann | |
55 | 25d6d12a | Michael Hanselmann | |
56 | 7f30777b | Michael Hanselmann | def _RequireJobQueueLock(fn): |
57 | 7f30777b | Michael Hanselmann | """Decorator for job queue manipulating functions. |
58 | 7f30777b | Michael Hanselmann | |
59 | 7f30777b | Michael Hanselmann | """ |
60 | 8785cb30 | Michael Hanselmann | QUEUE_LOCK_TIMEOUT = 10 |
61 | 8785cb30 | Michael Hanselmann | |
62 | 7f30777b | Michael Hanselmann | def wrapper(*args, **kwargs): |
63 | 7f30777b | Michael Hanselmann | # Locking in exclusive, blocking mode because there could be several |
64 | 506cff12 | Michael Hanselmann | # children running at the same time. Waiting up to 10 seconds. |
65 | 8785cb30 | Michael Hanselmann | queue_lock.Exclusive(blocking=True, timeout=QUEUE_LOCK_TIMEOUT) |
66 | 7f30777b | Michael Hanselmann | try: |
67 | 7f30777b | Michael Hanselmann | return fn(*args, **kwargs) |
68 | 7f30777b | Michael Hanselmann | finally: |
69 | 7f30777b | Michael Hanselmann | queue_lock.Unlock() |
70 | 8785cb30 | Michael Hanselmann | |
71 | 7f30777b | Michael Hanselmann | return wrapper |
72 | 7f30777b | Michael Hanselmann | |
73 | 7f30777b | Michael Hanselmann | |
74 | 19205c39 | Michael Hanselmann | class NodeHttpServer(http.server.HttpServer): |
75 | 3ecf6786 | Iustin Pop | """The server implementation. |
76 | 3ecf6786 | Iustin Pop | |
77 | 3ecf6786 | Iustin Pop | This class holds all methods exposed over the RPC interface. |
78 | 3ecf6786 | Iustin Pop | |
79 | 3ecf6786 | Iustin Pop | """ |
80 | 2d54e29c | Iustin Pop | # too many public methods, and unused args - all methods get params |
81 | 2d54e29c | Iustin Pop | # due to the API |
82 | 2d54e29c | Iustin Pop | # pylint: disable-msg=R0904,W0613 |
83 | cc28af80 | Michael Hanselmann | def __init__(self, *args, **kwargs): |
84 | 19205c39 | Michael Hanselmann | http.server.HttpServer.__init__(self, *args, **kwargs) |
85 | cc28af80 | Michael Hanselmann | self.noded_pid = os.getpid() |
86 | cc28af80 | Michael Hanselmann | |
87 | cc28af80 | Michael Hanselmann | def HandleRequest(self, req): |
88 | 1df6506c | Michael Hanselmann | """Handle a request. |
89 | a8083063 | Iustin Pop | |
90 | 098c0958 | Michael Hanselmann | """ |
91 | 19205c39 | Michael Hanselmann | if req.request_method.upper() != http.HTTP_PUT: |
92 | 84f2756e | Michael Hanselmann | raise http.HttpBadRequest() |
93 | 1df6506c | Michael Hanselmann | |
94 | cc28af80 | Michael Hanselmann | path = req.request_path |
95 | 81010134 | Iustin Pop | if path.startswith("/"): |
96 | 81010134 | Iustin Pop | path = path[1:] |
97 | 81010134 | Iustin Pop | |
98 | 1df6506c | Michael Hanselmann | method = getattr(self, "perspective_%s" % path, None) |
99 | 1df6506c | Michael Hanselmann | if method is None: |
100 | 84f2756e | Michael Hanselmann | raise http.HttpNotFound() |
101 | a8083063 | Iustin Pop | |
102 | 81010134 | Iustin Pop | try: |
103 | ab221ddf | Michael Hanselmann | result = (True, method(serializer.LoadJson(req.request_body))) |
104 | 4dd42c9d | Iustin Pop | |
105 | 0623d351 | Iustin Pop | except backend.RPCFail, err: |
106 | 0623d351 | Iustin Pop | # our custom failure exception; str(err) works fine if the |
107 | 0623d351 | Iustin Pop | # exception was constructed with a single argument, and in |
108 | 0623d351 | Iustin Pop | # this case, err.message == err.args[0] == str(err) |
109 | ab221ddf | Michael Hanselmann | result = (False, str(err)) |
110 | 9ae49f27 | Guido Trotter | except errors.QuitGanetiException, err: |
111 | 84b58db2 | Michael Hanselmann | # Tell parent to quit |
112 | 0623d351 | Iustin Pop | logging.info("Shutting down the node daemon, arguments: %s", |
113 | 0623d351 | Iustin Pop | str(err.args)) |
114 | cc28af80 | Michael Hanselmann | os.kill(self.noded_pid, signal.SIGTERM) |
115 | 0623d351 | Iustin Pop | # And return the error's arguments, which must be already in |
116 | 0623d351 | Iustin Pop | # correct tuple format |
117 | ab221ddf | Michael Hanselmann | result = err.args |
118 | 4dd42c9d | Iustin Pop | except Exception, err: |
119 | 0623d351 | Iustin Pop | logging.exception("Error in RPC call") |
120 | ab221ddf | Michael Hanselmann | result = (False, "Error while executing backend function: %s" % str(err)) |
121 | ab221ddf | Michael Hanselmann | |
122 | ab221ddf | Michael Hanselmann | return serializer.DumpJson(result, indent=False) |
123 | a8083063 | Iustin Pop | |
124 | a8083063 | Iustin Pop | # the new block devices -------------------------- |
125 | a8083063 | Iustin Pop | |
126 | 3ecf6786 | Iustin Pop | @staticmethod |
127 | 3ecf6786 | Iustin Pop | def perspective_blockdev_create(params): |
128 | 3ecf6786 | Iustin Pop | """Create a block device. |
129 | 3ecf6786 | Iustin Pop | |
130 | 3ecf6786 | Iustin Pop | """ |
131 | 3f78eef2 | Iustin Pop | bdev_s, size, owner, on_primary, info = params |
132 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
133 | a8083063 | Iustin Pop | if bdev is None: |
134 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
135 | 821d1bd1 | Iustin Pop | return backend.BlockdevCreate(bdev, size, owner, on_primary, info) |
136 | a8083063 | Iustin Pop | |
137 | 3ecf6786 | Iustin Pop | @staticmethod |
138 | 3ecf6786 | Iustin Pop | def perspective_blockdev_remove(params): |
139 | 3ecf6786 | Iustin Pop | """Remove a block device. |
140 | 3ecf6786 | Iustin Pop | |
141 | 3ecf6786 | Iustin Pop | """ |
142 | a8083063 | Iustin Pop | bdev_s = params[0] |
143 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
144 | 821d1bd1 | Iustin Pop | return backend.BlockdevRemove(bdev) |
145 | a8083063 | Iustin Pop | |
146 | 3ecf6786 | Iustin Pop | @staticmethod |
147 | f3e513ad | Iustin Pop | def perspective_blockdev_rename(params): |
148 | f3e513ad | Iustin Pop | """Remove a block device. |
149 | f3e513ad | Iustin Pop | |
150 | f3e513ad | Iustin Pop | """ |
151 | f3e513ad | Iustin Pop | devlist = [(objects.Disk.FromDict(ds), uid) for ds, uid in params] |
152 | 821d1bd1 | Iustin Pop | return backend.BlockdevRename(devlist) |
153 | f3e513ad | Iustin Pop | |
154 | f3e513ad | Iustin Pop | @staticmethod |
155 | 3ecf6786 | Iustin Pop | def perspective_blockdev_assemble(params): |
156 | 3ecf6786 | Iustin Pop | """Assemble a block device. |
157 | 3ecf6786 | Iustin Pop | |
158 | 3ecf6786 | Iustin Pop | """ |
159 | 3f78eef2 | Iustin Pop | bdev_s, owner, on_primary = params |
160 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
161 | a8083063 | Iustin Pop | if bdev is None: |
162 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
163 | 821d1bd1 | Iustin Pop | return backend.BlockdevAssemble(bdev, owner, on_primary) |
164 | a8083063 | Iustin Pop | |
165 | 3ecf6786 | Iustin Pop | @staticmethod |
166 | 3ecf6786 | Iustin Pop | def perspective_blockdev_shutdown(params): |
167 | 3ecf6786 | Iustin Pop | """Shutdown a block device. |
168 | 3ecf6786 | Iustin Pop | |
169 | 3ecf6786 | Iustin Pop | """ |
170 | a8083063 | Iustin Pop | bdev_s = params[0] |
171 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
172 | a8083063 | Iustin Pop | if bdev is None: |
173 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
174 | 821d1bd1 | Iustin Pop | return backend.BlockdevShutdown(bdev) |
175 | a8083063 | Iustin Pop | |
176 | 3ecf6786 | Iustin Pop | @staticmethod |
177 | 153d9724 | Iustin Pop | def perspective_blockdev_addchildren(params): |
178 | 3ecf6786 | Iustin Pop | """Add a child to a mirror device. |
179 | 3ecf6786 | Iustin Pop | |
180 | 3ecf6786 | Iustin Pop | Note: this is only valid for mirror devices. It's the caller's duty |
181 | 3ecf6786 | Iustin Pop | to send a correct disk, otherwise we raise an error. |
182 | 3ecf6786 | Iustin Pop | |
183 | 3ecf6786 | Iustin Pop | """ |
184 | a8083063 | Iustin Pop | bdev_s, ndev_s = params |
185 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
186 | 153d9724 | Iustin Pop | ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s] |
187 | 153d9724 | Iustin Pop | if bdev is None or ndevs.count(None) > 0: |
188 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
189 | 821d1bd1 | Iustin Pop | return backend.BlockdevAddchildren(bdev, ndevs) |
190 | a8083063 | Iustin Pop | |
191 | 3ecf6786 | Iustin Pop | @staticmethod |
192 | 153d9724 | Iustin Pop | def perspective_blockdev_removechildren(params): |
193 | 3ecf6786 | Iustin Pop | """Remove a child from a mirror device. |
194 | 3ecf6786 | Iustin Pop | |
195 | 3ecf6786 | Iustin Pop | This is only valid for mirror devices, of course. It's the callers |
196 | 3ecf6786 | Iustin Pop | duty to send a correct disk, otherwise we raise an error. |
197 | 3ecf6786 | Iustin Pop | |
198 | 3ecf6786 | Iustin Pop | """ |
199 | a8083063 | Iustin Pop | bdev_s, ndev_s = params |
200 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
201 | 153d9724 | Iustin Pop | ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s] |
202 | 153d9724 | Iustin Pop | if bdev is None or ndevs.count(None) > 0: |
203 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
204 | 821d1bd1 | Iustin Pop | return backend.BlockdevRemovechildren(bdev, ndevs) |
205 | a8083063 | Iustin Pop | |
206 | 3ecf6786 | Iustin Pop | @staticmethod |
207 | 3ecf6786 | Iustin Pop | def perspective_blockdev_getmirrorstatus(params): |
208 | 3ecf6786 | Iustin Pop | """Return the mirror status for a list of disks. |
209 | 3ecf6786 | Iustin Pop | |
210 | 3ecf6786 | Iustin Pop | """ |
211 | 319856a9 | Michael Hanselmann | disks = [objects.Disk.FromDict(dsk_s) |
212 | 36145b12 | Michael Hanselmann | for dsk_s in params] |
213 | 36145b12 | Michael Hanselmann | return [status.ToDict() |
214 | 36145b12 | Michael Hanselmann | for status in backend.BlockdevGetmirrorstatus(disks)] |
215 | a8083063 | Iustin Pop | |
216 | 3ecf6786 | Iustin Pop | @staticmethod |
217 | 3ecf6786 | Iustin Pop | def perspective_blockdev_find(params): |
218 | 3ecf6786 | Iustin Pop | """Expose the FindBlockDevice functionality for a disk. |
219 | 3ecf6786 | Iustin Pop | |
220 | 3ecf6786 | Iustin Pop | This will try to find but not activate a disk. |
221 | 3ecf6786 | Iustin Pop | |
222 | 3ecf6786 | Iustin Pop | """ |
223 | 319856a9 | Michael Hanselmann | disk = objects.Disk.FromDict(params[0]) |
224 | ddfe2228 | Michael Hanselmann | |
225 | ddfe2228 | Michael Hanselmann | result = backend.BlockdevFind(disk) |
226 | ddfe2228 | Michael Hanselmann | if result is None: |
227 | ddfe2228 | Michael Hanselmann | return None |
228 | ddfe2228 | Michael Hanselmann | |
229 | ddfe2228 | Michael Hanselmann | return result.ToDict() |
230 | a8083063 | Iustin Pop | |
231 | 3ecf6786 | Iustin Pop | @staticmethod |
232 | 3ecf6786 | Iustin Pop | def perspective_blockdev_snapshot(params): |
233 | 3ecf6786 | Iustin Pop | """Create a snapshot device. |
234 | 3ecf6786 | Iustin Pop | |
235 | 3ecf6786 | Iustin Pop | Note that this is only valid for LVM disks, if we get passed |
236 | 3ecf6786 | Iustin Pop | something else we raise an exception. The snapshot device can be |
237 | 3ecf6786 | Iustin Pop | remove by calling the generic block device remove call. |
238 | 3ecf6786 | Iustin Pop | |
239 | 3ecf6786 | Iustin Pop | """ |
240 | 319856a9 | Michael Hanselmann | cfbd = objects.Disk.FromDict(params[0]) |
241 | 821d1bd1 | Iustin Pop | return backend.BlockdevSnapshot(cfbd) |
242 | a8083063 | Iustin Pop | |
243 | 4c8ba8b3 | Iustin Pop | @staticmethod |
244 | 4c8ba8b3 | Iustin Pop | def perspective_blockdev_grow(params): |
245 | 4c8ba8b3 | Iustin Pop | """Grow a stack of devices. |
246 | 4c8ba8b3 | Iustin Pop | |
247 | 4c8ba8b3 | Iustin Pop | """ |
248 | 4c8ba8b3 | Iustin Pop | cfbd = objects.Disk.FromDict(params[0]) |
249 | 4c8ba8b3 | Iustin Pop | amount = params[1] |
250 | 821d1bd1 | Iustin Pop | return backend.BlockdevGrow(cfbd, amount) |
251 | 4c8ba8b3 | Iustin Pop | |
252 | d61cbe76 | Iustin Pop | @staticmethod |
253 | d61cbe76 | Iustin Pop | def perspective_blockdev_close(params): |
254 | d61cbe76 | Iustin Pop | """Closes the given block devices. |
255 | d61cbe76 | Iustin Pop | |
256 | d61cbe76 | Iustin Pop | """ |
257 | b2e7666a | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in params[1]] |
258 | 821d1bd1 | Iustin Pop | return backend.BlockdevClose(params[0], disks) |
259 | d61cbe76 | Iustin Pop | |
260 | 968a7623 | Iustin Pop | @staticmethod |
261 | 968a7623 | Iustin Pop | def perspective_blockdev_getsize(params): |
262 | 968a7623 | Iustin Pop | """Compute the sizes of the given block devices. |
263 | 968a7623 | Iustin Pop | |
264 | 968a7623 | Iustin Pop | """ |
265 | 968a7623 | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in params[0]] |
266 | 968a7623 | Iustin Pop | return backend.BlockdevGetsize(disks) |
267 | 968a7623 | Iustin Pop | |
268 | 858f3d18 | Iustin Pop | @staticmethod |
269 | 858f3d18 | Iustin Pop | def perspective_blockdev_export(params): |
270 | 858f3d18 | Iustin Pop | """Compute the sizes of the given block devices. |
271 | 858f3d18 | Iustin Pop | |
272 | 858f3d18 | Iustin Pop | """ |
273 | 858f3d18 | Iustin Pop | disk = objects.Disk.FromDict(params[0]) |
274 | 858f3d18 | Iustin Pop | dest_node, dest_path, cluster_name = params[1:] |
275 | 858f3d18 | Iustin Pop | return backend.BlockdevExport(disk, dest_node, dest_path, cluster_name) |
276 | 858f3d18 | Iustin Pop | |
277 | 6b93ec9d | Iustin Pop | # blockdev/drbd specific methods ---------- |
278 | 6b93ec9d | Iustin Pop | |
279 | 6b93ec9d | Iustin Pop | @staticmethod |
280 | 6b93ec9d | Iustin Pop | def perspective_drbd_disconnect_net(params): |
281 | 6b93ec9d | Iustin Pop | """Disconnects the network connection of drbd disks. |
282 | 6b93ec9d | Iustin Pop | |
283 | 6b93ec9d | Iustin Pop | Note that this is only valid for drbd disks, so the members of the |
284 | 6b93ec9d | Iustin Pop | disk list must all be drbd devices. |
285 | 6b93ec9d | Iustin Pop | |
286 | 6b93ec9d | Iustin Pop | """ |
287 | 6b93ec9d | Iustin Pop | nodes_ip, disks = params |
288 | 6b93ec9d | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in disks] |
289 | 6b93ec9d | Iustin Pop | return backend.DrbdDisconnectNet(nodes_ip, disks) |
290 | 6b93ec9d | Iustin Pop | |
291 | 6b93ec9d | Iustin Pop | @staticmethod |
292 | 6b93ec9d | Iustin Pop | def perspective_drbd_attach_net(params): |
293 | 6b93ec9d | Iustin Pop | """Attaches the network connection of drbd disks. |
294 | 6b93ec9d | Iustin Pop | |
295 | 6b93ec9d | Iustin Pop | Note that this is only valid for drbd disks, so the members of the |
296 | 6b93ec9d | Iustin Pop | disk list must all be drbd devices. |
297 | 6b93ec9d | Iustin Pop | |
298 | 6b93ec9d | Iustin Pop | """ |
299 | 6b93ec9d | Iustin Pop | nodes_ip, disks, instance_name, multimaster = params |
300 | 6b93ec9d | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in disks] |
301 | 821d1bd1 | Iustin Pop | return backend.DrbdAttachNet(nodes_ip, disks, |
302 | 821d1bd1 | Iustin Pop | instance_name, multimaster) |
303 | 6b93ec9d | Iustin Pop | |
304 | 6b93ec9d | Iustin Pop | @staticmethod |
305 | 6b93ec9d | Iustin Pop | def perspective_drbd_wait_sync(params): |
306 | 6b93ec9d | Iustin Pop | """Wait until DRBD disks are synched. |
307 | 6b93ec9d | Iustin Pop | |
308 | 6b93ec9d | Iustin Pop | Note that this is only valid for drbd disks, so the members of the |
309 | 6b93ec9d | Iustin Pop | disk list must all be drbd devices. |
310 | 6b93ec9d | Iustin Pop | |
311 | 6b93ec9d | Iustin Pop | """ |
312 | 6b93ec9d | Iustin Pop | nodes_ip, disks = params |
313 | 6b93ec9d | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in disks] |
314 | 6b93ec9d | Iustin Pop | return backend.DrbdWaitSync(nodes_ip, disks) |
315 | 6b93ec9d | Iustin Pop | |
316 | a8083063 | Iustin Pop | # export/import -------------------------- |
317 | a8083063 | Iustin Pop | |
318 | 3ecf6786 | Iustin Pop | @staticmethod |
319 | 3ecf6786 | Iustin Pop | def perspective_snapshot_export(params): |
320 | 3ecf6786 | Iustin Pop | """Export a given snapshot. |
321 | 3ecf6786 | Iustin Pop | |
322 | 3ecf6786 | Iustin Pop | """ |
323 | 319856a9 | Michael Hanselmann | disk = objects.Disk.FromDict(params[0]) |
324 | a8083063 | Iustin Pop | dest_node = params[1] |
325 | 319856a9 | Michael Hanselmann | instance = objects.Instance.FromDict(params[2]) |
326 | 62c9ec92 | Iustin Pop | cluster_name = params[3] |
327 | 74c47259 | Iustin Pop | dev_idx = params[4] |
328 | 74c47259 | Iustin Pop | return backend.ExportSnapshot(disk, dest_node, instance, |
329 | 74c47259 | Iustin Pop | cluster_name, dev_idx) |
330 | 3ecf6786 | Iustin Pop | |
331 | 3ecf6786 | Iustin Pop | @staticmethod |
332 | 3ecf6786 | Iustin Pop | def perspective_finalize_export(params): |
333 | 3ecf6786 | Iustin Pop | """Expose the finalize export functionality. |
334 | a8083063 | Iustin Pop | |
335 | 3ecf6786 | Iustin Pop | """ |
336 | 319856a9 | Michael Hanselmann | instance = objects.Instance.FromDict(params[0]) |
337 | 319856a9 | Michael Hanselmann | snap_disks = [objects.Disk.FromDict(str_data) |
338 | a8083063 | Iustin Pop | for str_data in params[1]] |
339 | a8083063 | Iustin Pop | return backend.FinalizeExport(instance, snap_disks) |
340 | a8083063 | Iustin Pop | |
341 | 3ecf6786 | Iustin Pop | @staticmethod |
342 | 3ecf6786 | Iustin Pop | def perspective_export_info(params): |
343 | 3ecf6786 | Iustin Pop | """Query information about an existing export on this node. |
344 | 3ecf6786 | Iustin Pop | |
345 | 3ecf6786 | Iustin Pop | The given path may not contain an export, in which case we return |
346 | 3ecf6786 | Iustin Pop | None. |
347 | 3ecf6786 | Iustin Pop | |
348 | 3ecf6786 | Iustin Pop | """ |
349 | 3ecf6786 | Iustin Pop | path = params[0] |
350 | 3eccac06 | Iustin Pop | return backend.ExportInfo(path) |
351 | a8083063 | Iustin Pop | |
352 | 3ecf6786 | Iustin Pop | @staticmethod |
353 | 3ecf6786 | Iustin Pop | def perspective_export_list(params): |
354 | 3ecf6786 | Iustin Pop | """List the available exports on this node. |
355 | 3ecf6786 | Iustin Pop | |
356 | 3ecf6786 | Iustin Pop | Note that as opposed to export_info, which may query data about an |
357 | 3ecf6786 | Iustin Pop | export in any path, this only queries the standard Ganeti path |
358 | 3ecf6786 | Iustin Pop | (constants.EXPORT_DIR). |
359 | 3ecf6786 | Iustin Pop | |
360 | 3ecf6786 | Iustin Pop | """ |
361 | a8083063 | Iustin Pop | return backend.ListExports() |
362 | a8083063 | Iustin Pop | |
363 | 3ecf6786 | Iustin Pop | @staticmethod |
364 | 3ecf6786 | Iustin Pop | def perspective_export_remove(params): |
365 | 3ecf6786 | Iustin Pop | """Remove an export. |
366 | 3ecf6786 | Iustin Pop | |
367 | 3ecf6786 | Iustin Pop | """ |
368 | a8083063 | Iustin Pop | export = params[0] |
369 | a8083063 | Iustin Pop | return backend.RemoveExport(export) |
370 | a8083063 | Iustin Pop | |
371 | a8083063 | Iustin Pop | # volume -------------------------- |
372 | a8083063 | Iustin Pop | |
373 | 3ecf6786 | Iustin Pop | @staticmethod |
374 | b2a6ccd4 | Iustin Pop | def perspective_lv_list(params): |
375 | 3ecf6786 | Iustin Pop | """Query the list of logical volumes in a given volume group. |
376 | 3ecf6786 | Iustin Pop | |
377 | 3ecf6786 | Iustin Pop | """ |
378 | a8083063 | Iustin Pop | vgname = params[0] |
379 | c26a6bd2 | Iustin Pop | return backend.GetVolumeList(vgname) |
380 | a8083063 | Iustin Pop | |
381 | 3ecf6786 | Iustin Pop | @staticmethod |
382 | 3ecf6786 | Iustin Pop | def perspective_vg_list(params): |
383 | 3ecf6786 | Iustin Pop | """Query the list of volume groups. |
384 | 3ecf6786 | Iustin Pop | |
385 | 3ecf6786 | Iustin Pop | """ |
386 | a8083063 | Iustin Pop | return backend.ListVolumeGroups() |
387 | a8083063 | Iustin Pop | |
388 | e337de97 | Michael Hanselmann | # Storage -------------------------- |
389 | e337de97 | Michael Hanselmann | |
390 | e337de97 | Michael Hanselmann | @staticmethod |
391 | e337de97 | Michael Hanselmann | def perspective_storage_list(params): |
392 | e337de97 | Michael Hanselmann | """Get list of storage units. |
393 | e337de97 | Michael Hanselmann | |
394 | e337de97 | Michael Hanselmann | """ |
395 | e337de97 | Michael Hanselmann | (su_name, su_args, name, fields) = params |
396 | e337de97 | Michael Hanselmann | return storage.GetStorage(su_name, *su_args).List(name, fields) |
397 | e337de97 | Michael Hanselmann | |
398 | 8979196a | Michael Hanselmann | @staticmethod |
399 | 8979196a | Michael Hanselmann | def perspective_storage_modify(params): |
400 | 8979196a | Michael Hanselmann | """Modify a storage unit. |
401 | 8979196a | Michael Hanselmann | |
402 | 8979196a | Michael Hanselmann | """ |
403 | 8979196a | Michael Hanselmann | (su_name, su_args, name, changes) = params |
404 | 8979196a | Michael Hanselmann | return storage.GetStorage(su_name, *su_args).Modify(name, changes) |
405 | 8979196a | Michael Hanselmann | |
406 | 637b8d7e | Michael Hanselmann | @staticmethod |
407 | 637b8d7e | Michael Hanselmann | def perspective_storage_execute(params): |
408 | 637b8d7e | Michael Hanselmann | """Execute an operation on a storage unit. |
409 | 637b8d7e | Michael Hanselmann | |
410 | 637b8d7e | Michael Hanselmann | """ |
411 | 637b8d7e | Michael Hanselmann | (su_name, su_args, name, op) = params |
412 | 637b8d7e | Michael Hanselmann | return storage.GetStorage(su_name, *su_args).Execute(name, op) |
413 | 637b8d7e | Michael Hanselmann | |
414 | a8083063 | Iustin Pop | # bridge -------------------------- |
415 | a8083063 | Iustin Pop | |
416 | 3ecf6786 | Iustin Pop | @staticmethod |
417 | 3ecf6786 | Iustin Pop | def perspective_bridges_exist(params): |
418 | 3ecf6786 | Iustin Pop | """Check if all bridges given exist on this node. |
419 | 3ecf6786 | Iustin Pop | |
420 | 3ecf6786 | Iustin Pop | """ |
421 | a8083063 | Iustin Pop | bridges_list = params[0] |
422 | a8083063 | Iustin Pop | return backend.BridgesExist(bridges_list) |
423 | a8083063 | Iustin Pop | |
424 | a8083063 | Iustin Pop | # instance -------------------------- |
425 | a8083063 | Iustin Pop | |
426 | 3ecf6786 | Iustin Pop | @staticmethod |
427 | 3ecf6786 | Iustin Pop | def perspective_instance_os_add(params): |
428 | 3ecf6786 | Iustin Pop | """Install an OS on a given instance. |
429 | 3ecf6786 | Iustin Pop | |
430 | 3ecf6786 | Iustin Pop | """ |
431 | d15a9ad3 | Guido Trotter | inst_s = params[0] |
432 | 319856a9 | Michael Hanselmann | inst = objects.Instance.FromDict(inst_s) |
433 | e557bae9 | Guido Trotter | reinstall = params[1] |
434 | e557bae9 | Guido Trotter | return backend.InstanceOsAdd(inst, reinstall) |
435 | a8083063 | Iustin Pop | |
436 | 3ecf6786 | Iustin Pop | @staticmethod |
437 | decd5f45 | Iustin Pop | def perspective_instance_run_rename(params): |
438 | decd5f45 | Iustin Pop | """Runs the OS rename script for an instance. |
439 | decd5f45 | Iustin Pop | |
440 | decd5f45 | Iustin Pop | """ |
441 | d15a9ad3 | Guido Trotter | inst_s, old_name = params |
442 | 319856a9 | Michael Hanselmann | inst = objects.Instance.FromDict(inst_s) |
443 | d15a9ad3 | Guido Trotter | return backend.RunRenameInstance(inst, old_name) |
444 | decd5f45 | Iustin Pop | |
445 | decd5f45 | Iustin Pop | @staticmethod |
446 | 3ecf6786 | Iustin Pop | def perspective_instance_os_import(params): |
447 | 3ecf6786 | Iustin Pop | """Run the import function of an OS onto a given instance. |
448 | 3ecf6786 | Iustin Pop | |
449 | 3ecf6786 | Iustin Pop | """ |
450 | 6c0af70e | Guido Trotter | inst_s, src_node, src_images, cluster_name = params |
451 | 319856a9 | Michael Hanselmann | inst = objects.Instance.FromDict(inst_s) |
452 | 6c0af70e | Guido Trotter | return backend.ImportOSIntoInstance(inst, src_node, src_images, |
453 | 6c0af70e | Guido Trotter | cluster_name) |
454 | a8083063 | Iustin Pop | |
455 | 3ecf6786 | Iustin Pop | @staticmethod |
456 | 3ecf6786 | Iustin Pop | def perspective_instance_shutdown(params): |
457 | 3ecf6786 | Iustin Pop | """Shutdown an instance. |
458 | 3ecf6786 | Iustin Pop | |
459 | 3ecf6786 | Iustin Pop | """ |
460 | 319856a9 | Michael Hanselmann | instance = objects.Instance.FromDict(params[0]) |
461 | 6263189c | Guido Trotter | timeout = params[1] |
462 | 6263189c | Guido Trotter | return backend.InstanceShutdown(instance, timeout) |
463 | a8083063 | Iustin Pop | |
464 | 3ecf6786 | Iustin Pop | @staticmethod |
465 | 3ecf6786 | Iustin Pop | def perspective_instance_start(params): |
466 | 3ecf6786 | Iustin Pop | """Start an instance. |
467 | 3ecf6786 | Iustin Pop | |
468 | 3ecf6786 | Iustin Pop | """ |
469 | 319856a9 | Michael Hanselmann | instance = objects.Instance.FromDict(params[0]) |
470 | 07813a9e | Iustin Pop | return backend.StartInstance(instance) |
471 | a8083063 | Iustin Pop | |
472 | 3ecf6786 | Iustin Pop | @staticmethod |
473 | 6906a9d8 | Guido Trotter | def perspective_migration_info(params): |
474 | 6906a9d8 | Guido Trotter | """Gather information about an instance to be migrated. |
475 | 6906a9d8 | Guido Trotter | |
476 | 6906a9d8 | Guido Trotter | """ |
477 | 6906a9d8 | Guido Trotter | instance = objects.Instance.FromDict(params[0]) |
478 | 6906a9d8 | Guido Trotter | return backend.MigrationInfo(instance) |
479 | 6906a9d8 | Guido Trotter | |
480 | 6906a9d8 | Guido Trotter | @staticmethod |
481 | 6906a9d8 | Guido Trotter | def perspective_accept_instance(params): |
482 | 6906a9d8 | Guido Trotter | """Prepare the node to accept an instance. |
483 | 6906a9d8 | Guido Trotter | |
484 | 6906a9d8 | Guido Trotter | """ |
485 | 6906a9d8 | Guido Trotter | instance, info, target = params |
486 | 6906a9d8 | Guido Trotter | instance = objects.Instance.FromDict(instance) |
487 | 6906a9d8 | Guido Trotter | return backend.AcceptInstance(instance, info, target) |
488 | 6906a9d8 | Guido Trotter | |
489 | 6906a9d8 | Guido Trotter | @staticmethod |
490 | 6906a9d8 | Guido Trotter | def perspective_finalize_migration(params): |
491 | 6906a9d8 | Guido Trotter | """Finalize the instance migration. |
492 | 6906a9d8 | Guido Trotter | |
493 | 6906a9d8 | Guido Trotter | """ |
494 | 6906a9d8 | Guido Trotter | instance, info, success = params |
495 | 6906a9d8 | Guido Trotter | instance = objects.Instance.FromDict(instance) |
496 | 6906a9d8 | Guido Trotter | return backend.FinalizeMigration(instance, info, success) |
497 | 6906a9d8 | Guido Trotter | |
498 | 6906a9d8 | Guido Trotter | @staticmethod |
499 | 2a10865c | Iustin Pop | def perspective_instance_migrate(params): |
500 | 2a10865c | Iustin Pop | """Migrates an instance. |
501 | 2a10865c | Iustin Pop | |
502 | 2a10865c | Iustin Pop | """ |
503 | 2a10865c | Iustin Pop | instance, target, live = params |
504 | 9f0e6b37 | Iustin Pop | instance = objects.Instance.FromDict(instance) |
505 | 2a10865c | Iustin Pop | return backend.MigrateInstance(instance, target, live) |
506 | 2a10865c | Iustin Pop | |
507 | 2a10865c | Iustin Pop | @staticmethod |
508 | 007a2f3e | Alexander Schreiber | def perspective_instance_reboot(params): |
509 | 007a2f3e | Alexander Schreiber | """Reboot an instance. |
510 | 007a2f3e | Alexander Schreiber | |
511 | 007a2f3e | Alexander Schreiber | """ |
512 | 007a2f3e | Alexander Schreiber | instance = objects.Instance.FromDict(params[0]) |
513 | 007a2f3e | Alexander Schreiber | reboot_type = params[1] |
514 | 17c3f802 | Guido Trotter | shutdown_timeout = params[2] |
515 | 17c3f802 | Guido Trotter | return backend.InstanceReboot(instance, reboot_type, shutdown_timeout) |
516 | 007a2f3e | Alexander Schreiber | |
517 | 007a2f3e | Alexander Schreiber | @staticmethod |
518 | 3ecf6786 | Iustin Pop | def perspective_instance_info(params): |
519 | 3ecf6786 | Iustin Pop | """Query instance information. |
520 | 3ecf6786 | Iustin Pop | |
521 | 3ecf6786 | Iustin Pop | """ |
522 | 16ad1a83 | Iustin Pop | return backend.GetInstanceInfo(params[0], params[1]) |
523 | a8083063 | Iustin Pop | |
524 | 3ecf6786 | Iustin Pop | @staticmethod |
525 | 56e7640c | Iustin Pop | def perspective_instance_migratable(params): |
526 | 56e7640c | Iustin Pop | """Query whether the specified instance can be migrated. |
527 | 56e7640c | Iustin Pop | |
528 | 56e7640c | Iustin Pop | """ |
529 | 56e7640c | Iustin Pop | instance = objects.Instance.FromDict(params[0]) |
530 | 56e7640c | Iustin Pop | return backend.GetInstanceMigratable(instance) |
531 | 56e7640c | Iustin Pop | |
532 | 56e7640c | Iustin Pop | @staticmethod |
533 | 3ecf6786 | Iustin Pop | def perspective_all_instances_info(params): |
534 | 3ecf6786 | Iustin Pop | """Query information about all instances. |
535 | 3ecf6786 | Iustin Pop | |
536 | 3ecf6786 | Iustin Pop | """ |
537 | e69d05fd | Iustin Pop | return backend.GetAllInstancesInfo(params[0]) |
538 | a8083063 | Iustin Pop | |
539 | 3ecf6786 | Iustin Pop | @staticmethod |
540 | 3ecf6786 | Iustin Pop | def perspective_instance_list(params): |
541 | 3ecf6786 | Iustin Pop | """Query the list of running instances. |
542 | 3ecf6786 | Iustin Pop | |
543 | 3ecf6786 | Iustin Pop | """ |
544 | c26a6bd2 | Iustin Pop | return backend.GetInstanceList(params[0]) |
545 | a8083063 | Iustin Pop | |
546 | a8083063 | Iustin Pop | # node -------------------------- |
547 | a8083063 | Iustin Pop | |
548 | 3ecf6786 | Iustin Pop | @staticmethod |
549 | 16abfbc2 | Alexander Schreiber | def perspective_node_tcp_ping(params): |
550 | 16abfbc2 | Alexander Schreiber | """Do a TcpPing on the remote node. |
551 | 16abfbc2 | Alexander Schreiber | |
552 | 16abfbc2 | Alexander Schreiber | """ |
553 | b15d625f | Iustin Pop | return utils.TcpPing(params[1], params[2], timeout=params[3], |
554 | b15d625f | Iustin Pop | live_port_needed=params[4], source=params[0]) |
555 | 16abfbc2 | Alexander Schreiber | |
556 | 16abfbc2 | Alexander Schreiber | @staticmethod |
557 | caad16e2 | Iustin Pop | def perspective_node_has_ip_address(params): |
558 | caad16e2 | Iustin Pop | """Checks if a node has the given ip address. |
559 | caad16e2 | Iustin Pop | |
560 | caad16e2 | Iustin Pop | """ |
561 | c26a6bd2 | Iustin Pop | return utils.OwnIpAddress(params[0]) |
562 | caad16e2 | Iustin Pop | |
563 | caad16e2 | Iustin Pop | @staticmethod |
564 | 3ecf6786 | Iustin Pop | def perspective_node_info(params): |
565 | 3ecf6786 | Iustin Pop | """Query node information. |
566 | 3ecf6786 | Iustin Pop | |
567 | 3ecf6786 | Iustin Pop | """ |
568 | e69d05fd | Iustin Pop | vgname, hypervisor_type = params |
569 | e69d05fd | Iustin Pop | return backend.GetNodeInfo(vgname, hypervisor_type) |
570 | a8083063 | Iustin Pop | |
571 | 3ecf6786 | Iustin Pop | @staticmethod |
572 | 3ecf6786 | Iustin Pop | def perspective_node_add(params): |
573 | 3ecf6786 | Iustin Pop | """Complete the registration of this node in the cluster. |
574 | 3ecf6786 | Iustin Pop | |
575 | 3ecf6786 | Iustin Pop | """ |
576 | a8083063 | Iustin Pop | return backend.AddNode(params[0], params[1], params[2], |
577 | a8083063 | Iustin Pop | params[3], params[4], params[5]) |
578 | a8083063 | Iustin Pop | |
579 | 3ecf6786 | Iustin Pop | @staticmethod |
580 | 3ecf6786 | Iustin Pop | def perspective_node_verify(params): |
581 | 3ecf6786 | Iustin Pop | """Run a verify sequence on this node. |
582 | 3ecf6786 | Iustin Pop | |
583 | 3ecf6786 | Iustin Pop | """ |
584 | 62c9ec92 | Iustin Pop | return backend.VerifyNode(params[0], params[1]) |
585 | a8083063 | Iustin Pop | |
586 | 3ecf6786 | Iustin Pop | @staticmethod |
587 | 3ecf6786 | Iustin Pop | def perspective_node_start_master(params): |
588 | 3ecf6786 | Iustin Pop | """Promote this node to master status. |
589 | 3ecf6786 | Iustin Pop | |
590 | 3ecf6786 | Iustin Pop | """ |
591 | 3583908a | Guido Trotter | return backend.StartMaster(params[0], params[1]) |
592 | a8083063 | Iustin Pop | |
593 | 3ecf6786 | Iustin Pop | @staticmethod |
594 | 3ecf6786 | Iustin Pop | def perspective_node_stop_master(params): |
595 | 3ecf6786 | Iustin Pop | """Demote this node from master status. |
596 | 3ecf6786 | Iustin Pop | |
597 | 3ecf6786 | Iustin Pop | """ |
598 | 1c65840b | Iustin Pop | return backend.StopMaster(params[0]) |
599 | a8083063 | Iustin Pop | |
600 | 3ecf6786 | Iustin Pop | @staticmethod |
601 | 3ecf6786 | Iustin Pop | def perspective_node_leave_cluster(params): |
602 | 3ecf6786 | Iustin Pop | """Cleanup after leaving a cluster. |
603 | 3ecf6786 | Iustin Pop | |
604 | 3ecf6786 | Iustin Pop | """ |
605 | b989b9d9 | Ken Wehr | return backend.LeaveCluster(params[0]) |
606 | a8083063 | Iustin Pop | |
607 | 3ecf6786 | Iustin Pop | @staticmethod |
608 | 3ecf6786 | Iustin Pop | def perspective_node_volumes(params): |
609 | 3ecf6786 | Iustin Pop | """Query the list of all logical volume groups. |
610 | 3ecf6786 | Iustin Pop | |
611 | 3ecf6786 | Iustin Pop | """ |
612 | dcb93971 | Michael Hanselmann | return backend.NodeVolumes() |
613 | dcb93971 | Michael Hanselmann | |
614 | 56aa9fd5 | Iustin Pop | @staticmethod |
615 | 56aa9fd5 | Iustin Pop | def perspective_node_demote_from_mc(params): |
616 | 56aa9fd5 | Iustin Pop | """Demote a node from the master candidate role. |
617 | 56aa9fd5 | Iustin Pop | |
618 | 56aa9fd5 | Iustin Pop | """ |
619 | 56aa9fd5 | Iustin Pop | return backend.DemoteFromMC() |
620 | 56aa9fd5 | Iustin Pop | |
621 | 56aa9fd5 | Iustin Pop | |
622 | f5118ade | Iustin Pop | @staticmethod |
623 | f5118ade | Iustin Pop | def perspective_node_powercycle(params): |
624 | f5118ade | Iustin Pop | """Tries to powercycle the nod. |
625 | f5118ade | Iustin Pop | |
626 | f5118ade | Iustin Pop | """ |
627 | f5118ade | Iustin Pop | hypervisor_type = params[0] |
628 | f5118ade | Iustin Pop | return backend.PowercycleNode(hypervisor_type) |
629 | f5118ade | Iustin Pop | |
630 | f5118ade | Iustin Pop | |
631 | a8083063 | Iustin Pop | # cluster -------------------------- |
632 | a8083063 | Iustin Pop | |
633 | 3ecf6786 | Iustin Pop | @staticmethod |
634 | 3ecf6786 | Iustin Pop | def perspective_version(params): |
635 | 3ecf6786 | Iustin Pop | """Query version information. |
636 | 3ecf6786 | Iustin Pop | |
637 | 3ecf6786 | Iustin Pop | """ |
638 | c26a6bd2 | Iustin Pop | return constants.PROTOCOL_VERSION |
639 | a8083063 | Iustin Pop | |
640 | 3ecf6786 | Iustin Pop | @staticmethod |
641 | 3ecf6786 | Iustin Pop | def perspective_upload_file(params): |
642 | 3ecf6786 | Iustin Pop | """Upload a file. |
643 | 3ecf6786 | Iustin Pop | |
644 | 3ecf6786 | Iustin Pop | Note that the backend implementation imposes strict rules on which |
645 | 3ecf6786 | Iustin Pop | files are accepted. |
646 | 3ecf6786 | Iustin Pop | |
647 | 3ecf6786 | Iustin Pop | """ |
648 | a8083063 | Iustin Pop | return backend.UploadFile(*params) |
649 | a8083063 | Iustin Pop | |
650 | 4e071d3b | Iustin Pop | @staticmethod |
651 | 4e071d3b | Iustin Pop | def perspective_master_info(params): |
652 | 4e071d3b | Iustin Pop | """Query master information. |
653 | 4e071d3b | Iustin Pop | |
654 | 4e071d3b | Iustin Pop | """ |
655 | 4e071d3b | Iustin Pop | return backend.GetMasterInfo() |
656 | a8083063 | Iustin Pop | |
657 | 6ddc95ec | Michael Hanselmann | @staticmethod |
658 | 6ddc95ec | Michael Hanselmann | def perspective_write_ssconf_files(params): |
659 | 6ddc95ec | Michael Hanselmann | """Write ssconf files. |
660 | 6ddc95ec | Michael Hanselmann | |
661 | 6ddc95ec | Michael Hanselmann | """ |
662 | 03d1dba2 | Michael Hanselmann | (values,) = params |
663 | 03d1dba2 | Michael Hanselmann | return backend.WriteSsconfFiles(values) |
664 | 6ddc95ec | Michael Hanselmann | |
665 | a8083063 | Iustin Pop | # os ----------------------- |
666 | a8083063 | Iustin Pop | |
667 | 3ecf6786 | Iustin Pop | @staticmethod |
668 | 3ecf6786 | Iustin Pop | def perspective_os_diagnose(params): |
669 | 3ecf6786 | Iustin Pop | """Query detailed information about existing OSes. |
670 | 3ecf6786 | Iustin Pop | |
671 | 3ecf6786 | Iustin Pop | """ |
672 | 255dcebd | Iustin Pop | return backend.DiagnoseOS() |
673 | a8083063 | Iustin Pop | |
674 | 3ecf6786 | Iustin Pop | @staticmethod |
675 | 3ecf6786 | Iustin Pop | def perspective_os_get(params): |
676 | 3ecf6786 | Iustin Pop | """Query information about a given OS. |
677 | 3ecf6786 | Iustin Pop | |
678 | 3ecf6786 | Iustin Pop | """ |
679 | a8083063 | Iustin Pop | name = params[0] |
680 | 255dcebd | Iustin Pop | os_obj = backend.OSFromDisk(name) |
681 | c26a6bd2 | Iustin Pop | return os_obj.ToDict() |
682 | a8083063 | Iustin Pop | |
683 | a8083063 | Iustin Pop | # hooks ----------------------- |
684 | a8083063 | Iustin Pop | |
685 | 3ecf6786 | Iustin Pop | @staticmethod |
686 | 3ecf6786 | Iustin Pop | def perspective_hooks_runner(params): |
687 | 3ecf6786 | Iustin Pop | """Run hook scripts. |
688 | 3ecf6786 | Iustin Pop | |
689 | 3ecf6786 | Iustin Pop | """ |
690 | a8083063 | Iustin Pop | hpath, phase, env = params |
691 | a8083063 | Iustin Pop | hr = backend.HooksRunner() |
692 | a8083063 | Iustin Pop | return hr.RunHooks(hpath, phase, env) |
693 | a8083063 | Iustin Pop | |
694 | 8d528b7c | Iustin Pop | # iallocator ----------------- |
695 | 8d528b7c | Iustin Pop | |
696 | 8d528b7c | Iustin Pop | @staticmethod |
697 | 8d528b7c | Iustin Pop | def perspective_iallocator_runner(params): |
698 | 8d528b7c | Iustin Pop | """Run an iallocator script. |
699 | 8d528b7c | Iustin Pop | |
700 | 8d528b7c | Iustin Pop | """ |
701 | 8d528b7c | Iustin Pop | name, idata = params |
702 | 8d528b7c | Iustin Pop | iar = backend.IAllocatorRunner() |
703 | 8d528b7c | Iustin Pop | return iar.Run(name, idata) |
704 | 8d528b7c | Iustin Pop | |
705 | 06009e27 | Iustin Pop | # test ----------------------- |
706 | 06009e27 | Iustin Pop | |
707 | 06009e27 | Iustin Pop | @staticmethod |
708 | 06009e27 | Iustin Pop | def perspective_test_delay(params): |
709 | 06009e27 | Iustin Pop | """Run test delay. |
710 | 06009e27 | Iustin Pop | |
711 | 06009e27 | Iustin Pop | """ |
712 | 06009e27 | Iustin Pop | duration = params[0] |
713 | c26a6bd2 | Iustin Pop | status, rval = utils.TestDelay(duration) |
714 | c26a6bd2 | Iustin Pop | if not status: |
715 | c26a6bd2 | Iustin Pop | raise backend.RPCFail(rval) |
716 | c26a6bd2 | Iustin Pop | return rval |
717 | 06009e27 | Iustin Pop | |
718 | 4e071d3b | Iustin Pop | # file storage --------------- |
719 | 4e071d3b | Iustin Pop | |
720 | a5d7fb43 | Manuel Franceschini | @staticmethod |
721 | a5d7fb43 | Manuel Franceschini | def perspective_file_storage_dir_create(params): |
722 | a5d7fb43 | Manuel Franceschini | """Create the file storage directory. |
723 | a5d7fb43 | Manuel Franceschini | |
724 | a5d7fb43 | Manuel Franceschini | """ |
725 | a5d7fb43 | Manuel Franceschini | file_storage_dir = params[0] |
726 | a5d7fb43 | Manuel Franceschini | return backend.CreateFileStorageDir(file_storage_dir) |
727 | a5d7fb43 | Manuel Franceschini | |
728 | a5d7fb43 | Manuel Franceschini | @staticmethod |
729 | a5d7fb43 | Manuel Franceschini | def perspective_file_storage_dir_remove(params): |
730 | a5d7fb43 | Manuel Franceschini | """Remove the file storage directory. |
731 | a5d7fb43 | Manuel Franceschini | |
732 | a5d7fb43 | Manuel Franceschini | """ |
733 | a5d7fb43 | Manuel Franceschini | file_storage_dir = params[0] |
734 | a5d7fb43 | Manuel Franceschini | return backend.RemoveFileStorageDir(file_storage_dir) |
735 | a5d7fb43 | Manuel Franceschini | |
736 | a5d7fb43 | Manuel Franceschini | @staticmethod |
737 | a5d7fb43 | Manuel Franceschini | def perspective_file_storage_dir_rename(params): |
738 | a5d7fb43 | Manuel Franceschini | """Rename the file storage directory. |
739 | a5d7fb43 | Manuel Franceschini | |
740 | a5d7fb43 | Manuel Franceschini | """ |
741 | a5d7fb43 | Manuel Franceschini | old_file_storage_dir = params[0] |
742 | a5d7fb43 | Manuel Franceschini | new_file_storage_dir = params[1] |
743 | a5d7fb43 | Manuel Franceschini | return backend.RenameFileStorageDir(old_file_storage_dir, |
744 | a5d7fb43 | Manuel Franceschini | new_file_storage_dir) |
745 | a5d7fb43 | Manuel Franceschini | |
746 | 4e071d3b | Iustin Pop | # jobs ------------------------ |
747 | 4e071d3b | Iustin Pop | |
748 | ca52cdeb | Michael Hanselmann | @staticmethod |
749 | 7f30777b | Michael Hanselmann | @_RequireJobQueueLock |
750 | ca52cdeb | Michael Hanselmann | def perspective_jobqueue_update(params): |
751 | ca52cdeb | Michael Hanselmann | """Update job queue. |
752 | ca52cdeb | Michael Hanselmann | |
753 | ca52cdeb | Michael Hanselmann | """ |
754 | ca52cdeb | Michael Hanselmann | (file_name, content) = params |
755 | 7f30777b | Michael Hanselmann | return backend.JobQueueUpdate(file_name, content) |
756 | ca52cdeb | Michael Hanselmann | |
757 | ca52cdeb | Michael Hanselmann | @staticmethod |
758 | f1f3f45c | Michael Hanselmann | @_RequireJobQueueLock |
759 | ca52cdeb | Michael Hanselmann | def perspective_jobqueue_purge(params): |
760 | ca52cdeb | Michael Hanselmann | """Purge job queue. |
761 | ca52cdeb | Michael Hanselmann | |
762 | ca52cdeb | Michael Hanselmann | """ |
763 | ca52cdeb | Michael Hanselmann | return backend.JobQueuePurge() |
764 | ca52cdeb | Michael Hanselmann | |
765 | af5ebcb1 | Michael Hanselmann | @staticmethod |
766 | af5ebcb1 | Michael Hanselmann | @_RequireJobQueueLock |
767 | af5ebcb1 | Michael Hanselmann | def perspective_jobqueue_rename(params): |
768 | af5ebcb1 | Michael Hanselmann | """Rename a job queue file. |
769 | af5ebcb1 | Michael Hanselmann | |
770 | af5ebcb1 | Michael Hanselmann | """ |
771 | dd875d32 | Michael Hanselmann | # TODO: What if a file fails to rename? |
772 | c26a6bd2 | Iustin Pop | return [backend.JobQueueRename(old, new) for old, new in params] |
773 | af5ebcb1 | Michael Hanselmann | |
774 | 5d672980 | Iustin Pop | @staticmethod |
775 | 5d672980 | Iustin Pop | def perspective_jobqueue_set_drain(params): |
776 | 5d672980 | Iustin Pop | """Set/unset the queue drain flag. |
777 | 5d672980 | Iustin Pop | |
778 | 5d672980 | Iustin Pop | """ |
779 | 5d672980 | Iustin Pop | drain_flag = params[0] |
780 | 5d672980 | Iustin Pop | return backend.JobQueueSetDrainFlag(drain_flag) |
781 | 5d672980 | Iustin Pop | |
782 | 5d672980 | Iustin Pop | |
783 | 6217e295 | Iustin Pop | # hypervisor --------------- |
784 | 6217e295 | Iustin Pop | |
785 | 6217e295 | Iustin Pop | @staticmethod |
786 | 6217e295 | Iustin Pop | def perspective_hypervisor_validate_params(params): |
787 | 6217e295 | Iustin Pop | """Validate the hypervisor parameters. |
788 | 6217e295 | Iustin Pop | |
789 | 6217e295 | Iustin Pop | """ |
790 | 6217e295 | Iustin Pop | (hvname, hvparams) = params |
791 | 6217e295 | Iustin Pop | return backend.ValidateHVParams(hvname, hvparams) |
792 | 6217e295 | Iustin Pop | |
793 | a8083063 | Iustin Pop | |
794 | f93427cd | Iustin Pop | def CheckNoded(_, args): |
795 | f93427cd | Iustin Pop | """Initial checks whether to run or exit with a failure. |
796 | f93427cd | Iustin Pop | |
797 | f93427cd | Iustin Pop | """ |
798 | f93427cd | Iustin Pop | if args: # noded doesn't take any arguments |
799 | f93427cd | Iustin Pop | print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" % |
800 | f93427cd | Iustin Pop | sys.argv[0]) |
801 | f93427cd | Iustin Pop | sys.exit(constants.EXIT_FAILURE) |
802 | f93427cd | Iustin Pop | |
803 | f93427cd | Iustin Pop | |
804 | 2d54e29c | Iustin Pop | def ExecNoded(options, _): |
805 | 6c948699 | Michael Hanselmann | """Main node daemon function, executed with the PID file held. |
806 | 3ecf6786 | Iustin Pop | |
807 | 3ecf6786 | Iustin Pop | """ |
808 | 7260cfbe | Iustin Pop | global queue_lock # pylint: disable-msg=W0603 |
809 | 25d6d12a | Michael Hanselmann | |
810 | 04ccf5e9 | Guido Trotter | # Read SSL certificate |
811 | 3b1b0cb6 | Guido Trotter | if options.ssl: |
812 | 3b1b0cb6 | Guido Trotter | ssl_params = http.HttpSslParams(ssl_key_path=options.ssl_key, |
813 | 3b1b0cb6 | Guido Trotter | ssl_cert_path=options.ssl_cert) |
814 | 3b1b0cb6 | Guido Trotter | else: |
815 | 3b1b0cb6 | Guido Trotter | ssl_params = None |
816 | 7d88772a | Iustin Pop | |
817 | 04ccf5e9 | Guido Trotter | # Prepare job queue |
818 | 04ccf5e9 | Guido Trotter | queue_lock = jstore.InitAndVerifyQueue(must_lock=False) |
819 | 7d88772a | Iustin Pop | |
820 | 04ccf5e9 | Guido Trotter | mainloop = daemon.Mainloop() |
821 | 04ccf5e9 | Guido Trotter | server = NodeHttpServer(mainloop, options.bind_address, options.port, |
822 | 04ccf5e9 | Guido Trotter | ssl_params=ssl_params, ssl_verify_peer=True) |
823 | 04ccf5e9 | Guido Trotter | server.Start() |
824 | 04ccf5e9 | Guido Trotter | try: |
825 | 04ccf5e9 | Guido Trotter | mainloop.Run() |
826 | 04ccf5e9 | Guido Trotter | finally: |
827 | 04ccf5e9 | Guido Trotter | server.Stop() |
828 | a8083063 | Iustin Pop | |
829 | a8083063 | Iustin Pop | |
830 | 04ccf5e9 | Guido Trotter | def main(): |
831 | 04ccf5e9 | Guido Trotter | """Main function for the node daemon. |
832 | 04ccf5e9 | Guido Trotter | |
833 | 04ccf5e9 | Guido Trotter | """ |
834 | 04ccf5e9 | Guido Trotter | parser = OptionParser(description="Ganeti node daemon", |
835 | 04ccf5e9 | Guido Trotter | usage="%prog [-f] [-d] [-p port] [-b ADDRESS]", |
836 | 04ccf5e9 | Guido Trotter | version="%%prog (ganeti) %s" % |
837 | 04ccf5e9 | Guido Trotter | constants.RELEASE_VERSION) |
838 | 9dae41ad | Guido Trotter | dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS] |
839 | 9dae41ad | Guido Trotter | dirs.append((constants.LOG_OS_DIR, 0750)) |
840 | 9dae41ad | Guido Trotter | dirs.append((constants.LOCK_DIR, 1777)) |
841 | 24cd3744 | Iustin Pop | daemon.GenericMain(constants.NODED, parser, dirs, CheckNoded, ExecNoded, |
842 | 0648750e | Michael Hanselmann | default_ssl_cert=constants.SSL_CERT_FILE, |
843 | 0648750e | Michael Hanselmann | default_ssl_key=constants.SSL_CERT_FILE) |
844 | 73d927a2 | Guido Trotter | |
845 | a8083063 | Iustin Pop | |
846 | 3ecf6786 | Iustin Pop | if __name__ == '__main__': |
847 | a8083063 | Iustin Pop | main() |