diff options
| author | Alan Conway <aconway@apache.org> | 2013-04-11 19:03:07 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2013-04-11 19:03:07 +0000 |
| commit | 821b355a4b91e1e2e078915d46833d962e7bd1cb (patch) | |
| tree | e683d7aceba74f4bf86ca98207a020f73f34bf5a /tools | |
| parent | 1731e76015ace6fc304e66f79c1c670d6fcb76f6 (diff) | |
| download | qpid-python-821b355a4b91e1e2e078915d46833d962e7bd1cb.tar.gz | |
QPID-4738: Add "qpid-ha status --all" option.
Show status of all cluster members.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1467053 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/src/py/qpid-ha | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/tools/src/py/qpid-ha b/tools/src/py/qpid-ha index 3d56f24fb8..26029187a3 100755 --- a/tools/src/py/qpid-ha +++ b/tools/src/py/qpid-ha @@ -19,7 +19,7 @@ # under the License. # -import optparse, sys, time, os +import optparse, sys, time, os, re from qpid.messaging import Connection from qpid.messaging import Message as QpidMessage from qpidtoollibs.broker import BrokerAgent @@ -38,6 +38,9 @@ class ExitStatus(Exception): class Command: commands = {} + def add(self, optname, metavar, type, help): + self.op.add_option(optname, metavar=metavar, type=type, help=help, action="store") + def __init__(self, name, help, arg_names=[]): Command.commands[name] = self self.name = name @@ -50,11 +53,7 @@ class Command: self.op.add_option("--ssl-key", action="store", type="string", metavar="<key>", help="Client SSL private key (PEM Format)") self.op.add_option("-b", "--broker", action="store", type="string", default="localhost:5672", metavar="<address>", help="Address of qpidd broker with syntax: [username/password@] hostname | ip-address [:<port>]") - def execute(self, args): - opts, args = self.op.parse_args(args) - if len(args) != len(self.arg_names)+1: - self.op.print_help() - raise Exception("Wrong number of arguments") + def connect(self, opts): conn_options = {} if opts.sasl_mechanism: conn_options['sasl_mechanisms'] = opts.sasl_mechanism @@ -65,10 +64,17 @@ class Command: self.op.error("missing '--ssl-certificate' (required by '--ssl-key')") conn_options['ssl_keyfile'] = opts.ssl_key conn_options['client_properties'] = {'qpid.ha-admin' : 1} - connection = Connection.establish(opts.broker, **conn_options) qmf_broker = BrokerAgent(connection) ha_broker = qmf_broker.getHaBroker() + return (connection, qmf_broker, ha_broker) + + def execute(self, args): + opts, args = self.op.parse_args(args) + if len(args) != len(self.arg_names)+1: + self.op.print_help() + raise Exception("Wrong number of arguments") + connection, qmf_broker, ha_broker = self.connect(opts) if not ha_broker: raise Exception("HA module is not loaded on broker at %s" % opts.broker) try: self.do_execute(qmf_broker, ha_broker, opts, args) finally: connection.close() @@ -92,11 +98,24 @@ class StatusCmd(Command): self.op.add_option( "--is-primary", action="store_true", default=False, help="Don't print status. Return 0 if the broker is primary, 1 otherwise") + self.op.add_option( + "--all", action="store_true", default=False, + help="Print status for all brokers in the cluster.") def do_execute(self, qmf_broker, ha_broker, opts, args): if opts.is_primary: if not ha_broker.status in ["active", "recovering"]: raise ExitStatus(1) if opts.expect: if opts.expect != ha_broker.status: raise ExitStatus(1) + if opts.all: + opts.all=False + brokers = re.sub(r'(^amqp:)|(tcp:)', "", ha_broker.brokersUrl).split(",") + for b in brokers: + opts.broker = b + try: + connection, qmf_broker, ha_broker = self.connect(opts) + print b, ha_broker.status + except Exception,e: + print b, e else: print ha_broker.status @@ -112,11 +131,9 @@ ReplicateCmd() class SetCmd(Command): def __init__(self): Command.__init__(self, "set", "Set HA configuration settings") - def add(optname, metavar, type, help): - self.op.add_option(optname, metavar=metavar, type=type, help=help, action="store") - add("--brokers-url", "<url>", "string", "URL with address of each broker in the cluster. Used by brokers to connect to each other.") - add("--public-url", "<url>", "string", "URL advertised to clients to connect to the cluster. May be a list or a VIP.") - add("--backups", "<n>", "int", "Expect <n> backups to be running"), + self.add("--brokers-url", "<url>", "string", "URL with address of each broker in the cluster. Used by brokers to connect to each other.") + self.add("--public-url", "<url>", "string", "URL advertised to clients to connect to the cluster. May be a list or a VIP.") + self.add("--backups", "<n>", "int", "Expect <n> backups to be running"), def do_execute(self, qmf_broker, ha_broker, opts, args): if (opts.brokers_url): qmf_broker._method("setBrokersUrl", {"url":opts.brokers_url}, HA_BROKER) |
