lightning-sdk 2025.9.23__py3-none-any.whl → 2025.9.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightning_sdk/__init__.py +3 -2
- lightning_sdk/cli/entrypoint.py +3 -1
- lightning_sdk/cli/groups.py +8 -1
- lightning_sdk/cli/legacy/download.py +3 -4
- lightning_sdk/cli/legacy/entrypoint.py +1 -1
- lightning_sdk/cli/legacy/upload.py +2 -3
- lightning_sdk/cli/studio/__init__.py +2 -0
- lightning_sdk/cli/studio/connect.py +94 -0
- lightning_sdk/cli/studio/create.py +19 -5
- lightning_sdk/cli/studio/delete.py +9 -5
- lightning_sdk/cli/studio/list.py +5 -1
- lightning_sdk/cli/studio/ssh.py +12 -54
- lightning_sdk/cli/studio/start.py +26 -3
- lightning_sdk/cli/studio/stop.py +7 -3
- lightning_sdk/cli/studio/switch.py +21 -5
- lightning_sdk/cli/utils/ssh_connection.py +51 -0
- lightning_sdk/cli/utils/studio_selection.py +22 -15
- lightning_sdk/cli/vm/__init__.py +20 -0
- lightning_sdk/cli/vm/create.py +33 -0
- lightning_sdk/cli/vm/delete.py +25 -0
- lightning_sdk/cli/vm/list.py +30 -0
- lightning_sdk/cli/vm/ssh.py +31 -0
- lightning_sdk/cli/vm/start.py +60 -0
- lightning_sdk/cli/vm/stop.py +25 -0
- lightning_sdk/cli/vm/switch.py +38 -0
- lightning_sdk/lightning_cloud/openapi/__init__.py +20 -1
- lightning_sdk/lightning_cloud/openapi/api/assistants_service_api.py +2 -95
- lightning_sdk/lightning_cloud/openapi/api/billing_service_api.py +24 -8
- lightning_sdk/lightning_cloud/openapi/api/cluster_service_api.py +420 -0
- lightning_sdk/lightning_cloud/openapi/api/jobs_service_api.py +121 -0
- lightning_sdk/lightning_cloud/openapi/api/storage_service_api.py +655 -0
- lightning_sdk/lightning_cloud/openapi/models/__init__.py +20 -1
- lightning_sdk/lightning_cloud/openapi/models/create_machine_request_represents_the_request_to_create_a_machine.py +435 -0
- lightning_sdk/lightning_cloud/openapi/models/job_id_reportroutingtelemetry_body.py +123 -0
- lightning_sdk/lightning_cloud/openapi/models/project_id_storagetransfers_body.py +149 -0
- lightning_sdk/lightning_cloud/openapi/models/user_id_affiliatelinks_body.py +107 -3
- lightning_sdk/lightning_cloud/openapi/models/v1_abort_storage_transfer_response.py +97 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_assistant_session_daily_aggregated.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_cloud_provider.py +2 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_cluster_accelerator.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_cluster_spec.py +53 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_cluster_type.py +1 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_create_machine_response.py +123 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_create_project_request.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_delete_machine_response.py +97 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_external_cluster_spec.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_get_machine_response.py +123 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_get_user_response.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_kubernetes_direct_v1.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_lightning_elastic_cluster_v1.py +97 -0
- lightning_sdk/lightning_cloud/openapi/models/{v1_get_model_total_usage_metrics_response.py → v1_list_machines_response.py} +37 -37
- lightning_sdk/lightning_cloud/openapi/models/v1_list_storage_transfers_response.py +123 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_machine.py +539 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_machine_direct_v1.py +123 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_pause_storage_transfer_response.py +97 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_purchase_annual_upsell_request.py +123 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_report_deployment_routing_telemetry_response.py +97 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_resume_storage_transfer_response.py +97 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_routing_telemetry.py +79 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_rule_resource.py +1 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_slack_notifier.py +149 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_slack_notifier_type.py +105 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_storage_transfer.py +435 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_storage_transfer_status.py +108 -0
- lightning_sdk/lightning_cloud/openapi/models/v1_update_user_request.py +27 -1
- lightning_sdk/lightning_cloud/openapi/models/v1_user_features.py +105 -79
- lightning_sdk/studio.py +55 -11
- lightning_sdk/teamspace.py +11 -2
- {lightning_sdk-2025.9.23.dist-info → lightning_sdk-2025.9.30.dist-info}/METADATA +1 -1
- {lightning_sdk-2025.9.23.dist-info → lightning_sdk-2025.9.30.dist-info}/RECORD +74 -45
- {lightning_sdk-2025.9.23.dist-info → lightning_sdk-2025.9.30.dist-info}/LICENSE +0 -0
- {lightning_sdk-2025.9.23.dist-info → lightning_sdk-2025.9.30.dist-info}/WHEEL +0 -0
- {lightning_sdk-2025.9.23.dist-info → lightning_sdk-2025.9.30.dist-info}/entry_points.txt +0 -0
- {lightning_sdk-2025.9.23.dist-info → lightning_sdk-2025.9.30.dist-info}/top_level.txt +0 -0
lightning_sdk/__init__.py
CHANGED
|
@@ -9,7 +9,7 @@ from lightning_sdk.mmt import MMT
|
|
|
9
9
|
from lightning_sdk.organization import Organization
|
|
10
10
|
from lightning_sdk.plugin import JobsPlugin, MultiMachineTrainingPlugin, Plugin, SlurmJobsPlugin
|
|
11
11
|
from lightning_sdk.status import Status
|
|
12
|
-
from lightning_sdk.studio import Studio
|
|
12
|
+
from lightning_sdk.studio import VM, Studio
|
|
13
13
|
from lightning_sdk.teamspace import ConnectionType, FolderLocation, Teamspace
|
|
14
14
|
from lightning_sdk.user import User
|
|
15
15
|
|
|
@@ -32,8 +32,9 @@ __all__ = [
|
|
|
32
32
|
"Studio",
|
|
33
33
|
"Teamspace",
|
|
34
34
|
"User",
|
|
35
|
+
"VM",
|
|
35
36
|
]
|
|
36
37
|
|
|
37
|
-
__version__ = "2025.09.
|
|
38
|
+
__version__ = "2025.09.30"
|
|
38
39
|
_check_version_and_prompt_upgrade(__version__)
|
|
39
40
|
_set_tqdm_envvars_noninteractive()
|
lightning_sdk/cli/entrypoint.py
CHANGED
|
@@ -21,6 +21,7 @@ from lightning_sdk.cli.groups import (
|
|
|
21
21
|
# job,
|
|
22
22
|
# mmt,
|
|
23
23
|
studio,
|
|
24
|
+
vm,
|
|
24
25
|
)
|
|
25
26
|
from lightning_sdk.cli.utils import CustomHelpFormatter, rich_to_str
|
|
26
27
|
from lightning_sdk.constants import _LIGHTNING_DEBUG
|
|
@@ -40,7 +41,7 @@ def _notify_exception(exception_type: Type[BaseException], value: BaseException,
|
|
|
40
41
|
if _LIGHTNING_DEBUG:
|
|
41
42
|
tb_text = "".join(traceback.format_exception(exception_type, value, tb))
|
|
42
43
|
renderables.append(Text("\n\nFull traceback:\n", style="bold yellow"))
|
|
43
|
-
renderables.append(Syntax(tb_text, "python", theme="monokai", line_numbers=False, word_wrap=True))
|
|
44
|
+
renderables.append(Syntax(tb_text, "python", theme="monokai light", line_numbers=False, word_wrap=True))
|
|
44
45
|
else:
|
|
45
46
|
renderables.append(Text("\n\n🐞 To view the full traceback, set: LIGHTNING_DEBUG=1"))
|
|
46
47
|
|
|
@@ -83,6 +84,7 @@ main_cli.add_command(config)
|
|
|
83
84
|
# main_cli.add_command(job)
|
|
84
85
|
# main_cli.add_command(mmt)
|
|
85
86
|
main_cli.add_command(studio)
|
|
87
|
+
main_cli.add_command(vm)
|
|
86
88
|
if os.environ.get("LIGHTNING_EXPERIMENTAL_CLI_ONLY", "0") != "1":
|
|
87
89
|
#### LEGACY COMMANDS ####
|
|
88
90
|
# these commands are currently supported for backwards compatibility, but will potentially be removed in the future.
|
lightning_sdk/cli/groups.py
CHANGED
|
@@ -6,6 +6,7 @@ from lightning_sdk.cli.config import register_commands as register_config_comman
|
|
|
6
6
|
from lightning_sdk.cli.job import register_commands as register_job_commands
|
|
7
7
|
from lightning_sdk.cli.mmt import register_commands as register_mmt_commands
|
|
8
8
|
from lightning_sdk.cli.studio import register_commands as register_studio_commands
|
|
9
|
+
from lightning_sdk.cli.vm import register_commands as register_vm_commands
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
@click.group(name="studio")
|
|
@@ -25,7 +26,12 @@ def mmt() -> None:
|
|
|
25
26
|
|
|
26
27
|
@click.group(name="config")
|
|
27
28
|
def config() -> None:
|
|
28
|
-
"""Manage Lightning SDK and
|
|
29
|
+
"""Manage Lightning SDK and CLI configuration."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@click.group(name="vm")
|
|
33
|
+
def vm() -> None:
|
|
34
|
+
"""Manage Lightning AI VMs."""
|
|
29
35
|
|
|
30
36
|
|
|
31
37
|
# Register config commands with the main config group
|
|
@@ -33,3 +39,4 @@ register_job_commands(job)
|
|
|
33
39
|
register_mmt_commands(mmt)
|
|
34
40
|
register_studio_commands(studio)
|
|
35
41
|
register_config_commands(config)
|
|
42
|
+
register_vm_commands(vm)
|
|
@@ -14,7 +14,7 @@ from lightning_sdk.cli.legacy.studios_menu import _StudiosMenu
|
|
|
14
14
|
from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
15
15
|
from lightning_sdk.models import download_model
|
|
16
16
|
from lightning_sdk.studio import Studio
|
|
17
|
-
from lightning_sdk.utils.resolve import _get_authed_user
|
|
17
|
+
from lightning_sdk.utils.resolve import _get_authed_user
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def _expand_remote_path(path: str) -> str:
|
|
@@ -242,7 +242,7 @@ def _resolve_studio(studio: Optional[str]) -> Studio:
|
|
|
242
242
|
and (re.match(studio_name, st["name"]) or studio_name in st["name"]),
|
|
243
243
|
possible_studios,
|
|
244
244
|
)
|
|
245
|
-
if not possible_studios:
|
|
245
|
+
if not len(possible_studios):
|
|
246
246
|
raise ValueError(
|
|
247
247
|
f"Could not find Studio like '{studio}', please consider update your filtering pattern."
|
|
248
248
|
)
|
|
@@ -260,8 +260,7 @@ def _resolve_studio(studio: Optional[str]) -> Studio:
|
|
|
260
260
|
"Please contact Lightning AI directly to resolve this issue."
|
|
261
261
|
) from e
|
|
262
262
|
|
|
263
|
-
|
|
264
|
-
return Studio(**selected_studio)
|
|
263
|
+
return Studio(**selected_studio)
|
|
265
264
|
|
|
266
265
|
|
|
267
266
|
@download.command(name="licenses")
|
|
@@ -48,7 +48,7 @@ def _notify_exception(exception_type: Type[BaseException], value: BaseException,
|
|
|
48
48
|
if _LIGHTNING_DEBUG:
|
|
49
49
|
tb_text = "".join(traceback.format_exception(exception_type, value, tb))
|
|
50
50
|
renderables.append(Text("\n\nFull traceback:\n", style="bold yellow"))
|
|
51
|
-
renderables.append(Syntax(tb_text, "python", theme="monokai", line_numbers=False, word_wrap=True))
|
|
51
|
+
renderables.append(Syntax(tb_text, "python", theme="monokai light", line_numbers=False, word_wrap=True))
|
|
52
52
|
else:
|
|
53
53
|
renderables.append(Text("\n\n🐞 To view the full traceback, set: LIGHTNING_DEBUG=1"))
|
|
54
54
|
|
|
@@ -20,7 +20,7 @@ from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
|
20
20
|
from lightning_sdk.constants import _LIGHTNING_DEBUG
|
|
21
21
|
from lightning_sdk.models import upload_model as _upload_model
|
|
22
22
|
from lightning_sdk.studio import Studio
|
|
23
|
-
from lightning_sdk.utils.resolve import _get_authed_user
|
|
23
|
+
from lightning_sdk.utils.resolve import _get_authed_user
|
|
24
24
|
|
|
25
25
|
_STUDIO_UPLOAD_STATUS_PATH = "~/.lightning/studios/uploads"
|
|
26
26
|
|
|
@@ -285,8 +285,7 @@ def _resolve_studio(studio: Optional[str]) -> Studio:
|
|
|
285
285
|
"Please contact Lightning AI directly to resolve this issue."
|
|
286
286
|
) from e
|
|
287
287
|
|
|
288
|
-
|
|
289
|
-
return Studio(**selected_studio)
|
|
288
|
+
return Studio(**selected_studio)
|
|
290
289
|
|
|
291
290
|
|
|
292
291
|
def _print_docker_push(lines: Generator, console: Console, progress: Progress, push_task: rich.progress.TaskID) -> None:
|
|
@@ -5,6 +5,7 @@ import click
|
|
|
5
5
|
|
|
6
6
|
def register_commands(group: click.Group) -> None:
|
|
7
7
|
"""Register studio commands with the given group."""
|
|
8
|
+
from lightning_sdk.cli.studio.connect import connect_studio
|
|
8
9
|
from lightning_sdk.cli.studio.create import create_studio
|
|
9
10
|
from lightning_sdk.cli.studio.delete import delete_studio
|
|
10
11
|
from lightning_sdk.cli.studio.list import list_studios
|
|
@@ -20,3 +21,4 @@ def register_commands(group: click.Group) -> None:
|
|
|
20
21
|
group.add_command(start_studio)
|
|
21
22
|
group.add_command(stop_studio)
|
|
22
23
|
group.add_command(switch_studio)
|
|
24
|
+
group.add_command(connect_studio)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Studio connect command."""
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from lightning_sdk.cli.utils.richt_print import studio_name_link
|
|
10
|
+
from lightning_sdk.cli.utils.save_to_config import save_studio_to_config, save_teamspace_to_config
|
|
11
|
+
from lightning_sdk.cli.utils.ssh_connection import download_ssh_keys
|
|
12
|
+
from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
13
|
+
from lightning_sdk.lightning_cloud.login import Auth
|
|
14
|
+
from lightning_sdk.lightning_cloud.openapi.rest import ApiException
|
|
15
|
+
from lightning_sdk.machine import CloudProvider
|
|
16
|
+
from lightning_sdk.studio import Studio
|
|
17
|
+
from lightning_sdk.utils.names import random_unique_name
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.command("connect")
|
|
21
|
+
@click.argument("name", required=False)
|
|
22
|
+
@click.option("--teamspace", help="Override default teamspace (format: owner/teamspace)")
|
|
23
|
+
@click.option(
|
|
24
|
+
"--cloud-provider",
|
|
25
|
+
help="The cloud provider to start the studio on. Defaults to teamspace default.",
|
|
26
|
+
type=click.Choice(m.name for m in list(CloudProvider)),
|
|
27
|
+
)
|
|
28
|
+
@click.option(
|
|
29
|
+
"--cloud-account",
|
|
30
|
+
help="The cloud account to create the studio on. Defaults to teamspace default.",
|
|
31
|
+
type=click.STRING,
|
|
32
|
+
)
|
|
33
|
+
@click.option("--gpus", help="The number of GPUs to start the studio on. ", type=click.INT)
|
|
34
|
+
def connect_studio(
|
|
35
|
+
name: Optional[str] = None,
|
|
36
|
+
teamspace: Optional[str] = None,
|
|
37
|
+
cloud_provider: Optional[str] = None,
|
|
38
|
+
cloud_account: Optional[str] = None,
|
|
39
|
+
gpus: Optional[int] = None,
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Connect to a Studio.
|
|
42
|
+
|
|
43
|
+
Example:
|
|
44
|
+
lightning studio connect
|
|
45
|
+
"""
|
|
46
|
+
menu = TeamspacesMenu()
|
|
47
|
+
|
|
48
|
+
resolved_teamspace = menu(teamspace)
|
|
49
|
+
save_teamspace_to_config(resolved_teamspace, overwrite=False)
|
|
50
|
+
|
|
51
|
+
if cloud_provider is not None:
|
|
52
|
+
cloud_provider = CloudProvider(cloud_provider)
|
|
53
|
+
|
|
54
|
+
name = name or random_unique_name()
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
studio = Studio(
|
|
58
|
+
name=name,
|
|
59
|
+
teamspace=resolved_teamspace,
|
|
60
|
+
create_ok=True,
|
|
61
|
+
cloud_provider=cloud_provider,
|
|
62
|
+
cloud_account=cloud_account,
|
|
63
|
+
)
|
|
64
|
+
except (RuntimeError, ValueError, ApiException):
|
|
65
|
+
raise ValueError(f"Could not create Studio: '{name}'") from None
|
|
66
|
+
|
|
67
|
+
click.echo(f"Connecting to Studio '{studio_name_link(studio)}' ...")
|
|
68
|
+
|
|
69
|
+
machine = "CPU"
|
|
70
|
+
Studio.show_progress = True
|
|
71
|
+
if gpus:
|
|
72
|
+
# TODO: handle something like gpus=4:L4
|
|
73
|
+
pass
|
|
74
|
+
|
|
75
|
+
save_studio_to_config(studio)
|
|
76
|
+
studio.start(machine, interruptible=True)
|
|
77
|
+
|
|
78
|
+
ssh_private_key_path = _configure_ssh_internal()
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
ssh_command = (
|
|
82
|
+
f"ssh -i {ssh_private_key_path} -o UserKnownHostsFile=/dev/null s_{studio._studio.id}@ssh.lightning.ai"
|
|
83
|
+
)
|
|
84
|
+
subprocess.run(ssh_command.split())
|
|
85
|
+
except Exception as ex:
|
|
86
|
+
print(f"Failed to establish SSH connection: {ex}")
|
|
87
|
+
sys.exit(1)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _configure_ssh_internal() -> str:
|
|
91
|
+
"""Internal function to configure SSH without Click decorators."""
|
|
92
|
+
auth = Auth()
|
|
93
|
+
auth.authenticate()
|
|
94
|
+
return download_ssh_keys(auth.api_key, force_download=False)
|
|
@@ -9,7 +9,7 @@ from lightning_sdk.cli.utils.save_to_config import save_teamspace_to_config
|
|
|
9
9
|
from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
10
10
|
from lightning_sdk.lightning_cloud.openapi.rest import ApiException
|
|
11
11
|
from lightning_sdk.machine import CloudProvider
|
|
12
|
-
from lightning_sdk.studio import Studio
|
|
12
|
+
from lightning_sdk.studio import VM, Studio
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@click.command("create")
|
|
@@ -36,6 +36,16 @@ def create_studio(
|
|
|
36
36
|
Example:
|
|
37
37
|
lightning studio create
|
|
38
38
|
"""
|
|
39
|
+
create_impl(name=name, teamspace=teamspace, cloud_provider=cloud_provider, cloud_account=cloud_account, vm=False)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def create_impl(
|
|
43
|
+
name: Optional[str],
|
|
44
|
+
teamspace: Optional[str],
|
|
45
|
+
cloud_provider: Optional[str],
|
|
46
|
+
cloud_account: Optional[str],
|
|
47
|
+
vm: bool,
|
|
48
|
+
) -> None:
|
|
39
49
|
menu = TeamspacesMenu()
|
|
40
50
|
|
|
41
51
|
resolved_teamspace = menu(teamspace)
|
|
@@ -44,8 +54,12 @@ def create_studio(
|
|
|
44
54
|
if cloud_provider is not None:
|
|
45
55
|
cloud_provider = CloudProvider(cloud_provider)
|
|
46
56
|
|
|
57
|
+
create_cls = VM if vm else Studio
|
|
58
|
+
cls_name = create_cls.__qualname__
|
|
59
|
+
|
|
47
60
|
try:
|
|
48
|
-
|
|
61
|
+
create_cls = VM if vm else Studio
|
|
62
|
+
studio = create_cls(
|
|
49
63
|
name=name,
|
|
50
64
|
teamspace=resolved_teamspace,
|
|
51
65
|
create_ok=True,
|
|
@@ -54,7 +68,7 @@ def create_studio(
|
|
|
54
68
|
)
|
|
55
69
|
except (RuntimeError, ValueError, ApiException):
|
|
56
70
|
if name:
|
|
57
|
-
raise ValueError(f"Could not create
|
|
58
|
-
raise ValueError(f"Could not create
|
|
71
|
+
raise ValueError(f"Could not create {cls_name}: '{name}'. Does the {cls_name} exist?") from None
|
|
72
|
+
raise ValueError(f"Could not create {cls_name}: '{name}'. Please provide a {cls_name} name") from None
|
|
59
73
|
|
|
60
|
-
click.echo(f"
|
|
74
|
+
click.echo(f"{cls_name} {studio_name_link(studio)} created successfully")
|
|
@@ -12,7 +12,7 @@ from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
|
12
12
|
@click.option(
|
|
13
13
|
"--name",
|
|
14
14
|
help=(
|
|
15
|
-
"The name of the studio to
|
|
15
|
+
"The name of the studio to delete. "
|
|
16
16
|
"If not provided, will try to infer from environment, "
|
|
17
17
|
"use the default value from the config or prompt for interactive selection."
|
|
18
18
|
),
|
|
@@ -25,21 +25,25 @@ def delete_studio(name: Optional[str] = None, teamspace: Optional[str] = None) -
|
|
|
25
25
|
lightning studio delete --name my-studio
|
|
26
26
|
|
|
27
27
|
"""
|
|
28
|
+
return delete_impl(name=name, teamspace=teamspace, vm=False)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def delete_impl(name: Optional[str], teamspace: Optional[str], vm: bool) -> None:
|
|
28
32
|
menu = TeamspacesMenu()
|
|
29
33
|
resolved_teamspace = menu(teamspace=teamspace)
|
|
30
34
|
|
|
31
|
-
menu = StudiosMenu(resolved_teamspace)
|
|
35
|
+
menu = StudiosMenu(resolved_teamspace, vm=vm)
|
|
32
36
|
studio = menu(studio=name)
|
|
33
37
|
|
|
34
38
|
studio_name = f"{studio.teamspace.owner.name}/{studio.teamspace.name}/{studio.name}"
|
|
35
39
|
confirmed = click.confirm(
|
|
36
|
-
f"Are you sure you want to delete studio '{studio_name}'?",
|
|
40
|
+
f"Are you sure you want to delete {studio._cls_name} '{studio_name}'?",
|
|
37
41
|
abort=True,
|
|
38
42
|
)
|
|
39
43
|
if not confirmed:
|
|
40
|
-
click.echo("
|
|
44
|
+
click.echo(f"{studio._cls_name} deletion cancelled")
|
|
41
45
|
return
|
|
42
46
|
|
|
43
47
|
studio.delete()
|
|
44
48
|
|
|
45
|
-
click.echo(f"
|
|
49
|
+
click.echo(f"{studio._cls_name} '{studio.name}' deleted successfully")
|
lightning_sdk/cli/studio/list.py
CHANGED
|
@@ -35,13 +35,17 @@ def list_studios(teamspace: Optional[str] = None, all: bool = False, sort_by: Op
|
|
|
35
35
|
lightning studio list --teamspace owner/teamspace
|
|
36
36
|
|
|
37
37
|
"""
|
|
38
|
+
return list_impl(teamspace=teamspace, all=all, sort_by=sort_by, vm=False)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def list_impl(teamspace: Optional[str], all: bool, sort_by: Optional[str], vm: bool) -> None: # noqa: A002
|
|
38
42
|
menu = TeamspacesMenu()
|
|
39
43
|
teamspace_resolved = menu(teamspace=teamspace)
|
|
40
44
|
save_teamspace_to_config(teamspace_resolved, overwrite=False)
|
|
41
45
|
|
|
42
46
|
user = _get_authed_user()
|
|
43
47
|
|
|
44
|
-
studios = teamspace_resolved.studios
|
|
48
|
+
studios = teamspace_resolved.vms if vm else teamspace_resolved.studios
|
|
45
49
|
|
|
46
50
|
table = Table(
|
|
47
51
|
pad_edge=True,
|
lightning_sdk/cli/studio/ssh.py
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"""Studio SSH command."""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
|
-
import platform
|
|
5
3
|
import subprocess
|
|
6
|
-
import uuid
|
|
7
|
-
from pathlib import Path
|
|
8
4
|
from typing import List, Optional
|
|
9
5
|
|
|
10
6
|
import click
|
|
11
7
|
|
|
12
8
|
from lightning_sdk.cli.utils.save_to_config import save_studio_to_config
|
|
9
|
+
from lightning_sdk.cli.utils.ssh_connection import download_ssh_keys
|
|
13
10
|
from lightning_sdk.cli.utils.studio_selection import StudiosMenu
|
|
14
11
|
from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
15
12
|
from lightning_sdk.lightning_cloud.login import Auth
|
|
16
|
-
from lightning_sdk.utils.config import _DEFAULT_CONFIG_FILE_PATH
|
|
17
13
|
|
|
18
14
|
|
|
19
15
|
@click.command("ssh")
|
|
20
16
|
@click.option(
|
|
21
17
|
"--name",
|
|
22
18
|
help=(
|
|
23
|
-
"The name of the studio to
|
|
19
|
+
"The name of the studio to ssh into. "
|
|
24
20
|
"If not provided, will try to infer from environment, "
|
|
25
21
|
"use the default value from the config or prompt for interactive selection."
|
|
26
22
|
),
|
|
@@ -39,15 +35,21 @@ def ssh_studio(name: Optional[str] = None, teamspace: Optional[str] = None, opti
|
|
|
39
35
|
Example:
|
|
40
36
|
lightning studio ssh --name my-studio
|
|
41
37
|
"""
|
|
38
|
+
return ssh_impl(name=name, teamspace=teamspace, option=option, vm=False)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def ssh_impl(name: Optional[str], teamspace: Optional[str], option: Optional[List[str]], vm: bool) -> None:
|
|
42
42
|
auth = Auth()
|
|
43
43
|
auth.authenticate()
|
|
44
|
-
ssh_private_key_path =
|
|
44
|
+
ssh_private_key_path = download_ssh_keys(auth.api_key, force_download=False)
|
|
45
45
|
|
|
46
46
|
menu = TeamspacesMenu()
|
|
47
47
|
resolved_teamspace = menu(teamspace=teamspace)
|
|
48
48
|
|
|
49
|
-
menu = StudiosMenu(resolved_teamspace)
|
|
50
|
-
studio = menu(
|
|
49
|
+
menu = StudiosMenu(resolved_teamspace, vm=vm)
|
|
50
|
+
studio = menu(
|
|
51
|
+
studio=name,
|
|
52
|
+
)
|
|
51
53
|
save_studio_to_config(studio)
|
|
52
54
|
|
|
53
55
|
ssh_options = " -o " + " -o ".join(option) if option else ""
|
|
@@ -57,53 +59,9 @@ def ssh_studio(name: Optional[str] = None, teamspace: Optional[str] = None, opti
|
|
|
57
59
|
subprocess.run(ssh_command.split())
|
|
58
60
|
except Exception:
|
|
59
61
|
# redownload the keys to be sure they are up to date
|
|
60
|
-
|
|
62
|
+
download_ssh_keys(auth.api_key, force_download=True)
|
|
61
63
|
try:
|
|
62
64
|
subprocess.run(ssh_command.split())
|
|
63
65
|
except Exception:
|
|
64
66
|
# TODO: make this a generic CLI error
|
|
65
67
|
raise RuntimeError("Failed to establish SSH connection") from None
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def _download_ssh_keys(
|
|
69
|
-
api_key: str,
|
|
70
|
-
force_download: bool = False,
|
|
71
|
-
ssh_key_name: str = "lightning_rsa",
|
|
72
|
-
) -> None:
|
|
73
|
-
"""Download the SSH key for a User."""
|
|
74
|
-
ssh_private_key_path = os.path.join(os.path.expanduser(os.path.dirname(_DEFAULT_CONFIG_FILE_PATH)), ssh_key_name)
|
|
75
|
-
|
|
76
|
-
os.makedirs(os.path.dirname(ssh_private_key_path), exist_ok=True)
|
|
77
|
-
|
|
78
|
-
if not os.path.isfile(ssh_private_key_path) or force_download:
|
|
79
|
-
key_id = str(uuid.uuid4())
|
|
80
|
-
_download_file(
|
|
81
|
-
f"https://lightning.ai/setup/ssh-gen?t={api_key}&id={key_id}&machineName={platform.node()}",
|
|
82
|
-
ssh_private_key_path,
|
|
83
|
-
overwrite=True,
|
|
84
|
-
chmod=0o600,
|
|
85
|
-
)
|
|
86
|
-
_download_file(
|
|
87
|
-
f"https://lightning.ai/setup/ssh-public?t={api_key}&id={key_id}",
|
|
88
|
-
ssh_private_key_path + ".pub",
|
|
89
|
-
overwrite=True,
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
return ssh_private_key_path
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def _download_file(url: str, local_path: Path, overwrite: bool = True, chmod: Optional[int] = None) -> None:
|
|
96
|
-
"""Download a file from a URL."""
|
|
97
|
-
import requests
|
|
98
|
-
|
|
99
|
-
if os.path.isfile(local_path) and not overwrite:
|
|
100
|
-
raise FileExistsError(f"The file {local_path} already exists and overwrite is set to False.")
|
|
101
|
-
|
|
102
|
-
response = requests.get(url, stream=True)
|
|
103
|
-
response.raise_for_status()
|
|
104
|
-
|
|
105
|
-
with open(local_path, "wb") as file:
|
|
106
|
-
for chunk in response.iter_content(chunk_size=8192):
|
|
107
|
-
file.write(chunk)
|
|
108
|
-
if chmod is not None:
|
|
109
|
-
os.chmod(local_path, 0o600)
|
|
@@ -9,7 +9,7 @@ from lightning_sdk.cli.utils.save_to_config import save_studio_to_config
|
|
|
9
9
|
from lightning_sdk.cli.utils.studio_selection import StudiosMenu
|
|
10
10
|
from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
11
11
|
from lightning_sdk.machine import CloudProvider, Machine
|
|
12
|
-
from lightning_sdk.studio import Studio
|
|
12
|
+
from lightning_sdk.studio import VM, Studio
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
@click.command("start")
|
|
@@ -57,6 +57,28 @@ def start_studio(
|
|
|
57
57
|
lightning studio start --name my-studio
|
|
58
58
|
|
|
59
59
|
"""
|
|
60
|
+
return start_impl(
|
|
61
|
+
name=name,
|
|
62
|
+
teamspace=teamspace,
|
|
63
|
+
create=create,
|
|
64
|
+
machine=machine,
|
|
65
|
+
interruptible=interruptible,
|
|
66
|
+
cloud_provider=cloud_provider,
|
|
67
|
+
cloud_account=cloud_account,
|
|
68
|
+
vm=False,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def start_impl(
|
|
73
|
+
name: Optional[str],
|
|
74
|
+
teamspace: Optional[str],
|
|
75
|
+
create: bool,
|
|
76
|
+
machine: str,
|
|
77
|
+
interruptible: bool,
|
|
78
|
+
cloud_provider: Optional[str],
|
|
79
|
+
cloud_account: Optional[str],
|
|
80
|
+
vm: bool,
|
|
81
|
+
) -> None:
|
|
60
82
|
menu = TeamspacesMenu()
|
|
61
83
|
resolved_teamspace = menu(teamspace=teamspace)
|
|
62
84
|
|
|
@@ -64,10 +86,11 @@ def start_studio(
|
|
|
64
86
|
cloud_provider = CloudProvider(cloud_provider)
|
|
65
87
|
|
|
66
88
|
if not create:
|
|
67
|
-
menu = StudiosMenu(resolved_teamspace)
|
|
89
|
+
menu = StudiosMenu(resolved_teamspace, vm=vm)
|
|
68
90
|
studio = menu(studio=name)
|
|
69
91
|
else:
|
|
70
|
-
|
|
92
|
+
create_cls = VM if vm else Studio
|
|
93
|
+
studio = create_cls(
|
|
71
94
|
name=name,
|
|
72
95
|
teamspace=resolved_teamspace,
|
|
73
96
|
create_ok=create,
|
lightning_sdk/cli/studio/stop.py
CHANGED
|
@@ -14,7 +14,7 @@ from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
|
14
14
|
@click.option(
|
|
15
15
|
"--name",
|
|
16
16
|
help=(
|
|
17
|
-
"The name of the studio to
|
|
17
|
+
"The name of the studio to stop. "
|
|
18
18
|
"If not provided, will try to infer from environment, "
|
|
19
19
|
"use the default value from the config or prompt for interactive selection."
|
|
20
20
|
),
|
|
@@ -27,15 +27,19 @@ def stop_studio(name: Optional[str] = None, teamspace: Optional[str] = None) ->
|
|
|
27
27
|
lightning studio stop --name my-studio
|
|
28
28
|
|
|
29
29
|
"""
|
|
30
|
+
return stop_impl(name=name, teamspace=teamspace, vm=False)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def stop_impl(name: Optional[str], teamspace: Optional[str], vm: bool) -> None:
|
|
30
34
|
# missing studio_name and teamspace are handled by the studio class
|
|
31
35
|
menu = TeamspacesMenu()
|
|
32
36
|
resolved_teamspace = menu(teamspace=teamspace)
|
|
33
37
|
|
|
34
|
-
menu = StudiosMenu(resolved_teamspace)
|
|
38
|
+
menu = StudiosMenu(resolved_teamspace, vm=vm)
|
|
35
39
|
studio = menu(studio=name)
|
|
36
40
|
|
|
37
41
|
studio.stop()
|
|
38
42
|
|
|
39
43
|
save_studio_to_config(studio)
|
|
40
44
|
|
|
41
|
-
click.echo(f"
|
|
45
|
+
click.echo(f"{studio._cls_name} {studio_name_link(studio)} stopped successfully")
|
|
@@ -9,14 +9,13 @@ from lightning_sdk.cli.utils.save_to_config import save_studio_to_config
|
|
|
9
9
|
from lightning_sdk.cli.utils.studio_selection import StudiosMenu
|
|
10
10
|
from lightning_sdk.cli.utils.teamspace_selection import TeamspacesMenu
|
|
11
11
|
from lightning_sdk.machine import Machine
|
|
12
|
-
from lightning_sdk.studio import Studio
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
@click.command("switch")
|
|
16
15
|
@click.option(
|
|
17
16
|
"--name",
|
|
18
17
|
help=(
|
|
19
|
-
"The name of the studio to
|
|
18
|
+
"The name of the studio to switch to a different machine. "
|
|
20
19
|
"If not provided, will try to infer from environment, "
|
|
21
20
|
"use the default value from the config or prompt for interactive selection."
|
|
22
21
|
),
|
|
@@ -35,16 +34,33 @@ def switch_studio(
|
|
|
35
34
|
interruptible: bool = False,
|
|
36
35
|
) -> None:
|
|
37
36
|
"""Switch a Studio to a different machine type."""
|
|
37
|
+
return switch_impl(
|
|
38
|
+
name=name,
|
|
39
|
+
teamspace=teamspace,
|
|
40
|
+
machine=machine,
|
|
41
|
+
interruptible=interruptible,
|
|
42
|
+
vm=False,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def switch_impl(
|
|
47
|
+
name: Optional[str],
|
|
48
|
+
teamspace: Optional[str],
|
|
49
|
+
machine: Optional[str],
|
|
50
|
+
interruptible: bool,
|
|
51
|
+
vm: bool,
|
|
52
|
+
) -> None:
|
|
38
53
|
menu = TeamspacesMenu()
|
|
39
54
|
resolved_teamspace = menu(teamspace=teamspace)
|
|
40
55
|
|
|
41
|
-
menu = StudiosMenu(resolved_teamspace)
|
|
56
|
+
menu = StudiosMenu(resolved_teamspace, vm=vm)
|
|
42
57
|
studio = menu(studio=name)
|
|
43
58
|
|
|
44
59
|
resolved_machine = Machine.from_str(machine)
|
|
45
|
-
|
|
60
|
+
|
|
61
|
+
studio.__class__.show_progress = True
|
|
46
62
|
studio.switch_machine(resolved_machine, interruptible=interruptible)
|
|
47
63
|
|
|
48
64
|
save_studio_to_config(studio)
|
|
49
65
|
|
|
50
|
-
click.echo(f"
|
|
66
|
+
click.echo(f"{studio._cls_name} {studio_name_link(studio)} switched to machine '{resolved_machine}' successfully")
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import platform
|
|
3
|
+
import uuid
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from lightning_sdk.utils.config import _DEFAULT_CONFIG_FILE_PATH
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def download_ssh_keys(
|
|
11
|
+
api_key: str | None,
|
|
12
|
+
force_download: bool = False,
|
|
13
|
+
ssh_key_name: str = "lightning_rsa",
|
|
14
|
+
) -> str:
|
|
15
|
+
"""Download the SSH key for a User."""
|
|
16
|
+
ssh_private_key_path = os.path.join(os.path.expanduser(os.path.dirname(_DEFAULT_CONFIG_FILE_PATH)), ssh_key_name)
|
|
17
|
+
|
|
18
|
+
os.makedirs(os.path.dirname(ssh_private_key_path), exist_ok=True)
|
|
19
|
+
|
|
20
|
+
if not os.path.isfile(ssh_private_key_path) or force_download:
|
|
21
|
+
key_id = str(uuid.uuid4())
|
|
22
|
+
download_file(
|
|
23
|
+
f"https://lightning.ai/setup/ssh-gen?t={api_key}&id={key_id}&machineName={platform.node()}",
|
|
24
|
+
Path(ssh_private_key_path),
|
|
25
|
+
overwrite=True,
|
|
26
|
+
chmod=0o600,
|
|
27
|
+
)
|
|
28
|
+
download_file(
|
|
29
|
+
f"https://lightning.ai/setup/ssh-public?t={api_key}&id={key_id}",
|
|
30
|
+
Path(ssh_private_key_path + ".pub"),
|
|
31
|
+
overwrite=True,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
return ssh_private_key_path
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def download_file(url: str, local_path: Path, overwrite: bool = True, chmod: Optional[int] = None) -> None:
|
|
38
|
+
"""Download a file from a URL."""
|
|
39
|
+
import requests
|
|
40
|
+
|
|
41
|
+
if os.path.isfile(local_path) and not overwrite:
|
|
42
|
+
raise FileExistsError(f"The file {local_path} already exists and overwrite is set to False.")
|
|
43
|
+
|
|
44
|
+
response = requests.get(url, stream=True)
|
|
45
|
+
response.raise_for_status()
|
|
46
|
+
|
|
47
|
+
with open(local_path, "wb") as file:
|
|
48
|
+
for chunk in response.iter_content(chunk_size=8192):
|
|
49
|
+
file.write(chunk)
|
|
50
|
+
if chmod is not None:
|
|
51
|
+
os.chmod(local_path, 0o600)
|