From 1c65840bad209afd799ac7cac771921abbb948e2 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 30 Jul 2008 08:32:38 +0000 Subject: [PATCH] Add a new parameter to backend.(Start|Stop)Master This patch adds a new, unused for now, parameter to the start and stop master operations in backend. The idea behind it is that we need to be able to control whether the IP (de)activation is coupled with daemon startup/shutdown. The callers are also modified to pass this parameter (even if unused for now). Reviewed-by: ultrotter --- daemons/ganeti-noded | 4 ++-- lib/backend.py | 15 +++++++++------ lib/cmdlib.py | 10 +++++----- lib/rpc.py | 9 ++++----- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index c52a74ea7..449e010b8 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -407,14 +407,14 @@ class NodeDaemonRequestHandler(http.HTTPRequestHandler): """Promote this node to master status. """ - return backend.StartMaster() + return backend.StartMaster(params[0]) @staticmethod def perspective_node_stop_master(params): """Demote this node from master status. """ - return backend.StopMaster() + return backend.StopMaster(params[0]) @staticmethod def perspective_node_leave_cluster(params): diff --git a/lib/backend.py b/lib/backend.py index ca9ac7c12..b78a5ecc0 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -47,12 +47,13 @@ def _GetSshRunner(): return ssh.SshRunner() -def StartMaster(): +def StartMaster(start_daemons): """Activate local node as master node. - There are two needed steps for this: - - run the master script - - register the cron script + The function will always try activate the IP address of the master + (if someone else has it, then it won't). Then, if the start_daemons + parameter is True, it will also start the master daemons + (ganet-masterd and ganeti-rapi). """ result = utils.RunCmd([constants.MASTER_SCRIPT, "-d", "start"]) @@ -65,10 +66,12 @@ def StartMaster(): return True -def StopMaster(): +def StopMaster(stop_daemons): """Deactivate this node as master. - This runs the master stop script. + The function will always try to deactivate the IP address of the + master. Then, if the stop_daemons parameter is True, it will also + stop the master daemons (ganet-masterd and ganeti-rapi). """ result = utils.RunCmd([constants.MASTER_SCRIPT, "-d", "stop"]) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 744e2a1ed..5cde39493 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -416,7 +416,7 @@ class LUDestroyCluster(NoHooksLU): """ master = self.sstore.GetMasterNode() - if not rpc.call_node_stop_master(master): + if not rpc.call_node_stop_master(master, False): raise errors.OpExecError("Could not disable the master role") priv_key, pub_key, _ = ssh.GetUserFiles(constants.GANETI_RUNAS) utils.CreateBackup(priv_key) @@ -962,7 +962,7 @@ class LURenameCluster(LogicalUnit): # shutdown the master IP master = ss.GetMasterNode() - if not rpc.call_node_stop_master(master): + if not rpc.call_node_stop_master(master, False): raise errors.OpExecError("Could not disable the master role") try: @@ -985,7 +985,7 @@ class LURenameCluster(LogicalUnit): logger.Error("copy of file %s to node %s failed" % (fname, to_node)) finally: - if not rpc.call_node_start_master(master): + if not rpc.call_node_start_master(master, False): logger.Error("Could not re-enable the master role on the master," " please restart manually.") @@ -1737,7 +1737,7 @@ class LUMasterFailover(LogicalUnit): logger.Info("setting master to %s, old master: %s" % (self.new_master, self.old_master)) - if not rpc.call_node_stop_master(self.old_master): + if not rpc.call_node_stop_master(self.old_master, True): logger.Error("could disable the master role on the old master" " %s, please disable manually" % self.old_master) @@ -1748,7 +1748,7 @@ class LUMasterFailover(LogicalUnit): logger.Error("could not distribute the new simple store master file" " to the other nodes, please check.") - if not rpc.call_node_start_master(self.new_master): + if not rpc.call_node_start_master(self.new_master, True): logger.Error("could not start the master role on the new master" " %s, please check" % self.new_master) feedback_fn("Error in activating the master IP on the new master," diff --git a/lib/rpc.py b/lib/rpc.py index f2c85db11..1304c12f0 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -362,25 +362,25 @@ def call_node_verify(node_list, checkdict): return c.getresult() -def call_node_start_master(node): +def call_node_start_master(node, start_daemons): """Tells a node to activate itself as a master. This is a single-node call. """ - c = Client("node_start_master", []) + c = Client("node_start_master", [start_daemons]) c.connect(node) c.run() return c.getresult().get(node, False) -def call_node_stop_master(node): +def call_node_stop_master(node, stop_daemons): """Tells a node to demote itself from master status. This is a single-node call. """ - c = Client("node_stop_master", []) + c = Client("node_stop_master", [stop_daemons]) c.connect(node) c.run() return c.getresult().get(node, False) @@ -803,4 +803,3 @@ def call_file_storage_dir_rename(node, old_file_storage_dir, c.connect(node) c.run() return c.getresult().get(node, False) - -- GitLab