root / lib / server / noded.py @ be9150ea
History | View | Annotate | Download (32.1 kB)
1 | 69cf3abd | Michael Hanselmann | #
|
---|---|---|---|
2 | a8083063 | Iustin Pop | #
|
3 | a8083063 | Iustin Pop | |
4 | cad0723b | Iustin Pop | # Copyright (C) 2006, 2007, 2010, 2011, 2012 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 | b459a848 | Andrea Spadaccini | # pylint: disable=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 | f01738fc | Iustin Pop | import codecs |
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 | 8f096849 | Helga Velroyen | from ganeti.storage import container |
49 | ab221ddf | Michael Hanselmann | from ganeti import serializer |
50 | a744b676 | Manuel Franceschini | from ganeti import netutils |
51 | a5ce2ea2 | Michael Hanselmann | from ganeti import pathutils |
52 | ee501db1 | Michael Hanselmann | from ganeti import ssconf |
53 | a8083063 | Iustin Pop | |
54 | b459a848 | Andrea Spadaccini | import ganeti.http.server # pylint: disable=W0611 |
55 | 19205c39 | Michael Hanselmann | |
56 | a8083063 | Iustin Pop | |
57 | 25d6d12a | Michael Hanselmann | queue_lock = None
|
58 | 25d6d12a | Michael Hanselmann | |
59 | 25d6d12a | Michael Hanselmann | |
60 | 8e00f36a | Michele Tartara | def _extendReasonTrail(trail, source, reason=""): |
61 | 8e00f36a | Michele Tartara | """Extend the reason trail with noded information
|
62 | 8e00f36a | Michele Tartara |
|
63 | 8e00f36a | Michele Tartara | The trail is extended by appending the name of the noded functionality
|
64 | 8e00f36a | Michele Tartara | """
|
65 | 8e00f36a | Michele Tartara | assert trail is not None |
66 | 8e00f36a | Michele Tartara | trail_source = "%s:%s" % (constants.OPCODE_REASON_SRC_NODED, source)
|
67 | 8e00f36a | Michele Tartara | trail.append((trail_source, reason, utils.EpochNano())) |
68 | 8e00f36a | Michele Tartara | |
69 | 8e00f36a | Michele Tartara | |
70 | 81198f6e | Iustin Pop | def _PrepareQueueLock(): |
71 | 81198f6e | Iustin Pop | """Try to prepare the queue lock.
|
72 | 81198f6e | Iustin Pop |
|
73 | 81198f6e | Iustin Pop | @return: None for success, otherwise an exception object
|
74 | 81198f6e | Iustin Pop |
|
75 | 81198f6e | Iustin Pop | """
|
76 | b459a848 | Andrea Spadaccini | global queue_lock # pylint: disable=W0603 |
77 | 81198f6e | Iustin Pop | |
78 | 81198f6e | Iustin Pop | if queue_lock is not None: |
79 | 81198f6e | Iustin Pop | return None |
80 | 81198f6e | Iustin Pop | |
81 | 81198f6e | Iustin Pop | # Prepare job queue
|
82 | 81198f6e | Iustin Pop | try:
|
83 | 81198f6e | Iustin Pop | queue_lock = jstore.InitAndVerifyQueue(must_lock=False)
|
84 | 81198f6e | Iustin Pop | return None |
85 | 81198f6e | Iustin Pop | except EnvironmentError, err: |
86 | 81198f6e | Iustin Pop | return err
|
87 | 81198f6e | Iustin Pop | |
88 | 81198f6e | Iustin Pop | |
89 | 7f30777b | Michael Hanselmann | def _RequireJobQueueLock(fn): |
90 | 7f30777b | Michael Hanselmann | """Decorator for job queue manipulating functions.
|
91 | 7f30777b | Michael Hanselmann |
|
92 | 7f30777b | Michael Hanselmann | """
|
93 | 8785cb30 | Michael Hanselmann | QUEUE_LOCK_TIMEOUT = 10
|
94 | 8785cb30 | Michael Hanselmann | |
95 | 7f30777b | Michael Hanselmann | def wrapper(*args, **kwargs): |
96 | 7f30777b | Michael Hanselmann | # Locking in exclusive, blocking mode because there could be several
|
97 | 506cff12 | Michael Hanselmann | # children running at the same time. Waiting up to 10 seconds.
|
98 | 81198f6e | Iustin Pop | if _PrepareQueueLock() is not None: |
99 | 81198f6e | Iustin Pop | raise errors.JobQueueError("Job queue failed initialization," |
100 | 81198f6e | Iustin Pop | " cannot update jobs")
|
101 | 8785cb30 | Michael Hanselmann | queue_lock.Exclusive(blocking=True, timeout=QUEUE_LOCK_TIMEOUT)
|
102 | 7f30777b | Michael Hanselmann | try:
|
103 | 7f30777b | Michael Hanselmann | return fn(*args, **kwargs)
|
104 | 7f30777b | Michael Hanselmann | finally:
|
105 | 7f30777b | Michael Hanselmann | queue_lock.Unlock() |
106 | 8785cb30 | Michael Hanselmann | |
107 | 7f30777b | Michael Hanselmann | return wrapper
|
108 | 7f30777b | Michael Hanselmann | |
109 | 7f30777b | Michael Hanselmann | |
110 | 1651d116 | Michael Hanselmann | def _DecodeImportExportIO(ieio, ieioargs): |
111 | 1651d116 | Michael Hanselmann | """Decodes import/export I/O information.
|
112 | 1651d116 | Michael Hanselmann |
|
113 | 1651d116 | Michael Hanselmann | """
|
114 | 1651d116 | Michael Hanselmann | if ieio == constants.IEIO_RAW_DISK:
|
115 | 1651d116 | Michael Hanselmann | assert len(ieioargs) == 1 |
116 | 1651d116 | Michael Hanselmann | return (objects.Disk.FromDict(ieioargs[0]), ) |
117 | 1651d116 | Michael Hanselmann | |
118 | 1651d116 | Michael Hanselmann | if ieio == constants.IEIO_SCRIPT:
|
119 | 1651d116 | Michael Hanselmann | assert len(ieioargs) == 2 |
120 | 1651d116 | Michael Hanselmann | return (objects.Disk.FromDict(ieioargs[0]), ieioargs[1]) |
121 | 1651d116 | Michael Hanselmann | |
122 | 1651d116 | Michael Hanselmann | return ieioargs
|
123 | 1651d116 | Michael Hanselmann | |
124 | 1651d116 | Michael Hanselmann | |
125 | 4a90bd4f | Michele Tartara | def _DefaultAlternative(value, default): |
126 | a82d9394 | Michael Hanselmann | """Returns value or, if evaluating to False, a default value.
|
127 | 4a90bd4f | Michele Tartara |
|
128 | a82d9394 | Michael Hanselmann | Returns the given value, unless it evaluates to False. In the latter case the
|
129 | a82d9394 | Michael Hanselmann | default value is returned.
|
130 | a82d9394 | Michael Hanselmann |
|
131 | a82d9394 | Michael Hanselmann | @param value: Value to return if it doesn't evaluate to False
|
132 | a82d9394 | Michael Hanselmann | @param default: Default value
|
133 | a82d9394 | Michael Hanselmann | @return: Given value or the default
|
134 | 4a90bd4f | Michele Tartara |
|
135 | 4a90bd4f | Michele Tartara | """
|
136 | 4a90bd4f | Michele Tartara | if value:
|
137 | 4a90bd4f | Michele Tartara | return value
|
138 | 4a90bd4f | Michele Tartara | |
139 | 4a90bd4f | Michele Tartara | return default
|
140 | 4a90bd4f | Michele Tartara | |
141 | 4a90bd4f | Michele Tartara | |
142 | 38b77287 | Luca Bigliardi | class MlockallRequestExecutor(http.server.HttpServerRequestExecutor): |
143 | cca5b3fc | Michael Hanselmann | """Subclass ensuring request handlers are locked in RAM.
|
144 | 38b77287 | Luca Bigliardi |
|
145 | 38b77287 | Luca Bigliardi | """
|
146 | 38b77287 | Luca Bigliardi | def __init__(self, *args, **kwargs): |
147 | 38b77287 | Luca Bigliardi | utils.Mlockall() |
148 | 38b77287 | Luca Bigliardi | |
149 | 38b77287 | Luca Bigliardi | http.server.HttpServerRequestExecutor.__init__(self, *args, **kwargs)
|
150 | 38b77287 | Luca Bigliardi | |
151 | 38b77287 | Luca Bigliardi | |
152 | e0003509 | Michael Hanselmann | class NodeRequestHandler(http.server.HttpServerHandler): |
153 | 3ecf6786 | Iustin Pop | """The server implementation.
|
154 | 3ecf6786 | Iustin Pop |
|
155 | 3ecf6786 | Iustin Pop | This class holds all methods exposed over the RPC interface.
|
156 | 3ecf6786 | Iustin Pop |
|
157 | 3ecf6786 | Iustin Pop | """
|
158 | 2d54e29c | Iustin Pop | # too many public methods, and unused args - all methods get params
|
159 | 2d54e29c | Iustin Pop | # due to the API
|
160 | b459a848 | Andrea Spadaccini | # pylint: disable=R0904,W0613
|
161 | e0003509 | Michael Hanselmann | def __init__(self): |
162 | e0003509 | Michael Hanselmann | http.server.HttpServerHandler.__init__(self)
|
163 | cc28af80 | Michael Hanselmann | self.noded_pid = os.getpid()
|
164 | cc28af80 | Michael Hanselmann | |
165 | cc28af80 | Michael Hanselmann | def HandleRequest(self, req): |
166 | 1df6506c | Michael Hanselmann | """Handle a request.
|
167 | a8083063 | Iustin Pop |
|
168 | 098c0958 | Michael Hanselmann | """
|
169 | a7862455 | Iustin Pop | if req.request_method.upper() != http.HTTP_POST:
|
170 | a7862455 | Iustin Pop | raise http.HttpBadRequest("Only the POST method is supported") |
171 | 1df6506c | Michael Hanselmann | |
172 | cc28af80 | Michael Hanselmann | path = req.request_path |
173 | 81010134 | Iustin Pop | if path.startswith("/"): |
174 | 81010134 | Iustin Pop | path = path[1:]
|
175 | 81010134 | Iustin Pop | |
176 | 1df6506c | Michael Hanselmann | method = getattr(self, "perspective_%s" % path, None) |
177 | 1df6506c | Michael Hanselmann | if method is None: |
178 | 84f2756e | Michael Hanselmann | raise http.HttpNotFound()
|
179 | a8083063 | Iustin Pop | |
180 | 81010134 | Iustin Pop | try:
|
181 | ab221ddf | Michael Hanselmann | result = (True, method(serializer.LoadJson(req.request_body)))
|
182 | 4dd42c9d | Iustin Pop | |
183 | 0623d351 | Iustin Pop | except backend.RPCFail, err:
|
184 | 0623d351 | Iustin Pop | # our custom failure exception; str(err) works fine if the
|
185 | 0623d351 | Iustin Pop | # exception was constructed with a single argument, and in
|
186 | 0623d351 | Iustin Pop | # this case, err.message == err.args[0] == str(err)
|
187 | ab221ddf | Michael Hanselmann | result = (False, str(err)) |
188 | 9ae49f27 | Guido Trotter | except errors.QuitGanetiException, err:
|
189 | 84b58db2 | Michael Hanselmann | # Tell parent to quit
|
190 | 0623d351 | Iustin Pop | logging.info("Shutting down the node daemon, arguments: %s",
|
191 | 0623d351 | Iustin Pop | str(err.args))
|
192 | cc28af80 | Michael Hanselmann | os.kill(self.noded_pid, signal.SIGTERM)
|
193 | 0623d351 | Iustin Pop | # And return the error's arguments, which must be already in
|
194 | 0623d351 | Iustin Pop | # correct tuple format
|
195 | ab221ddf | Michael Hanselmann | result = err.args |
196 | 4dd42c9d | Iustin Pop | except Exception, err: |
197 | 0623d351 | Iustin Pop | logging.exception("Error in RPC call")
|
198 | ab221ddf | Michael Hanselmann | result = (False, "Error while executing backend function: %s" % str(err)) |
199 | ab221ddf | Michael Hanselmann | |
200 | a182a3ed | Michael Hanselmann | return serializer.DumpJson(result)
|
201 | a8083063 | Iustin Pop | |
202 | a8083063 | Iustin Pop | # the new block devices --------------------------
|
203 | a8083063 | Iustin Pop | |
204 | 3ecf6786 | Iustin Pop | @staticmethod
|
205 | 3ecf6786 | Iustin Pop | def perspective_blockdev_create(params): |
206 | 3ecf6786 | Iustin Pop | """Create a block device.
|
207 | 3ecf6786 | Iustin Pop |
|
208 | 3ecf6786 | Iustin Pop | """
|
209 | ee1478e5 | Bernardo Dal Seno | (bdev_s, size, owner, on_primary, info, excl_stor) = params |
210 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
211 | a8083063 | Iustin Pop | if bdev is None: |
212 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
213 | ee1478e5 | Bernardo Dal Seno | return backend.BlockdevCreate(bdev, size, owner, on_primary, info,
|
214 | ee1478e5 | Bernardo Dal Seno | excl_stor) |
215 | a8083063 | Iustin Pop | |
216 | 3ecf6786 | Iustin Pop | @staticmethod
|
217 | 9c007da8 | Renรฉ Nussbaumer | def perspective_blockdev_pause_resume_sync(params): |
218 | 9c007da8 | Renรฉ Nussbaumer | """Pause/resume sync of a block device.
|
219 | 9c007da8 | Renรฉ Nussbaumer |
|
220 | 9c007da8 | Renรฉ Nussbaumer | """
|
221 | 9c007da8 | Renรฉ Nussbaumer | disks_s, pause = params |
222 | 9c007da8 | Renรฉ Nussbaumer | disks = [objects.Disk.FromDict(bdev_s) for bdev_s in disks_s] |
223 | 9c007da8 | Renรฉ Nussbaumer | return backend.BlockdevPauseResumeSync(disks, pause)
|
224 | 9c007da8 | Renรฉ Nussbaumer | |
225 | 9c007da8 | Renรฉ Nussbaumer | @staticmethod
|
226 | 271b7cf9 | Renรฉ Nussbaumer | def perspective_blockdev_wipe(params): |
227 | 271b7cf9 | Renรฉ Nussbaumer | """Wipe a block device.
|
228 | 271b7cf9 | Renรฉ Nussbaumer |
|
229 | 271b7cf9 | Renรฉ Nussbaumer | """
|
230 | 271b7cf9 | Renรฉ Nussbaumer | bdev_s, offset, size = params |
231 | 271b7cf9 | Renรฉ Nussbaumer | bdev = objects.Disk.FromDict(bdev_s) |
232 | 271b7cf9 | Renรฉ Nussbaumer | return backend.BlockdevWipe(bdev, offset, size)
|
233 | 271b7cf9 | Renรฉ Nussbaumer | |
234 | 271b7cf9 | Renรฉ Nussbaumer | @staticmethod
|
235 | 3ecf6786 | Iustin Pop | def perspective_blockdev_remove(params): |
236 | 3ecf6786 | Iustin Pop | """Remove a block device.
|
237 | 3ecf6786 | Iustin Pop |
|
238 | 3ecf6786 | Iustin Pop | """
|
239 | a8083063 | Iustin Pop | bdev_s = params[0]
|
240 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
241 | 821d1bd1 | Iustin Pop | return backend.BlockdevRemove(bdev)
|
242 | a8083063 | Iustin Pop | |
243 | 3ecf6786 | Iustin Pop | @staticmethod
|
244 | f3e513ad | Iustin Pop | def perspective_blockdev_rename(params): |
245 | f3e513ad | Iustin Pop | """Remove a block device.
|
246 | f3e513ad | Iustin Pop |
|
247 | f3e513ad | Iustin Pop | """
|
248 | 8a31717c | Michael Hanselmann | devlist = [(objects.Disk.FromDict(ds), uid) for ds, uid in params[0]] |
249 | 821d1bd1 | Iustin Pop | return backend.BlockdevRename(devlist)
|
250 | f3e513ad | Iustin Pop | |
251 | f3e513ad | Iustin Pop | @staticmethod
|
252 | 3ecf6786 | Iustin Pop | def perspective_blockdev_assemble(params): |
253 | 3ecf6786 | Iustin Pop | """Assemble a block device.
|
254 | 3ecf6786 | Iustin Pop |
|
255 | 3ecf6786 | Iustin Pop | """
|
256 | c417e115 | Iustin Pop | bdev_s, owner, on_primary, idx = params |
257 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
258 | a8083063 | Iustin Pop | if bdev is None: |
259 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
260 | c417e115 | Iustin Pop | return backend.BlockdevAssemble(bdev, owner, on_primary, idx)
|
261 | a8083063 | Iustin Pop | |
262 | 3ecf6786 | Iustin Pop | @staticmethod
|
263 | 3ecf6786 | Iustin Pop | def perspective_blockdev_shutdown(params): |
264 | 3ecf6786 | Iustin Pop | """Shutdown a block device.
|
265 | 3ecf6786 | Iustin Pop |
|
266 | 3ecf6786 | Iustin Pop | """
|
267 | a8083063 | Iustin Pop | bdev_s = params[0]
|
268 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
269 | a8083063 | Iustin Pop | if bdev is None: |
270 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
271 | 821d1bd1 | Iustin Pop | return backend.BlockdevShutdown(bdev)
|
272 | a8083063 | Iustin Pop | |
273 | 3ecf6786 | Iustin Pop | @staticmethod
|
274 | 153d9724 | Iustin Pop | def perspective_blockdev_addchildren(params): |
275 | 3ecf6786 | Iustin Pop | """Add a child to a mirror device.
|
276 | 3ecf6786 | Iustin Pop |
|
277 | 3ecf6786 | Iustin Pop | Note: this is only valid for mirror devices. It's the caller's duty
|
278 | 3ecf6786 | Iustin Pop | to send a correct disk, otherwise we raise an error.
|
279 | 3ecf6786 | Iustin Pop |
|
280 | 3ecf6786 | Iustin Pop | """
|
281 | a8083063 | Iustin Pop | bdev_s, ndev_s = params |
282 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
283 | 153d9724 | Iustin Pop | ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s] |
284 | 153d9724 | Iustin Pop | if bdev is None or ndevs.count(None) > 0: |
285 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
286 | 821d1bd1 | Iustin Pop | return backend.BlockdevAddchildren(bdev, ndevs)
|
287 | a8083063 | Iustin Pop | |
288 | 3ecf6786 | Iustin Pop | @staticmethod
|
289 | 153d9724 | Iustin Pop | def perspective_blockdev_removechildren(params): |
290 | 3ecf6786 | Iustin Pop | """Remove a child from a mirror device.
|
291 | 3ecf6786 | Iustin Pop |
|
292 | 3ecf6786 | Iustin Pop | This is only valid for mirror devices, of course. It's the callers
|
293 | 3ecf6786 | Iustin Pop | duty to send a correct disk, otherwise we raise an error.
|
294 | 3ecf6786 | Iustin Pop |
|
295 | 3ecf6786 | Iustin Pop | """
|
296 | a8083063 | Iustin Pop | bdev_s, ndev_s = params |
297 | 319856a9 | Michael Hanselmann | bdev = objects.Disk.FromDict(bdev_s) |
298 | 153d9724 | Iustin Pop | ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s] |
299 | 153d9724 | Iustin Pop | if bdev is None or ndevs.count(None) > 0: |
300 | a8083063 | Iustin Pop | raise ValueError("can't unserialize data!") |
301 | 821d1bd1 | Iustin Pop | return backend.BlockdevRemovechildren(bdev, ndevs)
|
302 | a8083063 | Iustin Pop | |
303 | 3ecf6786 | Iustin Pop | @staticmethod
|
304 | 3ecf6786 | Iustin Pop | def perspective_blockdev_getmirrorstatus(params): |
305 | 3ecf6786 | Iustin Pop | """Return the mirror status for a list of disks.
|
306 | 3ecf6786 | Iustin Pop |
|
307 | 3ecf6786 | Iustin Pop | """
|
308 | 319856a9 | Michael Hanselmann | disks = [objects.Disk.FromDict(dsk_s) |
309 | e437117f | Michael Hanselmann | for dsk_s in params[0]] |
310 | 36145b12 | Michael Hanselmann | return [status.ToDict()
|
311 | 36145b12 | Michael Hanselmann | for status in backend.BlockdevGetmirrorstatus(disks)] |
312 | a8083063 | Iustin Pop | |
313 | 3ecf6786 | Iustin Pop | @staticmethod
|
314 | b8d26c6e | Michael Hanselmann | def perspective_blockdev_getmirrorstatus_multi(params): |
315 | b8d26c6e | Michael Hanselmann | """Return the mirror status for a list of disks.
|
316 | b8d26c6e | Michael Hanselmann |
|
317 | b8d26c6e | Michael Hanselmann | """
|
318 | b8d26c6e | Michael Hanselmann | (node_disks, ) = params |
319 | b8d26c6e | Michael Hanselmann | |
320 | 5449685e | Iustin Pop | disks = [objects.Disk.FromDict(dsk_s) for dsk_s in node_disks] |
321 | b8d26c6e | Michael Hanselmann | |
322 | c6a9dffa | Michael Hanselmann | result = [] |
323 | c6a9dffa | Michael Hanselmann | |
324 | c6a9dffa | Michael Hanselmann | for (success, status) in backend.BlockdevGetmirrorstatusMulti(disks): |
325 | c6a9dffa | Michael Hanselmann | if success:
|
326 | c6a9dffa | Michael Hanselmann | result.append((success, status.ToDict())) |
327 | c6a9dffa | Michael Hanselmann | else:
|
328 | c6a9dffa | Michael Hanselmann | result.append((success, status)) |
329 | c6a9dffa | Michael Hanselmann | |
330 | c6a9dffa | Michael Hanselmann | return result
|
331 | b8d26c6e | Michael Hanselmann | |
332 | b8d26c6e | Michael Hanselmann | @staticmethod
|
333 | 3ecf6786 | Iustin Pop | def perspective_blockdev_find(params): |
334 | 3ecf6786 | Iustin Pop | """Expose the FindBlockDevice functionality for a disk.
|
335 | 3ecf6786 | Iustin Pop |
|
336 | 3ecf6786 | Iustin Pop | This will try to find but not activate a disk.
|
337 | 3ecf6786 | Iustin Pop |
|
338 | 3ecf6786 | Iustin Pop | """
|
339 | 319856a9 | Michael Hanselmann | disk = objects.Disk.FromDict(params[0])
|
340 | ddfe2228 | Michael Hanselmann | |
341 | ddfe2228 | Michael Hanselmann | result = backend.BlockdevFind(disk) |
342 | ddfe2228 | Michael Hanselmann | if result is None: |
343 | ddfe2228 | Michael Hanselmann | return None |
344 | ddfe2228 | Michael Hanselmann | |
345 | ddfe2228 | Michael Hanselmann | return result.ToDict()
|
346 | a8083063 | Iustin Pop | |
347 | 3ecf6786 | Iustin Pop | @staticmethod
|
348 | 3ecf6786 | Iustin Pop | def perspective_blockdev_snapshot(params): |
349 | 3ecf6786 | Iustin Pop | """Create a snapshot device.
|
350 | 3ecf6786 | Iustin Pop |
|
351 | 3ecf6786 | Iustin Pop | Note that this is only valid for LVM disks, if we get passed
|
352 | 3ecf6786 | Iustin Pop | something else we raise an exception. The snapshot device can be
|
353 | 3ecf6786 | Iustin Pop | remove by calling the generic block device remove call.
|
354 | 3ecf6786 | Iustin Pop |
|
355 | 3ecf6786 | Iustin Pop | """
|
356 | 319856a9 | Michael Hanselmann | cfbd = objects.Disk.FromDict(params[0])
|
357 | 821d1bd1 | Iustin Pop | return backend.BlockdevSnapshot(cfbd)
|
358 | a8083063 | Iustin Pop | |
359 | 4c8ba8b3 | Iustin Pop | @staticmethod
|
360 | 4c8ba8b3 | Iustin Pop | def perspective_blockdev_grow(params): |
361 | 4c8ba8b3 | Iustin Pop | """Grow a stack of devices.
|
362 | 4c8ba8b3 | Iustin Pop |
|
363 | 4c8ba8b3 | Iustin Pop | """
|
364 | e43a624e | Bernardo Dal Seno | if len(params) < 5: |
365 | e43a624e | Bernardo Dal Seno | raise ValueError("Received only %s parameters in blockdev_grow," |
366 | e43a624e | Bernardo Dal Seno | " old master?" % len(params)) |
367 | 4c8ba8b3 | Iustin Pop | cfbd = objects.Disk.FromDict(params[0])
|
368 | 4c8ba8b3 | Iustin Pop | amount = params[1]
|
369 | a59faf4b | Iustin Pop | dryrun = params[2]
|
370 | cad0723b | Iustin Pop | backingstore = params[3]
|
371 | be9150ea | Bernardo Dal Seno | excl_stor = params[4]
|
372 | be9150ea | Bernardo Dal Seno | return backend.BlockdevGrow(cfbd, amount, dryrun, backingstore, excl_stor)
|
373 | 4c8ba8b3 | Iustin Pop | |
374 | d61cbe76 | Iustin Pop | @staticmethod
|
375 | d61cbe76 | Iustin Pop | def perspective_blockdev_close(params): |
376 | d61cbe76 | Iustin Pop | """Closes the given block devices.
|
377 | d61cbe76 | Iustin Pop |
|
378 | d61cbe76 | Iustin Pop | """
|
379 | b2e7666a | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in params[1]] |
380 | 821d1bd1 | Iustin Pop | return backend.BlockdevClose(params[0], disks) |
381 | d61cbe76 | Iustin Pop | |
382 | 968a7623 | Iustin Pop | @staticmethod
|
383 | 6ef8077e | Bernardo Dal Seno | def perspective_blockdev_getdimensions(params): |
384 | 968a7623 | Iustin Pop | """Compute the sizes of the given block devices.
|
385 | 968a7623 | Iustin Pop |
|
386 | 968a7623 | Iustin Pop | """
|
387 | 968a7623 | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in params[0]] |
388 | 6ef8077e | Bernardo Dal Seno | return backend.BlockdevGetdimensions(disks)
|
389 | 968a7623 | Iustin Pop | |
390 | 858f3d18 | Iustin Pop | @staticmethod
|
391 | 858f3d18 | Iustin Pop | def perspective_blockdev_export(params): |
392 | 858f3d18 | Iustin Pop | """Compute the sizes of the given block devices.
|
393 | 858f3d18 | Iustin Pop |
|
394 | 858f3d18 | Iustin Pop | """
|
395 | 858f3d18 | Iustin Pop | disk = objects.Disk.FromDict(params[0])
|
396 | 858f3d18 | Iustin Pop | dest_node, dest_path, cluster_name = params[1:]
|
397 | 858f3d18 | Iustin Pop | return backend.BlockdevExport(disk, dest_node, dest_path, cluster_name)
|
398 | 858f3d18 | Iustin Pop | |
399 | 48e175a2 | Iustin Pop | @staticmethod
|
400 | 48e175a2 | Iustin Pop | def perspective_blockdev_setinfo(params): |
401 | 48e175a2 | Iustin Pop | """Sets metadata information on the given block device.
|
402 | 48e175a2 | Iustin Pop |
|
403 | 48e175a2 | Iustin Pop | """
|
404 | 48e175a2 | Iustin Pop | (disk, info) = params |
405 | 48e175a2 | Iustin Pop | disk = objects.Disk.FromDict(disk) |
406 | 48e175a2 | Iustin Pop | return backend.BlockdevSetInfo(disk, info)
|
407 | 48e175a2 | Iustin Pop | |
408 | 6b93ec9d | Iustin Pop | # blockdev/drbd specific methods ----------
|
409 | 6b93ec9d | Iustin Pop | |
410 | 6b93ec9d | Iustin Pop | @staticmethod
|
411 | 6b93ec9d | Iustin Pop | def perspective_drbd_disconnect_net(params): |
412 | 6b93ec9d | Iustin Pop | """Disconnects the network connection of drbd disks.
|
413 | 6b93ec9d | Iustin Pop |
|
414 | 6b93ec9d | Iustin Pop | Note that this is only valid for drbd disks, so the members of the
|
415 | 6b93ec9d | Iustin Pop | disk list must all be drbd devices.
|
416 | 6b93ec9d | Iustin Pop |
|
417 | 6b93ec9d | Iustin Pop | """
|
418 | 1c3231aa | Thomas Thrainer | nodes_ip, disks, target_node_uuid = params |
419 | 6b93ec9d | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in disks] |
420 | 1c3231aa | Thomas Thrainer | return backend.DrbdDisconnectNet(target_node_uuid, nodes_ip, disks)
|
421 | 6b93ec9d | Iustin Pop | |
422 | 6b93ec9d | Iustin Pop | @staticmethod
|
423 | 6b93ec9d | Iustin Pop | def perspective_drbd_attach_net(params): |
424 | 6b93ec9d | Iustin Pop | """Attaches the network connection of drbd disks.
|
425 | 6b93ec9d | Iustin Pop |
|
426 | 6b93ec9d | Iustin Pop | Note that this is only valid for drbd disks, so the members of the
|
427 | 6b93ec9d | Iustin Pop | disk list must all be drbd devices.
|
428 | 6b93ec9d | Iustin Pop |
|
429 | 6b93ec9d | Iustin Pop | """
|
430 | 1c3231aa | Thomas Thrainer | nodes_ip, disks, instance_name, multimaster, target_node_uuid = params |
431 | 6b93ec9d | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in disks] |
432 | 1c3231aa | Thomas Thrainer | return backend.DrbdAttachNet(target_node_uuid, nodes_ip, disks,
|
433 | 1c3231aa | Thomas Thrainer | instance_name, multimaster) |
434 | 6b93ec9d | Iustin Pop | |
435 | 6b93ec9d | Iustin Pop | @staticmethod
|
436 | 6b93ec9d | Iustin Pop | def perspective_drbd_wait_sync(params): |
437 | 6b93ec9d | Iustin Pop | """Wait until DRBD disks are synched.
|
438 | 6b93ec9d | Iustin Pop |
|
439 | 6b93ec9d | Iustin Pop | Note that this is only valid for drbd disks, so the members of the
|
440 | 6b93ec9d | Iustin Pop | disk list must all be drbd devices.
|
441 | 6b93ec9d | Iustin Pop |
|
442 | 6b93ec9d | Iustin Pop | """
|
443 | 1c3231aa | Thomas Thrainer | nodes_ip, disks, target_node_uuid = params |
444 | 6b93ec9d | Iustin Pop | disks = [objects.Disk.FromDict(cf) for cf in disks] |
445 | 1c3231aa | Thomas Thrainer | return backend.DrbdWaitSync(target_node_uuid, nodes_ip, disks)
|
446 | 6b93ec9d | Iustin Pop | |
447 | c46b9782 | Luca Bigliardi | @staticmethod
|
448 | c46b9782 | Luca Bigliardi | def perspective_drbd_helper(params): |
449 | c46b9782 | Luca Bigliardi | """Query drbd helper.
|
450 | c46b9782 | Luca Bigliardi |
|
451 | c46b9782 | Luca Bigliardi | """
|
452 | c46b9782 | Luca Bigliardi | return backend.GetDrbdUsermodeHelper()
|
453 | c46b9782 | Luca Bigliardi | |
454 | a8083063 | Iustin Pop | # export/import --------------------------
|
455 | a8083063 | Iustin Pop | |
456 | 3ecf6786 | Iustin Pop | @staticmethod
|
457 | 3ecf6786 | Iustin Pop | def perspective_finalize_export(params): |
458 | 3ecf6786 | Iustin Pop | """Expose the finalize export functionality.
|
459 | a8083063 | Iustin Pop |
|
460 | 3ecf6786 | Iustin Pop | """
|
461 | 319856a9 | Michael Hanselmann | instance = objects.Instance.FromDict(params[0])
|
462 | 7b651654 | Michael Hanselmann | |
463 | 7b651654 | Michael Hanselmann | snap_disks = [] |
464 | 7b651654 | Michael Hanselmann | for disk in params[1]: |
465 | 7b651654 | Michael Hanselmann | if isinstance(disk, bool): |
466 | 7b651654 | Michael Hanselmann | snap_disks.append(disk) |
467 | 7b651654 | Michael Hanselmann | else:
|
468 | 7b651654 | Michael Hanselmann | snap_disks.append(objects.Disk.FromDict(disk)) |
469 | 7b651654 | Michael Hanselmann | |
470 | a8083063 | Iustin Pop | return backend.FinalizeExport(instance, snap_disks)
|
471 | a8083063 | Iustin Pop | |
472 | 3ecf6786 | Iustin Pop | @staticmethod
|
473 | 3ecf6786 | Iustin Pop | def perspective_export_info(params): |
474 | 3ecf6786 | Iustin Pop | """Query information about an existing export on this node.
|
475 | 3ecf6786 | Iustin Pop |
|
476 | 3ecf6786 | Iustin Pop | The given path may not contain an export, in which case we return
|
477 | 3ecf6786 | Iustin Pop | None.
|
478 | 3ecf6786 | Iustin Pop |
|
479 | 3ecf6786 | Iustin Pop | """
|
480 | 3ecf6786 | Iustin Pop | path = params[0]
|
481 | 3eccac06 | Iustin Pop | return backend.ExportInfo(path)
|
482 | a8083063 | Iustin Pop | |
483 | 3ecf6786 | Iustin Pop | @staticmethod
|
484 | 3ecf6786 | Iustin Pop | def perspective_export_list(params): |
485 | 3ecf6786 | Iustin Pop | """List the available exports on this node.
|
486 | 3ecf6786 | Iustin Pop |
|
487 | 3ecf6786 | Iustin Pop | Note that as opposed to export_info, which may query data about an
|
488 | 3ecf6786 | Iustin Pop | export in any path, this only queries the standard Ganeti path
|
489 | a5ce2ea2 | Michael Hanselmann | (pathutils.EXPORT_DIR).
|
490 | 3ecf6786 | Iustin Pop |
|
491 | 3ecf6786 | Iustin Pop | """
|
492 | a8083063 | Iustin Pop | return backend.ListExports()
|
493 | a8083063 | Iustin Pop | |
494 | 3ecf6786 | Iustin Pop | @staticmethod
|
495 | 3ecf6786 | Iustin Pop | def perspective_export_remove(params): |
496 | 3ecf6786 | Iustin Pop | """Remove an export.
|
497 | 3ecf6786 | Iustin Pop |
|
498 | 3ecf6786 | Iustin Pop | """
|
499 | a8083063 | Iustin Pop | export = params[0]
|
500 | a8083063 | Iustin Pop | return backend.RemoveExport(export)
|
501 | a8083063 | Iustin Pop | |
502 | 2be7273c | Apollon Oikonomopoulos | # block device ---------------------
|
503 | 2be7273c | Apollon Oikonomopoulos | @staticmethod
|
504 | 2be7273c | Apollon Oikonomopoulos | def perspective_bdev_sizes(params): |
505 | 2be7273c | Apollon Oikonomopoulos | """Query the list of block devices
|
506 | 2be7273c | Apollon Oikonomopoulos |
|
507 | 2be7273c | Apollon Oikonomopoulos | """
|
508 | 2be7273c | Apollon Oikonomopoulos | devices = params[0]
|
509 | 2be7273c | Apollon Oikonomopoulos | return backend.GetBlockDevSizes(devices)
|
510 | 2be7273c | Apollon Oikonomopoulos | |
511 | a8083063 | Iustin Pop | # volume --------------------------
|
512 | a8083063 | Iustin Pop | |
513 | 3ecf6786 | Iustin Pop | @staticmethod
|
514 | b2a6ccd4 | Iustin Pop | def perspective_lv_list(params): |
515 | 3ecf6786 | Iustin Pop | """Query the list of logical volumes in a given volume group.
|
516 | 3ecf6786 | Iustin Pop |
|
517 | 3ecf6786 | Iustin Pop | """
|
518 | a8083063 | Iustin Pop | vgname = params[0]
|
519 | c26a6bd2 | Iustin Pop | return backend.GetVolumeList(vgname)
|
520 | a8083063 | Iustin Pop | |
521 | 3ecf6786 | Iustin Pop | @staticmethod
|
522 | 3ecf6786 | Iustin Pop | def perspective_vg_list(params): |
523 | 3ecf6786 | Iustin Pop | """Query the list of volume groups.
|
524 | 3ecf6786 | Iustin Pop |
|
525 | 3ecf6786 | Iustin Pop | """
|
526 | a8083063 | Iustin Pop | return backend.ListVolumeGroups()
|
527 | a8083063 | Iustin Pop | |
528 | e337de97 | Michael Hanselmann | # Storage --------------------------
|
529 | e337de97 | Michael Hanselmann | |
530 | e337de97 | Michael Hanselmann | @staticmethod
|
531 | e337de97 | Michael Hanselmann | def perspective_storage_list(params): |
532 | e337de97 | Michael Hanselmann | """Get list of storage units.
|
533 | e337de97 | Michael Hanselmann |
|
534 | e337de97 | Michael Hanselmann | """
|
535 | e337de97 | Michael Hanselmann | (su_name, su_args, name, fields) = params |
536 | c23bb217 | Helga Velroyen | return container.GetStorage(su_name, *su_args).List(name, fields)
|
537 | e337de97 | Michael Hanselmann | |
538 | 8979196a | Michael Hanselmann | @staticmethod
|
539 | 8979196a | Michael Hanselmann | def perspective_storage_modify(params): |
540 | 8979196a | Michael Hanselmann | """Modify a storage unit.
|
541 | 8979196a | Michael Hanselmann |
|
542 | 8979196a | Michael Hanselmann | """
|
543 | 8979196a | Michael Hanselmann | (su_name, su_args, name, changes) = params |
544 | c23bb217 | Helga Velroyen | return container.GetStorage(su_name, *su_args).Modify(name, changes)
|
545 | 8979196a | Michael Hanselmann | |
546 | 637b8d7e | Michael Hanselmann | @staticmethod
|
547 | 637b8d7e | Michael Hanselmann | def perspective_storage_execute(params): |
548 | 637b8d7e | Michael Hanselmann | """Execute an operation on a storage unit.
|
549 | 637b8d7e | Michael Hanselmann |
|
550 | 637b8d7e | Michael Hanselmann | """
|
551 | 637b8d7e | Michael Hanselmann | (su_name, su_args, name, op) = params |
552 | c23bb217 | Helga Velroyen | return container.GetStorage(su_name, *su_args).Execute(name, op)
|
553 | 637b8d7e | Michael Hanselmann | |
554 | a8083063 | Iustin Pop | # bridge --------------------------
|
555 | a8083063 | Iustin Pop | |
556 | 3ecf6786 | Iustin Pop | @staticmethod
|
557 | 3ecf6786 | Iustin Pop | def perspective_bridges_exist(params): |
558 | 3ecf6786 | Iustin Pop | """Check if all bridges given exist on this node.
|
559 | 3ecf6786 | Iustin Pop |
|
560 | 3ecf6786 | Iustin Pop | """
|
561 | a8083063 | Iustin Pop | bridges_list = params[0]
|
562 | a8083063 | Iustin Pop | return backend.BridgesExist(bridges_list)
|
563 | a8083063 | Iustin Pop | |
564 | a8083063 | Iustin Pop | # instance --------------------------
|
565 | a8083063 | Iustin Pop | |
566 | 3ecf6786 | Iustin Pop | @staticmethod
|
567 | 3ecf6786 | Iustin Pop | def perspective_instance_os_add(params): |
568 | 3ecf6786 | Iustin Pop | """Install an OS on a given instance.
|
569 | 3ecf6786 | Iustin Pop |
|
570 | 3ecf6786 | Iustin Pop | """
|
571 | d15a9ad3 | Guido Trotter | inst_s = params[0]
|
572 | 319856a9 | Michael Hanselmann | inst = objects.Instance.FromDict(inst_s) |
573 | e557bae9 | Guido Trotter | reinstall = params[1]
|
574 | 4a0e011f | Iustin Pop | debug = params[2]
|
575 | 4a0e011f | Iustin Pop | return backend.InstanceOsAdd(inst, reinstall, debug)
|
576 | a8083063 | Iustin Pop | |
577 | 3ecf6786 | Iustin Pop | @staticmethod
|
578 | decd5f45 | Iustin Pop | def perspective_instance_run_rename(params): |
579 | decd5f45 | Iustin Pop | """Runs the OS rename script for an instance.
|
580 | decd5f45 | Iustin Pop |
|
581 | decd5f45 | Iustin Pop | """
|
582 | 4a0e011f | Iustin Pop | inst_s, old_name, debug = params |
583 | 319856a9 | Michael Hanselmann | inst = objects.Instance.FromDict(inst_s) |
584 | 4a0e011f | Iustin Pop | return backend.RunRenameInstance(inst, old_name, debug)
|
585 | decd5f45 | Iustin Pop | |
586 | decd5f45 | Iustin Pop | @staticmethod
|
587 | 3ecf6786 | Iustin Pop | def perspective_instance_shutdown(params): |
588 | 3ecf6786 | Iustin Pop | """Shutdown an instance.
|
589 | 3ecf6786 | Iustin Pop |
|
590 | 3ecf6786 | Iustin Pop | """
|
591 | 319856a9 | Michael Hanselmann | instance = objects.Instance.FromDict(params[0])
|
592 | 6263189c | Guido Trotter | timeout = params[1]
|
593 | 1f350e0f | Michele Tartara | trail = params[2]
|
594 | 1f350e0f | Michele Tartara | _extendReasonTrail(trail, "shutdown")
|
595 | 1f350e0f | Michele Tartara | return backend.InstanceShutdown(instance, timeout, trail)
|
596 | a8083063 | Iustin Pop | |
597 | 3ecf6786 | Iustin Pop | @staticmethod
|
598 | 3ecf6786 | Iustin Pop | def perspective_instance_start(params): |
599 | 3ecf6786 | Iustin Pop | """Start an instance.
|
600 | 3ecf6786 | Iustin Pop |
|
601 | 3ecf6786 | Iustin Pop | """
|
602 | 1fa6fcba | Michele Tartara | (instance_name, startup_paused, trail) = params |
603 | 323f9095 | Stephen Shirley | instance = objects.Instance.FromDict(instance_name) |
604 | 1fa6fcba | Michele Tartara | _extendReasonTrail(trail, "start")
|
605 | 1fa6fcba | Michele Tartara | return backend.StartInstance(instance, startup_paused, trail)
|
606 | a8083063 | Iustin Pop | |
607 | 3ecf6786 | Iustin Pop | @staticmethod
|
608 | 6906a9d8 | Guido Trotter | def perspective_migration_info(params): |
609 | 6906a9d8 | Guido Trotter | """Gather information about an instance to be migrated.
|
610 | 6906a9d8 | Guido Trotter |
|
611 | 6906a9d8 | Guido Trotter | """
|
612 | 6906a9d8 | Guido Trotter | instance = objects.Instance.FromDict(params[0])
|
613 | 6906a9d8 | Guido Trotter | return backend.MigrationInfo(instance)
|
614 | 6906a9d8 | Guido Trotter | |
615 | 6906a9d8 | Guido Trotter | @staticmethod
|
616 | 6906a9d8 | Guido Trotter | def perspective_accept_instance(params): |
617 | 6906a9d8 | Guido Trotter | """Prepare the node to accept an instance.
|
618 | 6906a9d8 | Guido Trotter |
|
619 | 6906a9d8 | Guido Trotter | """
|
620 | 6906a9d8 | Guido Trotter | instance, info, target = params |
621 | 6906a9d8 | Guido Trotter | instance = objects.Instance.FromDict(instance) |
622 | 6906a9d8 | Guido Trotter | return backend.AcceptInstance(instance, info, target)
|
623 | 6906a9d8 | Guido Trotter | |
624 | 6906a9d8 | Guido Trotter | @staticmethod
|
625 | 6a1434d7 | Andrea Spadaccini | def perspective_instance_finalize_migration_dst(params): |
626 | 6a1434d7 | Andrea Spadaccini | """Finalize the instance migration on the destination node.
|
627 | 6906a9d8 | Guido Trotter |
|
628 | 6906a9d8 | Guido Trotter | """
|
629 | 6906a9d8 | Guido Trotter | instance, info, success = params |
630 | 6906a9d8 | Guido Trotter | instance = objects.Instance.FromDict(instance) |
631 | 6a1434d7 | Andrea Spadaccini | return backend.FinalizeMigrationDst(instance, info, success)
|
632 | 6906a9d8 | Guido Trotter | |
633 | 6906a9d8 | Guido Trotter | @staticmethod
|
634 | 2a10865c | Iustin Pop | def perspective_instance_migrate(params): |
635 | 2a10865c | Iustin Pop | """Migrates an instance.
|
636 | 2a10865c | Iustin Pop |
|
637 | 2a10865c | Iustin Pop | """
|
638 | bc0a2284 | Helga Velroyen | cluster_name, instance, target, live = params |
639 | 9f0e6b37 | Iustin Pop | instance = objects.Instance.FromDict(instance) |
640 | bc0a2284 | Helga Velroyen | return backend.MigrateInstance(cluster_name, instance, target, live)
|
641 | 2a10865c | Iustin Pop | |
642 | 2a10865c | Iustin Pop | @staticmethod
|
643 | 6a1434d7 | Andrea Spadaccini | def perspective_instance_finalize_migration_src(params): |
644 | 6a1434d7 | Andrea Spadaccini | """Finalize the instance migration on the source node.
|
645 | 6a1434d7 | Andrea Spadaccini |
|
646 | 6a1434d7 | Andrea Spadaccini | """
|
647 | 6a1434d7 | Andrea Spadaccini | instance, success, live = params |
648 | 6a1434d7 | Andrea Spadaccini | instance = objects.Instance.FromDict(instance) |
649 | 6a1434d7 | Andrea Spadaccini | return backend.FinalizeMigrationSource(instance, success, live)
|
650 | 6a1434d7 | Andrea Spadaccini | |
651 | 6a1434d7 | Andrea Spadaccini | @staticmethod
|
652 | 6a1434d7 | Andrea Spadaccini | def perspective_instance_get_migration_status(params): |
653 | 6a1434d7 | Andrea Spadaccini | """Reports migration status.
|
654 | 6a1434d7 | Andrea Spadaccini |
|
655 | 6a1434d7 | Andrea Spadaccini | """
|
656 | 6a1434d7 | Andrea Spadaccini | instance = objects.Instance.FromDict(params[0])
|
657 | 6a1434d7 | Andrea Spadaccini | return backend.GetMigrationStatus(instance).ToDict()
|
658 | 6a1434d7 | Andrea Spadaccini | |
659 | 6a1434d7 | Andrea Spadaccini | @staticmethod
|
660 | 007a2f3e | Alexander Schreiber | def perspective_instance_reboot(params): |
661 | 007a2f3e | Alexander Schreiber | """Reboot an instance.
|
662 | 007a2f3e | Alexander Schreiber |
|
663 | 007a2f3e | Alexander Schreiber | """
|
664 | 007a2f3e | Alexander Schreiber | instance = objects.Instance.FromDict(params[0])
|
665 | 007a2f3e | Alexander Schreiber | reboot_type = params[1]
|
666 | 17c3f802 | Guido Trotter | shutdown_timeout = params[2]
|
667 | 55cec070 | Michele Tartara | trail = params[3]
|
668 | 55cec070 | Michele Tartara | _extendReasonTrail(trail, "reboot")
|
669 | 55cec070 | Michele Tartara | return backend.InstanceReboot(instance, reboot_type, shutdown_timeout,
|
670 | 55cec070 | Michele Tartara | trail) |
671 | 007a2f3e | Alexander Schreiber | |
672 | 007a2f3e | Alexander Schreiber | @staticmethod
|
673 | ebe466d8 | Guido Trotter | def perspective_instance_balloon_memory(params): |
674 | ebe466d8 | Guido Trotter | """Modify instance runtime memory.
|
675 | ebe466d8 | Guido Trotter |
|
676 | ebe466d8 | Guido Trotter | """
|
677 | ebe466d8 | Guido Trotter | instance_dict, memory = params |
678 | ebe466d8 | Guido Trotter | instance = objects.Instance.FromDict(instance_dict) |
679 | ebe466d8 | Guido Trotter | return backend.InstanceBalloonMemory(instance, memory)
|
680 | ebe466d8 | Guido Trotter | |
681 | ebe466d8 | Guido Trotter | @staticmethod
|
682 | 3ecf6786 | Iustin Pop | def perspective_instance_info(params): |
683 | 3ecf6786 | Iustin Pop | """Query instance information.
|
684 | 3ecf6786 | Iustin Pop |
|
685 | 3ecf6786 | Iustin Pop | """
|
686 | 0bbec3af | Helga Velroyen | (instance_name, hypervisor_name, hvparams) = params |
687 | 0bbec3af | Helga Velroyen | return backend.GetInstanceInfo(instance_name, hypervisor_name, hvparams)
|
688 | a8083063 | Iustin Pop | |
689 | 3ecf6786 | Iustin Pop | @staticmethod
|
690 | 56e7640c | Iustin Pop | def perspective_instance_migratable(params): |
691 | 56e7640c | Iustin Pop | """Query whether the specified instance can be migrated.
|
692 | 56e7640c | Iustin Pop |
|
693 | 56e7640c | Iustin Pop | """
|
694 | 56e7640c | Iustin Pop | instance = objects.Instance.FromDict(params[0])
|
695 | 56e7640c | Iustin Pop | return backend.GetInstanceMigratable(instance)
|
696 | 56e7640c | Iustin Pop | |
697 | 56e7640c | Iustin Pop | @staticmethod
|
698 | 3ecf6786 | Iustin Pop | def perspective_all_instances_info(params): |
699 | 3ecf6786 | Iustin Pop | """Query information about all instances.
|
700 | 3ecf6786 | Iustin Pop |
|
701 | 3ecf6786 | Iustin Pop | """
|
702 | 0200a1af | Helga Velroyen | (hypervisor_list, all_hvparams) = params |
703 | 0200a1af | Helga Velroyen | return backend.GetAllInstancesInfo(hypervisor_list, all_hvparams)
|
704 | a8083063 | Iustin Pop | |
705 | 3ecf6786 | Iustin Pop | @staticmethod
|
706 | 3ecf6786 | Iustin Pop | def perspective_instance_list(params): |
707 | 3ecf6786 | Iustin Pop | """Query the list of running instances.
|
708 | 3ecf6786 | Iustin Pop |
|
709 | 3ecf6786 | Iustin Pop | """
|
710 | 8ac806e6 | Helga Velroyen | (hypervisor_list, hvparams) = params |
711 | 8ac806e6 | Helga Velroyen | return backend.GetInstanceList(hypervisor_list, hvparams)
|
712 | a8083063 | Iustin Pop | |
713 | a8083063 | Iustin Pop | # node --------------------------
|
714 | a8083063 | Iustin Pop | |
715 | 3ecf6786 | Iustin Pop | @staticmethod
|
716 | caad16e2 | Iustin Pop | def perspective_node_has_ip_address(params): |
717 | caad16e2 | Iustin Pop | """Checks if a node has the given ip address.
|
718 | caad16e2 | Iustin Pop |
|
719 | caad16e2 | Iustin Pop | """
|
720 | 8b312c1d | Manuel Franceschini | return netutils.IPAddress.Own(params[0]) |
721 | caad16e2 | Iustin Pop | |
722 | caad16e2 | Iustin Pop | @staticmethod
|
723 | 3ecf6786 | Iustin Pop | def perspective_node_info(params): |
724 | 3ecf6786 | Iustin Pop | """Query node information.
|
725 | 3ecf6786 | Iustin Pop |
|
726 | 3ecf6786 | Iustin Pop | """
|
727 | 030ab01a | Helga Velroyen | (storage_units, hv_specs, excl_stor) = params |
728 | 030ab01a | Helga Velroyen | return backend.GetNodeInfo(storage_units, hv_specs, excl_stor)
|
729 | a8083063 | Iustin Pop | |
730 | 3ecf6786 | Iustin Pop | @staticmethod
|
731 | 19ddc57a | Renรฉ Nussbaumer | def perspective_etc_hosts_modify(params): |
732 | 19ddc57a | Renรฉ Nussbaumer | """Modify a node entry in /etc/hosts.
|
733 | 19ddc57a | Renรฉ Nussbaumer |
|
734 | 19ddc57a | Renรฉ Nussbaumer | """
|
735 | 19ddc57a | Renรฉ Nussbaumer | backend.EtcHostsModify(params[0], params[1], params[2]) |
736 | 19ddc57a | Renรฉ Nussbaumer | |
737 | 19ddc57a | Renรฉ Nussbaumer | return True |
738 | 19ddc57a | Renรฉ Nussbaumer | |
739 | 19ddc57a | Renรฉ Nussbaumer | @staticmethod
|
740 | 3ecf6786 | Iustin Pop | def perspective_node_verify(params): |
741 | 3ecf6786 | Iustin Pop | """Run a verify sequence on this node.
|
742 | 3ecf6786 | Iustin Pop |
|
743 | 3ecf6786 | Iustin Pop | """
|
744 | 5b0dfcef | Helga Velroyen | (what, cluster_name, hvparams) = params |
745 | 5b0dfcef | Helga Velroyen | return backend.VerifyNode(what, cluster_name, hvparams)
|
746 | a8083063 | Iustin Pop | |
747 | 14fe92c7 | Bernardo Dal Seno | @classmethod
|
748 | 14fe92c7 | Bernardo Dal Seno | def perspective_node_verify_light(cls, params): |
749 | 14fe92c7 | Bernardo Dal Seno | """Run a light verify sequence on this node.
|
750 | 14fe92c7 | Bernardo Dal Seno |
|
751 | 14fe92c7 | Bernardo Dal Seno | """
|
752 | 14fe92c7 | Bernardo Dal Seno | # So far it's the same as the normal node_verify
|
753 | 14fe92c7 | Bernardo Dal Seno | return cls.perspective_node_verify(params)
|
754 | 14fe92c7 | Bernardo Dal Seno | |
755 | 3ecf6786 | Iustin Pop | @staticmethod
|
756 | fb460cf7 | Andrea Spadaccini | def perspective_node_start_master_daemons(params): |
757 | fb460cf7 | Andrea Spadaccini | """Start the master daemons on this node.
|
758 | 3ecf6786 | Iustin Pop |
|
759 | 3ecf6786 | Iustin Pop | """
|
760 | fb460cf7 | Andrea Spadaccini | return backend.StartMasterDaemons(params[0]) |
761 | fb460cf7 | Andrea Spadaccini | |
762 | fb460cf7 | Andrea Spadaccini | @staticmethod
|
763 | fb460cf7 | Andrea Spadaccini | def perspective_node_activate_master_ip(params): |
764 | fb460cf7 | Andrea Spadaccini | """Activate the master IP on this node.
|
765 | fb460cf7 | Andrea Spadaccini |
|
766 | fb460cf7 | Andrea Spadaccini | """
|
767 | c79198a0 | Andrea Spadaccini | master_params = objects.MasterNetworkParameters.FromDict(params[0])
|
768 | 57c7bc57 | Andrea Spadaccini | return backend.ActivateMasterIp(master_params, params[1]) |
769 | fb460cf7 | Andrea Spadaccini | |
770 | fb460cf7 | Andrea Spadaccini | @staticmethod
|
771 | fb460cf7 | Andrea Spadaccini | def perspective_node_deactivate_master_ip(params): |
772 | fb460cf7 | Andrea Spadaccini | """Deactivate the master IP on this node.
|
773 | fb460cf7 | Andrea Spadaccini |
|
774 | fb460cf7 | Andrea Spadaccini | """
|
775 | c79198a0 | Andrea Spadaccini | master_params = objects.MasterNetworkParameters.FromDict(params[0])
|
776 | 57c7bc57 | Andrea Spadaccini | return backend.DeactivateMasterIp(master_params, params[1]) |
777 | a8083063 | Iustin Pop | |
778 | 3ecf6786 | Iustin Pop | @staticmethod
|
779 | 3ecf6786 | Iustin Pop | def perspective_node_stop_master(params): |
780 | 7c74bbe0 | Andrea Spadaccini | """Stops master daemons on this node.
|
781 | 3ecf6786 | Iustin Pop |
|
782 | 3ecf6786 | Iustin Pop | """
|
783 | fb460cf7 | Andrea Spadaccini | return backend.StopMasterDaemons()
|
784 | a8083063 | Iustin Pop | |
785 | 3ecf6786 | Iustin Pop | @staticmethod
|
786 | 5a8648eb | Andrea Spadaccini | def perspective_node_change_master_netmask(params): |
787 | 5a8648eb | Andrea Spadaccini | """Change the master IP netmask.
|
788 | 5a8648eb | Andrea Spadaccini |
|
789 | 5a8648eb | Andrea Spadaccini | """
|
790 | 41e079ce | Andrea Spadaccini | return backend.ChangeMasterNetmask(params[0], params[1], params[2], |
791 | 41e079ce | Andrea Spadaccini | params[3])
|
792 | 5a8648eb | Andrea Spadaccini | |
793 | 5a8648eb | Andrea Spadaccini | @staticmethod
|
794 | 3ecf6786 | Iustin Pop | def perspective_node_leave_cluster(params): |
795 | 3ecf6786 | Iustin Pop | """Cleanup after leaving a cluster.
|
796 | 3ecf6786 | Iustin Pop |
|
797 | 3ecf6786 | Iustin Pop | """
|
798 | b989b9d9 | Ken Wehr | return backend.LeaveCluster(params[0]) |
799 | a8083063 | Iustin Pop | |
800 | 3ecf6786 | Iustin Pop | @staticmethod
|
801 | 3ecf6786 | Iustin Pop | def perspective_node_volumes(params): |
802 | 3ecf6786 | Iustin Pop | """Query the list of all logical volume groups.
|
803 | 3ecf6786 | Iustin Pop |
|
804 | 3ecf6786 | Iustin Pop | """
|
805 | dcb93971 | Michael Hanselmann | return backend.NodeVolumes()
|
806 | dcb93971 | Michael Hanselmann | |
807 | 56aa9fd5 | Iustin Pop | @staticmethod
|
808 | 56aa9fd5 | Iustin Pop | def perspective_node_demote_from_mc(params): |
809 | 56aa9fd5 | Iustin Pop | """Demote a node from the master candidate role.
|
810 | 56aa9fd5 | Iustin Pop |
|
811 | 56aa9fd5 | Iustin Pop | """
|
812 | 56aa9fd5 | Iustin Pop | return backend.DemoteFromMC()
|
813 | 56aa9fd5 | Iustin Pop | |
814 | f5118ade | Iustin Pop | @staticmethod
|
815 | f5118ade | Iustin Pop | def perspective_node_powercycle(params): |
816 | f5118ade | Iustin Pop | """Tries to powercycle the nod.
|
817 | f5118ade | Iustin Pop |
|
818 | f5118ade | Iustin Pop | """
|
819 | 8ef418bb | Helga Velroyen | (hypervisor_type, hvparams) = params |
820 | 8ef418bb | Helga Velroyen | return backend.PowercycleNode(hypervisor_type, hvparams)
|
821 | f5118ade | Iustin Pop | |
822 | a8083063 | Iustin Pop | # cluster --------------------------
|
823 | a8083063 | Iustin Pop | |
824 | 3ecf6786 | Iustin Pop | @staticmethod
|
825 | 3ecf6786 | Iustin Pop | def perspective_version(params): |
826 | 3ecf6786 | Iustin Pop | """Query version information.
|
827 | 3ecf6786 | Iustin Pop |
|
828 | 3ecf6786 | Iustin Pop | """
|
829 | c26a6bd2 | Iustin Pop | return constants.PROTOCOL_VERSION
|
830 | a8083063 | Iustin Pop | |
831 | 3ecf6786 | Iustin Pop | @staticmethod
|
832 | 3ecf6786 | Iustin Pop | def perspective_upload_file(params): |
833 | 3ecf6786 | Iustin Pop | """Upload a file.
|
834 | 3ecf6786 | Iustin Pop |
|
835 | 3ecf6786 | Iustin Pop | Note that the backend implementation imposes strict rules on which
|
836 | 3ecf6786 | Iustin Pop | files are accepted.
|
837 | 3ecf6786 | Iustin Pop |
|
838 | 3ecf6786 | Iustin Pop | """
|
839 | 415a7304 | Michael Hanselmann | return backend.UploadFile(*(params[0])) |
840 | a8083063 | Iustin Pop | |
841 | 4e071d3b | Iustin Pop | @staticmethod
|
842 | 4e071d3b | Iustin Pop | def perspective_master_info(params): |
843 | 4e071d3b | Iustin Pop | """Query master information.
|
844 | 4e071d3b | Iustin Pop |
|
845 | 4e071d3b | Iustin Pop | """
|
846 | 4e071d3b | Iustin Pop | return backend.GetMasterInfo()
|
847 | a8083063 | Iustin Pop | |
848 | 6ddc95ec | Michael Hanselmann | @staticmethod
|
849 | 4f6014d4 | Renรฉ Nussbaumer | def perspective_run_oob(params): |
850 | 4f6014d4 | Renรฉ Nussbaumer | """Runs oob on node.
|
851 | 4f6014d4 | Renรฉ Nussbaumer |
|
852 | 4f6014d4 | Renรฉ Nussbaumer | """
|
853 | 1aa88d95 | Renรฉ Nussbaumer | output = backend.RunOob(params[0], params[1], params[2], params[3]) |
854 | 1aa88d95 | Renรฉ Nussbaumer | if output:
|
855 | 1aa88d95 | Renรฉ Nussbaumer | result = serializer.LoadJson(output) |
856 | 1aa88d95 | Renรฉ Nussbaumer | else:
|
857 | 1aa88d95 | Renรฉ Nussbaumer | result = None
|
858 | 1aa88d95 | Renรฉ Nussbaumer | return result
|
859 | 4f6014d4 | Renรฉ Nussbaumer | |
860 | 4f6014d4 | Renรฉ Nussbaumer | @staticmethod
|
861 | db2203e0 | Michael Hanselmann | def perspective_restricted_command(params): |
862 | db2203e0 | Michael Hanselmann | """Runs a restricted command.
|
863 | db2203e0 | Michael Hanselmann |
|
864 | db2203e0 | Michael Hanselmann | """
|
865 | db2203e0 | Michael Hanselmann | (cmd, ) = params |
866 | db2203e0 | Michael Hanselmann | |
867 | 42bd26e8 | Michael Hanselmann | return backend.RunRestrictedCmd(cmd)
|
868 | db2203e0 | Michael Hanselmann | |
869 | db2203e0 | Michael Hanselmann | @staticmethod
|
870 | 6ddc95ec | Michael Hanselmann | def perspective_write_ssconf_files(params): |
871 | 6ddc95ec | Michael Hanselmann | """Write ssconf files.
|
872 | 6ddc95ec | Michael Hanselmann |
|
873 | 6ddc95ec | Michael Hanselmann | """
|
874 | 03d1dba2 | Michael Hanselmann | (values,) = params |
875 | ee501db1 | Michael Hanselmann | return ssconf.WriteSsconfFiles(values)
|
876 | 6ddc95ec | Michael Hanselmann | |
877 | 99e222b1 | Michael Hanselmann | @staticmethod
|
878 | ec5af888 | Michael Hanselmann | def perspective_get_watcher_pause(params): |
879 | ec5af888 | Michael Hanselmann | """Get watcher pause end.
|
880 | ec5af888 | Michael Hanselmann |
|
881 | ec5af888 | Michael Hanselmann | """
|
882 | ec5af888 | Michael Hanselmann | return utils.ReadWatcherPauseFile(pathutils.WATCHER_PAUSEFILE)
|
883 | ec5af888 | Michael Hanselmann | |
884 | ec5af888 | Michael Hanselmann | @staticmethod
|
885 | 99e222b1 | Michael Hanselmann | def perspective_set_watcher_pause(params): |
886 | 99e222b1 | Michael Hanselmann | """Set watcher pause.
|
887 | 99e222b1 | Michael Hanselmann |
|
888 | 99e222b1 | Michael Hanselmann | """
|
889 | 99e222b1 | Michael Hanselmann | (until, ) = params |
890 | 99e222b1 | Michael Hanselmann | return backend.SetWatcherPause(until)
|
891 | 99e222b1 | Michael Hanselmann | |
892 | a8083063 | Iustin Pop | # os -----------------------
|
893 | a8083063 | Iustin Pop | |
894 | 3ecf6786 | Iustin Pop | @staticmethod
|
895 | 3ecf6786 | Iustin Pop | def perspective_os_diagnose(params): |
896 | 3ecf6786 | Iustin Pop | """Query detailed information about existing OSes.
|
897 | 3ecf6786 | Iustin Pop |
|
898 | 3ecf6786 | Iustin Pop | """
|
899 | 255dcebd | Iustin Pop | return backend.DiagnoseOS()
|
900 | a8083063 | Iustin Pop | |
901 | 3ecf6786 | Iustin Pop | @staticmethod
|
902 | 3ecf6786 | Iustin Pop | def perspective_os_get(params): |
903 | 3ecf6786 | Iustin Pop | """Query information about a given OS.
|
904 | 3ecf6786 | Iustin Pop |
|
905 | 3ecf6786 | Iustin Pop | """
|
906 | a8083063 | Iustin Pop | name = params[0]
|
907 | 255dcebd | Iustin Pop | os_obj = backend.OSFromDisk(name) |
908 | c26a6bd2 | Iustin Pop | return os_obj.ToDict()
|
909 | a8083063 | Iustin Pop | |
910 | acd9ff9e | Iustin Pop | @staticmethod
|
911 | acd9ff9e | Iustin Pop | def perspective_os_validate(params): |
912 | acd9ff9e | Iustin Pop | """Run a given OS' validation routine.
|
913 | acd9ff9e | Iustin Pop |
|
914 | acd9ff9e | Iustin Pop | """
|
915 | acd9ff9e | Iustin Pop | required, name, checks, params = params |
916 | acd9ff9e | Iustin Pop | return backend.ValidateOS(required, name, checks, params)
|
917 | acd9ff9e | Iustin Pop | |
918 | b954f097 | Constantinos Venetsanopoulos | # extstorage -----------------------
|
919 | b954f097 | Constantinos Venetsanopoulos | |
920 | b954f097 | Constantinos Venetsanopoulos | @staticmethod
|
921 | b954f097 | Constantinos Venetsanopoulos | def perspective_extstorage_diagnose(params): |
922 | b954f097 | Constantinos Venetsanopoulos | """Query detailed information about existing extstorage providers.
|
923 | b954f097 | Constantinos Venetsanopoulos |
|
924 | b954f097 | Constantinos Venetsanopoulos | """
|
925 | b954f097 | Constantinos Venetsanopoulos | return backend.DiagnoseExtStorage()
|
926 | b954f097 | Constantinos Venetsanopoulos | |
927 | a8083063 | Iustin Pop | # hooks -----------------------
|
928 | a8083063 | Iustin Pop | |
929 | 3ecf6786 | Iustin Pop | @staticmethod
|
930 | 3ecf6786 | Iustin Pop | def perspective_hooks_runner(params): |
931 | 3ecf6786 | Iustin Pop | """Run hook scripts.
|
932 | 3ecf6786 | Iustin Pop |
|
933 | 3ecf6786 | Iustin Pop | """
|
934 | a8083063 | Iustin Pop | hpath, phase, env = params |
935 | a8083063 | Iustin Pop | hr = backend.HooksRunner() |
936 | a8083063 | Iustin Pop | return hr.RunHooks(hpath, phase, env)
|
937 | a8083063 | Iustin Pop | |
938 | 8d528b7c | Iustin Pop | # iallocator -----------------
|
939 | 8d528b7c | Iustin Pop | |
940 | 8d528b7c | Iustin Pop | @staticmethod
|
941 | 8d528b7c | Iustin Pop | def perspective_iallocator_runner(params): |
942 | 8d528b7c | Iustin Pop | """Run an iallocator script.
|
943 | 8d528b7c | Iustin Pop |
|
944 | 8d528b7c | Iustin Pop | """
|
945 | 8d528b7c | Iustin Pop | name, idata = params |
946 | 8d528b7c | Iustin Pop | iar = backend.IAllocatorRunner() |
947 | 8d528b7c | Iustin Pop | return iar.Run(name, idata)
|
948 | 8d528b7c | Iustin Pop | |
949 | 06009e27 | Iustin Pop | # test -----------------------
|
950 | 06009e27 | Iustin Pop | |
951 | 06009e27 | Iustin Pop | @staticmethod
|
952 | 06009e27 | Iustin Pop | def perspective_test_delay(params): |
953 | 06009e27 | Iustin Pop | """Run test delay.
|
954 | 06009e27 | Iustin Pop |
|
955 | 06009e27 | Iustin Pop | """
|
956 | 06009e27 | Iustin Pop | duration = params[0]
|
957 | c26a6bd2 | Iustin Pop | status, rval = utils.TestDelay(duration) |
958 | c26a6bd2 | Iustin Pop | if not status: |
959 | c26a6bd2 | Iustin Pop | raise backend.RPCFail(rval)
|
960 | c26a6bd2 | Iustin Pop | return rval
|
961 | 06009e27 | Iustin Pop | |
962 | 4e071d3b | Iustin Pop | # file storage ---------------
|
963 | 4e071d3b | Iustin Pop | |
964 | a5d7fb43 | Manuel Franceschini | @staticmethod
|
965 | a5d7fb43 | Manuel Franceschini | def perspective_file_storage_dir_create(params): |
966 | a5d7fb43 | Manuel Franceschini | """Create the file storage directory.
|
967 | a5d7fb43 | Manuel Franceschini |
|
968 | a5d7fb43 | Manuel Franceschini | """
|
969 | a5d7fb43 | Manuel Franceschini | file_storage_dir = params[0]
|
970 | a5d7fb43 | Manuel Franceschini | return backend.CreateFileStorageDir(file_storage_dir)
|
971 | a5d7fb43 | Manuel Franceschini | |
972 | a5d7fb43 | Manuel Franceschini | @staticmethod
|
973 | a5d7fb43 | Manuel Franceschini | def perspective_file_storage_dir_remove(params): |
974 | a5d7fb43 | Manuel Franceschini | """Remove the file storage directory.
|
975 | a5d7fb43 | Manuel Franceschini |
|
976 | a5d7fb43 | Manuel Franceschini | """
|
977 | a5d7fb43 | Manuel Franceschini | file_storage_dir = params[0]
|
978 | a5d7fb43 | Manuel Franceschini | return backend.RemoveFileStorageDir(file_storage_dir)
|
979 | a5d7fb43 | Manuel Franceschini | |
980 | a5d7fb43 | Manuel Franceschini | @staticmethod
|
981 | a5d7fb43 | Manuel Franceschini | def perspective_file_storage_dir_rename(params): |
982 | a5d7fb43 | Manuel Franceschini | """Rename the file storage directory.
|
983 | a5d7fb43 | Manuel Franceschini |
|
984 | a5d7fb43 | Manuel Franceschini | """
|
985 | a5d7fb43 | Manuel Franceschini | old_file_storage_dir = params[0]
|
986 | a5d7fb43 | Manuel Franceschini | new_file_storage_dir = params[1]
|
987 | a5d7fb43 | Manuel Franceschini | return backend.RenameFileStorageDir(old_file_storage_dir,
|
988 | a5d7fb43 | Manuel Franceschini | new_file_storage_dir) |
989 | a5d7fb43 | Manuel Franceschini | |
990 | 4e071d3b | Iustin Pop | # jobs ------------------------
|
991 | 4e071d3b | Iustin Pop | |
992 | ca52cdeb | Michael Hanselmann | @staticmethod
|
993 | 7f30777b | Michael Hanselmann | @_RequireJobQueueLock
|
994 | ca52cdeb | Michael Hanselmann | def perspective_jobqueue_update(params): |
995 | ca52cdeb | Michael Hanselmann | """Update job queue.
|
996 | ca52cdeb | Michael Hanselmann |
|
997 | ca52cdeb | Michael Hanselmann | """
|
998 | ca52cdeb | Michael Hanselmann | (file_name, content) = params |
999 | 7f30777b | Michael Hanselmann | return backend.JobQueueUpdate(file_name, content)
|
1000 | ca52cdeb | Michael Hanselmann | |
1001 | ca52cdeb | Michael Hanselmann | @staticmethod
|
1002 | f1f3f45c | Michael Hanselmann | @_RequireJobQueueLock
|
1003 | ca52cdeb | Michael Hanselmann | def perspective_jobqueue_purge(params): |
1004 | ca52cdeb | Michael Hanselmann | """Purge job queue.
|
1005 | ca52cdeb | Michael Hanselmann |
|
1006 | ca52cdeb | Michael Hanselmann | """
|
1007 | ca52cdeb | Michael Hanselmann | return backend.JobQueuePurge()
|
1008 | ca52cdeb | Michael Hanselmann | |
1009 | af5ebcb1 | Michael Hanselmann | @staticmethod
|
1010 | af5ebcb1 | Michael Hanselmann | @_RequireJobQueueLock
|
1011 | af5ebcb1 | Michael Hanselmann | def perspective_jobqueue_rename(params): |
1012 | af5ebcb1 | Michael Hanselmann | """Rename a job queue file.
|
1013 | af5ebcb1 | Michael Hanselmann |
|
1014 | af5ebcb1 | Michael Hanselmann | """
|
1015 | dd875d32 | Michael Hanselmann | # TODO: What if a file fails to rename?
|
1016 | fb1ffbca | Michael Hanselmann | return [backend.JobQueueRename(old, new) for old, new in params[0]] |
1017 | af5ebcb1 | Michael Hanselmann | |
1018 | be6c403e | Michael Hanselmann | @staticmethod
|
1019 | be6c403e | Michael Hanselmann | @_RequireJobQueueLock
|
1020 | be6c403e | Michael Hanselmann | def perspective_jobqueue_set_drain_flag(params): |
1021 | be6c403e | Michael Hanselmann | """Set job queue's drain flag.
|
1022 | be6c403e | Michael Hanselmann |
|
1023 | be6c403e | Michael Hanselmann | """
|
1024 | be6c403e | Michael Hanselmann | (flag, ) = params |
1025 | be6c403e | Michael Hanselmann | |
1026 | be6c403e | Michael Hanselmann | return jstore.SetDrainFlag(flag)
|
1027 | be6c403e | Michael Hanselmann | |
1028 | 6217e295 | Iustin Pop | # hypervisor ---------------
|
1029 | 6217e295 | Iustin Pop | |
1030 | 6217e295 | Iustin Pop | @staticmethod
|
1031 | 6217e295 | Iustin Pop | def perspective_hypervisor_validate_params(params): |
1032 | 6217e295 | Iustin Pop | """Validate the hypervisor parameters.
|
1033 | 6217e295 | Iustin Pop |
|
1034 | 6217e295 | Iustin Pop | """
|
1035 | 6217e295 | Iustin Pop | (hvname, hvparams) = params |
1036 | 6217e295 | Iustin Pop | return backend.ValidateHVParams(hvname, hvparams)
|
1037 | 6217e295 | Iustin Pop | |
1038 | f942a838 | Michael Hanselmann | # Crypto
|
1039 | f942a838 | Michael Hanselmann | |
1040 | f942a838 | Michael Hanselmann | @staticmethod
|
1041 | ef40fbfb | Michael Hanselmann | def perspective_x509_cert_create(params): |
1042 | f942a838 | Michael Hanselmann | """Creates a new X509 certificate for SSL/TLS.
|
1043 | f942a838 | Michael Hanselmann |
|
1044 | f942a838 | Michael Hanselmann | """
|
1045 | f942a838 | Michael Hanselmann | (validity, ) = params |
1046 | f942a838 | Michael Hanselmann | return backend.CreateX509Certificate(validity)
|
1047 | f942a838 | Michael Hanselmann | |
1048 | f942a838 | Michael Hanselmann | @staticmethod
|
1049 | ef40fbfb | Michael Hanselmann | def perspective_x509_cert_remove(params): |
1050 | f942a838 | Michael Hanselmann | """Removes a X509 certificate.
|
1051 | f942a838 | Michael Hanselmann |
|
1052 | f942a838 | Michael Hanselmann | """
|
1053 | f942a838 | Michael Hanselmann | (name, ) = params |
1054 | f942a838 | Michael Hanselmann | return backend.RemoveX509Certificate(name)
|
1055 | f942a838 | Michael Hanselmann | |
1056 | 1651d116 | Michael Hanselmann | # Import and export
|
1057 | 1651d116 | Michael Hanselmann | |
1058 | 1651d116 | Michael Hanselmann | @staticmethod
|
1059 | ef40fbfb | Michael Hanselmann | def perspective_import_start(params): |
1060 | 1651d116 | Michael Hanselmann | """Starts an import daemon.
|
1061 | 1651d116 | Michael Hanselmann |
|
1062 | 1651d116 | Michael Hanselmann | """
|
1063 | b8c160c1 | Michael Hanselmann | (opts_s, instance, component, (dest, dest_args)) = params |
1064 | eb630f50 | Michael Hanselmann | |
1065 | eb630f50 | Michael Hanselmann | opts = objects.ImportExportOptions.FromDict(opts_s) |
1066 | eb630f50 | Michael Hanselmann | |
1067 | eb630f50 | Michael Hanselmann | return backend.StartImportExportDaemon(constants.IEM_IMPORT, opts,
|
1068 | 1651d116 | Michael Hanselmann | None, None, |
1069 | 1651d116 | Michael Hanselmann | objects.Instance.FromDict(instance), |
1070 | 6613661a | Iustin Pop | component, dest, |
1071 | 1651d116 | Michael Hanselmann | _DecodeImportExportIO(dest, |
1072 | 1651d116 | Michael Hanselmann | dest_args)) |
1073 | eb630f50 | Michael Hanselmann | |
1074 | 1651d116 | Michael Hanselmann | @staticmethod
|
1075 | ef40fbfb | Michael Hanselmann | def perspective_export_start(params): |
1076 | 1651d116 | Michael Hanselmann | """Starts an export daemon.
|
1077 | 1651d116 | Michael Hanselmann |
|
1078 | 1651d116 | Michael Hanselmann | """
|
1079 | b8c160c1 | Michael Hanselmann | (opts_s, host, port, instance, component, (source, source_args)) = params |
1080 | eb630f50 | Michael Hanselmann | |
1081 | eb630f50 | Michael Hanselmann | opts = objects.ImportExportOptions.FromDict(opts_s) |
1082 | eb630f50 | Michael Hanselmann | |
1083 | eb630f50 | Michael Hanselmann | return backend.StartImportExportDaemon(constants.IEM_EXPORT, opts,
|
1084 | 1651d116 | Michael Hanselmann | host, port, |
1085 | 1651d116 | Michael Hanselmann | objects.Instance.FromDict(instance), |
1086 | 6613661a | Iustin Pop | component, source, |
1087 | 1651d116 | Michael Hanselmann | _DecodeImportExportIO(source, |
1088 | 1651d116 | Michael Hanselmann | source_args)) |
1089 | 1651d116 | Michael Hanselmann | |
1090 | 1651d116 | Michael Hanselmann | @staticmethod
|
1091 | ef40fbfb | Michael Hanselmann | def perspective_impexp_status(params): |
1092 | 1651d116 | Michael Hanselmann | """Retrieves the status of an import or export daemon.
|
1093 | 1651d116 | Michael Hanselmann |
|
1094 | 1651d116 | Michael Hanselmann | """
|
1095 | 1651d116 | Michael Hanselmann | return backend.GetImportExportStatus(params[0]) |
1096 | 1651d116 | Michael Hanselmann | |
1097 | 1651d116 | Michael Hanselmann | @staticmethod
|
1098 | f81c4737 | Michael Hanselmann | def perspective_impexp_abort(params): |
1099 | f81c4737 | Michael Hanselmann | """Aborts an import or export.
|
1100 | f81c4737 | Michael Hanselmann |
|
1101 | f81c4737 | Michael Hanselmann | """
|
1102 | f81c4737 | Michael Hanselmann | return backend.AbortImportExport(params[0]) |
1103 | f81c4737 | Michael Hanselmann | |
1104 | f81c4737 | Michael Hanselmann | @staticmethod
|
1105 | ef40fbfb | Michael Hanselmann | def perspective_impexp_cleanup(params): |
1106 | 1651d116 | Michael Hanselmann | """Cleans up after an import or export.
|
1107 | 1651d116 | Michael Hanselmann |
|
1108 | 1651d116 | Michael Hanselmann | """
|
1109 | 1651d116 | Michael Hanselmann | return backend.CleanupImportExport(params[0]) |
1110 | 1651d116 | Michael Hanselmann | |
1111 | a8083063 | Iustin Pop | |
1112 | f93427cd | Iustin Pop | def CheckNoded(_, args): |
1113 | f93427cd | Iustin Pop | """Initial checks whether to run or exit with a failure.
|
1114 | f93427cd | Iustin Pop |
|
1115 | f93427cd | Iustin Pop | """
|
1116 | f93427cd | Iustin Pop | if args: # noded doesn't take any arguments |
1117 | f93427cd | Iustin Pop | print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" % |
1118 | f93427cd | Iustin Pop | sys.argv[0])
|
1119 | f93427cd | Iustin Pop | sys.exit(constants.EXIT_FAILURE) |
1120 | f01738fc | Iustin Pop | try:
|
1121 | f01738fc | Iustin Pop | codecs.lookup("string-escape")
|
1122 | f01738fc | Iustin Pop | except LookupError: |
1123 | f01738fc | Iustin Pop | print >> sys.stderr, ("Can't load the string-escape code which is part" |
1124 | f01738fc | Iustin Pop | " of the Python installation. Is your installation"
|
1125 | f01738fc | Iustin Pop | " complete/correct? Aborting.")
|
1126 | f01738fc | Iustin Pop | sys.exit(constants.EXIT_FAILURE) |
1127 | f93427cd | Iustin Pop | |
1128 | f93427cd | Iustin Pop | |
1129 | 3ee53f1f | Iustin Pop | def PrepNoded(options, _): |
1130 | 3ee53f1f | Iustin Pop | """Preparation node daemon function, executed with the PID file held.
|
1131 | 3ecf6786 | Iustin Pop |
|
1132 | 3ecf6786 | Iustin Pop | """
|
1133 | bebf68d3 | Guido Trotter | if options.mlock:
|
1134 | bebf68d3 | Guido Trotter | request_executor_class = MlockallRequestExecutor |
1135 | 4c32a8bd | Luca Bigliardi | try:
|
1136 | 4c32a8bd | Luca Bigliardi | utils.Mlockall() |
1137 | 4c32a8bd | Luca Bigliardi | except errors.NoCtypesError:
|
1138 | 4c32a8bd | Luca Bigliardi | logging.warning("Cannot set memory lock, ctypes module not found")
|
1139 | 4c32a8bd | Luca Bigliardi | request_executor_class = http.server.HttpServerRequestExecutor |
1140 | bebf68d3 | Guido Trotter | else:
|
1141 | bebf68d3 | Guido Trotter | request_executor_class = http.server.HttpServerRequestExecutor |
1142 | 02bea2fc | Luca Bigliardi | |
1143 | 04ccf5e9 | Guido Trotter | # Read SSL certificate
|
1144 | 3b1b0cb6 | Guido Trotter | if options.ssl:
|
1145 | 3b1b0cb6 | Guido Trotter | ssl_params = http.HttpSslParams(ssl_key_path=options.ssl_key, |
1146 | 3b1b0cb6 | Guido Trotter | ssl_cert_path=options.ssl_cert) |
1147 | 3b1b0cb6 | Guido Trotter | else:
|
1148 | 3b1b0cb6 | Guido Trotter | ssl_params = None
|
1149 | 7d88772a | Iustin Pop | |
1150 | 81198f6e | Iustin Pop | err = _PrepareQueueLock() |
1151 | 81198f6e | Iustin Pop | if err is not None: |
1152 | 81198f6e | Iustin Pop | # this might be some kind of file-system/permission error; while
|
1153 | 81198f6e | Iustin Pop | # this breaks the job queue functionality, we shouldn't prevent
|
1154 | 81198f6e | Iustin Pop | # startup of the whole node daemon because of this
|
1155 | 81198f6e | Iustin Pop | logging.critical("Can't init/verify the queue, proceeding anyway: %s", err)
|
1156 | 7d88772a | Iustin Pop | |
1157 | e0003509 | Michael Hanselmann | handler = NodeRequestHandler() |
1158 | e0003509 | Michael Hanselmann | |
1159 | 04ccf5e9 | Guido Trotter | mainloop = daemon.Mainloop() |
1160 | e0003509 | Michael Hanselmann | server = \ |
1161 | e0003509 | Michael Hanselmann | http.server.HttpServer(mainloop, options.bind_address, options.port, |
1162 | 5ae4945a | Iustin Pop | handler, ssl_params=ssl_params, ssl_verify_peer=True,
|
1163 | 5ae4945a | Iustin Pop | request_executor_class=request_executor_class) |
1164 | 04ccf5e9 | Guido Trotter | server.Start() |
1165 | e0003509 | Michael Hanselmann | |
1166 | 3ee53f1f | Iustin Pop | return (mainloop, server)
|
1167 | 3ee53f1f | Iustin Pop | |
1168 | 5119f2ec | Michael Hanselmann | |
1169 | b459a848 | Andrea Spadaccini | def ExecNoded(options, args, prep_data): # pylint: disable=W0613 |
1170 | 3ee53f1f | Iustin Pop | """Main node daemon function, executed with the PID file held.
|
1171 | 3ee53f1f | Iustin Pop |
|
1172 | 3ee53f1f | Iustin Pop | """
|
1173 | 3ee53f1f | Iustin Pop | (mainloop, server) = prep_data |
1174 | 04ccf5e9 | Guido Trotter | try:
|
1175 | 04ccf5e9 | Guido Trotter | mainloop.Run() |
1176 | 04ccf5e9 | Guido Trotter | finally:
|
1177 | 04ccf5e9 | Guido Trotter | server.Stop() |
1178 | a8083063 | Iustin Pop | |
1179 | a8083063 | Iustin Pop | |
1180 | 5119f2ec | Michael Hanselmann | def Main(): |
1181 | 04ccf5e9 | Guido Trotter | """Main function for the node daemon.
|
1182 | 04ccf5e9 | Guido Trotter |
|
1183 | 04ccf5e9 | Guido Trotter | """
|
1184 | 04ccf5e9 | Guido Trotter | parser = OptionParser(description="Ganeti node daemon",
|
1185 | 802ed2aa | Klaus Aehlig | usage="%prog [-f] [-d] [-p port] [-b ADDRESS]\
|
1186 | 802ed2aa | Klaus Aehlig | \ [-i INTERFACE]",
|
1187 | 04ccf5e9 | Guido Trotter | version="%%prog (ganeti) %s" %
|
1188 | 04ccf5e9 | Guido Trotter | constants.RELEASE_VERSION) |
1189 | bebf68d3 | Guido Trotter | parser.add_option("--no-mlock", dest="mlock", |
1190 | bebf68d3 | Guido Trotter | help="Do not mlock the node memory in ram",
|
1191 | bebf68d3 | Guido Trotter | default=True, action="store_false") |
1192 | bebf68d3 | Guido Trotter | |
1193 | 3ee53f1f | Iustin Pop | daemon.GenericMain(constants.NODED, parser, CheckNoded, PrepNoded, ExecNoded, |
1194 | a5ce2ea2 | Michael Hanselmann | default_ssl_cert=pathutils.NODED_CERT_FILE, |
1195 | a5ce2ea2 | Michael Hanselmann | default_ssl_key=pathutils.NODED_CERT_FILE, |
1196 | 565083ef | Luca Bigliardi | console_logging=True) |