Statistics
| Branch: | Tag: | Revision:

root / lib / server / noded.py @ ee1478e5

History | View | Annotate | Download (30.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 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 ee1478e5 Bernardo Dal Seno
    (bdev_s, size, owner, on_primary, info, excl_stor) = 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 ee1478e5 Bernardo Dal Seno
    return backend.BlockdevCreate(bdev, size, owner, on_primary, info,
187 ee1478e5 Bernardo Dal Seno
                                  excl_stor)
188 a8083063 Iustin Pop
189 3ecf6786 Iustin Pop
  @staticmethod
190 9c007da8 Renรฉ Nussbaumer
  def perspective_blockdev_pause_resume_sync(params):
191 9c007da8 Renรฉ Nussbaumer
    """Pause/resume sync of a block device.
192 9c007da8 Renรฉ Nussbaumer

193 9c007da8 Renรฉ Nussbaumer
    """
194 9c007da8 Renรฉ Nussbaumer
    disks_s, pause = params
195 9c007da8 Renรฉ Nussbaumer
    disks = [objects.Disk.FromDict(bdev_s) for bdev_s in disks_s]
196 9c007da8 Renรฉ Nussbaumer
    return backend.BlockdevPauseResumeSync(disks, pause)
197 9c007da8 Renรฉ Nussbaumer
198 9c007da8 Renรฉ Nussbaumer
  @staticmethod
199 271b7cf9 Renรฉ Nussbaumer
  def perspective_blockdev_wipe(params):
200 271b7cf9 Renรฉ Nussbaumer
    """Wipe a block device.
201 271b7cf9 Renรฉ Nussbaumer

202 271b7cf9 Renรฉ Nussbaumer
    """
203 271b7cf9 Renรฉ Nussbaumer
    bdev_s, offset, size = params
204 271b7cf9 Renรฉ Nussbaumer
    bdev = objects.Disk.FromDict(bdev_s)
205 271b7cf9 Renรฉ Nussbaumer
    return backend.BlockdevWipe(bdev, offset, size)
206 271b7cf9 Renรฉ Nussbaumer
207 271b7cf9 Renรฉ Nussbaumer
  @staticmethod
208 3ecf6786 Iustin Pop
  def perspective_blockdev_remove(params):
209 3ecf6786 Iustin Pop
    """Remove a block device.
210 3ecf6786 Iustin Pop

211 3ecf6786 Iustin Pop
    """
212 a8083063 Iustin Pop
    bdev_s = params[0]
213 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
214 821d1bd1 Iustin Pop
    return backend.BlockdevRemove(bdev)
215 a8083063 Iustin Pop
216 3ecf6786 Iustin Pop
  @staticmethod
217 f3e513ad Iustin Pop
  def perspective_blockdev_rename(params):
218 f3e513ad Iustin Pop
    """Remove a block device.
219 f3e513ad Iustin Pop

220 f3e513ad Iustin Pop
    """
221 8a31717c Michael Hanselmann
    devlist = [(objects.Disk.FromDict(ds), uid) for ds, uid in params[0]]
222 821d1bd1 Iustin Pop
    return backend.BlockdevRename(devlist)
223 f3e513ad Iustin Pop
224 f3e513ad Iustin Pop
  @staticmethod
225 3ecf6786 Iustin Pop
  def perspective_blockdev_assemble(params):
226 3ecf6786 Iustin Pop
    """Assemble a block device.
227 3ecf6786 Iustin Pop

228 3ecf6786 Iustin Pop
    """
229 c417e115 Iustin Pop
    bdev_s, owner, on_primary, idx = params
230 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
231 a8083063 Iustin Pop
    if bdev is None:
232 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
233 c417e115 Iustin Pop
    return backend.BlockdevAssemble(bdev, owner, on_primary, idx)
234 a8083063 Iustin Pop
235 3ecf6786 Iustin Pop
  @staticmethod
236 3ecf6786 Iustin Pop
  def perspective_blockdev_shutdown(params):
237 3ecf6786 Iustin Pop
    """Shutdown a block device.
238 3ecf6786 Iustin Pop

239 3ecf6786 Iustin Pop
    """
240 a8083063 Iustin Pop
    bdev_s = params[0]
241 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
242 a8083063 Iustin Pop
    if bdev is None:
243 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
244 821d1bd1 Iustin Pop
    return backend.BlockdevShutdown(bdev)
245 a8083063 Iustin Pop
246 3ecf6786 Iustin Pop
  @staticmethod
247 153d9724 Iustin Pop
  def perspective_blockdev_addchildren(params):
248 3ecf6786 Iustin Pop
    """Add a child to a mirror device.
249 3ecf6786 Iustin Pop

250 3ecf6786 Iustin Pop
    Note: this is only valid for mirror devices. It's the caller's duty
251 3ecf6786 Iustin Pop
    to send a correct disk, otherwise we raise an error.
252 3ecf6786 Iustin Pop

253 3ecf6786 Iustin Pop
    """
254 a8083063 Iustin Pop
    bdev_s, ndev_s = params
255 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
256 153d9724 Iustin Pop
    ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
257 153d9724 Iustin Pop
    if bdev is None or ndevs.count(None) > 0:
258 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
259 821d1bd1 Iustin Pop
    return backend.BlockdevAddchildren(bdev, ndevs)
260 a8083063 Iustin Pop
261 3ecf6786 Iustin Pop
  @staticmethod
262 153d9724 Iustin Pop
  def perspective_blockdev_removechildren(params):
263 3ecf6786 Iustin Pop
    """Remove a child from a mirror device.
264 3ecf6786 Iustin Pop

265 3ecf6786 Iustin Pop
    This is only valid for mirror devices, of course. It's the callers
266 3ecf6786 Iustin Pop
    duty to send a correct disk, otherwise we raise an error.
267 3ecf6786 Iustin Pop

268 3ecf6786 Iustin Pop
    """
269 a8083063 Iustin Pop
    bdev_s, ndev_s = params
270 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
271 153d9724 Iustin Pop
    ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
272 153d9724 Iustin Pop
    if bdev is None or ndevs.count(None) > 0:
273 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
274 821d1bd1 Iustin Pop
    return backend.BlockdevRemovechildren(bdev, ndevs)
275 a8083063 Iustin Pop
276 3ecf6786 Iustin Pop
  @staticmethod
277 3ecf6786 Iustin Pop
  def perspective_blockdev_getmirrorstatus(params):
278 3ecf6786 Iustin Pop
    """Return the mirror status for a list of disks.
279 3ecf6786 Iustin Pop

280 3ecf6786 Iustin Pop
    """
281 319856a9 Michael Hanselmann
    disks = [objects.Disk.FromDict(dsk_s)
282 e437117f Michael Hanselmann
             for dsk_s in params[0]]
283 36145b12 Michael Hanselmann
    return [status.ToDict()
284 36145b12 Michael Hanselmann
            for status in backend.BlockdevGetmirrorstatus(disks)]
285 a8083063 Iustin Pop
286 3ecf6786 Iustin Pop
  @staticmethod
287 b8d26c6e Michael Hanselmann
  def perspective_blockdev_getmirrorstatus_multi(params):
288 b8d26c6e Michael Hanselmann
    """Return the mirror status for a list of disks.
289 b8d26c6e Michael Hanselmann

290 b8d26c6e Michael Hanselmann
    """
291 b8d26c6e Michael Hanselmann
    (node_disks, ) = params
292 b8d26c6e Michael Hanselmann
293 5449685e Iustin Pop
    disks = [objects.Disk.FromDict(dsk_s) for dsk_s in node_disks]
294 b8d26c6e Michael Hanselmann
295 c6a9dffa Michael Hanselmann
    result = []
296 c6a9dffa Michael Hanselmann
297 c6a9dffa Michael Hanselmann
    for (success, status) in backend.BlockdevGetmirrorstatusMulti(disks):
298 c6a9dffa Michael Hanselmann
      if success:
299 c6a9dffa Michael Hanselmann
        result.append((success, status.ToDict()))
300 c6a9dffa Michael Hanselmann
      else:
301 c6a9dffa Michael Hanselmann
        result.append((success, status))
302 c6a9dffa Michael Hanselmann
303 c6a9dffa Michael Hanselmann
    return result
304 b8d26c6e Michael Hanselmann
305 b8d26c6e Michael Hanselmann
  @staticmethod
306 3ecf6786 Iustin Pop
  def perspective_blockdev_find(params):
307 3ecf6786 Iustin Pop
    """Expose the FindBlockDevice functionality for a disk.
308 3ecf6786 Iustin Pop

309 3ecf6786 Iustin Pop
    This will try to find but not activate a disk.
310 3ecf6786 Iustin Pop

311 3ecf6786 Iustin Pop
    """
312 319856a9 Michael Hanselmann
    disk = objects.Disk.FromDict(params[0])
313 ddfe2228 Michael Hanselmann
314 ddfe2228 Michael Hanselmann
    result = backend.BlockdevFind(disk)
315 ddfe2228 Michael Hanselmann
    if result is None:
316 ddfe2228 Michael Hanselmann
      return None
317 ddfe2228 Michael Hanselmann
318 ddfe2228 Michael Hanselmann
    return result.ToDict()
319 a8083063 Iustin Pop
320 3ecf6786 Iustin Pop
  @staticmethod
321 3ecf6786 Iustin Pop
  def perspective_blockdev_snapshot(params):
322 3ecf6786 Iustin Pop
    """Create a snapshot device.
323 3ecf6786 Iustin Pop

324 3ecf6786 Iustin Pop
    Note that this is only valid for LVM disks, if we get passed
325 3ecf6786 Iustin Pop
    something else we raise an exception. The snapshot device can be
326 3ecf6786 Iustin Pop
    remove by calling the generic block device remove call.
327 3ecf6786 Iustin Pop

328 3ecf6786 Iustin Pop
    """
329 319856a9 Michael Hanselmann
    cfbd = objects.Disk.FromDict(params[0])
330 821d1bd1 Iustin Pop
    return backend.BlockdevSnapshot(cfbd)
331 a8083063 Iustin Pop
332 4c8ba8b3 Iustin Pop
  @staticmethod
333 4c8ba8b3 Iustin Pop
  def perspective_blockdev_grow(params):
334 4c8ba8b3 Iustin Pop
    """Grow a stack of devices.
335 4c8ba8b3 Iustin Pop

336 4c8ba8b3 Iustin Pop
    """
337 cad0723b Iustin Pop
    if len(params) < 4:
338 cad0723b Iustin Pop
      raise ValueError("Received only 3 parameters in blockdev_grow,"
339 cad0723b Iustin Pop
                       " old master?")
340 4c8ba8b3 Iustin Pop
    cfbd = objects.Disk.FromDict(params[0])
341 4c8ba8b3 Iustin Pop
    amount = params[1]
342 a59faf4b Iustin Pop
    dryrun = params[2]
343 cad0723b Iustin Pop
    backingstore = params[3]
344 cad0723b Iustin Pop
    return backend.BlockdevGrow(cfbd, amount, dryrun, backingstore)
345 4c8ba8b3 Iustin Pop
346 d61cbe76 Iustin Pop
  @staticmethod
347 d61cbe76 Iustin Pop
  def perspective_blockdev_close(params):
348 d61cbe76 Iustin Pop
    """Closes the given block devices.
349 d61cbe76 Iustin Pop

350 d61cbe76 Iustin Pop
    """
351 b2e7666a Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in params[1]]
352 821d1bd1 Iustin Pop
    return backend.BlockdevClose(params[0], disks)
353 d61cbe76 Iustin Pop
354 968a7623 Iustin Pop
  @staticmethod
355 968a7623 Iustin Pop
  def perspective_blockdev_getsize(params):
356 968a7623 Iustin Pop
    """Compute the sizes of the given block devices.
357 968a7623 Iustin Pop

358 968a7623 Iustin Pop
    """
359 968a7623 Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in params[0]]
360 968a7623 Iustin Pop
    return backend.BlockdevGetsize(disks)
361 968a7623 Iustin Pop
362 858f3d18 Iustin Pop
  @staticmethod
363 858f3d18 Iustin Pop
  def perspective_blockdev_export(params):
364 858f3d18 Iustin Pop
    """Compute the sizes of the given block devices.
365 858f3d18 Iustin Pop

366 858f3d18 Iustin Pop
    """
367 858f3d18 Iustin Pop
    disk = objects.Disk.FromDict(params[0])
368 858f3d18 Iustin Pop
    dest_node, dest_path, cluster_name = params[1:]
369 858f3d18 Iustin Pop
    return backend.BlockdevExport(disk, dest_node, dest_path, cluster_name)
370 858f3d18 Iustin Pop
371 48e175a2 Iustin Pop
  @staticmethod
372 48e175a2 Iustin Pop
  def perspective_blockdev_setinfo(params):
373 48e175a2 Iustin Pop
    """Sets metadata information on the given block device.
374 48e175a2 Iustin Pop

375 48e175a2 Iustin Pop
    """
376 48e175a2 Iustin Pop
    (disk, info) = params
377 48e175a2 Iustin Pop
    disk = objects.Disk.FromDict(disk)
378 48e175a2 Iustin Pop
    return backend.BlockdevSetInfo(disk, info)
379 48e175a2 Iustin Pop
380 6b93ec9d Iustin Pop
  # blockdev/drbd specific methods ----------
381 6b93ec9d Iustin Pop
382 6b93ec9d Iustin Pop
  @staticmethod
383 6b93ec9d Iustin Pop
  def perspective_drbd_disconnect_net(params):
384 6b93ec9d Iustin Pop
    """Disconnects the network connection of drbd disks.
385 6b93ec9d Iustin Pop

386 6b93ec9d Iustin Pop
    Note that this is only valid for drbd disks, so the members of the
387 6b93ec9d Iustin Pop
    disk list must all be drbd devices.
388 6b93ec9d Iustin Pop

389 6b93ec9d Iustin Pop
    """
390 6b93ec9d Iustin Pop
    nodes_ip, disks = params
391 6b93ec9d Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in disks]
392 6b93ec9d Iustin Pop
    return backend.DrbdDisconnectNet(nodes_ip, disks)
393 6b93ec9d Iustin Pop
394 6b93ec9d Iustin Pop
  @staticmethod
395 6b93ec9d Iustin Pop
  def perspective_drbd_attach_net(params):
396 6b93ec9d Iustin Pop
    """Attaches the network connection of drbd disks.
397 6b93ec9d Iustin Pop

398 6b93ec9d Iustin Pop
    Note that this is only valid for drbd disks, so the members of the
399 6b93ec9d Iustin Pop
    disk list must all be drbd devices.
400 6b93ec9d Iustin Pop

401 6b93ec9d Iustin Pop
    """
402 6b93ec9d Iustin Pop
    nodes_ip, disks, instance_name, multimaster = params
403 6b93ec9d Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in disks]
404 821d1bd1 Iustin Pop
    return backend.DrbdAttachNet(nodes_ip, disks,
405 821d1bd1 Iustin Pop
                                     instance_name, multimaster)
406 6b93ec9d Iustin Pop
407 6b93ec9d Iustin Pop
  @staticmethod
408 6b93ec9d Iustin Pop
  def perspective_drbd_wait_sync(params):
409 6b93ec9d Iustin Pop
    """Wait until DRBD disks are synched.
410 6b93ec9d Iustin Pop

411 6b93ec9d Iustin Pop
    Note that this is only valid for drbd disks, so the members of the
412 6b93ec9d Iustin Pop
    disk list must all be drbd devices.
413 6b93ec9d Iustin Pop

414 6b93ec9d Iustin Pop
    """
415 6b93ec9d Iustin Pop
    nodes_ip, disks = params
416 6b93ec9d Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in disks]
417 6b93ec9d Iustin Pop
    return backend.DrbdWaitSync(nodes_ip, disks)
418 6b93ec9d Iustin Pop
419 c46b9782 Luca Bigliardi
  @staticmethod
420 c46b9782 Luca Bigliardi
  def perspective_drbd_helper(params):
421 c46b9782 Luca Bigliardi
    """Query drbd helper.
422 c46b9782 Luca Bigliardi

423 c46b9782 Luca Bigliardi
    """
424 c46b9782 Luca Bigliardi
    return backend.GetDrbdUsermodeHelper()
425 c46b9782 Luca Bigliardi
426 a8083063 Iustin Pop
  # export/import  --------------------------
427 a8083063 Iustin Pop
428 3ecf6786 Iustin Pop
  @staticmethod
429 3ecf6786 Iustin Pop
  def perspective_finalize_export(params):
430 3ecf6786 Iustin Pop
    """Expose the finalize export functionality.
431 a8083063 Iustin Pop

432 3ecf6786 Iustin Pop
    """
433 319856a9 Michael Hanselmann
    instance = objects.Instance.FromDict(params[0])
434 7b651654 Michael Hanselmann
435 7b651654 Michael Hanselmann
    snap_disks = []
436 7b651654 Michael Hanselmann
    for disk in params[1]:
437 7b651654 Michael Hanselmann
      if isinstance(disk, bool):
438 7b651654 Michael Hanselmann
        snap_disks.append(disk)
439 7b651654 Michael Hanselmann
      else:
440 7b651654 Michael Hanselmann
        snap_disks.append(objects.Disk.FromDict(disk))
441 7b651654 Michael Hanselmann
442 a8083063 Iustin Pop
    return backend.FinalizeExport(instance, snap_disks)
443 a8083063 Iustin Pop
444 3ecf6786 Iustin Pop
  @staticmethod
445 3ecf6786 Iustin Pop
  def perspective_export_info(params):
446 3ecf6786 Iustin Pop
    """Query information about an existing export on this node.
447 3ecf6786 Iustin Pop

448 3ecf6786 Iustin Pop
    The given path may not contain an export, in which case we return
449 3ecf6786 Iustin Pop
    None.
450 3ecf6786 Iustin Pop

451 3ecf6786 Iustin Pop
    """
452 3ecf6786 Iustin Pop
    path = params[0]
453 3eccac06 Iustin Pop
    return backend.ExportInfo(path)
454 a8083063 Iustin Pop
455 3ecf6786 Iustin Pop
  @staticmethod
456 3ecf6786 Iustin Pop
  def perspective_export_list(params):
457 3ecf6786 Iustin Pop
    """List the available exports on this node.
458 3ecf6786 Iustin Pop

459 3ecf6786 Iustin Pop
    Note that as opposed to export_info, which may query data about an
460 3ecf6786 Iustin Pop
    export in any path, this only queries the standard Ganeti path
461 a5ce2ea2 Michael Hanselmann
    (pathutils.EXPORT_DIR).
462 3ecf6786 Iustin Pop

463 3ecf6786 Iustin Pop
    """
464 a8083063 Iustin Pop
    return backend.ListExports()
465 a8083063 Iustin Pop
466 3ecf6786 Iustin Pop
  @staticmethod
467 3ecf6786 Iustin Pop
  def perspective_export_remove(params):
468 3ecf6786 Iustin Pop
    """Remove an export.
469 3ecf6786 Iustin Pop

470 3ecf6786 Iustin Pop
    """
471 a8083063 Iustin Pop
    export = params[0]
472 a8083063 Iustin Pop
    return backend.RemoveExport(export)
473 a8083063 Iustin Pop
474 2be7273c Apollon Oikonomopoulos
  # block device ---------------------
475 2be7273c Apollon Oikonomopoulos
  @staticmethod
476 2be7273c Apollon Oikonomopoulos
  def perspective_bdev_sizes(params):
477 2be7273c Apollon Oikonomopoulos
    """Query the list of block devices
478 2be7273c Apollon Oikonomopoulos

479 2be7273c Apollon Oikonomopoulos
    """
480 2be7273c Apollon Oikonomopoulos
    devices = params[0]
481 2be7273c Apollon Oikonomopoulos
    return backend.GetBlockDevSizes(devices)
482 2be7273c Apollon Oikonomopoulos
483 a8083063 Iustin Pop
  # volume  --------------------------
484 a8083063 Iustin Pop
485 3ecf6786 Iustin Pop
  @staticmethod
486 b2a6ccd4 Iustin Pop
  def perspective_lv_list(params):
487 3ecf6786 Iustin Pop
    """Query the list of logical volumes in a given volume group.
488 3ecf6786 Iustin Pop

489 3ecf6786 Iustin Pop
    """
490 a8083063 Iustin Pop
    vgname = params[0]
491 c26a6bd2 Iustin Pop
    return backend.GetVolumeList(vgname)
492 a8083063 Iustin Pop
493 3ecf6786 Iustin Pop
  @staticmethod
494 3ecf6786 Iustin Pop
  def perspective_vg_list(params):
495 3ecf6786 Iustin Pop
    """Query the list of volume groups.
496 3ecf6786 Iustin Pop

497 3ecf6786 Iustin Pop
    """
498 a8083063 Iustin Pop
    return backend.ListVolumeGroups()
499 a8083063 Iustin Pop
500 e337de97 Michael Hanselmann
  # Storage --------------------------
501 e337de97 Michael Hanselmann
502 e337de97 Michael Hanselmann
  @staticmethod
503 e337de97 Michael Hanselmann
  def perspective_storage_list(params):
504 e337de97 Michael Hanselmann
    """Get list of storage units.
505 e337de97 Michael Hanselmann

506 e337de97 Michael Hanselmann
    """
507 e337de97 Michael Hanselmann
    (su_name, su_args, name, fields) = params
508 e337de97 Michael Hanselmann
    return storage.GetStorage(su_name, *su_args).List(name, fields)
509 e337de97 Michael Hanselmann
510 8979196a Michael Hanselmann
  @staticmethod
511 8979196a Michael Hanselmann
  def perspective_storage_modify(params):
512 8979196a Michael Hanselmann
    """Modify a storage unit.
513 8979196a Michael Hanselmann

514 8979196a Michael Hanselmann
    """
515 8979196a Michael Hanselmann
    (su_name, su_args, name, changes) = params
516 8979196a Michael Hanselmann
    return storage.GetStorage(su_name, *su_args).Modify(name, changes)
517 8979196a Michael Hanselmann
518 637b8d7e Michael Hanselmann
  @staticmethod
519 637b8d7e Michael Hanselmann
  def perspective_storage_execute(params):
520 637b8d7e Michael Hanselmann
    """Execute an operation on a storage unit.
521 637b8d7e Michael Hanselmann

522 637b8d7e Michael Hanselmann
    """
523 637b8d7e Michael Hanselmann
    (su_name, su_args, name, op) = params
524 637b8d7e Michael Hanselmann
    return storage.GetStorage(su_name, *su_args).Execute(name, op)
525 637b8d7e Michael Hanselmann
526 a8083063 Iustin Pop
  # bridge  --------------------------
527 a8083063 Iustin Pop
528 3ecf6786 Iustin Pop
  @staticmethod
529 3ecf6786 Iustin Pop
  def perspective_bridges_exist(params):
530 3ecf6786 Iustin Pop
    """Check if all bridges given exist on this node.
531 3ecf6786 Iustin Pop

532 3ecf6786 Iustin Pop
    """
533 a8083063 Iustin Pop
    bridges_list = params[0]
534 a8083063 Iustin Pop
    return backend.BridgesExist(bridges_list)
535 a8083063 Iustin Pop
536 a8083063 Iustin Pop
  # instance  --------------------------
537 a8083063 Iustin Pop
538 3ecf6786 Iustin Pop
  @staticmethod
539 3ecf6786 Iustin Pop
  def perspective_instance_os_add(params):
540 3ecf6786 Iustin Pop
    """Install an OS on a given instance.
541 3ecf6786 Iustin Pop

542 3ecf6786 Iustin Pop
    """
543 d15a9ad3 Guido Trotter
    inst_s = params[0]
544 319856a9 Michael Hanselmann
    inst = objects.Instance.FromDict(inst_s)
545 e557bae9 Guido Trotter
    reinstall = params[1]
546 4a0e011f Iustin Pop
    debug = params[2]
547 4a0e011f Iustin Pop
    return backend.InstanceOsAdd(inst, reinstall, debug)
548 a8083063 Iustin Pop
549 3ecf6786 Iustin Pop
  @staticmethod
550 decd5f45 Iustin Pop
  def perspective_instance_run_rename(params):
551 decd5f45 Iustin Pop
    """Runs the OS rename script for an instance.
552 decd5f45 Iustin Pop

553 decd5f45 Iustin Pop
    """
554 4a0e011f Iustin Pop
    inst_s, old_name, debug = params
555 319856a9 Michael Hanselmann
    inst = objects.Instance.FromDict(inst_s)
556 4a0e011f Iustin Pop
    return backend.RunRenameInstance(inst, old_name, debug)
557 decd5f45 Iustin Pop
558 decd5f45 Iustin Pop
  @staticmethod
559 3ecf6786 Iustin Pop
  def perspective_instance_shutdown(params):
560 3ecf6786 Iustin Pop
    """Shutdown an instance.
561 3ecf6786 Iustin Pop

562 3ecf6786 Iustin Pop
    """
563 319856a9 Michael Hanselmann
    instance = objects.Instance.FromDict(params[0])
564 6263189c Guido Trotter
    timeout = params[1]
565 6263189c Guido Trotter
    return backend.InstanceShutdown(instance, timeout)
566 a8083063 Iustin Pop
567 3ecf6786 Iustin Pop
  @staticmethod
568 3ecf6786 Iustin Pop
  def perspective_instance_start(params):
569 3ecf6786 Iustin Pop
    """Start an instance.
570 3ecf6786 Iustin Pop

571 3ecf6786 Iustin Pop
    """
572 323f9095 Stephen Shirley
    (instance_name, startup_paused) = params
573 323f9095 Stephen Shirley
    instance = objects.Instance.FromDict(instance_name)
574 323f9095 Stephen Shirley
    return backend.StartInstance(instance, startup_paused)
575 a8083063 Iustin Pop
576 3ecf6786 Iustin Pop
  @staticmethod
577 6906a9d8 Guido Trotter
  def perspective_migration_info(params):
578 6906a9d8 Guido Trotter
    """Gather information about an instance to be migrated.
579 6906a9d8 Guido Trotter

580 6906a9d8 Guido Trotter
    """
581 6906a9d8 Guido Trotter
    instance = objects.Instance.FromDict(params[0])
582 6906a9d8 Guido Trotter
    return backend.MigrationInfo(instance)
583 6906a9d8 Guido Trotter
584 6906a9d8 Guido Trotter
  @staticmethod
585 6906a9d8 Guido Trotter
  def perspective_accept_instance(params):
586 6906a9d8 Guido Trotter
    """Prepare the node to accept an instance.
587 6906a9d8 Guido Trotter

588 6906a9d8 Guido Trotter
    """
589 6906a9d8 Guido Trotter
    instance, info, target = params
590 6906a9d8 Guido Trotter
    instance = objects.Instance.FromDict(instance)
591 6906a9d8 Guido Trotter
    return backend.AcceptInstance(instance, info, target)
592 6906a9d8 Guido Trotter
593 6906a9d8 Guido Trotter
  @staticmethod
594 6a1434d7 Andrea Spadaccini
  def perspective_instance_finalize_migration_dst(params):
595 6a1434d7 Andrea Spadaccini
    """Finalize the instance migration on the destination node.
596 6906a9d8 Guido Trotter

597 6906a9d8 Guido Trotter
    """
598 6906a9d8 Guido Trotter
    instance, info, success = params
599 6906a9d8 Guido Trotter
    instance = objects.Instance.FromDict(instance)
600 6a1434d7 Andrea Spadaccini
    return backend.FinalizeMigrationDst(instance, info, success)
601 6906a9d8 Guido Trotter
602 6906a9d8 Guido Trotter
  @staticmethod
603 2a10865c Iustin Pop
  def perspective_instance_migrate(params):
604 2a10865c Iustin Pop
    """Migrates an instance.
605 2a10865c Iustin Pop

606 2a10865c Iustin Pop
    """
607 2a10865c Iustin Pop
    instance, target, live = params
608 9f0e6b37 Iustin Pop
    instance = objects.Instance.FromDict(instance)
609 2a10865c Iustin Pop
    return backend.MigrateInstance(instance, target, live)
610 2a10865c Iustin Pop
611 2a10865c Iustin Pop
  @staticmethod
612 6a1434d7 Andrea Spadaccini
  def perspective_instance_finalize_migration_src(params):
613 6a1434d7 Andrea Spadaccini
    """Finalize the instance migration on the source node.
614 6a1434d7 Andrea Spadaccini

615 6a1434d7 Andrea Spadaccini
    """
616 6a1434d7 Andrea Spadaccini
    instance, success, live = params
617 6a1434d7 Andrea Spadaccini
    instance = objects.Instance.FromDict(instance)
618 6a1434d7 Andrea Spadaccini
    return backend.FinalizeMigrationSource(instance, success, live)
619 6a1434d7 Andrea Spadaccini
620 6a1434d7 Andrea Spadaccini
  @staticmethod
621 6a1434d7 Andrea Spadaccini
  def perspective_instance_get_migration_status(params):
622 6a1434d7 Andrea Spadaccini
    """Reports migration status.
623 6a1434d7 Andrea Spadaccini

624 6a1434d7 Andrea Spadaccini
    """
625 6a1434d7 Andrea Spadaccini
    instance = objects.Instance.FromDict(params[0])
626 6a1434d7 Andrea Spadaccini
    return backend.GetMigrationStatus(instance).ToDict()
627 6a1434d7 Andrea Spadaccini
628 6a1434d7 Andrea Spadaccini
  @staticmethod
629 007a2f3e Alexander Schreiber
  def perspective_instance_reboot(params):
630 007a2f3e Alexander Schreiber
    """Reboot an instance.
631 007a2f3e Alexander Schreiber

632 007a2f3e Alexander Schreiber
    """
633 007a2f3e Alexander Schreiber
    instance = objects.Instance.FromDict(params[0])
634 007a2f3e Alexander Schreiber
    reboot_type = params[1]
635 17c3f802 Guido Trotter
    shutdown_timeout = params[2]
636 17c3f802 Guido Trotter
    return backend.InstanceReboot(instance, reboot_type, shutdown_timeout)
637 007a2f3e Alexander Schreiber
638 007a2f3e Alexander Schreiber
  @staticmethod
639 ebe466d8 Guido Trotter
  def perspective_instance_balloon_memory(params):
640 ebe466d8 Guido Trotter
    """Modify instance runtime memory.
641 ebe466d8 Guido Trotter

642 ebe466d8 Guido Trotter
    """
643 ebe466d8 Guido Trotter
    instance_dict, memory = params
644 ebe466d8 Guido Trotter
    instance = objects.Instance.FromDict(instance_dict)
645 ebe466d8 Guido Trotter
    return backend.InstanceBalloonMemory(instance, memory)
646 ebe466d8 Guido Trotter
647 ebe466d8 Guido Trotter
  @staticmethod
648 3ecf6786 Iustin Pop
  def perspective_instance_info(params):
649 3ecf6786 Iustin Pop
    """Query instance information.
650 3ecf6786 Iustin Pop

651 3ecf6786 Iustin Pop
    """
652 16ad1a83 Iustin Pop
    return backend.GetInstanceInfo(params[0], params[1])
653 a8083063 Iustin Pop
654 3ecf6786 Iustin Pop
  @staticmethod
655 56e7640c Iustin Pop
  def perspective_instance_migratable(params):
656 56e7640c Iustin Pop
    """Query whether the specified instance can be migrated.
657 56e7640c Iustin Pop

658 56e7640c Iustin Pop
    """
659 56e7640c Iustin Pop
    instance = objects.Instance.FromDict(params[0])
660 56e7640c Iustin Pop
    return backend.GetInstanceMigratable(instance)
661 56e7640c Iustin Pop
662 56e7640c Iustin Pop
  @staticmethod
663 3ecf6786 Iustin Pop
  def perspective_all_instances_info(params):
664 3ecf6786 Iustin Pop
    """Query information about all instances.
665 3ecf6786 Iustin Pop

666 3ecf6786 Iustin Pop
    """
667 e69d05fd Iustin Pop
    return backend.GetAllInstancesInfo(params[0])
668 a8083063 Iustin Pop
669 3ecf6786 Iustin Pop
  @staticmethod
670 3ecf6786 Iustin Pop
  def perspective_instance_list(params):
671 3ecf6786 Iustin Pop
    """Query the list of running instances.
672 3ecf6786 Iustin Pop

673 3ecf6786 Iustin Pop
    """
674 c26a6bd2 Iustin Pop
    return backend.GetInstanceList(params[0])
675 a8083063 Iustin Pop
676 a8083063 Iustin Pop
  # node --------------------------
677 a8083063 Iustin Pop
678 3ecf6786 Iustin Pop
  @staticmethod
679 caad16e2 Iustin Pop
  def perspective_node_has_ip_address(params):
680 caad16e2 Iustin Pop
    """Checks if a node has the given ip address.
681 caad16e2 Iustin Pop

682 caad16e2 Iustin Pop
    """
683 8b312c1d Manuel Franceschini
    return netutils.IPAddress.Own(params[0])
684 caad16e2 Iustin Pop
685 caad16e2 Iustin Pop
  @staticmethod
686 3ecf6786 Iustin Pop
  def perspective_node_info(params):
687 3ecf6786 Iustin Pop
    """Query node information.
688 3ecf6786 Iustin Pop

689 3ecf6786 Iustin Pop
    """
690 78519c10 Michael Hanselmann
    (vg_names, hv_names) = params
691 78519c10 Michael Hanselmann
    return backend.GetNodeInfo(vg_names, hv_names)
692 a8083063 Iustin Pop
693 3ecf6786 Iustin Pop
  @staticmethod
694 19ddc57a Renรฉ Nussbaumer
  def perspective_etc_hosts_modify(params):
695 19ddc57a Renรฉ Nussbaumer
    """Modify a node entry in /etc/hosts.
696 19ddc57a Renรฉ Nussbaumer

697 19ddc57a Renรฉ Nussbaumer
    """
698 19ddc57a Renรฉ Nussbaumer
    backend.EtcHostsModify(params[0], params[1], params[2])
699 19ddc57a Renรฉ Nussbaumer
700 19ddc57a Renรฉ Nussbaumer
    return True
701 19ddc57a Renรฉ Nussbaumer
702 19ddc57a Renรฉ Nussbaumer
  @staticmethod
703 3ecf6786 Iustin Pop
  def perspective_node_verify(params):
704 3ecf6786 Iustin Pop
    """Run a verify sequence on this node.
705 3ecf6786 Iustin Pop

706 3ecf6786 Iustin Pop
    """
707 62c9ec92 Iustin Pop
    return backend.VerifyNode(params[0], params[1])
708 a8083063 Iustin Pop
709 3ecf6786 Iustin Pop
  @staticmethod
710 fb460cf7 Andrea Spadaccini
  def perspective_node_start_master_daemons(params):
711 fb460cf7 Andrea Spadaccini
    """Start the master daemons on this node.
712 3ecf6786 Iustin Pop

713 3ecf6786 Iustin Pop
    """
714 fb460cf7 Andrea Spadaccini
    return backend.StartMasterDaemons(params[0])
715 fb460cf7 Andrea Spadaccini
716 fb460cf7 Andrea Spadaccini
  @staticmethod
717 fb460cf7 Andrea Spadaccini
  def perspective_node_activate_master_ip(params):
718 fb460cf7 Andrea Spadaccini
    """Activate the master IP on this node.
719 fb460cf7 Andrea Spadaccini

720 fb460cf7 Andrea Spadaccini
    """
721 c79198a0 Andrea Spadaccini
    master_params = objects.MasterNetworkParameters.FromDict(params[0])
722 57c7bc57 Andrea Spadaccini
    return backend.ActivateMasterIp(master_params, params[1])
723 fb460cf7 Andrea Spadaccini
724 fb460cf7 Andrea Spadaccini
  @staticmethod
725 fb460cf7 Andrea Spadaccini
  def perspective_node_deactivate_master_ip(params):
726 fb460cf7 Andrea Spadaccini
    """Deactivate the master IP on this node.
727 fb460cf7 Andrea Spadaccini

728 fb460cf7 Andrea Spadaccini
    """
729 c79198a0 Andrea Spadaccini
    master_params = objects.MasterNetworkParameters.FromDict(params[0])
730 57c7bc57 Andrea Spadaccini
    return backend.DeactivateMasterIp(master_params, params[1])
731 a8083063 Iustin Pop
732 3ecf6786 Iustin Pop
  @staticmethod
733 3ecf6786 Iustin Pop
  def perspective_node_stop_master(params):
734 7c74bbe0 Andrea Spadaccini
    """Stops master daemons on this node.
735 3ecf6786 Iustin Pop

736 3ecf6786 Iustin Pop
    """
737 fb460cf7 Andrea Spadaccini
    return backend.StopMasterDaemons()
738 a8083063 Iustin Pop
739 3ecf6786 Iustin Pop
  @staticmethod
740 5a8648eb Andrea Spadaccini
  def perspective_node_change_master_netmask(params):
741 5a8648eb Andrea Spadaccini
    """Change the master IP netmask.
742 5a8648eb Andrea Spadaccini

743 5a8648eb Andrea Spadaccini
    """
744 41e079ce Andrea Spadaccini
    return backend.ChangeMasterNetmask(params[0], params[1], params[2],
745 41e079ce Andrea Spadaccini
                                       params[3])
746 5a8648eb Andrea Spadaccini
747 5a8648eb Andrea Spadaccini
  @staticmethod
748 3ecf6786 Iustin Pop
  def perspective_node_leave_cluster(params):
749 3ecf6786 Iustin Pop
    """Cleanup after leaving a cluster.
750 3ecf6786 Iustin Pop

751 3ecf6786 Iustin Pop
    """
752 b989b9d9 Ken Wehr
    return backend.LeaveCluster(params[0])
753 a8083063 Iustin Pop
754 3ecf6786 Iustin Pop
  @staticmethod
755 3ecf6786 Iustin Pop
  def perspective_node_volumes(params):
756 3ecf6786 Iustin Pop
    """Query the list of all logical volume groups.
757 3ecf6786 Iustin Pop

758 3ecf6786 Iustin Pop
    """
759 dcb93971 Michael Hanselmann
    return backend.NodeVolumes()
760 dcb93971 Michael Hanselmann
761 56aa9fd5 Iustin Pop
  @staticmethod
762 56aa9fd5 Iustin Pop
  def perspective_node_demote_from_mc(params):
763 56aa9fd5 Iustin Pop
    """Demote a node from the master candidate role.
764 56aa9fd5 Iustin Pop

765 56aa9fd5 Iustin Pop
    """
766 56aa9fd5 Iustin Pop
    return backend.DemoteFromMC()
767 56aa9fd5 Iustin Pop
768 f5118ade Iustin Pop
  @staticmethod
769 f5118ade Iustin Pop
  def perspective_node_powercycle(params):
770 f5118ade Iustin Pop
    """Tries to powercycle the nod.
771 f5118ade Iustin Pop

772 f5118ade Iustin Pop
    """
773 f5118ade Iustin Pop
    hypervisor_type = params[0]
774 f5118ade Iustin Pop
    return backend.PowercycleNode(hypervisor_type)
775 f5118ade Iustin Pop
776 a8083063 Iustin Pop
  # cluster --------------------------
777 a8083063 Iustin Pop
778 3ecf6786 Iustin Pop
  @staticmethod
779 3ecf6786 Iustin Pop
  def perspective_version(params):
780 3ecf6786 Iustin Pop
    """Query version information.
781 3ecf6786 Iustin Pop

782 3ecf6786 Iustin Pop
    """
783 c26a6bd2 Iustin Pop
    return constants.PROTOCOL_VERSION
784 a8083063 Iustin Pop
785 3ecf6786 Iustin Pop
  @staticmethod
786 3ecf6786 Iustin Pop
  def perspective_upload_file(params):
787 3ecf6786 Iustin Pop
    """Upload a file.
788 3ecf6786 Iustin Pop

789 3ecf6786 Iustin Pop
    Note that the backend implementation imposes strict rules on which
790 3ecf6786 Iustin Pop
    files are accepted.
791 3ecf6786 Iustin Pop

792 3ecf6786 Iustin Pop
    """
793 415a7304 Michael Hanselmann
    return backend.UploadFile(*(params[0]))
794 a8083063 Iustin Pop
795 4e071d3b Iustin Pop
  @staticmethod
796 4e071d3b Iustin Pop
  def perspective_master_info(params):
797 4e071d3b Iustin Pop
    """Query master information.
798 4e071d3b Iustin Pop

799 4e071d3b Iustin Pop
    """
800 4e071d3b Iustin Pop
    return backend.GetMasterInfo()
801 a8083063 Iustin Pop
802 6ddc95ec Michael Hanselmann
  @staticmethod
803 4f6014d4 Renรฉ Nussbaumer
  def perspective_run_oob(params):
804 4f6014d4 Renรฉ Nussbaumer
    """Runs oob on node.
805 4f6014d4 Renรฉ Nussbaumer

806 4f6014d4 Renรฉ Nussbaumer
    """
807 1aa88d95 Renรฉ Nussbaumer
    output = backend.RunOob(params[0], params[1], params[2], params[3])
808 1aa88d95 Renรฉ Nussbaumer
    if output:
809 1aa88d95 Renรฉ Nussbaumer
      result = serializer.LoadJson(output)
810 1aa88d95 Renรฉ Nussbaumer
    else:
811 1aa88d95 Renรฉ Nussbaumer
      result = None
812 1aa88d95 Renรฉ Nussbaumer
    return result
813 4f6014d4 Renรฉ Nussbaumer
814 4f6014d4 Renรฉ Nussbaumer
  @staticmethod
815 db2203e0 Michael Hanselmann
  def perspective_restricted_command(params):
816 db2203e0 Michael Hanselmann
    """Runs a restricted command.
817 db2203e0 Michael Hanselmann

818 db2203e0 Michael Hanselmann
    """
819 db2203e0 Michael Hanselmann
    (cmd, ) = params
820 db2203e0 Michael Hanselmann
821 42bd26e8 Michael Hanselmann
    return backend.RunRestrictedCmd(cmd)
822 db2203e0 Michael Hanselmann
823 db2203e0 Michael Hanselmann
  @staticmethod
824 6ddc95ec Michael Hanselmann
  def perspective_write_ssconf_files(params):
825 6ddc95ec Michael Hanselmann
    """Write ssconf files.
826 6ddc95ec Michael Hanselmann

827 6ddc95ec Michael Hanselmann
    """
828 03d1dba2 Michael Hanselmann
    (values,) = params
829 ee501db1 Michael Hanselmann
    return ssconf.WriteSsconfFiles(values)
830 6ddc95ec Michael Hanselmann
831 99e222b1 Michael Hanselmann
  @staticmethod
832 ec5af888 Michael Hanselmann
  def perspective_get_watcher_pause(params):
833 ec5af888 Michael Hanselmann
    """Get watcher pause end.
834 ec5af888 Michael Hanselmann

835 ec5af888 Michael Hanselmann
    """
836 ec5af888 Michael Hanselmann
    return utils.ReadWatcherPauseFile(pathutils.WATCHER_PAUSEFILE)
837 ec5af888 Michael Hanselmann
838 ec5af888 Michael Hanselmann
  @staticmethod
839 99e222b1 Michael Hanselmann
  def perspective_set_watcher_pause(params):
840 99e222b1 Michael Hanselmann
    """Set watcher pause.
841 99e222b1 Michael Hanselmann

842 99e222b1 Michael Hanselmann
    """
843 99e222b1 Michael Hanselmann
    (until, ) = params
844 99e222b1 Michael Hanselmann
    return backend.SetWatcherPause(until)
845 99e222b1 Michael Hanselmann
846 a8083063 Iustin Pop
  # os -----------------------
847 a8083063 Iustin Pop
848 3ecf6786 Iustin Pop
  @staticmethod
849 3ecf6786 Iustin Pop
  def perspective_os_diagnose(params):
850 3ecf6786 Iustin Pop
    """Query detailed information about existing OSes.
851 3ecf6786 Iustin Pop

852 3ecf6786 Iustin Pop
    """
853 255dcebd Iustin Pop
    return backend.DiagnoseOS()
854 a8083063 Iustin Pop
855 3ecf6786 Iustin Pop
  @staticmethod
856 3ecf6786 Iustin Pop
  def perspective_os_get(params):
857 3ecf6786 Iustin Pop
    """Query information about a given OS.
858 3ecf6786 Iustin Pop

859 3ecf6786 Iustin Pop
    """
860 a8083063 Iustin Pop
    name = params[0]
861 255dcebd Iustin Pop
    os_obj = backend.OSFromDisk(name)
862 c26a6bd2 Iustin Pop
    return os_obj.ToDict()
863 a8083063 Iustin Pop
864 acd9ff9e Iustin Pop
  @staticmethod
865 acd9ff9e Iustin Pop
  def perspective_os_validate(params):
866 acd9ff9e Iustin Pop
    """Run a given OS' validation routine.
867 acd9ff9e Iustin Pop

868 acd9ff9e Iustin Pop
    """
869 acd9ff9e Iustin Pop
    required, name, checks, params = params
870 acd9ff9e Iustin Pop
    return backend.ValidateOS(required, name, checks, params)
871 acd9ff9e Iustin Pop
872 a8083063 Iustin Pop
  # hooks -----------------------
873 a8083063 Iustin Pop
874 3ecf6786 Iustin Pop
  @staticmethod
875 3ecf6786 Iustin Pop
  def perspective_hooks_runner(params):
876 3ecf6786 Iustin Pop
    """Run hook scripts.
877 3ecf6786 Iustin Pop

878 3ecf6786 Iustin Pop
    """
879 a8083063 Iustin Pop
    hpath, phase, env = params
880 a8083063 Iustin Pop
    hr = backend.HooksRunner()
881 a8083063 Iustin Pop
    return hr.RunHooks(hpath, phase, env)
882 a8083063 Iustin Pop
883 8d528b7c Iustin Pop
  # iallocator -----------------
884 8d528b7c Iustin Pop
885 8d528b7c Iustin Pop
  @staticmethod
886 8d528b7c Iustin Pop
  def perspective_iallocator_runner(params):
887 8d528b7c Iustin Pop
    """Run an iallocator script.
888 8d528b7c Iustin Pop

889 8d528b7c Iustin Pop
    """
890 8d528b7c Iustin Pop
    name, idata = params
891 8d528b7c Iustin Pop
    iar = backend.IAllocatorRunner()
892 8d528b7c Iustin Pop
    return iar.Run(name, idata)
893 8d528b7c Iustin Pop
894 06009e27 Iustin Pop
  # test -----------------------
895 06009e27 Iustin Pop
896 06009e27 Iustin Pop
  @staticmethod
897 06009e27 Iustin Pop
  def perspective_test_delay(params):
898 06009e27 Iustin Pop
    """Run test delay.
899 06009e27 Iustin Pop

900 06009e27 Iustin Pop
    """
901 06009e27 Iustin Pop
    duration = params[0]
902 c26a6bd2 Iustin Pop
    status, rval = utils.TestDelay(duration)
903 c26a6bd2 Iustin Pop
    if not status:
904 c26a6bd2 Iustin Pop
      raise backend.RPCFail(rval)
905 c26a6bd2 Iustin Pop
    return rval
906 06009e27 Iustin Pop
907 4e071d3b Iustin Pop
  # file storage ---------------
908 4e071d3b Iustin Pop
909 a5d7fb43 Manuel Franceschini
  @staticmethod
910 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_create(params):
911 a5d7fb43 Manuel Franceschini
    """Create the file storage directory.
912 a5d7fb43 Manuel Franceschini

913 a5d7fb43 Manuel Franceschini
    """
914 a5d7fb43 Manuel Franceschini
    file_storage_dir = params[0]
915 a5d7fb43 Manuel Franceschini
    return backend.CreateFileStorageDir(file_storage_dir)
916 a5d7fb43 Manuel Franceschini
917 a5d7fb43 Manuel Franceschini
  @staticmethod
918 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_remove(params):
919 a5d7fb43 Manuel Franceschini
    """Remove the file storage directory.
920 a5d7fb43 Manuel Franceschini

921 a5d7fb43 Manuel Franceschini
    """
922 a5d7fb43 Manuel Franceschini
    file_storage_dir = params[0]
923 a5d7fb43 Manuel Franceschini
    return backend.RemoveFileStorageDir(file_storage_dir)
924 a5d7fb43 Manuel Franceschini
925 a5d7fb43 Manuel Franceschini
  @staticmethod
926 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_rename(params):
927 a5d7fb43 Manuel Franceschini
    """Rename the file storage directory.
928 a5d7fb43 Manuel Franceschini

929 a5d7fb43 Manuel Franceschini
    """
930 a5d7fb43 Manuel Franceschini
    old_file_storage_dir = params[0]
931 a5d7fb43 Manuel Franceschini
    new_file_storage_dir = params[1]
932 a5d7fb43 Manuel Franceschini
    return backend.RenameFileStorageDir(old_file_storage_dir,
933 a5d7fb43 Manuel Franceschini
                                        new_file_storage_dir)
934 a5d7fb43 Manuel Franceschini
935 4e071d3b Iustin Pop
  # jobs ------------------------
936 4e071d3b Iustin Pop
937 ca52cdeb Michael Hanselmann
  @staticmethod
938 7f30777b Michael Hanselmann
  @_RequireJobQueueLock
939 ca52cdeb Michael Hanselmann
  def perspective_jobqueue_update(params):
940 ca52cdeb Michael Hanselmann
    """Update job queue.
941 ca52cdeb Michael Hanselmann

942 ca52cdeb Michael Hanselmann
    """
943 ca52cdeb Michael Hanselmann
    (file_name, content) = params
944 7f30777b Michael Hanselmann
    return backend.JobQueueUpdate(file_name, content)
945 ca52cdeb Michael Hanselmann
946 ca52cdeb Michael Hanselmann
  @staticmethod
947 f1f3f45c Michael Hanselmann
  @_RequireJobQueueLock
948 ca52cdeb Michael Hanselmann
  def perspective_jobqueue_purge(params):
949 ca52cdeb Michael Hanselmann
    """Purge job queue.
950 ca52cdeb Michael Hanselmann

951 ca52cdeb Michael Hanselmann
    """
952 ca52cdeb Michael Hanselmann
    return backend.JobQueuePurge()
953 ca52cdeb Michael Hanselmann
954 af5ebcb1 Michael Hanselmann
  @staticmethod
955 af5ebcb1 Michael Hanselmann
  @_RequireJobQueueLock
956 af5ebcb1 Michael Hanselmann
  def perspective_jobqueue_rename(params):
957 af5ebcb1 Michael Hanselmann
    """Rename a job queue file.
958 af5ebcb1 Michael Hanselmann

959 af5ebcb1 Michael Hanselmann
    """
960 dd875d32 Michael Hanselmann
    # TODO: What if a file fails to rename?
961 fb1ffbca Michael Hanselmann
    return [backend.JobQueueRename(old, new) for old, new in params[0]]
962 af5ebcb1 Michael Hanselmann
963 be6c403e Michael Hanselmann
  @staticmethod
964 be6c403e Michael Hanselmann
  @_RequireJobQueueLock
965 be6c403e Michael Hanselmann
  def perspective_jobqueue_set_drain_flag(params):
966 be6c403e Michael Hanselmann
    """Set job queue's drain flag.
967 be6c403e Michael Hanselmann

968 be6c403e Michael Hanselmann
    """
969 be6c403e Michael Hanselmann
    (flag, ) = params
970 be6c403e Michael Hanselmann
971 be6c403e Michael Hanselmann
    return jstore.SetDrainFlag(flag)
972 be6c403e Michael Hanselmann
973 6217e295 Iustin Pop
  # hypervisor ---------------
974 6217e295 Iustin Pop
975 6217e295 Iustin Pop
  @staticmethod
976 6217e295 Iustin Pop
  def perspective_hypervisor_validate_params(params):
977 6217e295 Iustin Pop
    """Validate the hypervisor parameters.
978 6217e295 Iustin Pop

979 6217e295 Iustin Pop
    """
980 6217e295 Iustin Pop
    (hvname, hvparams) = params
981 6217e295 Iustin Pop
    return backend.ValidateHVParams(hvname, hvparams)
982 6217e295 Iustin Pop
983 f942a838 Michael Hanselmann
  # Crypto
984 f942a838 Michael Hanselmann
985 f942a838 Michael Hanselmann
  @staticmethod
986 ef40fbfb Michael Hanselmann
  def perspective_x509_cert_create(params):
987 f942a838 Michael Hanselmann
    """Creates a new X509 certificate for SSL/TLS.
988 f942a838 Michael Hanselmann

989 f942a838 Michael Hanselmann
    """
990 f942a838 Michael Hanselmann
    (validity, ) = params
991 f942a838 Michael Hanselmann
    return backend.CreateX509Certificate(validity)
992 f942a838 Michael Hanselmann
993 f942a838 Michael Hanselmann
  @staticmethod
994 ef40fbfb Michael Hanselmann
  def perspective_x509_cert_remove(params):
995 f942a838 Michael Hanselmann
    """Removes a X509 certificate.
996 f942a838 Michael Hanselmann

997 f942a838 Michael Hanselmann
    """
998 f942a838 Michael Hanselmann
    (name, ) = params
999 f942a838 Michael Hanselmann
    return backend.RemoveX509Certificate(name)
1000 f942a838 Michael Hanselmann
1001 1651d116 Michael Hanselmann
  # Import and export
1002 1651d116 Michael Hanselmann
1003 1651d116 Michael Hanselmann
  @staticmethod
1004 ef40fbfb Michael Hanselmann
  def perspective_import_start(params):
1005 1651d116 Michael Hanselmann
    """Starts an import daemon.
1006 1651d116 Michael Hanselmann

1007 1651d116 Michael Hanselmann
    """
1008 b8c160c1 Michael Hanselmann
    (opts_s, instance, component, (dest, dest_args)) = params
1009 eb630f50 Michael Hanselmann
1010 eb630f50 Michael Hanselmann
    opts = objects.ImportExportOptions.FromDict(opts_s)
1011 eb630f50 Michael Hanselmann
1012 eb630f50 Michael Hanselmann
    return backend.StartImportExportDaemon(constants.IEM_IMPORT, opts,
1013 1651d116 Michael Hanselmann
                                           None, None,
1014 1651d116 Michael Hanselmann
                                           objects.Instance.FromDict(instance),
1015 6613661a Iustin Pop
                                           component, dest,
1016 1651d116 Michael Hanselmann
                                           _DecodeImportExportIO(dest,
1017 1651d116 Michael Hanselmann
                                                                 dest_args))
1018 eb630f50 Michael Hanselmann
1019 1651d116 Michael Hanselmann
  @staticmethod
1020 ef40fbfb Michael Hanselmann
  def perspective_export_start(params):
1021 1651d116 Michael Hanselmann
    """Starts an export daemon.
1022 1651d116 Michael Hanselmann

1023 1651d116 Michael Hanselmann
    """
1024 b8c160c1 Michael Hanselmann
    (opts_s, host, port, instance, component, (source, source_args)) = params
1025 eb630f50 Michael Hanselmann
1026 eb630f50 Michael Hanselmann
    opts = objects.ImportExportOptions.FromDict(opts_s)
1027 eb630f50 Michael Hanselmann
1028 eb630f50 Michael Hanselmann
    return backend.StartImportExportDaemon(constants.IEM_EXPORT, opts,
1029 1651d116 Michael Hanselmann
                                           host, port,
1030 1651d116 Michael Hanselmann
                                           objects.Instance.FromDict(instance),
1031 6613661a Iustin Pop
                                           component, source,
1032 1651d116 Michael Hanselmann
                                           _DecodeImportExportIO(source,
1033 1651d116 Michael Hanselmann
                                                                 source_args))
1034 1651d116 Michael Hanselmann
1035 1651d116 Michael Hanselmann
  @staticmethod
1036 ef40fbfb Michael Hanselmann
  def perspective_impexp_status(params):
1037 1651d116 Michael Hanselmann
    """Retrieves the status of an import or export daemon.
1038 1651d116 Michael Hanselmann

1039 1651d116 Michael Hanselmann
    """
1040 1651d116 Michael Hanselmann
    return backend.GetImportExportStatus(params[0])
1041 1651d116 Michael Hanselmann
1042 1651d116 Michael Hanselmann
  @staticmethod
1043 f81c4737 Michael Hanselmann
  def perspective_impexp_abort(params):
1044 f81c4737 Michael Hanselmann
    """Aborts an import or export.
1045 f81c4737 Michael Hanselmann

1046 f81c4737 Michael Hanselmann
    """
1047 f81c4737 Michael Hanselmann
    return backend.AbortImportExport(params[0])
1048 f81c4737 Michael Hanselmann
1049 f81c4737 Michael Hanselmann
  @staticmethod
1050 ef40fbfb Michael Hanselmann
  def perspective_impexp_cleanup(params):
1051 1651d116 Michael Hanselmann
    """Cleans up after an import or export.
1052 1651d116 Michael Hanselmann

1053 1651d116 Michael Hanselmann
    """
1054 1651d116 Michael Hanselmann
    return backend.CleanupImportExport(params[0])
1055 1651d116 Michael Hanselmann
1056 a8083063 Iustin Pop
1057 f93427cd Iustin Pop
def CheckNoded(_, args):
1058 f93427cd Iustin Pop
  """Initial checks whether to run or exit with a failure.
1059 f93427cd Iustin Pop

1060 f93427cd Iustin Pop
  """
1061 f93427cd Iustin Pop
  if args: # noded doesn't take any arguments
1062 f93427cd Iustin Pop
    print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" %
1063 f93427cd Iustin Pop
                          sys.argv[0])
1064 f93427cd Iustin Pop
    sys.exit(constants.EXIT_FAILURE)
1065 f01738fc Iustin Pop
  try:
1066 f01738fc Iustin Pop
    codecs.lookup("string-escape")
1067 f01738fc Iustin Pop
  except LookupError:
1068 f01738fc Iustin Pop
    print >> sys.stderr, ("Can't load the string-escape code which is part"
1069 f01738fc Iustin Pop
                          " of the Python installation. Is your installation"
1070 f01738fc Iustin Pop
                          " complete/correct? Aborting.")
1071 f01738fc Iustin Pop
    sys.exit(constants.EXIT_FAILURE)
1072 f93427cd Iustin Pop
1073 f93427cd Iustin Pop
1074 3ee53f1f Iustin Pop
def PrepNoded(options, _):
1075 3ee53f1f Iustin Pop
  """Preparation node daemon function, executed with the PID file held.
1076 3ecf6786 Iustin Pop

1077 3ecf6786 Iustin Pop
  """
1078 bebf68d3 Guido Trotter
  if options.mlock:
1079 bebf68d3 Guido Trotter
    request_executor_class = MlockallRequestExecutor
1080 4c32a8bd Luca Bigliardi
    try:
1081 4c32a8bd Luca Bigliardi
      utils.Mlockall()
1082 4c32a8bd Luca Bigliardi
    except errors.NoCtypesError:
1083 4c32a8bd Luca Bigliardi
      logging.warning("Cannot set memory lock, ctypes module not found")
1084 4c32a8bd Luca Bigliardi
      request_executor_class = http.server.HttpServerRequestExecutor
1085 bebf68d3 Guido Trotter
  else:
1086 bebf68d3 Guido Trotter
    request_executor_class = http.server.HttpServerRequestExecutor
1087 02bea2fc Luca Bigliardi
1088 04ccf5e9 Guido Trotter
  # Read SSL certificate
1089 3b1b0cb6 Guido Trotter
  if options.ssl:
1090 3b1b0cb6 Guido Trotter
    ssl_params = http.HttpSslParams(ssl_key_path=options.ssl_key,
1091 3b1b0cb6 Guido Trotter
                                    ssl_cert_path=options.ssl_cert)
1092 3b1b0cb6 Guido Trotter
  else:
1093 3b1b0cb6 Guido Trotter
    ssl_params = None
1094 7d88772a Iustin Pop
1095 81198f6e Iustin Pop
  err = _PrepareQueueLock()
1096 81198f6e Iustin Pop
  if err is not None:
1097 81198f6e Iustin Pop
    # this might be some kind of file-system/permission error; while
1098 81198f6e Iustin Pop
    # this breaks the job queue functionality, we shouldn't prevent
1099 81198f6e Iustin Pop
    # startup of the whole node daemon because of this
1100 81198f6e Iustin Pop
    logging.critical("Can't init/verify the queue, proceeding anyway: %s", err)
1101 7d88772a Iustin Pop
1102 e0003509 Michael Hanselmann
  handler = NodeRequestHandler()
1103 e0003509 Michael Hanselmann
1104 04ccf5e9 Guido Trotter
  mainloop = daemon.Mainloop()
1105 e0003509 Michael Hanselmann
  server = \
1106 e0003509 Michael Hanselmann
    http.server.HttpServer(mainloop, options.bind_address, options.port,
1107 5ae4945a Iustin Pop
                           handler, ssl_params=ssl_params, ssl_verify_peer=True,
1108 5ae4945a Iustin Pop
                           request_executor_class=request_executor_class)
1109 04ccf5e9 Guido Trotter
  server.Start()
1110 e0003509 Michael Hanselmann
1111 3ee53f1f Iustin Pop
  return (mainloop, server)
1112 3ee53f1f Iustin Pop
1113 5119f2ec Michael Hanselmann
1114 b459a848 Andrea Spadaccini
def ExecNoded(options, args, prep_data): # pylint: disable=W0613
1115 3ee53f1f Iustin Pop
  """Main node daemon function, executed with the PID file held.
1116 3ee53f1f Iustin Pop

1117 3ee53f1f Iustin Pop
  """
1118 3ee53f1f Iustin Pop
  (mainloop, server) = prep_data
1119 04ccf5e9 Guido Trotter
  try:
1120 04ccf5e9 Guido Trotter
    mainloop.Run()
1121 04ccf5e9 Guido Trotter
  finally:
1122 04ccf5e9 Guido Trotter
    server.Stop()
1123 a8083063 Iustin Pop
1124 a8083063 Iustin Pop
1125 5119f2ec Michael Hanselmann
def Main():
1126 04ccf5e9 Guido Trotter
  """Main function for the node daemon.
1127 04ccf5e9 Guido Trotter

1128 04ccf5e9 Guido Trotter
  """
1129 04ccf5e9 Guido Trotter
  parser = OptionParser(description="Ganeti node daemon",
1130 04ccf5e9 Guido Trotter
                        usage="%prog [-f] [-d] [-p port] [-b ADDRESS]",
1131 04ccf5e9 Guido Trotter
                        version="%%prog (ganeti) %s" %
1132 04ccf5e9 Guido Trotter
                        constants.RELEASE_VERSION)
1133 bebf68d3 Guido Trotter
  parser.add_option("--no-mlock", dest="mlock",
1134 bebf68d3 Guido Trotter
                    help="Do not mlock the node memory in ram",
1135 bebf68d3 Guido Trotter
                    default=True, action="store_false")
1136 bebf68d3 Guido Trotter
1137 3ee53f1f Iustin Pop
  daemon.GenericMain(constants.NODED, parser, CheckNoded, PrepNoded, ExecNoded,
1138 a5ce2ea2 Michael Hanselmann
                     default_ssl_cert=pathutils.NODED_CERT_FILE,
1139 a5ce2ea2 Michael Hanselmann
                     default_ssl_key=pathutils.NODED_CERT_FILE,
1140 565083ef Luca Bigliardi
                     console_logging=True)