Allow burnin to use an iallocator in instance creation
[ganeti-local] / daemons / ganeti-master
index 2840fd4..b24f43f 100755 (executable)
@@ -35,11 +35,9 @@ generic errors as other python code can cause exit with code 1.
 
 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
@@ -48,7 +46,7 @@ from ganeti import utils
 EXIT_OK = 0
 EXIT_SOME_ERROR = 1
 EXIT_NOTMASTER = constants.EXIT_NOTMASTER
-EXIT_NODESETUP_ERROR = 12
+EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR
 EXIT_DUPLICATE_IP = 13
 EXIT_ARGS_ERROR = 14
 
@@ -108,10 +106,9 @@ def StartMaster(master_netdev, master_ip, debug):
   """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")
@@ -151,6 +148,12 @@ def main():
   """
   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:
@@ -158,7 +161,7 @@ def main():
     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
@@ -168,9 +171,9 @@ def main():
   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()