Beispiel #1
0
    def run(self):
        client = Client.from_config(self.config)
        instances = {}
        for address in self.args['<address>']:
            service = client.container.lookup(address)
            for instance in service:
                if instance.log_endpoint:
                    instances[instance.log_endpoint] = instance, address

        ctx = zmq.Context.instance()
        sock = ctx.socket(zmq.SUB)
        sock.setsockopt_string(zmq.SUBSCRIBE, u'')
        for instance, service_type in six.itervalues(instances):
            sock.connect(instance.log_endpoint)

        level = get_loglevel(self.args['--level'])
        logger = logging.getLogger('iris-tail-cli')
        logger.setLevel(level)
        console = logging.StreamHandler()
        console.setLevel(level)
        console.setFormatter(logging.Formatter('[%(service_type)s][%(identity)s] [%(levelname)s] %(message)s'))
        logger.addHandler(console)
        try:
            while True:
                topic, endpoint, msg = sock.recv_multipart()
                level = getattr(logging, topic)
                instance, service_type = instances[endpoint]
                logger.log(level, msg, extra={
                    'identity': instance.identity[:10],
                    'service_type': service_type,
                })
        except KeyboardInterrupt:
            pass
Beispiel #2
0
 def run(self):
     client = Client.from_config(self.config)
     for service_type in sorted(client.container.discover()):
         p = client.container.lookup("iris://%s" % service_type)
         print("%s [%s]" % (self.terminal.red(service_type), len(p)))
         if self.args.get("--instances"):
             instances = sorted(p, key=lambda d: d.identity)
             for i, d in enumerate(p):
                 prefix = u"└─" if i == len(instances) - 1 else u"├─"
                 print(u"%s [%s] %s" % (prefix, d.identity[:10], d.endpoint))
Beispiel #3
0
    def run(self):
        event_type = self.args.get("<event-type>")

        class Subscriber(iris.Interface):
            @iris.event(event_type)
            def on_event(self, event):
                print("%s: %r" % (event.evt_type, event.body))

        client = Client.from_config(self.config, interface_cls=Subscriber)
        client.container.join()
Beispiel #4
0
 def run(self, **kwargs):
     client = Client.from_config(self.config, **kwargs)
     body = json.loads(self.args.get('<params>', '{}'))
     try:
         timeout = float(self.args.get('--timeout'))
     except ValueError:
         print("--timeout requires a number number (e.g. --timeout=0.42)")
         return 1
     response = client.request(self.args['<address>'], self.args['<func>'], body, timeout=timeout)
     print(response.body)
Beispiel #5
0
    def run(self):
        event_type = self.args.get('<event-type>')

        class Subscriber(iris.Interface):
            @iris.event(event_type)
            def on_event(self, event):
                print('%s: %r' % (event.evt_type, event.body))

        client = Client.from_config(self.config, interface_cls=Subscriber)
        client.container.join()
Beispiel #6
0
 def run(self):
     client = Client.from_config(self.config)
     for service_type in sorted(client.container.discover()):
         p = client.container.lookup('iris://%s' % service_type)
         print("%s [%s]" % (self.terminal.red(service_type), len(p)))
         if self.args.get('--instances'):
             instances = sorted(p, key=lambda d: d.identity)
             for i, d in enumerate(p):
                 prefix = u'└─' if i == len(instances) - 1 else u'├─'
                 print(u'%s [%s] %s' %
                       (prefix, d.identity[:10], d.endpoint))
Beispiel #7
0
 def run(self):
     client = Client.from_config(self.config)
     address = self.args['<address>']
     try:
         result = client.request(address, 'iris.inspect', {}).body
     except LookupFailure:
         logger.error("cannot resolve %s", address)
         sys.exit(1)
     print
     for method in result['methods']:
         print("rpc {name}({params})\n    {help}\n".format(
             name=self.terminal.red(method['name']),
             params=', '.join(method['params']),
             help='\n    '.join(textwrap.wrap(method['help'], 70)),
         ))
Beispiel #8
0
 def run(self):
     client = Client.from_config(self.config)
     address = self.args['<address>']
     try:
         result = client.request(address, 'iris.inspect', {}).body
     except LookupFailure:
         logger.error("cannot resolve %s", address)
         sys.exit(1)
     print
     for method in result['methods']:
         print("rpc {name}({params})\n    {help}\n".format(
             name=self.terminal.red(method['name']),
             params=', '.join(method['params']),
             help='\n    '.join(textwrap.wrap(method['help'], 70)),
         ))
Beispiel #9
0
 def run(self):
     client = Client.from_config(self.config)
     address = self.args["<address>"]
     try:
         result = client.request(address, "iris.inspect", {}).body
     except LookupFailure:
         logger.error("cannot resolve %s", address)
         sys.exit(1)
     print
     for method in result["methods"]:
         print(
             "rpc {name}({params})\n    {help}\n".format(
                 name=self.terminal.red(method["name"]),
                 params=", ".join(method["params"]),
                 help="\n    ".join(textwrap.wrap(method["help"], 70)),
             )
         )
Beispiel #10
0
 def run(self, **kwargs):
     client = Client.from_config(self.config, **kwargs)
     body = json.loads(self.args.get("<params>", "{}"))
     response = client.request(self.args["<address>"], self.args["<func>"], body)
     print(response.body)
Beispiel #11
0
    def run(self):
        event_type = self.args.get("<event-type>")
        body = json.loads(self.args.get("<body>"))

        client = Client.from_config(self.config)
        client.emit(event_type, body)
Beispiel #12
0
 def run(self, **kwargs):
     client = Client.from_config(self.config, **kwargs)
     body = json.loads(self.args.get('<params>', '{}'))
     response = client.request(self.args['<address>'], self.args['<func>'],
                               body)
     print(response.body)
Beispiel #13
0
    def run(self):
        event_type = self.args.get('<event-type>')
        body = json.loads(self.args.get('<body>'))

        client = Client.from_config(self.config)
        client.emit(event_type, body)
Beispiel #14
0
 def create_client(self, **kwargs):
     container, interface = self.create_container(**kwargs)
     return Client(container)