def execute(self, args: argparse.Namespace): """ Listen for events on the Tortuga websocket and print them to stdout. """ cm = ConfigManager() url, username, password, verify = get_web_service_config(args) # # If we get a URL from the environment or CLI, we need to transform # it from the installer REST API URL into a websocket URL # if url: # # Replace http[s] with ws[s] # url = url.replace('http', 'ws') # # Replace port with websocket port # url_parts = url.split(':') url = '{}:{}:{}'.format(url_parts[0], url_parts[1], cm.getWebsocketPort()) # # Otherwise, use the default URL from the config manager # else: url = '{}://{}:{}'.format(cm.getWebsocketScheme(), cm.getInstaller(), cm.getWebsocketPort()) ws_client = WebsocketClient(username=username, password=password, url=url, verify=verify) try: asyncio.get_event_loop().run_until_complete(ws_client.start()) except KeyboardInterrupt: sys.exit(0)
def execute(self, args: argparse.Namespace): """ Listen for events on the Tortuga websocket and print them to stdout. """ cm = ConfigManager() config: TortugaScriptConfig = self.get_config() if not config: raise Exception('Invalid configuration') # # Replace http[s] with ws[s] # url = config.url.replace('http', 'ws') # # Replace port with websocket port # url_parts = url.split(':') url = '{}:{}:{}'.format(url_parts[0], url_parts[1], cm.getWebsocketPort()) auth_method = config.get_auth_method() if auth_method == config.AUTH_METHOD_TOKEN: ws_client = WebsocketClient(token=config.get_token(), url=url, verify=config.verify) elif auth_method == config.AUTH_METHOD_PASSWORD: ws_client = WebsocketClient(username=config.username, password=config.password, url=url, verify=config.verify) else: raise Exception('Unsupported auth method: {}'.format(auth_method)) try: asyncio.get_event_loop().run_until_complete(ws_client.start()) except KeyboardInterrupt: sys.exit(0)