-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathnovnc
More file actions
executable file
·102 lines (86 loc) · 2.68 KB
/
novnc
File metadata and controls
executable file
·102 lines (86 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
# region copyright
# Copyright 2023-2026 NVIDIA Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# endregion
import os
import sys
import click
from src.python.config import c as config
from src.python.utils import (
colorize_error,
colorize_info,
deployments,
format_instance_role,
read_meta,
read_tf_output,
shell_command,
)
INSTANCE_ROLE_NAMES = ["isaac_workstation"]
# callback to validate deployment name
def deployments_callback(ctx, param, value):
if (value is None) or (value not in deployments()):
click.echo(
colorize_error(
f'Invalid deployment name "{value}". Must be one of: [{", ".join(deployments())}].'
)
)
ctx.abort()
return value
@click.command()
@click.option(
"--debug/--no-debug",
default=False,
show_default=True,
)
@click.argument(
"deployment_name",
required=True,
type=str,
callback=deployments_callback,
)
@click.option(
"--instance-role",
default="isaac_workstation",
type=click.Choice(INSTANCE_ROLE_NAMES),
help="Instance role",
)
def main(
instance_role: str,
debug: bool,
deployment_name: str,
):
vm_ip = read_tf_output(deployment_name, f"{instance_role}_ip", verbose=debug)
if vm_ip in ["NA", ""]:
click.echo(
colorize_info(
f'* No {format_instance_role(instance_role)} VM found for "{deployment_name}" deployment.'
)
)
raise click.Abort()
meta = read_meta(deployment_name, verbose=debug)
vnc_password = meta["input_params"].get("vnc_password", "")
url = f"http://{vm_ip}:6080/vnc.html?host={vm_ip}&port=6080&password={vnc_password}&resize=scale"
click.echo(colorize_info(f"* noVNC URL: {url}"))
if os.path.exists("/.dockerenv"):
# write URL to shared file so the host can pick it up
with open("/app/.open-url", "w") as f:
f.write(url)
if __name__ == "__main__":
if os.path.exists("/.dockerenv"):
# we're in docker, run command
main()
else:
# we're outside, start docker container first
shell_command(f"./run '{' '.join(sys.argv)}'", verbose=True)