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