From 26d0d088739b99b129f0d15385c2248c3bdcb008 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 25 Aug 2024 22:05:16 -0400 Subject: [PATCH] Add is-primary command Used by the cron to check if the node firing an autobackup is the primary node or not, so it will not multi-fire from all coordinators. --- client-cli/pvc/cli/cli.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/client-cli/pvc/cli/cli.py b/client-cli/pvc/cli/cli.py index a1aa71e4..6f77774d 100644 --- a/client-cli/pvc/cli/cli.py +++ b/client-cli/pvc/cli/cli.py @@ -724,6 +724,33 @@ def cli_node(): pass +############################################################################### +# > pvc node is-primary +############################################################################### +@click.command( + name="is-primary", + short_help="Check if this node is primary coordinator.", +) +@connection_req +@click.argument("node", default=DEFAULT_NODE_HOSTNAME) +def cli_node_is_primary( + node, +): + """ + Check if NODE (or this node if unset) is the current primary coordinator. + + Designed for scripting; returns no visible data, but the return code is 0 if the node + is primary, and 1 if it is not. + """ + + _, primary_node = pvc.lib.cluster.get_primary_node(CLI_CONFIG) + + if primary_node == node: + exit(0) + else: + exit(1) + + ############################################################################### # > pvc node primary ############################################################################### @@ -6525,6 +6552,7 @@ def cli( # Click command tree ############################################################################### +cli_node.add_command(cli_node_is_primary) cli_node.add_command(cli_node_primary) cli_node.add_command(cli_node_secondary) cli_node.add_command(cli_node_flush)