Commit 173e4632 authored by Jose A. Lopes's avatar Jose A. Lopes

RPC to start/stop a daemon on a node

This RPC will be needed so that changes to the cluster parameters for
enabled hypervisors, user shutdown, and vm capable nodes, can
start/stop the KVM daemon as necessary.
Signed-off-by: default avatarJose A. Lopes <>
Reviewed-by: default avatarHrvoje Ribicic <>
Reviewed-by: default avatarHelga Velroyen <>
parent 658dfed1
......@@ -1247,6 +1247,32 @@ def GetCryptoTokens(token_requests):
return tokens
def EnsureDaemon(daemon_name, run):
"""Ensures the given daemon is running or stopped.
@type daemon_name: string
@param daemon_name: name of the daemon (e.g., constants.KVMD)
@type run: bool
@param run: whether to start or stop the daemon
@rtype: bool
@return: 'True' if daemon successfully started/stopped,
'False' otherwise
allowed_daemons = [constants.KVMD]
if daemon_name not in allowed_daemons:
fn = lambda _: False
elif run:
fn = utils.EnsureDaemon
fn = utils.StopDaemon
return fn(daemon_name)
def GetBlockDevSizes(devices):
"""Return the size of the given block devices
......@@ -509,6 +509,10 @@ _NODE_CALLS = [
("token_request", None,
"List of tuples of requested crypto token types, actions"),
], None, None, "Handle crypto tokens of the node."),
("node_ensure_daemon", MULTI, None, constants.RPC_TMO_URGENT, [
("daemon", None, "Daemon name"),
("run", None, "Whether the daemon should be running or stopped"),
], None, None, "Ensure daemon is running on the node."),
......@@ -872,6 +872,14 @@ class NodeRequestHandler(http.server.HttpServerHandler):
token_requests = params[0]
return backend.GetCryptoTokens(token_requests)
def perspective_node_ensure_daemon(params):
"""Ensure daemon is running.
(daemon_name, run) = params
return backend.EnsureDaemon(daemon_name, run)
# cluster --------------------------
......@@ -469,6 +469,13 @@ def WaitForFdCondition(fdobj, event, timeout):
def EnsureDaemon(name):
"""Check for and start daemon if not alive.
@type name: string
@param name: daemon name
@rtype: bool
@return: 'True' if daemon successfully started,
'False' otherwise
result = RunCmd([pathutils.DAEMON_UTIL, "check-and-start", name])
if result.failed:
......@@ -482,6 +489,13 @@ def EnsureDaemon(name):
def StopDaemon(name):
"""Stop daemon
@type name: string
@param name: daemon name
@rtype: bool
@return: 'True' if daemon successfully stopped,
'False' otherwise
result = RunCmd([pathutils.DAEMON_UTIL, "stop", name])
if result.failed:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment