Statistics
| Branch: | Tag: | Revision:

root / daemons / ganeti-noded @ f93427cd

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