Statistics
| Branch: | Tag: | Revision:

root / lib / server / noded.py @ bbf50ea0

History | View | Annotate | Download (30.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 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 1a3c5d4e Bernardo Dal Seno
    (vg_names, hv_names, excl_stor) = params
691 1a3c5d4e Bernardo Dal Seno
    return backend.GetNodeInfo(vg_names, hv_names, excl_stor)
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 14fe92c7 Bernardo Dal Seno
  @classmethod
710 14fe92c7 Bernardo Dal Seno
  def perspective_node_verify_light(cls, params):
711 14fe92c7 Bernardo Dal Seno
    """Run a light verify sequence on this node.
712 14fe92c7 Bernardo Dal Seno

713 14fe92c7 Bernardo Dal Seno
    """
714 14fe92c7 Bernardo Dal Seno
    # So far it's the same as the normal node_verify
715 14fe92c7 Bernardo Dal Seno
    return cls.perspective_node_verify(params)
716 14fe92c7 Bernardo Dal Seno
717 3ecf6786 Iustin Pop
  @staticmethod
718 fb460cf7 Andrea Spadaccini
  def perspective_node_start_master_daemons(params):
719 fb460cf7 Andrea Spadaccini
    """Start the master daemons on this node.
720 3ecf6786 Iustin Pop

721 3ecf6786 Iustin Pop
    """
722 fb460cf7 Andrea Spadaccini
    return backend.StartMasterDaemons(params[0])
723 fb460cf7 Andrea Spadaccini
724 fb460cf7 Andrea Spadaccini
  @staticmethod
725 fb460cf7 Andrea Spadaccini
  def perspective_node_activate_master_ip(params):
726 fb460cf7 Andrea Spadaccini
    """Activate 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.ActivateMasterIp(master_params, params[1])
731 fb460cf7 Andrea Spadaccini
732 fb460cf7 Andrea Spadaccini
  @staticmethod
733 fb460cf7 Andrea Spadaccini
  def perspective_node_deactivate_master_ip(params):
734 fb460cf7 Andrea Spadaccini
    """Deactivate the master IP on this node.
735 fb460cf7 Andrea Spadaccini

736 fb460cf7 Andrea Spadaccini
    """
737 c79198a0 Andrea Spadaccini
    master_params = objects.MasterNetworkParameters.FromDict(params[0])
738 57c7bc57 Andrea Spadaccini
    return backend.DeactivateMasterIp(master_params, params[1])
739 a8083063 Iustin Pop
740 3ecf6786 Iustin Pop
  @staticmethod
741 3ecf6786 Iustin Pop
  def perspective_node_stop_master(params):
742 7c74bbe0 Andrea Spadaccini
    """Stops master daemons on this node.
743 3ecf6786 Iustin Pop

744 3ecf6786 Iustin Pop
    """
745 fb460cf7 Andrea Spadaccini
    return backend.StopMasterDaemons()
746 a8083063 Iustin Pop
747 3ecf6786 Iustin Pop
  @staticmethod
748 5a8648eb Andrea Spadaccini
  def perspective_node_change_master_netmask(params):
749 5a8648eb Andrea Spadaccini
    """Change the master IP netmask.
750 5a8648eb Andrea Spadaccini

751 5a8648eb Andrea Spadaccini
    """
752 41e079ce Andrea Spadaccini
    return backend.ChangeMasterNetmask(params[0], params[1], params[2],
753 41e079ce Andrea Spadaccini
                                       params[3])
754 5a8648eb Andrea Spadaccini
755 5a8648eb Andrea Spadaccini
  @staticmethod
756 3ecf6786 Iustin Pop
  def perspective_node_leave_cluster(params):
757 3ecf6786 Iustin Pop
    """Cleanup after leaving a cluster.
758 3ecf6786 Iustin Pop

759 3ecf6786 Iustin Pop
    """
760 b989b9d9 Ken Wehr
    return backend.LeaveCluster(params[0])
761 a8083063 Iustin Pop
762 3ecf6786 Iustin Pop
  @staticmethod
763 3ecf6786 Iustin Pop
  def perspective_node_volumes(params):
764 3ecf6786 Iustin Pop
    """Query the list of all logical volume groups.
765 3ecf6786 Iustin Pop

766 3ecf6786 Iustin Pop
    """
767 dcb93971 Michael Hanselmann
    return backend.NodeVolumes()
768 dcb93971 Michael Hanselmann
769 56aa9fd5 Iustin Pop
  @staticmethod
770 56aa9fd5 Iustin Pop
  def perspective_node_demote_from_mc(params):
771 56aa9fd5 Iustin Pop
    """Demote a node from the master candidate role.
772 56aa9fd5 Iustin Pop

773 56aa9fd5 Iustin Pop
    """
774 56aa9fd5 Iustin Pop
    return backend.DemoteFromMC()
775 56aa9fd5 Iustin Pop
776 f5118ade Iustin Pop
  @staticmethod
777 f5118ade Iustin Pop
  def perspective_node_powercycle(params):
778 f5118ade Iustin Pop
    """Tries to powercycle the nod.
779 f5118ade Iustin Pop

780 f5118ade Iustin Pop
    """
781 f5118ade Iustin Pop
    hypervisor_type = params[0]
782 f5118ade Iustin Pop
    return backend.PowercycleNode(hypervisor_type)
783 f5118ade Iustin Pop
784 a8083063 Iustin Pop
  # cluster --------------------------
785 a8083063 Iustin Pop
786 3ecf6786 Iustin Pop
  @staticmethod
787 3ecf6786 Iustin Pop
  def perspective_version(params):
788 3ecf6786 Iustin Pop
    """Query version information.
789 3ecf6786 Iustin Pop

790 3ecf6786 Iustin Pop
    """
791 c26a6bd2 Iustin Pop
    return constants.PROTOCOL_VERSION
792 a8083063 Iustin Pop
793 3ecf6786 Iustin Pop
  @staticmethod
794 3ecf6786 Iustin Pop
  def perspective_upload_file(params):
795 3ecf6786 Iustin Pop
    """Upload a file.
796 3ecf6786 Iustin Pop

797 3ecf6786 Iustin Pop
    Note that the backend implementation imposes strict rules on which
798 3ecf6786 Iustin Pop
    files are accepted.
799 3ecf6786 Iustin Pop

800 3ecf6786 Iustin Pop
    """
801 415a7304 Michael Hanselmann
    return backend.UploadFile(*(params[0]))
802 a8083063 Iustin Pop
803 4e071d3b Iustin Pop
  @staticmethod
804 4e071d3b Iustin Pop
  def perspective_master_info(params):
805 4e071d3b Iustin Pop
    """Query master information.
806 4e071d3b Iustin Pop

807 4e071d3b Iustin Pop
    """
808 4e071d3b Iustin Pop
    return backend.GetMasterInfo()
809 a8083063 Iustin Pop
810 6ddc95ec Michael Hanselmann
  @staticmethod
811 4f6014d4 Renรฉ Nussbaumer
  def perspective_run_oob(params):
812 4f6014d4 Renรฉ Nussbaumer
    """Runs oob on node.
813 4f6014d4 Renรฉ Nussbaumer

814 4f6014d4 Renรฉ Nussbaumer
    """
815 1aa88d95 Renรฉ Nussbaumer
    output = backend.RunOob(params[0], params[1], params[2], params[3])
816 1aa88d95 Renรฉ Nussbaumer
    if output:
817 1aa88d95 Renรฉ Nussbaumer
      result = serializer.LoadJson(output)
818 1aa88d95 Renรฉ Nussbaumer
    else:
819 1aa88d95 Renรฉ Nussbaumer
      result = None
820 1aa88d95 Renรฉ Nussbaumer
    return result
821 4f6014d4 Renรฉ Nussbaumer
822 4f6014d4 Renรฉ Nussbaumer
  @staticmethod
823 db2203e0 Michael Hanselmann
  def perspective_restricted_command(params):
824 db2203e0 Michael Hanselmann
    """Runs a restricted command.
825 db2203e0 Michael Hanselmann

826 db2203e0 Michael Hanselmann
    """
827 db2203e0 Michael Hanselmann
    (cmd, ) = params
828 db2203e0 Michael Hanselmann
829 42bd26e8 Michael Hanselmann
    return backend.RunRestrictedCmd(cmd)
830 db2203e0 Michael Hanselmann
831 db2203e0 Michael Hanselmann
  @staticmethod
832 6ddc95ec Michael Hanselmann
  def perspective_write_ssconf_files(params):
833 6ddc95ec Michael Hanselmann
    """Write ssconf files.
834 6ddc95ec Michael Hanselmann

835 6ddc95ec Michael Hanselmann
    """
836 03d1dba2 Michael Hanselmann
    (values,) = params
837 ee501db1 Michael Hanselmann
    return ssconf.WriteSsconfFiles(values)
838 6ddc95ec Michael Hanselmann
839 99e222b1 Michael Hanselmann
  @staticmethod
840 ec5af888 Michael Hanselmann
  def perspective_get_watcher_pause(params):
841 ec5af888 Michael Hanselmann
    """Get watcher pause end.
842 ec5af888 Michael Hanselmann

843 ec5af888 Michael Hanselmann
    """
844 ec5af888 Michael Hanselmann
    return utils.ReadWatcherPauseFile(pathutils.WATCHER_PAUSEFILE)
845 ec5af888 Michael Hanselmann
846 ec5af888 Michael Hanselmann
  @staticmethod
847 99e222b1 Michael Hanselmann
  def perspective_set_watcher_pause(params):
848 99e222b1 Michael Hanselmann
    """Set watcher pause.
849 99e222b1 Michael Hanselmann

850 99e222b1 Michael Hanselmann
    """
851 99e222b1 Michael Hanselmann
    (until, ) = params
852 99e222b1 Michael Hanselmann
    return backend.SetWatcherPause(until)
853 99e222b1 Michael Hanselmann
854 a8083063 Iustin Pop
  # os -----------------------
855 a8083063 Iustin Pop
856 3ecf6786 Iustin Pop
  @staticmethod
857 3ecf6786 Iustin Pop
  def perspective_os_diagnose(params):
858 3ecf6786 Iustin Pop
    """Query detailed information about existing OSes.
859 3ecf6786 Iustin Pop

860 3ecf6786 Iustin Pop
    """
861 255dcebd Iustin Pop
    return backend.DiagnoseOS()
862 a8083063 Iustin Pop
863 3ecf6786 Iustin Pop
  @staticmethod
864 3ecf6786 Iustin Pop
  def perspective_os_get(params):
865 3ecf6786 Iustin Pop
    """Query information about a given OS.
866 3ecf6786 Iustin Pop

867 3ecf6786 Iustin Pop
    """
868 a8083063 Iustin Pop
    name = params[0]
869 255dcebd Iustin Pop
    os_obj = backend.OSFromDisk(name)
870 c26a6bd2 Iustin Pop
    return os_obj.ToDict()
871 a8083063 Iustin Pop
872 acd9ff9e Iustin Pop
  @staticmethod
873 acd9ff9e Iustin Pop
  def perspective_os_validate(params):
874 acd9ff9e Iustin Pop
    """Run a given OS' validation routine.
875 acd9ff9e Iustin Pop

876 acd9ff9e Iustin Pop
    """
877 acd9ff9e Iustin Pop
    required, name, checks, params = params
878 acd9ff9e Iustin Pop
    return backend.ValidateOS(required, name, checks, params)
879 acd9ff9e Iustin Pop
880 b954f097 Constantinos Venetsanopoulos
  # extstorage -----------------------
881 b954f097 Constantinos Venetsanopoulos
882 b954f097 Constantinos Venetsanopoulos
  @staticmethod
883 b954f097 Constantinos Venetsanopoulos
  def perspective_extstorage_diagnose(params):
884 b954f097 Constantinos Venetsanopoulos
    """Query detailed information about existing extstorage providers.
885 b954f097 Constantinos Venetsanopoulos

886 b954f097 Constantinos Venetsanopoulos
    """
887 b954f097 Constantinos Venetsanopoulos
    return backend.DiagnoseExtStorage()
888 b954f097 Constantinos Venetsanopoulos
889 a8083063 Iustin Pop
  # hooks -----------------------
890 a8083063 Iustin Pop
891 3ecf6786 Iustin Pop
  @staticmethod
892 3ecf6786 Iustin Pop
  def perspective_hooks_runner(params):
893 3ecf6786 Iustin Pop
    """Run hook scripts.
894 3ecf6786 Iustin Pop

895 3ecf6786 Iustin Pop
    """
896 a8083063 Iustin Pop
    hpath, phase, env = params
897 a8083063 Iustin Pop
    hr = backend.HooksRunner()
898 a8083063 Iustin Pop
    return hr.RunHooks(hpath, phase, env)
899 a8083063 Iustin Pop
900 8d528b7c Iustin Pop
  # iallocator -----------------
901 8d528b7c Iustin Pop
902 8d528b7c Iustin Pop
  @staticmethod
903 8d528b7c Iustin Pop
  def perspective_iallocator_runner(params):
904 8d528b7c Iustin Pop
    """Run an iallocator script.
905 8d528b7c Iustin Pop

906 8d528b7c Iustin Pop
    """
907 8d528b7c Iustin Pop
    name, idata = params
908 8d528b7c Iustin Pop
    iar = backend.IAllocatorRunner()
909 8d528b7c Iustin Pop
    return iar.Run(name, idata)
910 8d528b7c Iustin Pop
911 06009e27 Iustin Pop
  # test -----------------------
912 06009e27 Iustin Pop
913 06009e27 Iustin Pop
  @staticmethod
914 06009e27 Iustin Pop
  def perspective_test_delay(params):
915 06009e27 Iustin Pop
    """Run test delay.
916 06009e27 Iustin Pop

917 06009e27 Iustin Pop
    """
918 06009e27 Iustin Pop
    duration = params[0]
919 c26a6bd2 Iustin Pop
    status, rval = utils.TestDelay(duration)
920 c26a6bd2 Iustin Pop
    if not status:
921 c26a6bd2 Iustin Pop
      raise backend.RPCFail(rval)
922 c26a6bd2 Iustin Pop
    return rval
923 06009e27 Iustin Pop
924 4e071d3b Iustin Pop
  # file storage ---------------
925 4e071d3b Iustin Pop
926 a5d7fb43 Manuel Franceschini
  @staticmethod
927 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_create(params):
928 a5d7fb43 Manuel Franceschini
    """Create the file storage directory.
929 a5d7fb43 Manuel Franceschini

930 a5d7fb43 Manuel Franceschini
    """
931 a5d7fb43 Manuel Franceschini
    file_storage_dir = params[0]
932 a5d7fb43 Manuel Franceschini
    return backend.CreateFileStorageDir(file_storage_dir)
933 a5d7fb43 Manuel Franceschini
934 a5d7fb43 Manuel Franceschini
  @staticmethod
935 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_remove(params):
936 a5d7fb43 Manuel Franceschini
    """Remove the file storage directory.
937 a5d7fb43 Manuel Franceschini

938 a5d7fb43 Manuel Franceschini
    """
939 a5d7fb43 Manuel Franceschini
    file_storage_dir = params[0]
940 a5d7fb43 Manuel Franceschini
    return backend.RemoveFileStorageDir(file_storage_dir)
941 a5d7fb43 Manuel Franceschini
942 a5d7fb43 Manuel Franceschini
  @staticmethod
943 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_rename(params):
944 a5d7fb43 Manuel Franceschini
    """Rename the file storage directory.
945 a5d7fb43 Manuel Franceschini

946 a5d7fb43 Manuel Franceschini
    """
947 a5d7fb43 Manuel Franceschini
    old_file_storage_dir = params[0]
948 a5d7fb43 Manuel Franceschini
    new_file_storage_dir = params[1]
949 a5d7fb43 Manuel Franceschini
    return backend.RenameFileStorageDir(old_file_storage_dir,
950 a5d7fb43 Manuel Franceschini
                                        new_file_storage_dir)
951 a5d7fb43 Manuel Franceschini
952 4e071d3b Iustin Pop
  # jobs ------------------------
953 4e071d3b Iustin Pop
954 ca52cdeb Michael Hanselmann
  @staticmethod
955 7f30777b Michael Hanselmann
  @_RequireJobQueueLock
956 ca52cdeb Michael Hanselmann
  def perspective_jobqueue_update(params):
957 ca52cdeb Michael Hanselmann
    """Update job queue.
958 ca52cdeb Michael Hanselmann

959 ca52cdeb Michael Hanselmann
    """
960 ca52cdeb Michael Hanselmann
    (file_name, content) = params
961 7f30777b Michael Hanselmann
    return backend.JobQueueUpdate(file_name, content)
962 ca52cdeb Michael Hanselmann
963 ca52cdeb Michael Hanselmann
  @staticmethod
964 f1f3f45c Michael Hanselmann
  @_RequireJobQueueLock
965 ca52cdeb Michael Hanselmann
  def perspective_jobqueue_purge(params):
966 ca52cdeb Michael Hanselmann
    """Purge job queue.
967 ca52cdeb Michael Hanselmann

968 ca52cdeb Michael Hanselmann
    """
969 ca52cdeb Michael Hanselmann
    return backend.JobQueuePurge()
970 ca52cdeb Michael Hanselmann
971 af5ebcb1 Michael Hanselmann
  @staticmethod
972 af5ebcb1 Michael Hanselmann
  @_RequireJobQueueLock
973 af5ebcb1 Michael Hanselmann
  def perspective_jobqueue_rename(params):
974 af5ebcb1 Michael Hanselmann
    """Rename a job queue file.
975 af5ebcb1 Michael Hanselmann

976 af5ebcb1 Michael Hanselmann
    """
977 dd875d32 Michael Hanselmann
    # TODO: What if a file fails to rename?
978 fb1ffbca Michael Hanselmann
    return [backend.JobQueueRename(old, new) for old, new in params[0]]
979 af5ebcb1 Michael Hanselmann
980 be6c403e Michael Hanselmann
  @staticmethod
981 be6c403e Michael Hanselmann
  @_RequireJobQueueLock
982 be6c403e Michael Hanselmann
  def perspective_jobqueue_set_drain_flag(params):
983 be6c403e Michael Hanselmann
    """Set job queue's drain flag.
984 be6c403e Michael Hanselmann

985 be6c403e Michael Hanselmann
    """
986 be6c403e Michael Hanselmann
    (flag, ) = params
987 be6c403e Michael Hanselmann
988 be6c403e Michael Hanselmann
    return jstore.SetDrainFlag(flag)
989 be6c403e Michael Hanselmann
990 6217e295 Iustin Pop
  # hypervisor ---------------
991 6217e295 Iustin Pop
992 6217e295 Iustin Pop
  @staticmethod
993 6217e295 Iustin Pop
  def perspective_hypervisor_validate_params(params):
994 6217e295 Iustin Pop
    """Validate the hypervisor parameters.
995 6217e295 Iustin Pop

996 6217e295 Iustin Pop
    """
997 6217e295 Iustin Pop
    (hvname, hvparams) = params
998 6217e295 Iustin Pop
    return backend.ValidateHVParams(hvname, hvparams)
999 6217e295 Iustin Pop
1000 f942a838 Michael Hanselmann
  # Crypto
1001 f942a838 Michael Hanselmann
1002 f942a838 Michael Hanselmann
  @staticmethod
1003 ef40fbfb Michael Hanselmann
  def perspective_x509_cert_create(params):
1004 f942a838 Michael Hanselmann
    """Creates a new X509 certificate for SSL/TLS.
1005 f942a838 Michael Hanselmann

1006 f942a838 Michael Hanselmann
    """
1007 f942a838 Michael Hanselmann
    (validity, ) = params
1008 f942a838 Michael Hanselmann
    return backend.CreateX509Certificate(validity)
1009 f942a838 Michael Hanselmann
1010 f942a838 Michael Hanselmann
  @staticmethod
1011 ef40fbfb Michael Hanselmann
  def perspective_x509_cert_remove(params):
1012 f942a838 Michael Hanselmann
    """Removes a X509 certificate.
1013 f942a838 Michael Hanselmann

1014 f942a838 Michael Hanselmann
    """
1015 f942a838 Michael Hanselmann
    (name, ) = params
1016 f942a838 Michael Hanselmann
    return backend.RemoveX509Certificate(name)
1017 f942a838 Michael Hanselmann
1018 1651d116 Michael Hanselmann
  # Import and export
1019 1651d116 Michael Hanselmann
1020 1651d116 Michael Hanselmann
  @staticmethod
1021 ef40fbfb Michael Hanselmann
  def perspective_import_start(params):
1022 1651d116 Michael Hanselmann
    """Starts an import daemon.
1023 1651d116 Michael Hanselmann

1024 1651d116 Michael Hanselmann
    """
1025 b8c160c1 Michael Hanselmann
    (opts_s, instance, component, (dest, dest_args)) = params
1026 eb630f50 Michael Hanselmann
1027 eb630f50 Michael Hanselmann
    opts = objects.ImportExportOptions.FromDict(opts_s)
1028 eb630f50 Michael Hanselmann
1029 eb630f50 Michael Hanselmann
    return backend.StartImportExportDaemon(constants.IEM_IMPORT, opts,
1030 1651d116 Michael Hanselmann
                                           None, None,
1031 1651d116 Michael Hanselmann
                                           objects.Instance.FromDict(instance),
1032 6613661a Iustin Pop
                                           component, dest,
1033 1651d116 Michael Hanselmann
                                           _DecodeImportExportIO(dest,
1034 1651d116 Michael Hanselmann
                                                                 dest_args))
1035 eb630f50 Michael Hanselmann
1036 1651d116 Michael Hanselmann
  @staticmethod
1037 ef40fbfb Michael Hanselmann
  def perspective_export_start(params):
1038 1651d116 Michael Hanselmann
    """Starts an export daemon.
1039 1651d116 Michael Hanselmann

1040 1651d116 Michael Hanselmann
    """
1041 b8c160c1 Michael Hanselmann
    (opts_s, host, port, instance, component, (source, source_args)) = params
1042 eb630f50 Michael Hanselmann
1043 eb630f50 Michael Hanselmann
    opts = objects.ImportExportOptions.FromDict(opts_s)
1044 eb630f50 Michael Hanselmann
1045 eb630f50 Michael Hanselmann
    return backend.StartImportExportDaemon(constants.IEM_EXPORT, opts,
1046 1651d116 Michael Hanselmann
                                           host, port,
1047 1651d116 Michael Hanselmann
                                           objects.Instance.FromDict(instance),
1048 6613661a Iustin Pop
                                           component, source,
1049 1651d116 Michael Hanselmann
                                           _DecodeImportExportIO(source,
1050 1651d116 Michael Hanselmann
                                                                 source_args))
1051 1651d116 Michael Hanselmann
1052 1651d116 Michael Hanselmann
  @staticmethod
1053 ef40fbfb Michael Hanselmann
  def perspective_impexp_status(params):
1054 1651d116 Michael Hanselmann
    """Retrieves the status of an import or export daemon.
1055 1651d116 Michael Hanselmann

1056 1651d116 Michael Hanselmann
    """
1057 1651d116 Michael Hanselmann
    return backend.GetImportExportStatus(params[0])
1058 1651d116 Michael Hanselmann
1059 1651d116 Michael Hanselmann
  @staticmethod
1060 f81c4737 Michael Hanselmann
  def perspective_impexp_abort(params):
1061 f81c4737 Michael Hanselmann
    """Aborts an import or export.
1062 f81c4737 Michael Hanselmann

1063 f81c4737 Michael Hanselmann
    """
1064 f81c4737 Michael Hanselmann
    return backend.AbortImportExport(params[0])
1065 f81c4737 Michael Hanselmann
1066 f81c4737 Michael Hanselmann
  @staticmethod
1067 ef40fbfb Michael Hanselmann
  def perspective_impexp_cleanup(params):
1068 1651d116 Michael Hanselmann
    """Cleans up after an import or export.
1069 1651d116 Michael Hanselmann

1070 1651d116 Michael Hanselmann
    """
1071 1651d116 Michael Hanselmann
    return backend.CleanupImportExport(params[0])
1072 1651d116 Michael Hanselmann
1073 a8083063 Iustin Pop
1074 f93427cd Iustin Pop
def CheckNoded(_, args):
1075 f93427cd Iustin Pop
  """Initial checks whether to run or exit with a failure.
1076 f93427cd Iustin Pop

1077 f93427cd Iustin Pop
  """
1078 f93427cd Iustin Pop
  if args: # noded doesn't take any arguments
1079 f93427cd Iustin Pop
    print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" %
1080 f93427cd Iustin Pop
                          sys.argv[0])
1081 f93427cd Iustin Pop
    sys.exit(constants.EXIT_FAILURE)
1082 f01738fc Iustin Pop
  try:
1083 f01738fc Iustin Pop
    codecs.lookup("string-escape")
1084 f01738fc Iustin Pop
  except LookupError:
1085 f01738fc Iustin Pop
    print >> sys.stderr, ("Can't load the string-escape code which is part"
1086 f01738fc Iustin Pop
                          " of the Python installation. Is your installation"
1087 f01738fc Iustin Pop
                          " complete/correct? Aborting.")
1088 f01738fc Iustin Pop
    sys.exit(constants.EXIT_FAILURE)
1089 f93427cd Iustin Pop
1090 f93427cd Iustin Pop
1091 3ee53f1f Iustin Pop
def PrepNoded(options, _):
1092 3ee53f1f Iustin Pop
  """Preparation node daemon function, executed with the PID file held.
1093 3ecf6786 Iustin Pop

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

1134 3ee53f1f Iustin Pop
  """
1135 3ee53f1f Iustin Pop
  (mainloop, server) = prep_data
1136 04ccf5e9 Guido Trotter
  try:
1137 04ccf5e9 Guido Trotter
    mainloop.Run()
1138 04ccf5e9 Guido Trotter
  finally:
1139 04ccf5e9 Guido Trotter
    server.Stop()
1140 a8083063 Iustin Pop
1141 a8083063 Iustin Pop
1142 5119f2ec Michael Hanselmann
def Main():
1143 04ccf5e9 Guido Trotter
  """Main function for the node daemon.
1144 04ccf5e9 Guido Trotter

1145 04ccf5e9 Guido Trotter
  """
1146 04ccf5e9 Guido Trotter
  parser = OptionParser(description="Ganeti node daemon",
1147 04ccf5e9 Guido Trotter
                        usage="%prog [-f] [-d] [-p port] [-b ADDRESS]",
1148 04ccf5e9 Guido Trotter
                        version="%%prog (ganeti) %s" %
1149 04ccf5e9 Guido Trotter
                        constants.RELEASE_VERSION)
1150 bebf68d3 Guido Trotter
  parser.add_option("--no-mlock", dest="mlock",
1151 bebf68d3 Guido Trotter
                    help="Do not mlock the node memory in ram",
1152 bebf68d3 Guido Trotter
                    default=True, action="store_false")
1153 bebf68d3 Guido Trotter
1154 3ee53f1f Iustin Pop
  daemon.GenericMain(constants.NODED, parser, CheckNoded, PrepNoded, ExecNoded,
1155 a5ce2ea2 Michael Hanselmann
                     default_ssl_cert=pathutils.NODED_CERT_FILE,
1156 a5ce2ea2 Michael Hanselmann
                     default_ssl_key=pathutils.NODED_CERT_FILE,
1157 565083ef Luca Bigliardi
                     console_logging=True)