Пример #1
0
def monitor_from_args(args, monitor_class=ApolloMonitor):
    """
    Prepare a CredClient from ArgumentParser args
    """
    # Prepare the STOMP connection and CredClient
    stomp_connection = syncstomp_from_args(args, 'tellme')
    tellme = CredClient(stomp_connection)

    # Auto-detect Apollo administration server and credentials
    zone = args.zone
    host_and_ports = find_service('_apollo_adm._tcp', zone)
    virtual_host = find_text('_apollo_vhost', zone)
    apollo_cred = tellme('apollo-admin')

    # There really should only be one host-port pair
    if len(host_and_ports) > 1:
        logger.warn('More than one apollo administration service found')

    if len(host_and_ports) == 0:
        logger.error('Apollo admin service not found')
        exit(1)

    if virtual_host is None:
        logger.error('Apollo vhost unknown')
        exit(1)

    # Construct the monitor
    host, port = host_and_ports[0]
    monitor = monitor_class(host=host,
                            port=port,
                            virtual_host=virtual_host,
                            username=apollo_cred['username'],
                            password=apollo_cred['password'])
    return monitor
Пример #2
0
    def __init__(self, host_and_ports=None, zone=None, prefer_localhost=False,
                 user=None, passcode=None, **kwargs):
        self.zone = zone

        # Find the hosts
        host_and_ports = host_and_ports or find_service('_stomp._tcp',
                                                        zone=zone)

        # Initialize superclass
        super(Connection, self).__init__(host_and_ports=host_and_ports,
                                         prefer_localhost=prefer_localhost,
                                         **kwargs)
        self.start()
        self.connect(username=user, passcode=passcode, wait=True)
Пример #3
0
def main():
    parser = ArgumentParser()
    parser.add_argument('--version', action='version',
                        version=syncstomp_version)
    add_argparse_group(parser)

    parser.add_argument('-F', '--file', type=str, dest='filename',
                        help=('File containing commands to be executed, '
                              'instead of prompting from the command prompt.')
                        )
    parser.add_argument('-S', '--stomp', type=float, dest='stomp', default=1.0,
                        help='Set the STOMP protocol version.')

    parser.set_defaults()
    args = parser.parse_args()
    logger = logger_from_args(args, 'stomp')

    # Use service autodiscovery
    servers = find_service('_stomp._tcp', args.zone)

    # Try to connect
    connected = False
    while not connected:
        if len(servers) == 0:
            logger.error("No servers left to try.")
            exit(1)
        (host, port) = servers.pop(0)
        logger.info("Trying %s port %d" % (host, port))

        try:
            st = StompCLI(host, port, args.username, args.password, args.stomp)
            connected = True
        except ConnectFailedException:
            pass

    if args.filename:
        st.do_run(args.filename)
    else:
        try:
            try:
                st.cmdloop()
            except KeyboardInterrupt:
                pass
        finally:
            st.onecmd('disconnect')
Пример #4
0
def monitor_from_args(args, monitor_class=ApolloMonitor):
    """
    Prepare a CredClient from ArgumentParser args
    """
    # Prepare the STOMP connection and CredClient
    stomp_connection = syncstomp_from_args(args, "tellme")
    tellme = CredClient(stomp_connection)

    # Auto-detect Apollo administration server and credentials
    zone = args.zone
    host_and_ports = find_service("_apollo_adm._tcp", zone)
    virtual_host = find_text("_apollo_vhost", zone)
    apollo_cred = tellme("apollo-admin")

    # There really should only be one host-port pair
    if len(host_and_ports) > 1:
        logger.warn("More than one apollo administration service found")

    if len(host_and_ports) == 0:
        logger.error("Apollo admin service not found")
        exit(1)

    if virtual_host is None:
        logger.error("Apollo vhost unknown")
        exit(1)

    # Construct the monitor
    host, port = host_and_ports[0]
    monitor = monitor_class(
        host=host,
        port=port,
        virtual_host=virtual_host,
        username=apollo_cred["username"],
        password=apollo_cred["password"],
    )
    return monitor