def start_shell(args: Namespace) -> None: data = {} if args.passphrase: data["passphrase"] = getpass.getpass("Enter new passphrase: ") config = parse_config(args.config_file, None, args.config, args.volume) resp = launch_command( args.master, "shells", config, args.template, context_path=args.context, data=data, ) if args.detach: print(resp["id"]) return command = None with api.ws(args.master, "shells/{}/events".format(resp["id"])) as ws: for msg in ws: if msg["service_ready_event"]: command = render.unmarshal(Command, msg["snapshot"]) break render_event_stream(msg) if command: _open_shell(args.master, command, args.ssh_opts)
def tail_tensorboard_logs(args: Namespace) -> None: url = "tensorboard/{}/events?follow={}&tail={}".format( args.tensorboard_id, args.follow, args.tail ) with api.ws(args.master, url) as ws: for msg in ws: render_event_stream(msg)
def tail_command_logs(args: Namespace) -> None: token = api.Authentication.instance().get_session_token() params = {"follow": args.follow, "tail": args.tail, "_auth": token} url = "commands/{}/events?{}".format(args.command_id, urllib.parse.urlencode(params)) with api.ws(args.master, url) as ws: for msg in ws: render_event_stream(msg)
def run_command(args: Namespace) -> None: config = parse_config(args.config_file, args.entrypoint, args.config, args.volume) resp = launch_command( args.master, "commands", config, args.template, context_path=args.context, ) if args.detach: print(resp["id"]) return url = "commands/{}/events".format(resp["id"]) with api.ws(args.master, url) as ws: for msg in ws: render_event_stream(msg)
def start_tensorboard(args: Namespace) -> None: if args.trial_ids is None and args.experiment_ids is None: print("Either experiment_ids or trial_ids must be specified.") sys.exit(1) config = parse_config(args.config_file, None, [], []) req_body = { "config": config, "trial_ids": args.trial_ids, "experiment_ids": args.experiment_ids, } if args.context is not None: req_body["user_files"], _ = context.read_context( args.context, constants.MAX_CONTEXT_SIZE) resp = api.post(args.master, "tensorboard", body=req_body).json() if args.detach: print(resp["id"]) return url = "tensorboard/{}/events".format(resp["id"]) with api.ws(args.master, url) as ws: for msg in ws: if msg["log_event"] is not None: # TensorBoard will print a url by default. The URL is incorrect since # TensorBoard is not aware of the master proxy address it is assigned. if "http" in msg["log_event"]: continue if msg["service_ready_event"]: if args.no_browser: url = api.make_url(args.master, resp["service_address"]) else: url = api.open(args.master, resp["service_address"]) print( colored("TensorBoard is running at: {}".format(url), "green")) render_event_stream(msg) break render_event_stream(msg)
def start_notebook(args: Namespace) -> None: config = parse_config(args.config_file, None, args.config, args.volume) resp = launch_command( args.master, "notebooks", config, args.template, context_path=args.context, ) if args.detach: print(resp["id"]) return with api.ws(args.master, "notebooks/{}/events".format(resp["id"])) as ws: for msg in ws: if msg["service_ready_event"] and not args.no_browser: url = api.open(args.master, resp["service_address"]) print( colored("Jupyter Notebook is running at: {}".format(url), "green")) render_event_stream(msg)
def tail_notebook_logs(args: Namespace) -> None: url = "notebooks/{}/events?follow={}&tail={}".format( args.notebook_id, args.follow, args.tail) with api.ws(args.master, url) as ws: for msg in ws: render_event_stream(msg)