Commit 19ddc57a authored by René Nussbaumer's avatar René Nussbaumer

Add RPC calls to update /etc/hosts

Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 17f7fd27
......@@ -608,6 +608,15 @@ class NodeHttpServer(http.server.HttpServer):
vgname, hypervisor_type = params
return backend.GetNodeInfo(vgname, hypervisor_type)
@staticmethod
def perspective_etc_hosts_modify(params):
"""Modify a node entry in /etc/hosts.
"""
backend.EtcHostsModify(params[0], params[1], params[2])
return True
@staticmethod
def perspective_node_verify(params):
"""Run a verify sequence on this node.
......
......@@ -350,6 +350,28 @@ def StopMaster(stop_daemons):
result.cmd, result.exit_code, result.output)
def EtcHostsModify(mode, host, ip):
"""Modify a host entry in /etc/hosts.
@param mode: The mode to operate. Either add or remove entry
@param host: The host to operate on
@param ip: The ip associated with the entry
"""
if mode == constants.ETC_HOSTS_ADD:
if not ip:
RPCFail("Mode 'add' needs 'ip' parameter, but parameter not"
" present")
utils.AddHostToEtcHosts(host, ip)
elif mode == constants.ETC_HOSTS_REMOVE:
if ip:
RPCFail("Mode 'remove' does not allow 'ip' parameter, but"
" parameter is present")
utils.RemoveHostFromEtcHosts(host)
else:
RPCFail("Mode not supported")
def LeaveCluster(modify_ssh_setup):
"""Cleans up and remove the current node.
......
......@@ -841,6 +841,10 @@ ELOG_PROGRESS = "progress"
ELOG_REMOTE_IMPORT = "remote-import"
ELOG_JQUEUE_TEST = "jqueue-test"
# /etc/hosts modification
ETC_HOSTS_ADD = "add"
ETC_HOSTS_REMOVE = "remove"
# Job queue test
JQT_MSGPREFIX = "TESTMSG="
JQT_EXPANDNAMES = "expandnames"
......
......@@ -873,6 +873,22 @@ class RpcRunner(object):
return self._MultiNodeCall(node_list, "node_info",
[vg_name, hypervisor_type])
@_RpcTimeout(_TMO_NORMAL)
def call_etc_hosts_modify(self, node, mode, name, ip):
"""Modify hosts file with name
@type node: string
@param node: The node to call
@type mode: string
@param mode: The mode to operate. Currently "add" or "remove"
@type name: string
@param name: The host name to be modified
@type ip: string
@param ip: The ip of the entry (just valid if mode is "add")
"""
return self._SingleNodeCall(node, "etc_hosts_modify", [mode, name, ip])
@_RpcTimeout(_TMO_NORMAL)
def call_node_verify(self, node_list, checkdict, cluster_name):
"""Request verification of given parameters.
......
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