Statistics
| Branch: | Tag: | Revision:

root / daemons / ganeti-noded @ 7e1fac25

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