import os
import sys
-import socket
from optparse import OptionParser
-from ganeti import logger
from ganeti import constants
from ganeti import errors
from ganeti import ssconf
EXIT_OK = 0
EXIT_SOME_ERROR = 1
-EXIT_NOTMASTER = 11
-EXIT_NODESETUP_ERROR = 12
+EXIT_NOTMASTER = constants.EXIT_NOTMASTER
+EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR
EXIT_DUPLICATE_IP = 13
EXIT_ARGS_ERROR = 14
"""Starts the master.
"""
- result = utils.RunCmd(["fping", "-q", master_ip])
- if not result.failed:
- r2 = utils.RunCmd(["fping", "-q", "-S127.0.0.1", master_ip])
- if not result.failed:
+ if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
+ if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT,
+ source=constants.LOCALHOST_IP_ADDRESS):
# we already have the ip:
if debug:
sys.stderr.write("Notice: already started.\n")
"""
options, args = ParseOptions()
debug = options.debug
+ try:
+ myself = utils.HostInfo()
+ except errors.ResolverError, err:
+ sys.stderr.write("Cannot resolve my own name (%s)\n" % err.args[0])
+ return EXIT_NODESETUP_ERROR
+
result = CheckNodeSetup(debug)
if not result:
if debug:
return EXIT_NODESETUP_ERROR
master_node, master_netdev, master_ip = result
- if socket.gethostname() != master_node and args[0] == "start":
+ if myself.name != master_node and args[0] == "start":
if debug:
sys.stderr.write("Not master, ignoring request.\n")
return EXIT_NOTMASTER
else:
fn = StopMaster
- return fn(master_netdev, master_ip, debug)
+ result = fn(master_netdev, master_ip, debug)
+ sys.exit(result)
-if __name__=='__main__':
- exit_code = main()
- sys.exit(exit_code)
+if __name__ == '__main__':
+ main()