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