---
 daemons/ganeti-confd |    3 ++-
 daemons/ganeti-noded |    3 ++-
 daemons/ganeti-rapi  |    3 ++-
 lib/daemon.py        |   21 +++++++++++----------
 4 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/daemons/ganeti-confd b/daemons/ganeti-confd
index c560e7f..4d19ea6 100755
--- a/daemons/ganeti-confd
+++ b/daemons/ganeti-confd
@@ -360,7 +360,8 @@ def main():
 
   dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
   dirs.append((constants.LOCK_DIR, 1777))
-  daemon.GenericMain(constants.CONFD, parser, dirs, CheckConfd, ExecConfd)
+  daemon.GenericMain(constants.CONFD, parser, dirs, CheckConfd, ExecConfd,
+                     default_port=utils.GetDaemonPort(constants.CONFD))
 
 
 if __name__ == "__main__":
diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 0486dd1..5ee2eef 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -819,7 +819,8 @@ def main():
   dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
   dirs.append((constants.LOG_OS_DIR, 0750))
   dirs.append((constants.LOCK_DIR, 1777))
-  daemon.GenericMain(constants.NODED, parser, dirs, None, ExecNoded)
+  daemon.GenericMain(constants.NODED, parser, dirs, None, ExecNoded,
+                     default_port=utils.GetDaemonPort(constants.NODED))
 
 
 if __name__ == '__main__':
diff --git a/daemons/ganeti-rapi b/daemons/ganeti-rapi
index 5928537..087a6db 100755
--- a/daemons/ganeti-rapi
+++ b/daemons/ganeti-rapi
@@ -222,7 +222,8 @@ def main():
 
   dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
   dirs.append((constants.LOG_OS_DIR, 0750))
-  daemon.GenericMain(constants.RAPI, parser, dirs, CheckRapi, ExecRapi)
+  daemon.GenericMain(constants.RAPI, parser, dirs, CheckRapi, ExecRapi,
+                     default_port=utils.GetDaemonPort(constants.RAPI))
 
 
 if __name__ == "__main__":
diff --git a/lib/daemon.py b/lib/daemon.py
index 6fb2f66..24f567f 100644
--- a/lib/daemon.py
+++ b/lib/daemon.py
@@ -221,7 +221,8 @@ class Mainloop(object):
     self._signal_wait.append(owner)
 
 
-def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
+def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn,
+                default_port=None):
   """Shared main function for daemons.
 
   @type daemon_name: string
@@ -237,6 +238,8 @@ def GenericMain(daemon_name, optionparser, dirs, check_fn, 
exec_fn):
   @type exec_fn: function which accepts (options, args)
   @param exec_fn: function that's executed with the daemon's pid file held, and
                   runs the daemon itself.
+  @type default_port: int
+  @param default_port: Default network port
 
   """
   optionparser.add_option("-f", "--foreground", dest="fork",
@@ -245,17 +248,15 @@ def GenericMain(daemon_name, optionparser, dirs, 
check_fn, exec_fn):
   optionparser.add_option("-d", "--debug", dest="debug",
                           help="Enable some debug messages",
                           default=False, action="store_true")
-  if daemon_name in constants.DAEMONS_PORTS:
-    # for networked daemons we also allow choosing the bind port and address.
-    # by default we use the port provided by utils.GetDaemonPort, and bind to
-    # 0.0.0.0 (which is represented by and empty bind address.
-    port = utils.GetDaemonPort(daemon_name)
+
+  if default_port is not None:
+    # For networked daemons we allow choosing the bind port and address
     optionparser.add_option("-p", "--port", dest="port",
-                            help="Network port (%s default)." % port,
-                            default=port, type="int")
+                            help="Network port (default: %s)" % default_port,
+                            default=default_port, type="int")
     optionparser.add_option("-b", "--bind", dest="bind_address",
-                            help="Bind address",
-                            default="", metavar="ADDRESS")
+                            help="Bind address (default: 0.0.0.0)",
+                            default="0.0.0.0", metavar="ADDRESS")
 
   if daemon_name in constants.DAEMONS_SSL:
     default_cert, default_key = constants.DAEMONS_SSL[daemon_name]
-- 
1.6.4.3

Reply via email to