from ganeti import http
from ganeti import utils
+import ganeti.http.server
+
queue_lock = None
return wrapper
-class NodeHttpServer(http.HttpServer):
+class NodeHttpServer(http.server.HttpServer):
"""The server implementation.
This class holds all methods exposed over the RPC interface.
"""
def __init__(self, *args, **kwargs):
- http.HttpServer.__init__(self, *args, **kwargs)
+ http.server.HttpServer.__init__(self, *args, **kwargs)
self.noded_pid = os.getpid()
def HandleRequest(self, req):
"""Handle a request.
"""
- if req.request_method.upper() != "PUT":
- raise http.HTTPBadRequest()
+ if req.request_method.upper() != http.HTTP_PUT:
+ raise http.HttpBadRequest()
path = req.request_path
if path.startswith("/"):
method = getattr(self, "perspective_%s" % path, None)
if method is None:
- raise http.HTTPNotFound()
+ raise http.HttpNotFound()
try:
try:
- return method(req.request_post_data)
+ return method(req.request_body)
except:
logging.exception("Error in RPC call")
raise
"""Closes the given block devices.
"""
- disks = [objects.Disk.FromDict(cf) for cf in params]
- return backend.CloseBlockDevices(disks)
+ disks = [objects.Disk.FromDict(cf) for cf in params[1]]
+ return backend.CloseBlockDevices(params[0], disks)
+
+ # blockdev/drbd specific methods ----------
+
+ @staticmethod
+ def perspective_drbd_disconnect_net(params):
+ """Disconnects the network connection of drbd disks.
+
+ Note that this is only valid for drbd disks, so the members of the
+ disk list must all be drbd devices.
+
+ """
+ nodes_ip, disks = params
+ disks = [objects.Disk.FromDict(cf) for cf in disks]
+ return backend.DrbdDisconnectNet(nodes_ip, disks)
+
+ @staticmethod
+ def perspective_drbd_attach_net(params):
+ """Attaches the network connection of drbd disks.
+
+ Note that this is only valid for drbd disks, so the members of the
+ disk list must all be drbd devices.
+
+ """
+ nodes_ip, disks, instance_name, multimaster = params
+ disks = [objects.Disk.FromDict(cf) for cf in disks]
+ return backend.DrbdAttachNet(nodes_ip, disks, instance_name, multimaster)
+
+ @staticmethod
+ def perspective_drbd_wait_sync(params):
+ """Wait until DRBD disks are synched.
+
+ Note that this is only valid for drbd disks, so the members of the
+ disk list must all be drbd devices.
+
+ """
+ nodes_ip, disks = params
+ disks = [objects.Disk.FromDict(cf) for cf in disks]
+ return backend.DrbdWaitSync(nodes_ip, disks)
# export/import --------------------------
return backend.GetInstanceInfo(params[0], params[1])
@staticmethod
+ def perspective_instance_migratable(params):
+ """Query whether the specified instance can be migrated.
+
+ """
+ instance = objects.Instance.FromDict(params[0])
+ return backend.GetInstanceMigratable(instance)
+
+ @staticmethod
def perspective_all_instances_info(params):
"""Query information about all instances.
"""
return backend.NodeVolumes()
+ @staticmethod
+ def perspective_node_demote_from_mc(params):
+ """Demote a node from the master candidate role.
+
+ """
+ return backend.DemoteFromMC()
+
+
# cluster --------------------------
@staticmethod
"""Write ssconf files.
"""
- return backend.WriteSsconfFiles()
+ (values,) = params
+ return backend.WriteSsconfFiles(values)
# os -----------------------
"""Rename a job queue file.
"""
- (old, new) = params
-
- return backend.JobQueueRename(old, new)
+ # TODO: What if a file fails to rename?
+ return [backend.JobQueueRename(old, new) for old, new in params]
@staticmethod
def perspective_jobqueue_set_drain(params):
def ParseOptions():
"""Parse the command line options.
- Returns:
- (options, args) as from OptionParser.parse_args()
+ @return: (options, args) as from OptionParser.parse_args()
"""
parser = OptionParser(description="Ganeti node daemon",
packaging.
"""
- dirs = [(val, 0755) for val in constants.SUB_RUN_DIRS]
+ dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
dirs.append((constants.LOG_OS_DIR, 0750))
for dir_name, dir_mode in dirs:
if not os.path.exists(dir_name):
options, args = ParseOptions()
utils.debug = options.debug
+
+ if options.fork:
+ utils.CloseFDs()
+
for fname in (constants.SSL_CERT_FILE,):
if not os.path.isfile(fname):
print "config %s not there, will not run." % fname