"""
(fd, tmp_file_name) = tempfile.mkstemp(dir=os.path.dirname(file_name))
try:
- # Set permissions before writing key
- os.chmod(tmp_file_name, 0600)
-
- result = utils.RunCmd(["openssl", "req", "-new", "-newkey", "rsa:1024",
- "-days", str(validity), "-nodes", "-x509",
- "-keyout", tmp_file_name, "-out", tmp_file_name,
- "-batch"])
- if result.failed:
- raise errors.OpExecError("Could not generate SSL certificate, command"
- " %s had exitcode %s and error message %s" %
- (result.cmd, result.exit_code, result.output))
-
- # Make read-only
- os.chmod(tmp_file_name, 0400)
-
- os.rename(tmp_file_name, file_name)
+ try:
+ # Set permissions before writing key
+ os.chmod(tmp_file_name, 0600)
+
+ result = utils.RunCmd(["openssl", "req", "-new", "-newkey", "rsa:1024",
+ "-days", str(validity), "-nodes", "-x509",
+ "-keyout", tmp_file_name, "-out", tmp_file_name,
+ "-batch"])
+ if result.failed:
+ raise errors.OpExecError("Could not generate SSL certificate, command"
+ " %s had exitcode %s and error message %s" %
+ (result.cmd, result.exit_code, result.output))
+
+ # Make read-only
+ os.chmod(tmp_file_name, 0400)
+
+ os.rename(tmp_file_name, file_name)
+ finally:
+ utils.RemoveFile(tmp_file_name)
finally:
- utils.RemoveFile(tmp_file_name)
+ os.close(fd)
def _InitGanetiServerSetup():
if config.ConfigWriter.IsCluster():
raise errors.OpPrereqError("Cluster is already initialised")
+ if not enabled_hypervisors:
+ raise errors.OpPrereqError("Enabled hypervisors list must contain at"
+ " least one member")
+ invalid_hvs = set(enabled_hypervisors) - constants.HYPER_TYPES
+ if invalid_hvs:
+ raise errors.OpPrereqError("Enabled hypervisors contains invalid"
+ " entries: %s" % invalid_hvs)
+
hostname = utils.HostInfo()
if hostname.ip.startswith("127."):
(node, result.fail_reason, result.output))
-def MasterFailover():
+def MasterFailover(no_voting=False):
"""Failover the master node.
This checks that we are not already the master, and will cause the
current master to cease being master, and the non-master to become
new master.
+ @type no_voting: boolean
+ @param no_voting: force the operation without remote nodes agreement
+ (dangerous)
+
"""
sstore = ssconf.SimpleStore()
" master candidates is:\n"
"%s" % ('\n'.join(mc_no_master)))
- vote_list = GatherMasterVotes(node_list)
-
- if vote_list:
- voted_master = vote_list[0][0]
- if voted_master is None:
- raise errors.OpPrereqError("Cluster is inconsistent, most nodes did not"
- " respond.")
- elif voted_master != old_master:
- raise errors.OpPrereqError("I have wrong configuration, I believe the"
- " master is %s but the other nodes voted for"
- " %s. Please resync the configuration of"
- " this node." % (old_master, voted_master))
+ if not no_voting:
+ vote_list = GatherMasterVotes(node_list)
+
+ if vote_list:
+ voted_master = vote_list[0][0]
+ if voted_master is None:
+ raise errors.OpPrereqError("Cluster is inconsistent, most nodes did"
+ " not respond.")
+ elif voted_master != old_master:
+ raise errors.OpPrereqError("I have a wrong configuration, I believe"
+ " the master is %s but the other nodes"
+ " voted %s. Please resync the configuration"
+ " of this node." %
+ (old_master, voted_master))
# end checks
rcode = 0
# cluster info
cfg.Update(cluster_info)
- result = rpc.RpcRunner.call_node_start_master(new_master, True)
+ # 2.0.X: Don't start the master if no_voting is true
+ result = rpc.RpcRunner.call_node_start_master(new_master, not no_voting)
if result.failed or not result.data:
logging.error("Could not start the master role on the new master"
" %s, please check", new_master)