コード例 #1
0
ファイル: pcsd.py プロジェクト: tradej/pcs
def pcsd_sync_certs(argv):
    nodes = utils.getNodesFromCorosyncConf()
    print(
        ("Synchronizing pcsd certificates on nodes {0}. pcsd needs to be "
         "restarted on the nodes in order to reload the certificates.").format(
             ", ".join(nodes)))
    print()
    pcsd_data = {'nodes': nodes}
    for cmd in ['send_local_certs', 'pcsd_restart_nodes']:
        error = ''
        output, retval = utils.run_pcsdcli(cmd, pcsd_data)
        if retval == 0 and output['status'] == 'ok' and output['data']:
            try:
                if output['data']['status'] != 'ok' and output['data']['text']:
                    error = output['data']['text']
            except KeyError:
                error = 'Unable to communicate with pcsd'
        else:
            error = 'Unable to sync pcsd certificates'
        if error:
            utils.err(error, False)
コード例 #2
0
ファイル: pcsd.py プロジェクト: WeiRG/pcs
def pcsd_sync_certs(argv):
    nodes = utils.getNodesFromCorosyncConf()
    print (
        "Synchronizing pcsd certificates on nodes {0}. pcsd needs to be "
        "restarted on the nodes in order to reload the certificates."
    ).format(", ".join(nodes))
    print
    pcsd_data = {'nodes': nodes}
    for cmd in ['send_local_certs', 'pcsd_restart_nodes']:
        error = ''
        output, retval = utils.run_pcsdcli(cmd, pcsd_data)
        if retval == 0 and output['status'] == 'ok' and output['data']:
            try:
                if output['data']['status'] != 'ok' and output['data']['text']:
                    error = output['data']['text']
            except KeyError:
                error = 'Unable to communicate with pcsd'
        else:
            error = 'Unable to sync pcsd certificates'
        if error:
            utils.err(error, False)
コード例 #3
0
ファイル: pcsd.py プロジェクト: akanouras/pcs
def pcsd_sync_certs(argv, exit_after_error=True):
    error = False
    nodes_sync = argv if argv else utils.getNodesFromCorosyncConf()
    nodes_restart = []

    print("Synchronizing pcsd certificates on nodes {0}...".format(
        ", ".join(nodes_sync)
    ))
    pcsd_data = {
        "nodes": nodes_sync,
    }
    output, retval = utils.run_pcsdcli("send_local_certs", pcsd_data)
    if retval == 0 and output["status"] == "ok" and output["data"]:
        try:
            sync_result = output["data"]
            if sync_result["node_status"]:
                for node, status in sync_result["node_status"].items():
                    print("{0}: {1}".format(node, status["text"]))
                    if status["status"] == "ok":
                        nodes_restart.append(node)
                    else:
                        error = True
            if sync_result["status"] != "ok":
                error = True
                utils.err(sync_result["text"], False)
            if error and not nodes_restart:
                if exit_after_error:
                    sys.exit(1)
                else:
                    return
            print()
        except (KeyError, AttributeError):
            utils.err("Unable to communicate with pcsd", exit_after_error)
            return
    else:
        utils.err("Unable to sync pcsd certificates", exit_after_error)
        return

    print("Restarting pcsd on the nodes in order to reload the certificates...")
    pcsd_data = {
        "nodes": nodes_restart,
    }
    output, retval = utils.run_pcsdcli("pcsd_restart_nodes", pcsd_data)
    if retval == 0 and output["status"] == "ok" and output["data"]:
        try:
            restart_result = output["data"]
            if restart_result["node_status"]:
                for node, status in restart_result["node_status"].items():
                    print("{0}: {1}".format(node, status["text"]))
                    if status["status"] != "ok":
                        error = True
            if restart_result["status"] != "ok":
                error = True
                utils.err(restart_result["text"], False)
            if error:
                if exit_after_error:
                    sys.exit(1)
                else:
                    return
        except (KeyError, AttributeError):
            utils.err("Unable to communicate with pcsd", exit_after_error)
            return
    else:
        utils.err("Unable to restart pcsd", exit_after_error)
        return