Statistics
| Branch: | Tag: | Revision:

root / daemons / ganeti-noded @ 560cbec1

History | View | Annotate | Download (25.4 kB)

1 a8083063 Iustin Pop
#!/usr/bin/python
2 a8083063 Iustin Pop
#
3 a8083063 Iustin Pop
4 a8083063 Iustin Pop
# Copyright (C) 2006, 2007 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 7260cfbe Iustin Pop
# pylint: disable-msg=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 a8083063 Iustin Pop
37 a8083063 Iustin Pop
from optparse import OptionParser
38 a8083063 Iustin Pop
39 a8083063 Iustin Pop
from ganeti import backend
40 a8083063 Iustin Pop
from ganeti import constants
41 a8083063 Iustin Pop
from ganeti import objects
42 a8083063 Iustin Pop
from ganeti import errors
43 25d6d12a Michael Hanselmann
from ganeti import jstore
44 cc28af80 Michael Hanselmann
from ganeti import daemon
45 1df6506c Michael Hanselmann
from ganeti import http
46 16abfbc2 Alexander Schreiber
from ganeti import utils
47 e337de97 Michael Hanselmann
from ganeti import storage
48 ab221ddf Michael Hanselmann
from ganeti import serializer
49 a8083063 Iustin Pop
50 30e4e741 Iustin Pop
import ganeti.http.server # pylint: disable-msg=W0611
51 19205c39 Michael Hanselmann
52 a8083063 Iustin Pop
53 25d6d12a Michael Hanselmann
queue_lock = None
54 25d6d12a Michael Hanselmann
55 25d6d12a Michael Hanselmann
56 81198f6e Iustin Pop
def _PrepareQueueLock():
57 81198f6e Iustin Pop
  """Try to prepare the queue lock.
58 81198f6e Iustin Pop
59 81198f6e Iustin Pop
  @return: None for success, otherwise an exception object
60 81198f6e Iustin Pop
61 81198f6e Iustin Pop
  """
62 81198f6e Iustin Pop
  global queue_lock # pylint: disable-msg=W0603
63 81198f6e Iustin Pop
64 81198f6e Iustin Pop
  if queue_lock is not None:
65 81198f6e Iustin Pop
    return None
66 81198f6e Iustin Pop
67 81198f6e Iustin Pop
  # Prepare job queue
68 81198f6e Iustin Pop
  try:
69 81198f6e Iustin Pop
    queue_lock = jstore.InitAndVerifyQueue(must_lock=False)
70 81198f6e Iustin Pop
    return None
71 81198f6e Iustin Pop
  except EnvironmentError, err:
72 81198f6e Iustin Pop
    return err
73 81198f6e Iustin Pop
74 81198f6e Iustin Pop
75 7f30777b Michael Hanselmann
def _RequireJobQueueLock(fn):
76 7f30777b Michael Hanselmann
  """Decorator for job queue manipulating functions.
77 7f30777b Michael Hanselmann
78 7f30777b Michael Hanselmann
  """
79 8785cb30 Michael Hanselmann
  QUEUE_LOCK_TIMEOUT = 10
80 8785cb30 Michael Hanselmann
81 7f30777b Michael Hanselmann
  def wrapper(*args, **kwargs):
82 7f30777b Michael Hanselmann
    # Locking in exclusive, blocking mode because there could be several
83 506cff12 Michael Hanselmann
    # children running at the same time. Waiting up to 10 seconds.
84 81198f6e Iustin Pop
    if _PrepareQueueLock() is not None:
85 81198f6e Iustin Pop
      raise errors.JobQueueError("Job queue failed initialization,"
86 81198f6e Iustin Pop
                                 " cannot update jobs")
87 8785cb30 Michael Hanselmann
    queue_lock.Exclusive(blocking=True, timeout=QUEUE_LOCK_TIMEOUT)
88 7f30777b Michael Hanselmann
    try:
89 7f30777b Michael Hanselmann
      return fn(*args, **kwargs)
90 7f30777b Michael Hanselmann
    finally:
91 7f30777b Michael Hanselmann
      queue_lock.Unlock()
92 8785cb30 Michael Hanselmann
93 7f30777b Michael Hanselmann
  return wrapper
94 7f30777b Michael Hanselmann
95 7f30777b Michael Hanselmann
96 1651d116 Michael Hanselmann
def _DecodeImportExportIO(ieio, ieioargs):
97 1651d116 Michael Hanselmann
  """Decodes import/export I/O information.
98 1651d116 Michael Hanselmann
99 1651d116 Michael Hanselmann
  """
100 1651d116 Michael Hanselmann
  if ieio == constants.IEIO_RAW_DISK:
101 1651d116 Michael Hanselmann
    assert len(ieioargs) == 1
102 1651d116 Michael Hanselmann
    return (objects.Disk.FromDict(ieioargs[0]), )
103 1651d116 Michael Hanselmann
104 1651d116 Michael Hanselmann
  if ieio == constants.IEIO_SCRIPT:
105 1651d116 Michael Hanselmann
    assert len(ieioargs) == 2
106 1651d116 Michael Hanselmann
    return (objects.Disk.FromDict(ieioargs[0]), ieioargs[1])
107 1651d116 Michael Hanselmann
108 1651d116 Michael Hanselmann
  return ieioargs
109 1651d116 Michael Hanselmann
110 1651d116 Michael Hanselmann
111 38b77287 Luca Bigliardi
class MlockallRequestExecutor(http.server.HttpServerRequestExecutor):
112 38b77287 Luca Bigliardi
  """Custom Request Executor class that ensures NodeHttpServer children are
113 38b77287 Luca Bigliardi
  locked in ram.
114 38b77287 Luca Bigliardi
115 38b77287 Luca Bigliardi
  """
116 38b77287 Luca Bigliardi
  def __init__(self, *args, **kwargs):
117 38b77287 Luca Bigliardi
    utils.Mlockall()
118 38b77287 Luca Bigliardi
119 38b77287 Luca Bigliardi
    http.server.HttpServerRequestExecutor.__init__(self, *args, **kwargs)
120 38b77287 Luca Bigliardi
121 38b77287 Luca Bigliardi
122 19205c39 Michael Hanselmann
class NodeHttpServer(http.server.HttpServer):
123 3ecf6786 Iustin Pop
  """The server implementation.
124 3ecf6786 Iustin Pop
125 3ecf6786 Iustin Pop
  This class holds all methods exposed over the RPC interface.
126 3ecf6786 Iustin Pop
127 3ecf6786 Iustin Pop
  """
128 2d54e29c Iustin Pop
  # too many public methods, and unused args - all methods get params
129 2d54e29c Iustin Pop
  # due to the API
130 2d54e29c Iustin Pop
  # pylint: disable-msg=R0904,W0613
131 cc28af80 Michael Hanselmann
  def __init__(self, *args, **kwargs):
132 19205c39 Michael Hanselmann
    http.server.HttpServer.__init__(self, *args, **kwargs)
133 cc28af80 Michael Hanselmann
    self.noded_pid = os.getpid()
134 cc28af80 Michael Hanselmann
135 cc28af80 Michael Hanselmann
  def HandleRequest(self, req):
136 1df6506c Michael Hanselmann
    """Handle a request.
137 a8083063 Iustin Pop
138 098c0958 Michael Hanselmann
    """
139 19205c39 Michael Hanselmann
    if req.request_method.upper() != http.HTTP_PUT:
140 84f2756e Michael Hanselmann
      raise http.HttpBadRequest()
141 1df6506c Michael Hanselmann
142 cc28af80 Michael Hanselmann
    path = req.request_path
143 81010134 Iustin Pop
    if path.startswith("/"):
144 81010134 Iustin Pop
      path = path[1:]
145 81010134 Iustin Pop
146 1df6506c Michael Hanselmann
    method = getattr(self, "perspective_%s" % path, None)
147 1df6506c Michael Hanselmann
    if method is None:
148 84f2756e Michael Hanselmann
      raise http.HttpNotFound()
149 a8083063 Iustin Pop
150 81010134 Iustin Pop
    try:
151 ab221ddf Michael Hanselmann
      result = (True, method(serializer.LoadJson(req.request_body)))
152 4dd42c9d Iustin Pop
153 0623d351 Iustin Pop
    except backend.RPCFail, err:
154 0623d351 Iustin Pop
      # our custom failure exception; str(err) works fine if the
155 0623d351 Iustin Pop
      # exception was constructed with a single argument, and in
156 0623d351 Iustin Pop
      # this case, err.message == err.args[0] == str(err)
157 ab221ddf Michael Hanselmann
      result = (False, str(err))
158 9ae49f27 Guido Trotter
    except errors.QuitGanetiException, err:
159 84b58db2 Michael Hanselmann
      # Tell parent to quit
160 0623d351 Iustin Pop
      logging.info("Shutting down the node daemon, arguments: %s",
161 0623d351 Iustin Pop
                   str(err.args))
162 cc28af80 Michael Hanselmann
      os.kill(self.noded_pid, signal.SIGTERM)
163 0623d351 Iustin Pop
      # And return the error's arguments, which must be already in
164 0623d351 Iustin Pop
      # correct tuple format
165 ab221ddf Michael Hanselmann
      result = err.args
166 4dd42c9d Iustin Pop
    except Exception, err:
167 0623d351 Iustin Pop
      logging.exception("Error in RPC call")
168 ab221ddf Michael Hanselmann
      result = (False, "Error while executing backend function: %s" % str(err))
169 ab221ddf Michael Hanselmann
170 ab221ddf Michael Hanselmann
    return serializer.DumpJson(result, indent=False)
171 a8083063 Iustin Pop
172 a8083063 Iustin Pop
  # the new block devices  --------------------------
173 a8083063 Iustin Pop
174 3ecf6786 Iustin Pop
  @staticmethod
175 3ecf6786 Iustin Pop
  def perspective_blockdev_create(params):
176 3ecf6786 Iustin Pop
    """Create a block device.
177 3ecf6786 Iustin Pop
178 3ecf6786 Iustin Pop
    """
179 3f78eef2 Iustin Pop
    bdev_s, size, owner, on_primary, info = params
180 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
181 a8083063 Iustin Pop
    if bdev is None:
182 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
183 821d1bd1 Iustin Pop
    return backend.BlockdevCreate(bdev, size, owner, on_primary, info)
184 a8083063 Iustin Pop
185 3ecf6786 Iustin Pop
  @staticmethod
186 3ecf6786 Iustin Pop
  def perspective_blockdev_remove(params):
187 3ecf6786 Iustin Pop
    """Remove a block device.
188 3ecf6786 Iustin Pop
189 3ecf6786 Iustin Pop
    """
190 a8083063 Iustin Pop
    bdev_s = params[0]
191 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
192 821d1bd1 Iustin Pop
    return backend.BlockdevRemove(bdev)
193 a8083063 Iustin Pop
194 3ecf6786 Iustin Pop
  @staticmethod
195 f3e513ad Iustin Pop
  def perspective_blockdev_rename(params):
196 f3e513ad Iustin Pop
    """Remove a block device.
197 f3e513ad Iustin Pop
198 f3e513ad Iustin Pop
    """
199 f3e513ad Iustin Pop
    devlist = [(objects.Disk.FromDict(ds), uid) for ds, uid in params]
200 821d1bd1 Iustin Pop
    return backend.BlockdevRename(devlist)
201 f3e513ad Iustin Pop
202 f3e513ad Iustin Pop
  @staticmethod
203 3ecf6786 Iustin Pop
  def perspective_blockdev_assemble(params):
204 3ecf6786 Iustin Pop
    """Assemble a block device.
205 3ecf6786 Iustin Pop
206 3ecf6786 Iustin Pop
    """
207 3f78eef2 Iustin Pop
    bdev_s, owner, on_primary = params
208 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
209 a8083063 Iustin Pop
    if bdev is None:
210 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
211 821d1bd1 Iustin Pop
    return backend.BlockdevAssemble(bdev, owner, on_primary)
212 a8083063 Iustin Pop
213 3ecf6786 Iustin Pop
  @staticmethod
214 3ecf6786 Iustin Pop
  def perspective_blockdev_shutdown(params):
215 3ecf6786 Iustin Pop
    """Shutdown a block device.
216 3ecf6786 Iustin Pop
217 3ecf6786 Iustin Pop
    """
218 a8083063 Iustin Pop
    bdev_s = params[0]
219 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
220 a8083063 Iustin Pop
    if bdev is None:
221 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
222 821d1bd1 Iustin Pop
    return backend.BlockdevShutdown(bdev)
223 a8083063 Iustin Pop
224 3ecf6786 Iustin Pop
  @staticmethod
225 153d9724 Iustin Pop
  def perspective_blockdev_addchildren(params):
226 3ecf6786 Iustin Pop
    """Add a child to a mirror device.
227 3ecf6786 Iustin Pop
228 3ecf6786 Iustin Pop
    Note: this is only valid for mirror devices. It's the caller's duty
229 3ecf6786 Iustin Pop
    to send a correct disk, otherwise we raise an error.
230 3ecf6786 Iustin Pop
231 3ecf6786 Iustin Pop
    """
232 a8083063 Iustin Pop
    bdev_s, ndev_s = params
233 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
234 153d9724 Iustin Pop
    ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
235 153d9724 Iustin Pop
    if bdev is None or ndevs.count(None) > 0:
236 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
237 821d1bd1 Iustin Pop
    return backend.BlockdevAddchildren(bdev, ndevs)
238 a8083063 Iustin Pop
239 3ecf6786 Iustin Pop
  @staticmethod
240 153d9724 Iustin Pop
  def perspective_blockdev_removechildren(params):
241 3ecf6786 Iustin Pop
    """Remove a child from a mirror device.
242 3ecf6786 Iustin Pop
243 3ecf6786 Iustin Pop
    This is only valid for mirror devices, of course. It's the callers
244 3ecf6786 Iustin Pop
    duty to send a correct disk, otherwise we raise an error.
245 3ecf6786 Iustin Pop
246 3ecf6786 Iustin Pop
    """
247 a8083063 Iustin Pop
    bdev_s, ndev_s = params
248 319856a9 Michael Hanselmann
    bdev = objects.Disk.FromDict(bdev_s)
249 153d9724 Iustin Pop
    ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
250 153d9724 Iustin Pop
    if bdev is None or ndevs.count(None) > 0:
251 a8083063 Iustin Pop
      raise ValueError("can't unserialize data!")
252 821d1bd1 Iustin Pop
    return backend.BlockdevRemovechildren(bdev, ndevs)
253 a8083063 Iustin Pop
254 3ecf6786 Iustin Pop
  @staticmethod
255 3ecf6786 Iustin Pop
  def perspective_blockdev_getmirrorstatus(params):
256 3ecf6786 Iustin Pop
    """Return the mirror status for a list of disks.
257 3ecf6786 Iustin Pop
258 3ecf6786 Iustin Pop
    """
259 319856a9 Michael Hanselmann
    disks = [objects.Disk.FromDict(dsk_s)
260 36145b12 Michael Hanselmann
             for dsk_s in params]
261 36145b12 Michael Hanselmann
    return [status.ToDict()
262 36145b12 Michael Hanselmann
            for status in backend.BlockdevGetmirrorstatus(disks)]
263 a8083063 Iustin Pop
264 3ecf6786 Iustin Pop
  @staticmethod
265 3ecf6786 Iustin Pop
  def perspective_blockdev_find(params):
266 3ecf6786 Iustin Pop
    """Expose the FindBlockDevice functionality for a disk.
267 3ecf6786 Iustin Pop
268 3ecf6786 Iustin Pop
    This will try to find but not activate a disk.
269 3ecf6786 Iustin Pop
270 3ecf6786 Iustin Pop
    """
271 319856a9 Michael Hanselmann
    disk = objects.Disk.FromDict(params[0])
272 ddfe2228 Michael Hanselmann
273 ddfe2228 Michael Hanselmann
    result = backend.BlockdevFind(disk)
274 ddfe2228 Michael Hanselmann
    if result is None:
275 ddfe2228 Michael Hanselmann
      return None
276 ddfe2228 Michael Hanselmann
277 ddfe2228 Michael Hanselmann
    return result.ToDict()
278 a8083063 Iustin Pop
279 3ecf6786 Iustin Pop
  @staticmethod
280 3ecf6786 Iustin Pop
  def perspective_blockdev_snapshot(params):
281 3ecf6786 Iustin Pop
    """Create a snapshot device.
282 3ecf6786 Iustin Pop
283 3ecf6786 Iustin Pop
    Note that this is only valid for LVM disks, if we get passed
284 3ecf6786 Iustin Pop
    something else we raise an exception. The snapshot device can be
285 3ecf6786 Iustin Pop
    remove by calling the generic block device remove call.
286 3ecf6786 Iustin Pop
287 3ecf6786 Iustin Pop
    """
288 319856a9 Michael Hanselmann
    cfbd = objects.Disk.FromDict(params[0])
289 821d1bd1 Iustin Pop
    return backend.BlockdevSnapshot(cfbd)
290 a8083063 Iustin Pop
291 4c8ba8b3 Iustin Pop
  @staticmethod
292 4c8ba8b3 Iustin Pop
  def perspective_blockdev_grow(params):
293 4c8ba8b3 Iustin Pop
    """Grow a stack of devices.
294 4c8ba8b3 Iustin Pop
295 4c8ba8b3 Iustin Pop
    """
296 4c8ba8b3 Iustin Pop
    cfbd = objects.Disk.FromDict(params[0])
297 4c8ba8b3 Iustin Pop
    amount = params[1]
298 821d1bd1 Iustin Pop
    return backend.BlockdevGrow(cfbd, amount)
299 4c8ba8b3 Iustin Pop
300 d61cbe76 Iustin Pop
  @staticmethod
301 d61cbe76 Iustin Pop
  def perspective_blockdev_close(params):
302 d61cbe76 Iustin Pop
    """Closes the given block devices.
303 d61cbe76 Iustin Pop
304 d61cbe76 Iustin Pop
    """
305 b2e7666a Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in params[1]]
306 821d1bd1 Iustin Pop
    return backend.BlockdevClose(params[0], disks)
307 d61cbe76 Iustin Pop
308 968a7623 Iustin Pop
  @staticmethod
309 968a7623 Iustin Pop
  def perspective_blockdev_getsize(params):
310 968a7623 Iustin Pop
    """Compute the sizes of the given block devices.
311 968a7623 Iustin Pop
312 968a7623 Iustin Pop
    """
313 968a7623 Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in params[0]]
314 968a7623 Iustin Pop
    return backend.BlockdevGetsize(disks)
315 968a7623 Iustin Pop
316 858f3d18 Iustin Pop
  @staticmethod
317 858f3d18 Iustin Pop
  def perspective_blockdev_export(params):
318 858f3d18 Iustin Pop
    """Compute the sizes of the given block devices.
319 858f3d18 Iustin Pop
320 858f3d18 Iustin Pop
    """
321 858f3d18 Iustin Pop
    disk = objects.Disk.FromDict(params[0])
322 858f3d18 Iustin Pop
    dest_node, dest_path, cluster_name = params[1:]
323 858f3d18 Iustin Pop
    return backend.BlockdevExport(disk, dest_node, dest_path, cluster_name)
324 858f3d18 Iustin Pop
325 6b93ec9d Iustin Pop
  # blockdev/drbd specific methods ----------
326 6b93ec9d Iustin Pop
327 6b93ec9d Iustin Pop
  @staticmethod
328 6b93ec9d Iustin Pop
  def perspective_drbd_disconnect_net(params):
329 6b93ec9d Iustin Pop
    """Disconnects the network connection of drbd disks.
330 6b93ec9d Iustin Pop
331 6b93ec9d Iustin Pop
    Note that this is only valid for drbd disks, so the members of the
332 6b93ec9d Iustin Pop
    disk list must all be drbd devices.
333 6b93ec9d Iustin Pop
334 6b93ec9d Iustin Pop
    """
335 6b93ec9d Iustin Pop
    nodes_ip, disks = params
336 6b93ec9d Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in disks]
337 6b93ec9d Iustin Pop
    return backend.DrbdDisconnectNet(nodes_ip, disks)
338 6b93ec9d Iustin Pop
339 6b93ec9d Iustin Pop
  @staticmethod
340 6b93ec9d Iustin Pop
  def perspective_drbd_attach_net(params):
341 6b93ec9d Iustin Pop
    """Attaches the network connection of drbd disks.
342 6b93ec9d Iustin Pop
343 6b93ec9d Iustin Pop
    Note that this is only valid for drbd disks, so the members of the
344 6b93ec9d Iustin Pop
    disk list must all be drbd devices.
345 6b93ec9d Iustin Pop
346 6b93ec9d Iustin Pop
    """
347 6b93ec9d Iustin Pop
    nodes_ip, disks, instance_name, multimaster = params
348 6b93ec9d Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in disks]
349 821d1bd1 Iustin Pop
    return backend.DrbdAttachNet(nodes_ip, disks,
350 821d1bd1 Iustin Pop
                                     instance_name, multimaster)
351 6b93ec9d Iustin Pop
352 6b93ec9d Iustin Pop
  @staticmethod
353 6b93ec9d Iustin Pop
  def perspective_drbd_wait_sync(params):
354 6b93ec9d Iustin Pop
    """Wait until DRBD disks are synched.
355 6b93ec9d Iustin Pop
356 6b93ec9d Iustin Pop
    Note that this is only valid for drbd disks, so the members of the
357 6b93ec9d Iustin Pop
    disk list must all be drbd devices.
358 6b93ec9d Iustin Pop
359 6b93ec9d Iustin Pop
    """
360 6b93ec9d Iustin Pop
    nodes_ip, disks = params
361 6b93ec9d Iustin Pop
    disks = [objects.Disk.FromDict(cf) for cf in disks]
362 6b93ec9d Iustin Pop
    return backend.DrbdWaitSync(nodes_ip, disks)
363 6b93ec9d Iustin Pop
364 a8083063 Iustin Pop
  # export/import  --------------------------
365 a8083063 Iustin Pop
366 3ecf6786 Iustin Pop
  @staticmethod
367 3ecf6786 Iustin Pop
  def perspective_finalize_export(params):
368 3ecf6786 Iustin Pop
    """Expose the finalize export functionality.
369 a8083063 Iustin Pop
370 3ecf6786 Iustin Pop
    """
371 319856a9 Michael Hanselmann
    instance = objects.Instance.FromDict(params[0])
372 7b651654 Michael Hanselmann
373 7b651654 Michael Hanselmann
    snap_disks = []
374 7b651654 Michael Hanselmann
    for disk in params[1]:
375 7b651654 Michael Hanselmann
      if isinstance(disk, bool):
376 7b651654 Michael Hanselmann
        snap_disks.append(disk)
377 7b651654 Michael Hanselmann
      else:
378 7b651654 Michael Hanselmann
        snap_disks.append(objects.Disk.FromDict(disk))
379 7b651654 Michael Hanselmann
380 a8083063 Iustin Pop
    return backend.FinalizeExport(instance, snap_disks)
381 a8083063 Iustin Pop
382 3ecf6786 Iustin Pop
  @staticmethod
383 3ecf6786 Iustin Pop
  def perspective_export_info(params):
384 3ecf6786 Iustin Pop
    """Query information about an existing export on this node.
385 3ecf6786 Iustin Pop
386 3ecf6786 Iustin Pop
    The given path may not contain an export, in which case we return
387 3ecf6786 Iustin Pop
    None.
388 3ecf6786 Iustin Pop
389 3ecf6786 Iustin Pop
    """
390 3ecf6786 Iustin Pop
    path = params[0]
391 3eccac06 Iustin Pop
    return backend.ExportInfo(path)
392 a8083063 Iustin Pop
393 3ecf6786 Iustin Pop
  @staticmethod
394 3ecf6786 Iustin Pop
  def perspective_export_list(params):
395 3ecf6786 Iustin Pop
    """List the available exports on this node.
396 3ecf6786 Iustin Pop
397 3ecf6786 Iustin Pop
    Note that as opposed to export_info, which may query data about an
398 3ecf6786 Iustin Pop
    export in any path, this only queries the standard Ganeti path
399 3ecf6786 Iustin Pop
    (constants.EXPORT_DIR).
400 3ecf6786 Iustin Pop
401 3ecf6786 Iustin Pop
    """
402 a8083063 Iustin Pop
    return backend.ListExports()
403 a8083063 Iustin Pop
404 3ecf6786 Iustin Pop
  @staticmethod
405 3ecf6786 Iustin Pop
  def perspective_export_remove(params):
406 3ecf6786 Iustin Pop
    """Remove an export.
407 3ecf6786 Iustin Pop
408 3ecf6786 Iustin Pop
    """
409 a8083063 Iustin Pop
    export = params[0]
410 a8083063 Iustin Pop
    return backend.RemoveExport(export)
411 a8083063 Iustin Pop
412 a8083063 Iustin Pop
  # volume  --------------------------
413 a8083063 Iustin Pop
414 3ecf6786 Iustin Pop
  @staticmethod
415 b2a6ccd4 Iustin Pop
  def perspective_lv_list(params):
416 3ecf6786 Iustin Pop
    """Query the list of logical volumes in a given volume group.
417 3ecf6786 Iustin Pop
418 3ecf6786 Iustin Pop
    """
419 a8083063 Iustin Pop
    vgname = params[0]
420 c26a6bd2 Iustin Pop
    return backend.GetVolumeList(vgname)
421 a8083063 Iustin Pop
422 3ecf6786 Iustin Pop
  @staticmethod
423 3ecf6786 Iustin Pop
  def perspective_vg_list(params):
424 3ecf6786 Iustin Pop
    """Query the list of volume groups.
425 3ecf6786 Iustin Pop
426 3ecf6786 Iustin Pop
    """
427 a8083063 Iustin Pop
    return backend.ListVolumeGroups()
428 a8083063 Iustin Pop
429 e337de97 Michael Hanselmann
  # Storage --------------------------
430 e337de97 Michael Hanselmann
431 e337de97 Michael Hanselmann
  @staticmethod
432 e337de97 Michael Hanselmann
  def perspective_storage_list(params):
433 e337de97 Michael Hanselmann
    """Get list of storage units.
434 e337de97 Michael Hanselmann
435 e337de97 Michael Hanselmann
    """
436 e337de97 Michael Hanselmann
    (su_name, su_args, name, fields) = params
437 e337de97 Michael Hanselmann
    return storage.GetStorage(su_name, *su_args).List(name, fields)
438 e337de97 Michael Hanselmann
439 8979196a Michael Hanselmann
  @staticmethod
440 8979196a Michael Hanselmann
  def perspective_storage_modify(params):
441 8979196a Michael Hanselmann
    """Modify a storage unit.
442 8979196a Michael Hanselmann
443 8979196a Michael Hanselmann
    """
444 8979196a Michael Hanselmann
    (su_name, su_args, name, changes) = params
445 8979196a Michael Hanselmann
    return storage.GetStorage(su_name, *su_args).Modify(name, changes)
446 8979196a Michael Hanselmann
447 637b8d7e Michael Hanselmann
  @staticmethod
448 637b8d7e Michael Hanselmann
  def perspective_storage_execute(params):
449 637b8d7e Michael Hanselmann
    """Execute an operation on a storage unit.
450 637b8d7e Michael Hanselmann
451 637b8d7e Michael Hanselmann
    """
452 637b8d7e Michael Hanselmann
    (su_name, su_args, name, op) = params
453 637b8d7e Michael Hanselmann
    return storage.GetStorage(su_name, *su_args).Execute(name, op)
454 637b8d7e Michael Hanselmann
455 a8083063 Iustin Pop
  # bridge  --------------------------
456 a8083063 Iustin Pop
457 3ecf6786 Iustin Pop
  @staticmethod
458 3ecf6786 Iustin Pop
  def perspective_bridges_exist(params):
459 3ecf6786 Iustin Pop
    """Check if all bridges given exist on this node.
460 3ecf6786 Iustin Pop
461 3ecf6786 Iustin Pop
    """
462 a8083063 Iustin Pop
    bridges_list = params[0]
463 a8083063 Iustin Pop
    return backend.BridgesExist(bridges_list)
464 a8083063 Iustin Pop
465 a8083063 Iustin Pop
  # instance  --------------------------
466 a8083063 Iustin Pop
467 3ecf6786 Iustin Pop
  @staticmethod
468 3ecf6786 Iustin Pop
  def perspective_instance_os_add(params):
469 3ecf6786 Iustin Pop
    """Install an OS on a given instance.
470 3ecf6786 Iustin Pop
471 3ecf6786 Iustin Pop
    """
472 d15a9ad3 Guido Trotter
    inst_s = params[0]
473 319856a9 Michael Hanselmann
    inst = objects.Instance.FromDict(inst_s)
474 e557bae9 Guido Trotter
    reinstall = params[1]
475 4a0e011f Iustin Pop
    debug = params[2]
476 4a0e011f Iustin Pop
    return backend.InstanceOsAdd(inst, reinstall, debug)
477 a8083063 Iustin Pop
478 3ecf6786 Iustin Pop
  @staticmethod
479 decd5f45 Iustin Pop
  def perspective_instance_run_rename(params):
480 decd5f45 Iustin Pop
    """Runs the OS rename script for an instance.
481 decd5f45 Iustin Pop
482 decd5f45 Iustin Pop
    """
483 4a0e011f Iustin Pop
    inst_s, old_name, debug = params
484 319856a9 Michael Hanselmann
    inst = objects.Instance.FromDict(inst_s)
485 4a0e011f Iustin Pop
    return backend.RunRenameInstance(inst, old_name, debug)
486 decd5f45 Iustin Pop
487 decd5f45 Iustin Pop
  @staticmethod
488 3ecf6786 Iustin Pop
  def perspective_instance_shutdown(params):
489 3ecf6786 Iustin Pop
    """Shutdown an instance.
490 3ecf6786 Iustin Pop
491 3ecf6786 Iustin Pop
    """
492 319856a9 Michael Hanselmann
    instance = objects.Instance.FromDict(params[0])
493 6263189c Guido Trotter
    timeout = params[1]
494 6263189c Guido Trotter
    return backend.InstanceShutdown(instance, timeout)
495 a8083063 Iustin Pop
496 3ecf6786 Iustin Pop
  @staticmethod
497 3ecf6786 Iustin Pop
  def perspective_instance_start(params):
498 3ecf6786 Iustin Pop
    """Start an instance.
499 3ecf6786 Iustin Pop
500 3ecf6786 Iustin Pop
    """
501 319856a9 Michael Hanselmann
    instance = objects.Instance.FromDict(params[0])
502 07813a9e Iustin Pop
    return backend.StartInstance(instance)
503 a8083063 Iustin Pop
504 3ecf6786 Iustin Pop
  @staticmethod
505 6906a9d8 Guido Trotter
  def perspective_migration_info(params):
506 6906a9d8 Guido Trotter
    """Gather information about an instance to be migrated.
507 6906a9d8 Guido Trotter
508 6906a9d8 Guido Trotter
    """
509 6906a9d8 Guido Trotter
    instance = objects.Instance.FromDict(params[0])
510 6906a9d8 Guido Trotter
    return backend.MigrationInfo(instance)
511 6906a9d8 Guido Trotter
512 6906a9d8 Guido Trotter
  @staticmethod
513 6906a9d8 Guido Trotter
  def perspective_accept_instance(params):
514 6906a9d8 Guido Trotter
    """Prepare the node to accept an instance.
515 6906a9d8 Guido Trotter
516 6906a9d8 Guido Trotter
    """
517 6906a9d8 Guido Trotter
    instance, info, target = params
518 6906a9d8 Guido Trotter
    instance = objects.Instance.FromDict(instance)
519 6906a9d8 Guido Trotter
    return backend.AcceptInstance(instance, info, target)
520 6906a9d8 Guido Trotter
521 6906a9d8 Guido Trotter
  @staticmethod
522 6906a9d8 Guido Trotter
  def perspective_finalize_migration(params):
523 6906a9d8 Guido Trotter
    """Finalize the instance migration.
524 6906a9d8 Guido Trotter
525 6906a9d8 Guido Trotter
    """
526 6906a9d8 Guido Trotter
    instance, info, success = params
527 6906a9d8 Guido Trotter
    instance = objects.Instance.FromDict(instance)
528 6906a9d8 Guido Trotter
    return backend.FinalizeMigration(instance, info, success)
529 6906a9d8 Guido Trotter
530 6906a9d8 Guido Trotter
  @staticmethod
531 2a10865c Iustin Pop
  def perspective_instance_migrate(params):
532 2a10865c Iustin Pop
    """Migrates an instance.
533 2a10865c Iustin Pop
534 2a10865c Iustin Pop
    """
535 2a10865c Iustin Pop
    instance, target, live = params
536 9f0e6b37 Iustin Pop
    instance = objects.Instance.FromDict(instance)
537 2a10865c Iustin Pop
    return backend.MigrateInstance(instance, target, live)
538 2a10865c Iustin Pop
539 2a10865c Iustin Pop
  @staticmethod
540 007a2f3e Alexander Schreiber
  def perspective_instance_reboot(params):
541 007a2f3e Alexander Schreiber
    """Reboot an instance.
542 007a2f3e Alexander Schreiber
543 007a2f3e Alexander Schreiber
    """
544 007a2f3e Alexander Schreiber
    instance = objects.Instance.FromDict(params[0])
545 007a2f3e Alexander Schreiber
    reboot_type = params[1]
546 17c3f802 Guido Trotter
    shutdown_timeout = params[2]
547 17c3f802 Guido Trotter
    return backend.InstanceReboot(instance, reboot_type, shutdown_timeout)
548 007a2f3e Alexander Schreiber
549 007a2f3e Alexander Schreiber
  @staticmethod
550 3ecf6786 Iustin Pop
  def perspective_instance_info(params):
551 3ecf6786 Iustin Pop
    """Query instance information.
552 3ecf6786 Iustin Pop
553 3ecf6786 Iustin Pop
    """
554 16ad1a83 Iustin Pop
    return backend.GetInstanceInfo(params[0], params[1])
555 a8083063 Iustin Pop
556 3ecf6786 Iustin Pop
  @staticmethod
557 56e7640c Iustin Pop
  def perspective_instance_migratable(params):
558 56e7640c Iustin Pop
    """Query whether the specified instance can be migrated.
559 56e7640c Iustin Pop
560 56e7640c Iustin Pop
    """
561 56e7640c Iustin Pop
    instance = objects.Instance.FromDict(params[0])
562 56e7640c Iustin Pop
    return backend.GetInstanceMigratable(instance)
563 56e7640c Iustin Pop
564 56e7640c Iustin Pop
  @staticmethod
565 3ecf6786 Iustin Pop
  def perspective_all_instances_info(params):
566 3ecf6786 Iustin Pop
    """Query information about all instances.
567 3ecf6786 Iustin Pop
568 3ecf6786 Iustin Pop
    """
569 e69d05fd Iustin Pop
    return backend.GetAllInstancesInfo(params[0])
570 a8083063 Iustin Pop
571 3ecf6786 Iustin Pop
  @staticmethod
572 3ecf6786 Iustin Pop
  def perspective_instance_list(params):
573 3ecf6786 Iustin Pop
    """Query the list of running instances.
574 3ecf6786 Iustin Pop
575 3ecf6786 Iustin Pop
    """
576 c26a6bd2 Iustin Pop
    return backend.GetInstanceList(params[0])
577 a8083063 Iustin Pop
578 a8083063 Iustin Pop
  # node --------------------------
579 a8083063 Iustin Pop
580 3ecf6786 Iustin Pop
  @staticmethod
581 16abfbc2 Alexander Schreiber
  def perspective_node_tcp_ping(params):
582 16abfbc2 Alexander Schreiber
    """Do a TcpPing on the remote node.
583 16abfbc2 Alexander Schreiber
584 16abfbc2 Alexander Schreiber
    """
585 b15d625f Iustin Pop
    return utils.TcpPing(params[1], params[2], timeout=params[3],
586 b15d625f Iustin Pop
                         live_port_needed=params[4], source=params[0])
587 16abfbc2 Alexander Schreiber
588 16abfbc2 Alexander Schreiber
  @staticmethod
589 caad16e2 Iustin Pop
  def perspective_node_has_ip_address(params):
590 caad16e2 Iustin Pop
    """Checks if a node has the given ip address.
591 caad16e2 Iustin Pop
592 caad16e2 Iustin Pop
    """
593 c26a6bd2 Iustin Pop
    return utils.OwnIpAddress(params[0])
594 caad16e2 Iustin Pop
595 caad16e2 Iustin Pop
  @staticmethod
596 3ecf6786 Iustin Pop
  def perspective_node_info(params):
597 3ecf6786 Iustin Pop
    """Query node information.
598 3ecf6786 Iustin Pop
599 3ecf6786 Iustin Pop
    """
600 e69d05fd Iustin Pop
    vgname, hypervisor_type = params
601 e69d05fd Iustin Pop
    return backend.GetNodeInfo(vgname, hypervisor_type)
602 a8083063 Iustin Pop
603 3ecf6786 Iustin Pop
  @staticmethod
604 3ecf6786 Iustin Pop
  def perspective_node_add(params):
605 3ecf6786 Iustin Pop
    """Complete the registration of this node in the cluster.
606 3ecf6786 Iustin Pop
607 3ecf6786 Iustin Pop
    """
608 a8083063 Iustin Pop
    return backend.AddNode(params[0], params[1], params[2],
609 a8083063 Iustin Pop
                           params[3], params[4], params[5])
610 a8083063 Iustin Pop
611 3ecf6786 Iustin Pop
  @staticmethod
612 3ecf6786 Iustin Pop
  def perspective_node_verify(params):
613 3ecf6786 Iustin Pop
    """Run a verify sequence on this node.
614 3ecf6786 Iustin Pop
615 3ecf6786 Iustin Pop
    """
616 62c9ec92 Iustin Pop
    return backend.VerifyNode(params[0], params[1])
617 a8083063 Iustin Pop
618 3ecf6786 Iustin Pop
  @staticmethod
619 3ecf6786 Iustin Pop
  def perspective_node_start_master(params):
620 3ecf6786 Iustin Pop
    """Promote this node to master status.
621 3ecf6786 Iustin Pop
622 3ecf6786 Iustin Pop
    """
623 3583908a Guido Trotter
    return backend.StartMaster(params[0], params[1])
624 a8083063 Iustin Pop
625 3ecf6786 Iustin Pop
  @staticmethod
626 3ecf6786 Iustin Pop
  def perspective_node_stop_master(params):
627 3ecf6786 Iustin Pop
    """Demote this node from master status.
628 3ecf6786 Iustin Pop
629 3ecf6786 Iustin Pop
    """
630 1c65840b Iustin Pop
    return backend.StopMaster(params[0])
631 a8083063 Iustin Pop
632 3ecf6786 Iustin Pop
  @staticmethod
633 3ecf6786 Iustin Pop
  def perspective_node_leave_cluster(params):
634 3ecf6786 Iustin Pop
    """Cleanup after leaving a cluster.
635 3ecf6786 Iustin Pop
636 3ecf6786 Iustin Pop
    """
637 b989b9d9 Ken Wehr
    return backend.LeaveCluster(params[0])
638 a8083063 Iustin Pop
639 3ecf6786 Iustin Pop
  @staticmethod
640 3ecf6786 Iustin Pop
  def perspective_node_volumes(params):
641 3ecf6786 Iustin Pop
    """Query the list of all logical volume groups.
642 3ecf6786 Iustin Pop
643 3ecf6786 Iustin Pop
    """
644 dcb93971 Michael Hanselmann
    return backend.NodeVolumes()
645 dcb93971 Michael Hanselmann
646 56aa9fd5 Iustin Pop
  @staticmethod
647 56aa9fd5 Iustin Pop
  def perspective_node_demote_from_mc(params):
648 56aa9fd5 Iustin Pop
    """Demote a node from the master candidate role.
649 56aa9fd5 Iustin Pop
650 56aa9fd5 Iustin Pop
    """
651 56aa9fd5 Iustin Pop
    return backend.DemoteFromMC()
652 56aa9fd5 Iustin Pop
653 56aa9fd5 Iustin Pop
654 f5118ade Iustin Pop
  @staticmethod
655 f5118ade Iustin Pop
  def perspective_node_powercycle(params):
656 f5118ade Iustin Pop
    """Tries to powercycle the nod.
657 f5118ade Iustin Pop
658 f5118ade Iustin Pop
    """
659 f5118ade Iustin Pop
    hypervisor_type = params[0]
660 f5118ade Iustin Pop
    return backend.PowercycleNode(hypervisor_type)
661 f5118ade Iustin Pop
662 f5118ade Iustin Pop
663 a8083063 Iustin Pop
  # cluster --------------------------
664 a8083063 Iustin Pop
665 3ecf6786 Iustin Pop
  @staticmethod
666 3ecf6786 Iustin Pop
  def perspective_version(params):
667 3ecf6786 Iustin Pop
    """Query version information.
668 3ecf6786 Iustin Pop
669 3ecf6786 Iustin Pop
    """
670 c26a6bd2 Iustin Pop
    return constants.PROTOCOL_VERSION
671 a8083063 Iustin Pop
672 3ecf6786 Iustin Pop
  @staticmethod
673 3ecf6786 Iustin Pop
  def perspective_upload_file(params):
674 3ecf6786 Iustin Pop
    """Upload a file.
675 3ecf6786 Iustin Pop
676 3ecf6786 Iustin Pop
    Note that the backend implementation imposes strict rules on which
677 3ecf6786 Iustin Pop
    files are accepted.
678 3ecf6786 Iustin Pop
679 3ecf6786 Iustin Pop
    """
680 a8083063 Iustin Pop
    return backend.UploadFile(*params)
681 a8083063 Iustin Pop
682 4e071d3b Iustin Pop
  @staticmethod
683 4e071d3b Iustin Pop
  def perspective_master_info(params):
684 4e071d3b Iustin Pop
    """Query master information.
685 4e071d3b Iustin Pop
686 4e071d3b Iustin Pop
    """
687 4e071d3b Iustin Pop
    return backend.GetMasterInfo()
688 a8083063 Iustin Pop
689 6ddc95ec Michael Hanselmann
  @staticmethod
690 6ddc95ec Michael Hanselmann
  def perspective_write_ssconf_files(params):
691 6ddc95ec Michael Hanselmann
    """Write ssconf files.
692 6ddc95ec Michael Hanselmann
693 6ddc95ec Michael Hanselmann
    """
694 03d1dba2 Michael Hanselmann
    (values,) = params
695 03d1dba2 Michael Hanselmann
    return backend.WriteSsconfFiles(values)
696 6ddc95ec Michael Hanselmann
697 a8083063 Iustin Pop
  # os -----------------------
698 a8083063 Iustin Pop
699 3ecf6786 Iustin Pop
  @staticmethod
700 3ecf6786 Iustin Pop
  def perspective_os_diagnose(params):
701 3ecf6786 Iustin Pop
    """Query detailed information about existing OSes.
702 3ecf6786 Iustin Pop
703 3ecf6786 Iustin Pop
    """
704 255dcebd Iustin Pop
    return backend.DiagnoseOS()
705 a8083063 Iustin Pop
706 3ecf6786 Iustin Pop
  @staticmethod
707 3ecf6786 Iustin Pop
  def perspective_os_get(params):
708 3ecf6786 Iustin Pop
    """Query information about a given OS.
709 3ecf6786 Iustin Pop
710 3ecf6786 Iustin Pop
    """
711 a8083063 Iustin Pop
    name = params[0]
712 255dcebd Iustin Pop
    os_obj = backend.OSFromDisk(name)
713 c26a6bd2 Iustin Pop
    return os_obj.ToDict()
714 a8083063 Iustin Pop
715 a8083063 Iustin Pop
  # hooks -----------------------
716 a8083063 Iustin Pop
717 3ecf6786 Iustin Pop
  @staticmethod
718 3ecf6786 Iustin Pop
  def perspective_hooks_runner(params):
719 3ecf6786 Iustin Pop
    """Run hook scripts.
720 3ecf6786 Iustin Pop
721 3ecf6786 Iustin Pop
    """
722 a8083063 Iustin Pop
    hpath, phase, env = params
723 a8083063 Iustin Pop
    hr = backend.HooksRunner()
724 a8083063 Iustin Pop
    return hr.RunHooks(hpath, phase, env)
725 a8083063 Iustin Pop
726 8d528b7c Iustin Pop
  # iallocator -----------------
727 8d528b7c Iustin Pop
728 8d528b7c Iustin Pop
  @staticmethod
729 8d528b7c Iustin Pop
  def perspective_iallocator_runner(params):
730 8d528b7c Iustin Pop
    """Run an iallocator script.
731 8d528b7c Iustin Pop
732 8d528b7c Iustin Pop
    """
733 8d528b7c Iustin Pop
    name, idata = params
734 8d528b7c Iustin Pop
    iar = backend.IAllocatorRunner()
735 8d528b7c Iustin Pop
    return iar.Run(name, idata)
736 8d528b7c Iustin Pop
737 06009e27 Iustin Pop
  # test -----------------------
738 06009e27 Iustin Pop
739 06009e27 Iustin Pop
  @staticmethod
740 06009e27 Iustin Pop
  def perspective_test_delay(params):
741 06009e27 Iustin Pop
    """Run test delay.
742 06009e27 Iustin Pop
743 06009e27 Iustin Pop
    """
744 06009e27 Iustin Pop
    duration = params[0]
745 c26a6bd2 Iustin Pop
    status, rval = utils.TestDelay(duration)
746 c26a6bd2 Iustin Pop
    if not status:
747 c26a6bd2 Iustin Pop
      raise backend.RPCFail(rval)
748 c26a6bd2 Iustin Pop
    return rval
749 06009e27 Iustin Pop
750 4e071d3b Iustin Pop
  # file storage ---------------
751 4e071d3b Iustin Pop
752 a5d7fb43 Manuel Franceschini
  @staticmethod
753 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_create(params):
754 a5d7fb43 Manuel Franceschini
    """Create the file storage directory.
755 a5d7fb43 Manuel Franceschini
756 a5d7fb43 Manuel Franceschini
    """
757 a5d7fb43 Manuel Franceschini
    file_storage_dir = params[0]
758 a5d7fb43 Manuel Franceschini
    return backend.CreateFileStorageDir(file_storage_dir)
759 a5d7fb43 Manuel Franceschini
760 a5d7fb43 Manuel Franceschini
  @staticmethod
761 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_remove(params):
762 a5d7fb43 Manuel Franceschini
    """Remove the file storage directory.
763 a5d7fb43 Manuel Franceschini
764 a5d7fb43 Manuel Franceschini
    """
765 a5d7fb43 Manuel Franceschini
    file_storage_dir = params[0]
766 a5d7fb43 Manuel Franceschini
    return backend.RemoveFileStorageDir(file_storage_dir)
767 a5d7fb43 Manuel Franceschini
768 a5d7fb43 Manuel Franceschini
  @staticmethod
769 a5d7fb43 Manuel Franceschini
  def perspective_file_storage_dir_rename(params):
770 a5d7fb43 Manuel Franceschini
    """Rename the file storage directory.
771 a5d7fb43 Manuel Franceschini
772 a5d7fb43 Manuel Franceschini
    """
773 a5d7fb43 Manuel Franceschini
    old_file_storage_dir = params[0]
774 a5d7fb43 Manuel Franceschini
    new_file_storage_dir = params[1]
775 a5d7fb43 Manuel Franceschini
    return backend.RenameFileStorageDir(old_file_storage_dir,
776 a5d7fb43 Manuel Franceschini
                                        new_file_storage_dir)
777 a5d7fb43 Manuel Franceschini
778 4e071d3b Iustin Pop
  # jobs ------------------------
779 4e071d3b Iustin Pop
780 ca52cdeb Michael Hanselmann
  @staticmethod
781 7f30777b Michael Hanselmann
  @_RequireJobQueueLock
782 ca52cdeb Michael Hanselmann
  def perspective_jobqueue_update(params):
783 ca52cdeb Michael Hanselmann
    """Update job queue.
784 ca52cdeb Michael Hanselmann
785 ca52cdeb Michael Hanselmann
    """
786 ca52cdeb Michael Hanselmann
    (file_name, content) = params
787 7f30777b Michael Hanselmann
    return backend.JobQueueUpdate(file_name, content)
788 ca52cdeb Michael Hanselmann
789 ca52cdeb Michael Hanselmann
  @staticmethod
790 f1f3f45c Michael Hanselmann
  @_RequireJobQueueLock
791 ca52cdeb Michael Hanselmann
  def perspective_jobqueue_purge(params):
792 ca52cdeb Michael Hanselmann
    """Purge job queue.
793 ca52cdeb Michael Hanselmann
794 ca52cdeb Michael Hanselmann
    """
795 ca52cdeb Michael Hanselmann
    return backend.JobQueuePurge()
796 ca52cdeb Michael Hanselmann
797 af5ebcb1 Michael Hanselmann
  @staticmethod
798 af5ebcb1 Michael Hanselmann
  @_RequireJobQueueLock
799 af5ebcb1 Michael Hanselmann
  def perspective_jobqueue_rename(params):
800 af5ebcb1 Michael Hanselmann
    """Rename a job queue file.
801 af5ebcb1 Michael Hanselmann
802 af5ebcb1 Michael Hanselmann
    """
803 dd875d32 Michael Hanselmann
    # TODO: What if a file fails to rename?
804 c26a6bd2 Iustin Pop
    return [backend.JobQueueRename(old, new) for old, new in params]
805 af5ebcb1 Michael Hanselmann
806 6217e295 Iustin Pop
  # hypervisor ---------------
807 6217e295 Iustin Pop
808 6217e295 Iustin Pop
  @staticmethod
809 6217e295 Iustin Pop
  def perspective_hypervisor_validate_params(params):
810 6217e295 Iustin Pop
    """Validate the hypervisor parameters.
811 6217e295 Iustin Pop
812 6217e295 Iustin Pop
    """
813 6217e295 Iustin Pop
    (hvname, hvparams) = params
814 6217e295 Iustin Pop
    return backend.ValidateHVParams(hvname, hvparams)
815 6217e295 Iustin Pop
816 f942a838 Michael Hanselmann
  # Crypto
817 f942a838 Michael Hanselmann
818 f942a838 Michael Hanselmann
  @staticmethod
819 ef40fbfb Michael Hanselmann
  def perspective_x509_cert_create(params):
820 f942a838 Michael Hanselmann
    """Creates a new X509 certificate for SSL/TLS.
821 f942a838 Michael Hanselmann
822 f942a838 Michael Hanselmann
    """
823 f942a838 Michael Hanselmann
    (validity, ) = params
824 f942a838 Michael Hanselmann
    return backend.CreateX509Certificate(validity)
825 f942a838 Michael Hanselmann
826 f942a838 Michael Hanselmann
  @staticmethod
827 ef40fbfb Michael Hanselmann
  def perspective_x509_cert_remove(params):
828 f942a838 Michael Hanselmann
    """Removes a X509 certificate.
829 f942a838 Michael Hanselmann
830 f942a838 Michael Hanselmann
    """
831 f942a838 Michael Hanselmann
    (name, ) = params
832 f942a838 Michael Hanselmann
    return backend.RemoveX509Certificate(name)
833 f942a838 Michael Hanselmann
834 1651d116 Michael Hanselmann
  # Import and export
835 1651d116 Michael Hanselmann
836 1651d116 Michael Hanselmann
  @staticmethod
837 ef40fbfb Michael Hanselmann
  def perspective_import_start(params):
838 1651d116 Michael Hanselmann
    """Starts an import daemon.
839 1651d116 Michael Hanselmann
840 1651d116 Michael Hanselmann
    """
841 eb630f50 Michael Hanselmann
    (opts_s, instance, dest, dest_args) = params
842 eb630f50 Michael Hanselmann
843 eb630f50 Michael Hanselmann
    opts = objects.ImportExportOptions.FromDict(opts_s)
844 eb630f50 Michael Hanselmann
845 eb630f50 Michael Hanselmann
    return backend.StartImportExportDaemon(constants.IEM_IMPORT, opts,
846 1651d116 Michael Hanselmann
                                           None, None,
847 1651d116 Michael Hanselmann
                                           objects.Instance.FromDict(instance),
848 1651d116 Michael Hanselmann
                                           dest,
849 1651d116 Michael Hanselmann
                                           _DecodeImportExportIO(dest,
850 1651d116 Michael Hanselmann
                                                                 dest_args))
851 eb630f50 Michael Hanselmann
852 1651d116 Michael Hanselmann
  @staticmethod
853 ef40fbfb Michael Hanselmann
  def perspective_export_start(params):
854 1651d116 Michael Hanselmann
    """Starts an export daemon.
855 1651d116 Michael Hanselmann
856 1651d116 Michael Hanselmann
    """
857 eb630f50 Michael Hanselmann
    (opts_s, host, port, instance, source, source_args) = params
858 eb630f50 Michael Hanselmann
859 eb630f50 Michael Hanselmann
    opts = objects.ImportExportOptions.FromDict(opts_s)
860 eb630f50 Michael Hanselmann
861 eb630f50 Michael Hanselmann
    return backend.StartImportExportDaemon(constants.IEM_EXPORT, opts,
862 1651d116 Michael Hanselmann
                                           host, port,
863 1651d116 Michael Hanselmann
                                           objects.Instance.FromDict(instance),
864 1651d116 Michael Hanselmann
                                           source,
865 1651d116 Michael Hanselmann
                                           _DecodeImportExportIO(source,
866 1651d116 Michael Hanselmann
                                                                 source_args))
867 1651d116 Michael Hanselmann
868 1651d116 Michael Hanselmann
  @staticmethod
869 ef40fbfb Michael Hanselmann
  def perspective_impexp_status(params):
870 1651d116 Michael Hanselmann
    """Retrieves the status of an import or export daemon.
871 1651d116 Michael Hanselmann
872 1651d116 Michael Hanselmann
    """
873 1651d116 Michael Hanselmann
    return backend.GetImportExportStatus(params[0])
874 1651d116 Michael Hanselmann
875 1651d116 Michael Hanselmann
  @staticmethod
876 f81c4737 Michael Hanselmann
  def perspective_impexp_abort(params):
877 f81c4737 Michael Hanselmann
    """Aborts an import or export.
878 f81c4737 Michael Hanselmann
879 f81c4737 Michael Hanselmann
    """
880 f81c4737 Michael Hanselmann
    return backend.AbortImportExport(params[0])
881 f81c4737 Michael Hanselmann
882 f81c4737 Michael Hanselmann
  @staticmethod
883 ef40fbfb Michael Hanselmann
  def perspective_impexp_cleanup(params):
884 1651d116 Michael Hanselmann
    """Cleans up after an import or export.
885 1651d116 Michael Hanselmann
886 1651d116 Michael Hanselmann
    """
887 1651d116 Michael Hanselmann
    return backend.CleanupImportExport(params[0])
888 1651d116 Michael Hanselmann
889 a8083063 Iustin Pop
890 f93427cd Iustin Pop
def CheckNoded(_, args):
891 f93427cd Iustin Pop
  """Initial checks whether to run or exit with a failure.
892 f93427cd Iustin Pop
893 f93427cd Iustin Pop
  """
894 f93427cd Iustin Pop
  if args: # noded doesn't take any arguments
895 f93427cd Iustin Pop
    print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" %
896 f93427cd Iustin Pop
                          sys.argv[0])
897 f93427cd Iustin Pop
    sys.exit(constants.EXIT_FAILURE)
898 f93427cd Iustin Pop
899 f93427cd Iustin Pop
900 2d54e29c Iustin Pop
def ExecNoded(options, _):
901 6c948699 Michael Hanselmann
  """Main node daemon function, executed with the PID file held.
902 3ecf6786 Iustin Pop
903 3ecf6786 Iustin Pop
  """
904 bebf68d3 Guido Trotter
  if options.mlock:
905 bebf68d3 Guido Trotter
    utils.Mlockall()
906 bebf68d3 Guido Trotter
    request_executor_class = MlockallRequestExecutor
907 bebf68d3 Guido Trotter
  else:
908 bebf68d3 Guido Trotter
    request_executor_class = http.server.HttpServerRequestExecutor
909 02bea2fc Luca Bigliardi
910 04ccf5e9 Guido Trotter
  # Read SSL certificate
911 3b1b0cb6 Guido Trotter
  if options.ssl:
912 3b1b0cb6 Guido Trotter
    ssl_params = http.HttpSslParams(ssl_key_path=options.ssl_key,
913 3b1b0cb6 Guido Trotter
                                    ssl_cert_path=options.ssl_cert)
914 3b1b0cb6 Guido Trotter
  else:
915 3b1b0cb6 Guido Trotter
    ssl_params = None
916 7d88772a Iustin Pop
917 81198f6e Iustin Pop
  err = _PrepareQueueLock()
918 81198f6e Iustin Pop
  if err is not None:
919 81198f6e Iustin Pop
    # this might be some kind of file-system/permission error; while
920 81198f6e Iustin Pop
    # this breaks the job queue functionality, we shouldn't prevent
921 81198f6e Iustin Pop
    # startup of the whole node daemon because of this
922 81198f6e Iustin Pop
    logging.critical("Can't init/verify the queue, proceeding anyway: %s", err)
923 7d88772a Iustin Pop
924 04ccf5e9 Guido Trotter
  mainloop = daemon.Mainloop()
925 04ccf5e9 Guido Trotter
  server = NodeHttpServer(mainloop, options.bind_address, options.port,
926 38b77287 Luca Bigliardi
                          ssl_params=ssl_params, ssl_verify_peer=True,
927 bebf68d3 Guido Trotter
                          request_executor_class=request_executor_class)
928 04ccf5e9 Guido Trotter
  server.Start()
929 04ccf5e9 Guido Trotter
  try:
930 04ccf5e9 Guido Trotter
    mainloop.Run()
931 04ccf5e9 Guido Trotter
  finally:
932 04ccf5e9 Guido Trotter
    server.Stop()
933 a8083063 Iustin Pop
934 a8083063 Iustin Pop
935 04ccf5e9 Guido Trotter
def main():
936 04ccf5e9 Guido Trotter
  """Main function for the node daemon.
937 04ccf5e9 Guido Trotter
938 04ccf5e9 Guido Trotter
  """
939 04ccf5e9 Guido Trotter
  parser = OptionParser(description="Ganeti node daemon",
940 04ccf5e9 Guido Trotter
                        usage="%prog [-f] [-d] [-p port] [-b ADDRESS]",
941 04ccf5e9 Guido Trotter
                        version="%%prog (ganeti) %s" %
942 04ccf5e9 Guido Trotter
                        constants.RELEASE_VERSION)
943 bebf68d3 Guido Trotter
  parser.add_option("--no-mlock", dest="mlock",
944 bebf68d3 Guido Trotter
                    help="Do not mlock the node memory in ram",
945 bebf68d3 Guido Trotter
                    default=True, action="store_false")
946 bebf68d3 Guido Trotter
947 9dae41ad Guido Trotter
  dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
948 9dae41ad Guido Trotter
  dirs.append((constants.LOG_OS_DIR, 0750))
949 9dae41ad Guido Trotter
  dirs.append((constants.LOCK_DIR, 1777))
950 f942a838 Michael Hanselmann
  dirs.append((constants.CRYPTO_KEYS_DIR, constants.CRYPTO_KEYS_DIR_MODE))
951 1651d116 Michael Hanselmann
  dirs.append((constants.IMPORT_EXPORT_DIR, constants.IMPORT_EXPORT_DIR_MODE))
952 24cd3744 Iustin Pop
  daemon.GenericMain(constants.NODED, parser, dirs, CheckNoded, ExecNoded,
953 084aba47 Michael Hanselmann
                     default_ssl_cert=constants.NODED_CERT_FILE,
954 1c54156d Luca Bigliardi
                     default_ssl_key=constants.NODED_CERT_FILE,
955 565083ef Luca Bigliardi
                     console_logging=True)
956 73d927a2 Guido Trotter
957 a8083063 Iustin Pop
958 3ecf6786 Iustin Pop
if __name__ == '__main__':
959 a8083063 Iustin Pop
  main()