Statistics
| Branch: | Tag: | Revision:

root / lib / server / noded.py @ ec5af888

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 3f78eef2 Iustin Pop
    bdev_s, size, owner, on_primary, info = params
183 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
184 a8083063 Iustin Pop
    if bdev is None:
185 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
186 821d1bd1 Iustin Pop
    return backend.BlockdevCreate(bdev, size, owner, on_primary, info)
187 a8083063 Iustin Pop
188 3ecf6786 Iustin Pop
  @staticmethod
189 9c007da8 René Nussbaumer
  def perspective_blockdev_pause_resume_sync(params):
190 9c007da8 René Nussbaumer
    """Pause/resume sync of a block device.
191 9c007da8 René Nussbaumer

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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