Minor fix in query.py
[ganeti-local] / lib / bootstrap.py
index a38296a..0944fb7 100644 (file)
@@ -41,9 +41,9 @@ from ganeti import serializer
 from ganeti import hypervisor
 from ganeti import bdev
 from ganeti import netutils
-from ganeti import backend
 from ganeti import luxi
 from ganeti import jstore
+from ganeti import pathutils
 
 
 # ec_id for InitConfig's temporary reservation manager
@@ -60,7 +60,7 @@ def _InitSSHSetup():
   permitted hosts and adds the hostkey to its own known hosts.
 
   """
-  priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.GANETI_RUNAS)
+  priv_key, pub_key, auth_keys = ssh.GetUserFiles(constants.SSH_LOGIN_USER)
 
   for name in priv_key, pub_key:
     if os.path.exists(name):
@@ -92,12 +92,12 @@ def GenerateClusterCrypto(new_cluster_cert, new_rapi_cert, new_spice_cert,
                           new_confd_hmac_key, new_cds,
                           rapi_cert_pem=None, spice_cert_pem=None,
                           spice_cacert_pem=None, cds=None,
-                          nodecert_file=constants.NODED_CERT_FILE,
-                          rapicert_file=constants.RAPI_CERT_FILE,
-                          spicecert_file=constants.SPICE_CERT_FILE,
-                          spicecacert_file=constants.SPICE_CACERT_FILE,
-                          hmackey_file=constants.CONFD_HMAC_KEY,
-                          cds_file=constants.CLUSTER_DOMAIN_SECRET_FILE):
+                          nodecert_file=pathutils.NODED_CERT_FILE,
+                          rapicert_file=pathutils.RAPI_CERT_FILE,
+                          spicecert_file=pathutils.SPICE_CERT_FILE,
+                          spicecacert_file=pathutils.SPICE_CACERT_FILE,
+                          hmackey_file=pathutils.CONFD_HMAC_KEY,
+                          cds_file=pathutils.CLUSTER_DOMAIN_SECRET_FILE):
   """Updates the cluster certificates, keys and secrets.
 
   @type new_cluster_cert: bool
@@ -208,7 +208,7 @@ def _InitGanetiServerSetup(master_name):
   # Generate cluster secrets
   GenerateClusterCrypto(True, False, False, False, False)
 
-  result = utils.RunCmd([constants.DAEMON_UTIL, "start", constants.NODED])
+  result = utils.RunCmd([pathutils.DAEMON_UTIL, "start", constants.NODED])
   if result.failed:
     raise errors.OpExecError("Could not start the node daemon, command %s"
                              " had exitcode %s and error %s" %
@@ -329,7 +329,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
   if ipcls.IsLoopback(hostname.ip):
     raise errors.OpPrereqError("This host's IP (%s) resolves to a loopback"
                                " address. Please fix DNS or %s." %
-                               (hostname.ip, constants.ETC_HOSTS),
+                               (hostname.ip, pathutils.ETC_HOSTS),
                                errors.ECODE_ENVIRON)
 
   if not ipcls.Own(hostname.ip):
@@ -412,7 +412,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
                                (master_netdev,
                                 result.output.strip()), errors.ECODE_INVAL)
 
-  dirs = [(constants.RUN_GANETI_DIR, constants.RUN_DIRS_MODE)]
+  dirs = [(pathutils.RUN_DIR, constants.RUN_DIRS_MODE)]
   utils.EnsureDirs(dirs)
 
   objects.UpgradeBeParams(beparams)
@@ -473,7 +473,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
                                errors.ECODE_INVAL)
 
   # set up ssh config and /etc/hosts
-  sshline = utils.ReadFile(constants.SSH_HOST_RSA_PUB)
+  sshline = utils.ReadFile(pathutils.SSH_HOST_RSA_PUB)
   sshkey = sshline.split(" ")[1]
 
   if modify_etc_hosts:
@@ -546,15 +546,15 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
                                     )
   InitConfig(constants.CONFIG_VERSION, cluster_config, master_node_config)
   cfg = config.ConfigWriter(offline=True)
-  ssh.WriteKnownHostsFile(cfg, constants.SSH_KNOWN_HOSTS_FILE)
+  ssh.WriteKnownHostsFile(cfg, pathutils.SSH_KNOWN_HOSTS_FILE)
   cfg.Update(cfg.GetClusterInfo(), logging.error)
-  backend.WriteSsconfFiles(cfg.GetSsconfValues())
+  ssconf.WriteSsconfFiles(cfg.GetSsconfValues())
 
   # set up the inter-node password and certificate
   _InitGanetiServerSetup(hostname.name)
 
   logging.debug("Starting daemons")
-  result = utils.RunCmd([constants.DAEMON_UTIL, "start-all"])
+  result = utils.RunCmd([pathutils.DAEMON_UTIL, "start-all"])
   if result.failed:
     raise errors.OpExecError("Could not start daemons, command %s"
                              " had exitcode %s and error %s" %
@@ -564,7 +564,7 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
 
 
 def InitConfig(version, cluster_config, master_node_config,
-               cfg_file=constants.CLUSTER_CONF_FILE):
+               cfg_file=pathutils.CLUSTER_CONF_FILE):
   """Create the initial cluster configuration.
 
   It will contain the current node, which will also be the master
@@ -603,6 +603,7 @@ def InitConfig(version, cluster_config, master_node_config,
                                    nodegroups=nodegroups,
                                    nodes=nodes,
                                    instances={},
+                                   networks={},
                                    serial_no=1,
                                    ctime=now, mtime=now)
   utils.WriteFile(cfg_file,
@@ -655,28 +656,26 @@ def SetupNodeDaemon(cluster_name, node, ssh_key_check):
   @param ssh_key_check: whether to do a strict key check
 
   """
-  family = ssconf.SimpleStore().GetPrimaryIPFamily()
+  sstore = ssconf.SimpleStore()
+  family = sstore.GetPrimaryIPFamily()
   sshrunner = ssh.SshRunner(cluster_name,
                             ipv6=(family == netutils.IP6Address.family))
 
-  bind_address = constants.IP4_ADDRESS_ANY
-  if family == netutils.IP6Address.family:
-    bind_address = constants.IP6_ADDRESS_ANY
-
   # set up inter-node password and certificate and restarts the node daemon
   # and then connect with ssh to set password and start ganeti-noded
   # note that all the below variables are sanitized at this point,
   # either by being constants or by the checks above
-  sshrunner.CopyFileToNode(node, constants.NODED_CERT_FILE)
-  sshrunner.CopyFileToNode(node, constants.RAPI_CERT_FILE)
-  sshrunner.CopyFileToNode(node, constants.SPICE_CERT_FILE)
-  sshrunner.CopyFileToNode(node, constants.SPICE_CACERT_FILE)
-  sshrunner.CopyFileToNode(node, constants.CONFD_HMAC_KEY)
-  mycommand = ("%s stop-all; %s start %s -b %s" %
-               (constants.DAEMON_UTIL, constants.DAEMON_UTIL, constants.NODED,
-                utils.ShellQuote(bind_address)))
-
-  result = sshrunner.Run(node, "root", mycommand, batch=False,
+  sshrunner.CopyFileToNode(node, pathutils.NODED_CERT_FILE)
+  sshrunner.CopyFileToNode(node, pathutils.RAPI_CERT_FILE)
+  sshrunner.CopyFileToNode(node, pathutils.SPICE_CERT_FILE)
+  sshrunner.CopyFileToNode(node, pathutils.SPICE_CACERT_FILE)
+  sshrunner.CopyFileToNode(node, pathutils.CONFD_HMAC_KEY)
+  for filename in sstore.GetFileList():
+    sshrunner.CopyFileToNode(node, filename)
+  mycommand = ("%s stop-all; %s start %s" %
+               (pathutils.DAEMON_UTIL, pathutils.DAEMON_UTIL, constants.NODED))
+
+  result = sshrunner.Run(node, constants.SSH_LOGIN_USER, mycommand, batch=False,
                          ask_key=ssh_key_check,
                          use_cluster_key=True,
                          strict_host_check=ssh_key_check)