Commit cd50653c authored by Guido Trotter's avatar Guido Trotter
Browse files

Change GetNodeDaemonPort to GetDaemonPort in utils



GetNodeDaemonPort is used to lookup the node daemon port in the services
file, and if not found to return the default one. We make it a generic
function, which accepts the daemon name in input, so that it can be used
by confd as well, to lookup its own udp port.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 775c6d3e
......@@ -773,7 +773,7 @@ def main():
print "config %s not there, will not run." % fname
sys.exit(constants.EXIT_NOTCLUSTER)
port = utils.GetNodeDaemonPort()
port = utils.GetDaemonPort(constants.NODED)
dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
dirs.append((constants.LOG_OS_DIR, 0750))
......
......@@ -476,7 +476,7 @@ def VerifyNode(what, cluster_name):
tmp[my_name] = ("Can't find my own primary/secondary IP"
" in the node list")
else:
port = utils.GetNodeDaemonPort()
port = utils.GetDaemonPort(constants.NODED)
for name, pip, sip in what[constants.NV_NODENETTEST]:
fail = []
if not utils.TcpPing(pip, port, source=my_pip):
......
......@@ -115,7 +115,15 @@ NODED_PID = "ganeti-noded"
RAPI_PID = "ganeti-rapi"
NODE_INITD_SCRIPT = _autoconf.SYSCONFDIR + "/init.d/ganeti"
DEFAULT_NODED_PORT = 1811
NODED = "ganeti-noded"
DAEMONS_PORTS = {
# daemon-name: ("proto", "default-port")
NODED: ("tcp", 1811),
}
DEFAULT_NODED_PORT = DAEMONS_PORTS[NODED][1]
FIRST_DRBD_PORT = 11000
LAST_DRBD_PORT = 14999
MASTER_SCRIPT = "ganeti-master"
......
......@@ -265,7 +265,7 @@ class RpcRunner(object):
"""
self._cfg = cfg
self.port = utils.GetNodeDaemonPort()
self.port = utils.GetDaemonPort(constants.NODED)
def _InstDict(self, instance, hvp=None, bep=None):
"""Convert the given instance to a dict.
......@@ -366,7 +366,7 @@ class RpcRunner(object):
"""
body = serializer.DumpJson(args, indent=False)
c = Client(procedure, body, utils.GetNodeDaemonPort())
c = Client(procedure, body, utils.GetDaemonPort(constants.NODED))
c.ConnectList(node_list, address_list=address_list)
return c.GetResults()
......@@ -388,7 +388,7 @@ class RpcRunner(object):
"""
body = serializer.DumpJson(args, indent=False)
c = Client(procedure, body, utils.GetNodeDaemonPort())
c = Client(procedure, body, utils.GetDaemonPort(constants.NODED))
c.ConnectNode(node)
return c.GetResults()[node]
......
......@@ -1679,20 +1679,26 @@ def MergeTime(timetuple):
return float(seconds) + (float(microseconds) * 0.000001)
def GetNodeDaemonPort():
"""Get the node daemon port for this cluster.
def GetDaemonPort(daemon_name):
"""Get the daemon port for this cluster.
Note that this routine does not read a ganeti-specific file, but
instead uses C{socket.getservbyname} to allow pre-customization of
this parameter outside of Ganeti.
@type daemon_name: string
@param daemon_name: daemon name (in constants.DAEMONS_PORTS)
@rtype: int
"""
if daemon_name not in constants.DAEMONS_PORTS:
raise errors.ProgrammerError("Unknown daemon: %s" % daemon_name)
(proto, default_port) = constants.DAEMONS_PORTS[daemon_name]
try:
port = socket.getservbyname("ganeti-noded", "tcp")
port = socket.getservbyname(daemon_name, proto)
except socket.error:
port = constants.DEFAULT_NODED_PORT
port = default_port
return port
......
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