Commit 57c7bc57 authored by Andrea Spadaccini's avatar Andrea Spadaccini
Browse files

Change master IP address RPCs for external script



Change the master IP address RPC call chain to accept the
use_external_master_ip_script parameter. Introduces an unused parameter
in backend.ActivateMasterIp and backend.DeactivateMasterIp, that will be
used in the next commit.
Signed-off-by: default avatarAndrea Spadaccini <spadaccio@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 17b0b812
......@@ -287,13 +287,18 @@ def RunLocalHooks(hook_opcode, hooks_path, env_builder_fn):
return decorator
def _BuildMasterIpEnv(master_params):
def _BuildMasterIpEnv(master_params, use_external_mip_script=None):
"""Builds environment variables for master IP hooks.
@type master_params: L{objects.MasterNetworkParameters}
@param master_params: network parameters of the master
@type use_external_mip_script: boolean
@param use_external_mip_script: whether to use an external master IP
address setup script (unused, but necessary per the implementation of the
_RunLocalHooks decorator)
"""
# pylint: disable=W0613
ver = netutils.IPAddress.GetVersionFromAddressFamily(master_params.ip_family)
env = {
"MASTER_NETDEV": master_params.netdev,
......@@ -307,13 +312,17 @@ def _BuildMasterIpEnv(master_params):
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup",
_BuildMasterIpEnv)
def ActivateMasterIp(master_params):
def ActivateMasterIp(master_params, use_external_mip_script):
"""Activate the IP address of the master daemon.
@type master_params: L{objects.MasterNetworkParameters}
@param master_params: network parameters of the master
@type use_external_mip_script: boolean
@param use_external_mip_script: whether to use an external master IP
address setup script
"""
# pylint: disable=W0613
err_msg = None
if netutils.TcpPing(master_params.ip, constants.DEFAULT_NODED_PORT):
if netutils.IPAddress.Own(master_params.ip):
......@@ -380,13 +389,17 @@ def StartMasterDaemons(no_voting):
@RunLocalHooks(constants.FAKE_OP_MASTER_TURNDOWN, "master-ip-turndown",
_BuildMasterIpEnv)
def DeactivateMasterIp(master_params):
def DeactivateMasterIp(master_params, use_external_mip_script):
"""Deactivate the master IP on this node.
@type master_params: L{objects.MasterNetworkParameters}
@param master_params: network parameters of the master
@type use_external_mip_script: boolean
@param use_external_mip_script: whether to use an external master IP
address setup script
"""
# pylint: disable=W0613
# TODO: log and report back to the caller the error failures; we
# need to decide in which case we fail the RPC for this
......
......@@ -571,8 +571,9 @@ def FinalizeClusterDestroy(master):
master_params = cfg.GetMasterNetworkParameters()
master_params.name = master
ems = cfg.GetUseExternalMipScript()
result = runner.call_node_deactivate_master_ip(master_params.name,
master_params)
master_params, ems)
msg = result.fail_msg
if msg:
......@@ -714,8 +715,9 @@ def MasterFailover(no_voting=False):
runner = rpc.BootstrapRunner()
master_params = cfg.GetMasterNetworkParameters()
master_params.name = old_master
ems = cfg.GetUseExternalMipScript()
result = runner.call_node_deactivate_master_ip(master_params.name,
master_params)
master_params, ems)
msg = result.fail_msg
if msg:
......
......@@ -1364,8 +1364,9 @@ class LUClusterDestroy(LogicalUnit):
# Run post hooks on master node before it's removed
_RunPostHook(self, master_params.name)
ems = self.cfg.GetUseExternalMipScript()
result = self.rpc.call_node_deactivate_master_ip(master_params.name,
master_params)
master_params, ems)
result.Raise("Could not disable the master role")
return master_params.name
......@@ -3358,8 +3359,9 @@ class LUClusterRename(LogicalUnit):
# shutdown the master IP
master_params = self.cfg.GetMasterNetworkParameters()
ems = self.cfg.GetUseExternalMipScript()
result = self.rpc.call_node_deactivate_master_ip(master_params.name,
master_params)
master_params, ems)
result.Raise("Could not disable the master role")
try:
......@@ -3379,7 +3381,7 @@ class LUClusterRename(LogicalUnit):
finally:
master_params.ip = new_ip
result = self.rpc.call_node_activate_master_ip(master_params.name,
master_params)
master_params, ems)
msg = result.fail_msg
if msg:
self.LogWarning("Could not re-enable the master role on"
......@@ -3737,10 +3739,11 @@ class LUClusterSetParams(LogicalUnit):
if self.op.master_netdev:
master_params = self.cfg.GetMasterNetworkParameters()
ems = self.cfg.GetUseExternalMipScript()
feedback_fn("Shutting down master ip on the current netdev (%s)" %
self.cluster.master_netdev)
result = self.rpc.call_node_deactivate_master_ip(master_params.name,
master_params)
master_params, ems)
result.Raise("Could not disable the master ip")
feedback_fn("Changing master_netdev from %s to %s" %
(master_params.netdev, self.op.master_netdev))
......@@ -3766,8 +3769,9 @@ class LUClusterSetParams(LogicalUnit):
master_params = self.cfg.GetMasterNetworkParameters()
feedback_fn("Starting the master ip on the new master netdev (%s)" %
self.op.master_netdev)
ems = self.cfg.GetUseExternalMipScript()
result = self.rpc.call_node_activate_master_ip(master_params.name,
master_params)
master_params, ems)
if result.fail_msg:
self.LogWarning("Could not re-enable the master ip on"
" the master, please restart manually: %s",
......@@ -3935,8 +3939,9 @@ class LUClusterActivateMasterIp(NoHooksLU):
"""
master_params = self.cfg.GetMasterNetworkParameters()
ems = self.cfg.GetUseExternalMipScript()
self.rpc.call_node_activate_master_ip(master_params.name,
master_params)
master_params, ems)
class LUClusterDeactivateMasterIp(NoHooksLU):
......@@ -3948,7 +3953,9 @@ class LUClusterDeactivateMasterIp(NoHooksLU):
"""
master_params = self.cfg.GetMasterNetworkParameters()
self.rpc.call_node_deactivate_master_ip(master_params.name, master_params)
ems = self.cfg.GetUseExternalMipScript()
self.rpc.call_node_deactivate_master_ip(master_params.name, master_params,
ems)
def _WaitForSync(lu, instance, disks=None, oneshot=False):
......
......@@ -490,12 +490,16 @@ CALLS = {
], None, "Starts master daemons on a node"),
("node_activate_master_ip", SINGLE, TMO_FAST, [
("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
("use_external_mip_script", None,
"Whether to use the user-provided master IP address setup script"),
], None,
"Activates master IP on a node"),
("node_stop_master", SINGLE, TMO_FAST, [], None,
"Deactivates master IP and stops master daemons on a node"),
("node_deactivate_master_ip", SINGLE, TMO_FAST, [
("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
("use_external_mip_script", None,
"Whether to use the user-provided master IP address setup script"),
], None,
"Deactivates master IP on a node"),
("node_change_master_netmask", SINGLE, TMO_FAST, [
......
......@@ -537,9 +537,10 @@ def ActivateMasterIP():
# activate ip
cfg = config.ConfigWriter()
master_params = cfg.GetMasterNetworkParameters()
ems = cfg.GetUseExternalMipScript()
runner = rpc.BootstrapRunner()
result = runner.call_node_activate_master_ip(master_params.name,
master_params)
master_params, ems)
msg = result.fail_msg
if msg:
......
......@@ -698,7 +698,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
master_params = objects.MasterNetworkParameters.FromDict(params[0])
return backend.ActivateMasterIp(master_params)
return backend.ActivateMasterIp(master_params, params[1])
@staticmethod
def perspective_node_deactivate_master_ip(params):
......@@ -706,7 +706,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
master_params = objects.MasterNetworkParameters.FromDict(params[0])
return backend.DeactivateMasterIp(master_params)
return backend.DeactivateMasterIp(master_params, params[1])
@staticmethod
def perspective_node_stop_master(params):
......
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