+ utils.WriteFile(file_name, data="%s\n" % utils.GenerateSecret(), mode=0400,
+ backup=True)
+
+
+def GenerateClusterCrypto(new_cluster_cert, new_rapi_cert, new_confd_hmac_key,
+ new_cds, rapi_cert_pem=None, cds=None,
+ nodecert_file=constants.NODED_CERT_FILE,
+ rapicert_file=constants.RAPI_CERT_FILE,
+ hmackey_file=constants.CONFD_HMAC_KEY,
+ cds_file=constants.CLUSTER_DOMAIN_SECRET_FILE):
+ """Updates the cluster certificates, keys and secrets.
+
+ @type new_cluster_cert: bool
+ @param new_cluster_cert: Whether to generate a new cluster certificate
+ @type new_rapi_cert: bool
+ @param new_rapi_cert: Whether to generate a new RAPI certificate
+ @type new_confd_hmac_key: bool
+ @param new_confd_hmac_key: Whether to generate a new HMAC key
+ @type new_cds: bool
+ @param new_cds: Whether to generate a new cluster domain secret
+ @type rapi_cert_pem: string
+ @param rapi_cert_pem: New RAPI certificate in PEM format
+ @type cds: string
+ @param cds: New cluster domain secret
+ @type nodecert_file: string
+ @param nodecert_file: optional override of the node cert file path
+ @type rapicert_file: string
+ @param rapicert_file: optional override of the rapi cert file path
+ @type hmackey_file: string
+ @param hmackey_file: optional override of the hmac key file path
+
+ """
+ # noded SSL certificate
+ cluster_cert_exists = os.path.exists(nodecert_file)
+ if new_cluster_cert or not cluster_cert_exists:
+ if cluster_cert_exists:
+ utils.CreateBackup(nodecert_file)
+
+ logging.debug("Generating new cluster certificate at %s", nodecert_file)
+ utils.GenerateSelfSignedSslCert(nodecert_file)