diff options
Diffstat (limited to 'qpid')
| -rwxr-xr-x | qpid/tools/src/py/qpid-ha | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/qpid/tools/src/py/qpid-ha b/qpid/tools/src/py/qpid-ha index 3d56f24fb8..26029187a3 100755 --- a/qpid/tools/src/py/qpid-ha +++ b/qpid/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) |
