Use utils.ReadFile to read SSL certificate
[ganeti-local] / lib / bootstrap.py
index 74cead0..8a6ca56 100644 (file)
@@ -38,8 +38,6 @@ from ganeti import constants
 from ganeti import objects
 from ganeti import ssconf
 
-from ganeti.rpc import RpcRunner
-
 def _InitSSHSetup(node):
   """Setup the SSH configuration for the cluster.
 
@@ -109,7 +107,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
                 master_netdev, file_storage_dir,
                 secondary_ip=None,
                 vg_name=None, beparams=None, hvparams=None,
-                enabled_hypervisors=None):
+                enabled_hypervisors=None, default_hypervisor=None):
   """Initialise the cluster.
 
   """
@@ -215,6 +213,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
     cluster_name=clustername.name,
     file_storage_dir=file_storage_dir,
     enabled_hypervisors=enabled_hypervisors,
+    default_hypervisor=default_hypervisor,
     beparams={constants.BEGR_DEFAULT: beparams},
     hvparams=hvparams,
     )
@@ -228,7 +227,7 @@ def InitCluster(cluster_name, mac_prefix, def_bridge,
 
   # start the master ip
   # TODO: Review rpc call from bootstrap
-  RpcRunner.call_node_start_master(hostname.name, True)
+  rpc.RpcRunner.call_node_start_master(hostname.name, True)
 
 
 def InitConfig(version, cluster_config, master_node_config,
@@ -273,9 +272,9 @@ def FinalizeClusterDestroy(master):
   begun in cmdlib.LUDestroyOpcode.
 
   """
-  if not RpcRunner.call_node_stop_master(master, True):
+  if not rpc.RpcRunner.call_node_stop_master(master, True):
     logging.warning("Could not disable the master role")
-  if not RpcRunner.call_node_leave_cluster(master):
+  if not rpc.RpcRunner.call_node_leave_cluster(master):
     logging.warning("Could not shutdown the node daemon and cleanup the node")
 
 
@@ -295,11 +294,7 @@ def SetupNodeDaemon(node, ssh_key_check):
   gntpass = utils.GetNodeDaemonPassword()
   if not re.match('^[a-zA-Z0-9.]{1,64}$', gntpass):
     raise errors.OpExecError("ganeti password corruption detected")
-  f = open(constants.SSL_CERT_FILE)
-  try:
-    gntpem = f.read(8192)
-  finally:
-    f.close()
+  gntpem = utils.ReadFile(constants.SSL_CERT_FILE)
   # in the base64 pem encoding, neither '!' nor '.' are valid chars,
   # so we use this to detect an invalid certificate; as long as the
   # cert doesn't contain this, the here-document will be correctly
@@ -371,7 +366,7 @@ def MasterFailover():
 
   logging.info("Setting master to %s, old master: %s", new_master, old_master)
 
-  if not RpcRunner.call_node_stop_master(old_master, True):
+  if not rpc.RpcRunner.call_node_stop_master(old_master, True):
     logging.error("Could not disable the master role on the old master"
                  " %s, please disable manually", old_master)
 
@@ -380,13 +375,13 @@ def MasterFailover():
 
   # Here we have a phase where no master should be running
 
-  if not RpcRunner.call_upload_file(cfg.GetNodeList(),
+  if not rpc.RpcRunner.call_upload_file(cfg.GetNodeList(),
                                     constants.CLUSTER_CONF_FILE):
     logging.error("Could not distribute the new configuration"
                   " to the other nodes, please check.")
 
 
-  if not RpcRunner.call_node_start_master(new_master, True):
+  if not rpc.RpcRunner.call_node_start_master(new_master, True):
     logging.error("Could not start the master role on the new master"
                   " %s, please check", new_master)
     rcode = 1