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