From e626053cd7f8f2473c7720deb117d0a384ac6d6f Mon Sep 17 00:00:00 2001 From: Swann Perarnau Date: Wed, 28 Nov 2018 16:09:16 -0600 Subject: [PATCH] [feature/fix] add listen command for upstream pub Add a listen command to get access to the event stream of the upstream pub/sub API. This patch gives back access from the command line to the power information of a container, including filtering the event stream to only have events relevent to this container. This changes the workflow a little bit for users, but should result in a cleaner access to profiling data in the future. Related to #18. --- bin/cmd | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/cmd b/bin/cmd index 694c5e4..0188d17 100755 --- a/bin/cmd +++ b/bin/cmd @@ -34,6 +34,22 @@ class CommandLineInterface(object): self.client.wait_connected() + def do_listen(self, argv): + """ Connect to the NRM and listen for pub/sub messages.""" + upstream_pub_port = 2345 + upstream_pub_param = "tcp://localhost:%d" % (upstream_pub_port) + self.pub_client = nrm.messaging.UpstreamPubClient(upstream_pub_param) + self.pub_client.wait_connected() + + while(True): + msg = self.pub_client.recvmsg() + if argv.uuid: + uuid = getattr(msg, 'container_uuid', None) + if argv.container == uuid: + logger.info("pub message", msg) + else: + logger.info("pub message", msg) + def do_run(self, argv): """ Connect to the NRM and ask to spawn a container and run a command in it. @@ -171,6 +187,13 @@ class CommandLineInterface(object): parser_list = subparsers.add_parser("list") parser_list.set_defaults(func=self.do_list) + # listen + parser_listen = subparsers.add_parser("listen") + parser_listen.add_argument("-u", "--uuid", + help="container uuid to listen for", + default=None) + parser_listen.set_defaults(func=self.do_listen) + # setpowerlimit parser_setpower = subparsers.add_parser("setpower") parser_setpower.add_argument("-f", "--follow", -- 2.26.2