On Jun 06 18:55, Hrvoje Ribicic wrote:
> On Fri, Jun 6, 2014 at 10:51 AM, 'Jose A. Lopes' via ganeti-devel <
> [email protected]> wrote:
>
> > 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: Jose A. Lopes <[email protected]>
> > ---
> > lib/backend.py | 22 ++++++++++++++++++++++
> > lib/rpc_defs.py | 4 ++++
> > lib/server/noded.py | 8 ++++++++
> > 3 files changed, 34 insertions(+)
> >
> > diff --git a/lib/backend.py b/lib/backend.py
> > index 98acdf0..062f952 100644
> > --- a/lib/backend.py
> > +++ b/lib/backend.py
> > @@ -1247,6 +1247,28 @@ 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
> > +
> > + """
> > + allowed_daemons = [constants.KVMD]
> > +
> > + if daemon_name not in allowed_daemons:
> > + fn = lambda _: False
> >
>
> Why not throw an error here?
This is aligned with the sematics of 'EnsureDaemon' and 'StopDaemon'.
The following interdiff improves the documentation.
diff --git a/lib/backend.py b/lib/backend.py
index 3018be6..fb34c4c 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1257,6 +1257,10 @@ def EnsureDaemon(daemon_name, run):
@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]
diff --git a/lib/utils/__init__.py b/lib/utils/__init__.py
index 50d88c0..ba2946a 100644
--- a/lib/utils/__init__.py
+++ b/lib/utils/__init__.py
@@ -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:
Thanks,
Jose
>
>
> > + elif run:
> > + fn = utils.EnsureDaemon
> > + else:
> > + fn = utils.StopDaemon
> > +
> > + return fn(daemon_name)
> > +
> > +
> > def GetBlockDevSizes(devices):
> > """Return the size of the given block devices
> >
> > diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py
> > index 6650c43..87891ca 100644
> > --- a/lib/rpc_defs.py
> > +++ b/lib/rpc_defs.py
> > @@ -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."),
> > ]
> >
> > _MISC_CALLS = [
> > diff --git a/lib/server/noded.py b/lib/server/noded.py
> > index 9731925..ecaa18e 100644
> > --- a/lib/server/noded.py
> > +++ b/lib/server/noded.py
> > @@ -872,6 +872,14 @@ class
> > NodeRequestHandler(http.server.HttpServerHandler):
> > token_requests = params[0]
> > return backend.GetCryptoTokens(token_requests)
> >
> > + @staticmethod
> > + def perspective_node_ensure_daemon(params):
> > + """Ensure daemon is running.
> > +
> > + """
> > + (daemon_name, run) = params
> > + return backend.EnsureDaemon(daemon_name, run)
> > +
> > # cluster --------------------------
> >
> > @staticmethod
> > --
> > 2.0.0.526.g5318336
> >
> >
--
Jose Antonio Lopes
Ganeti Engineering
Google Germany GmbH
Dienerstr. 12, 80331, München
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores
Steuernummer: 48/725/00206
Umsatzsteueridentifikationsnummer: DE813741370