take-me-cloud 0.1.0__tar.gz

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.

Potentially problematic release.


This version of take-me-cloud might be problematic. Click here for more details.

@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: take-me-cloud
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Requires-Python: >=3.13
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: lightning-sdk>=2026.4.23
8
+
9
+ # take-me-cloud
10
+
11
+ A CLI tool for seamless Lightning AI studio management and SSH configuration. Easily list all your accessible studios and automatically synchronize them with your `.ssh/config` file for quick SSH access.
12
+
13
+ ## Introduction
14
+
15
+ `take-me-cloud` simplifies working with Lightning AI studios by providing a unified command-line interface to:
16
+ - List all studios across your teamspaces and organizations
17
+ - View studio status and cluster information
18
+ - Automatically configure SSH access to your studios
19
+ - Preserve non-Lightning SSH hosts while keeping Lightning entries in sync
20
+
21
+ ## Features
22
+
23
+ 1. **Studio Discovery**: Connect to Lightning AI and discover all studios you have access to across teamspaces and organizations.
24
+ 2. **Studio Listing**: Display a formatted table of all accessible studios with their status, cluster, and metadata.
25
+ 3. **SSH Configuration**: Synchronize your Lightning studios with `~/.ssh/config`, enabling direct SSH access by studio name while preserving existing non-Lightning hosts.
26
+
27
+ ## Installation
28
+
29
+ ### Using `uv` (Recommended)
30
+
31
+ ```bash
32
+ uv env create --python 3.13
33
+ uv sync
34
+ uv run take-me-cloud --help
35
+ ```
36
+
37
+ ### Using `pip`
38
+
39
+ ```bash
40
+ pip install -e .
41
+ take-me-cloud --help
42
+ ```
43
+
44
+ ## Requirements
45
+
46
+ - Python >= 3.13
47
+ - `lightning-sdk >= 2026.4.23`
48
+
49
+ Set the following environment variables before using the CLI:
50
+ - `LIGHTNING_API_KEY`: Your Lightning AI API key
51
+ - `LIGHTNING_USER_ID`: Your Lightning AI user ID
52
+
53
+ ## Usage
54
+
55
+ ### List all accessible studios
56
+
57
+ ```bash
58
+ take-me-cloud --list
59
+ # or
60
+ take-me-cloud -ls
61
+ ```
62
+
63
+ Output:
64
+ ```
65
+ Studio Teamspace Owner Cluster State
66
+ ---------------------- --------------- ------------- ------------------------- -----------------------
67
+ modern-amaranth-ou1r myml vaishnavahari lightning-public-prod CLOUD_SPACE_STATE_READY
68
+ husky-coffee-72g7 myml vaishnavahari lightning-public-prod CLOUD_SPACE_STATE_READY
69
+ ```
70
+
71
+ ### Synchronize SSH configuration
72
+
73
+ ```bash
74
+ take-me-cloud --lock-ssh
75
+ ```
76
+
77
+ This command will:
78
+ - Ensure Lightning SSH keys exist in `~/.ssh/`
79
+ - Add all currently accessible studios to `~/.ssh/config` with proper SSH configuration
80
+ - Remove stale Lightning studio entries that are no longer accessible
81
+ - Preserve all non-Lightning hosts
82
+
83
+ Output:
84
+ ```
85
+ SSH config synchronized (lightning_hosts=12, non_lightning_hosts_preserved=1).
86
+ ```
87
+
88
+ ## SSH Configuration Details
89
+
90
+ Once `--lock-ssh` is run, you can SSH directly to any of your studios by name:
91
+
92
+ ```bash
93
+ ssh modern-amaranth-ou1r
94
+ ssh husky-coffee-72g7
95
+ ```
96
+
97
+ The SSH config uses:
98
+ - Lightning AI's standard SSH gateway: `ssh.lightning.ai`
99
+ - Automatic key-based authentication
100
+ - Studio-specific user credentials
101
+
102
+ ## Development
103
+
104
+ ### Run tests
105
+
106
+ ```bash
107
+ uv run python -m unittest discover -s tests -v
108
+ ```
109
+
110
+ ### Project structure
111
+
112
+ ```
113
+ take-me-cloud/
114
+ ├── take_me_cloud/
115
+ │ ├── __init__.py
116
+ │ ├── base.py # Core functionality (listing, SSH config)
117
+ │ ├── cli.py # CLI entry point and argument parsing
118
+ ├── tests/
119
+ │ ├── test_base.py # Core functionality tests
120
+ │ ├── test_cli.py # CLI tests
121
+ ├── doc/
122
+ │ ├── AGENT.md # Agent instructions
123
+ │ ├── FEATURES.md # Feature specifications
124
+ │ ├── TESTING.md # Testing requirements
125
+ ├── README.md
126
+ └── pyproject.toml
127
+ ```
128
+
129
+ ## License
130
+
131
+ MIT
@@ -0,0 +1,123 @@
1
+ # take-me-cloud
2
+
3
+ A CLI tool for seamless Lightning AI studio management and SSH configuration. Easily list all your accessible studios and automatically synchronize them with your `.ssh/config` file for quick SSH access.
4
+
5
+ ## Introduction
6
+
7
+ `take-me-cloud` simplifies working with Lightning AI studios by providing a unified command-line interface to:
8
+ - List all studios across your teamspaces and organizations
9
+ - View studio status and cluster information
10
+ - Automatically configure SSH access to your studios
11
+ - Preserve non-Lightning SSH hosts while keeping Lightning entries in sync
12
+
13
+ ## Features
14
+
15
+ 1. **Studio Discovery**: Connect to Lightning AI and discover all studios you have access to across teamspaces and organizations.
16
+ 2. **Studio Listing**: Display a formatted table of all accessible studios with their status, cluster, and metadata.
17
+ 3. **SSH Configuration**: Synchronize your Lightning studios with `~/.ssh/config`, enabling direct SSH access by studio name while preserving existing non-Lightning hosts.
18
+
19
+ ## Installation
20
+
21
+ ### Using `uv` (Recommended)
22
+
23
+ ```bash
24
+ uv env create --python 3.13
25
+ uv sync
26
+ uv run take-me-cloud --help
27
+ ```
28
+
29
+ ### Using `pip`
30
+
31
+ ```bash
32
+ pip install -e .
33
+ take-me-cloud --help
34
+ ```
35
+
36
+ ## Requirements
37
+
38
+ - Python >= 3.13
39
+ - `lightning-sdk >= 2026.4.23`
40
+
41
+ Set the following environment variables before using the CLI:
42
+ - `LIGHTNING_API_KEY`: Your Lightning AI API key
43
+ - `LIGHTNING_USER_ID`: Your Lightning AI user ID
44
+
45
+ ## Usage
46
+
47
+ ### List all accessible studios
48
+
49
+ ```bash
50
+ take-me-cloud --list
51
+ # or
52
+ take-me-cloud -ls
53
+ ```
54
+
55
+ Output:
56
+ ```
57
+ Studio Teamspace Owner Cluster State
58
+ ---------------------- --------------- ------------- ------------------------- -----------------------
59
+ modern-amaranth-ou1r myml vaishnavahari lightning-public-prod CLOUD_SPACE_STATE_READY
60
+ husky-coffee-72g7 myml vaishnavahari lightning-public-prod CLOUD_SPACE_STATE_READY
61
+ ```
62
+
63
+ ### Synchronize SSH configuration
64
+
65
+ ```bash
66
+ take-me-cloud --lock-ssh
67
+ ```
68
+
69
+ This command will:
70
+ - Ensure Lightning SSH keys exist in `~/.ssh/`
71
+ - Add all currently accessible studios to `~/.ssh/config` with proper SSH configuration
72
+ - Remove stale Lightning studio entries that are no longer accessible
73
+ - Preserve all non-Lightning hosts
74
+
75
+ Output:
76
+ ```
77
+ SSH config synchronized (lightning_hosts=12, non_lightning_hosts_preserved=1).
78
+ ```
79
+
80
+ ## SSH Configuration Details
81
+
82
+ Once `--lock-ssh` is run, you can SSH directly to any of your studios by name:
83
+
84
+ ```bash
85
+ ssh modern-amaranth-ou1r
86
+ ssh husky-coffee-72g7
87
+ ```
88
+
89
+ The SSH config uses:
90
+ - Lightning AI's standard SSH gateway: `ssh.lightning.ai`
91
+ - Automatic key-based authentication
92
+ - Studio-specific user credentials
93
+
94
+ ## Development
95
+
96
+ ### Run tests
97
+
98
+ ```bash
99
+ uv run python -m unittest discover -s tests -v
100
+ ```
101
+
102
+ ### Project structure
103
+
104
+ ```
105
+ take-me-cloud/
106
+ ├── take_me_cloud/
107
+ │ ├── __init__.py
108
+ │ ├── base.py # Core functionality (listing, SSH config)
109
+ │ ├── cli.py # CLI entry point and argument parsing
110
+ ├── tests/
111
+ │ ├── test_base.py # Core functionality tests
112
+ │ ├── test_cli.py # CLI tests
113
+ ├── doc/
114
+ │ ├── AGENT.md # Agent instructions
115
+ │ ├── FEATURES.md # Feature specifications
116
+ │ ├── TESTING.md # Testing requirements
117
+ ├── README.md
118
+ └── pyproject.toml
119
+ ```
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,12 @@
1
+ [project]
2
+ name = "take-me-cloud"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ dependencies = [
8
+ "lightning-sdk>=2026.4.23",
9
+ ]
10
+
11
+ [project.scripts]
12
+ take-me-cloud = "take_me_cloud.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ """take_me_cloud package."""
@@ -0,0 +1,225 @@
1
+
2
+ """Lightning AI studio listing helpers."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import dataclass
7
+ from pathlib import Path
8
+ from typing import Iterable
9
+
10
+ from lightning_sdk.api import TeamspaceApi, UserApi
11
+ from lightning_sdk.cli.legacy.configure import _download_ssh_keys
12
+ from lightning_sdk.cli.legacy.generate import _generate_ssh_config
13
+ from lightning_sdk.lightning_cloud.login import Auth
14
+
15
+
16
+ @dataclass(frozen=True, slots=True)
17
+ class StudioSummary:
18
+ """A compact view of a Lightning AI studio."""
19
+
20
+ name: str
21
+ teamspace: str
22
+ owner: str
23
+ cluster: str | None
24
+ state: str | None
25
+ description: str | None
26
+ studio_id: str | None
27
+
28
+
29
+ LIGHTNING_HOSTNAME = "ssh.lightning.ai"
30
+
31
+
32
+ def authenticate_lightning_from_env() -> Auth:
33
+ """Create a Lightning auth object from the shell environment."""
34
+
35
+ auth = Auth()
36
+ auth.authenticate()
37
+ if not auth.user_id or not auth.api_key:
38
+ raise ValueError("Set LIGHTNING_USER_ID and LIGHTNING_API_KEY before running take-me-cloud.")
39
+ return auth
40
+
41
+
42
+ def _studio_state(studio: object) -> str | None:
43
+ state = getattr(studio, "state", None)
44
+ if state is None:
45
+ state = getattr(studio, "code_status", None)
46
+ return str(state) if state is not None else None
47
+
48
+
49
+ def _resolve_authed_user() -> tuple[str, str]:
50
+ """Resolve the authenticated user's id and username from shell credentials."""
51
+
52
+ auth = authenticate_lightning_from_env()
53
+ user_api = UserApi()
54
+ user = user_api._get_user_by_id(auth.user_id)
55
+ return auth.user_id, user.username
56
+
57
+
58
+ def _collect_owned_teamspaces(user_id: str, user_name: str, api: TeamspaceApi, user_api: UserApi) -> Iterable[tuple[str, object]]:
59
+ owner_names = {user_id: user_name}
60
+ for organization in user_api._get_organizations_for_authed_user():
61
+ owner_names[organization.id] = organization.name
62
+
63
+ for owner_id, owner_name in owner_names.items():
64
+ for teamspace in api.list_teamspaces(owner_id=owner_id) or []:
65
+ yield owner_name, teamspace
66
+
67
+
68
+ def list_existing_studios() -> list[StudioSummary]:
69
+ """List all studios accessible to the authenticated Lightning AI user."""
70
+
71
+ user_id, user_name = _resolve_authed_user()
72
+ api = TeamspaceApi()
73
+ user_api = UserApi()
74
+
75
+ studios: list[StudioSummary] = []
76
+ seen_teamspaces: set[str] = set()
77
+
78
+ for owner_name, teamspace in _collect_owned_teamspaces(user_id, user_name, api, user_api):
79
+ if teamspace.id in seen_teamspaces:
80
+ continue
81
+ seen_teamspaces.add(teamspace.id)
82
+
83
+ for studio in api.list_studios(teamspace_id=teamspace.id):
84
+ studios.append(
85
+ StudioSummary(
86
+ name=getattr(studio, "name", ""),
87
+ teamspace=getattr(teamspace, "name", ""),
88
+ owner=owner_name,
89
+ cluster=getattr(studio, "cluster_id", None),
90
+ state=_studio_state(studio),
91
+ description=getattr(studio, "description", None),
92
+ studio_id=getattr(studio, "id", None),
93
+ )
94
+ )
95
+
96
+ return studios
97
+
98
+
99
+ def format_studios(studios: Iterable[StudioSummary]) -> str:
100
+ """Render studios as a compact plain-text table."""
101
+
102
+ rows = list(studios)
103
+ if not rows:
104
+ return "No studios found."
105
+
106
+ headers = ["Studio", "Teamspace", "Owner", "Cluster", "State"]
107
+ table_rows = [
108
+ [row.name, row.teamspace, row.owner, row.cluster or "-", row.state or "-"] for row in rows
109
+ ]
110
+
111
+ widths = [len(header) for header in headers]
112
+ for row in table_rows:
113
+ for index, value in enumerate(row):
114
+ widths[index] = max(widths[index], len(value))
115
+
116
+ def render_row(values: list[str]) -> str:
117
+ return " ".join(value.ljust(widths[index]) for index, value in enumerate(values))
118
+
119
+ lines = [render_row(headers), render_row(["-" * width for width in widths])]
120
+ lines.extend(render_row(row) for row in table_rows)
121
+ return "\n".join(lines)
122
+
123
+
124
+ def _ensure_lightning_ssh_keys(auth: Auth, ssh_dir: Path) -> Path:
125
+ """Ensure Lightning SSH key pair exists and return private key path."""
126
+
127
+ key_path = ssh_dir / "lightning_rsa"
128
+ pub_path = ssh_dir / "lightning_rsa.pub"
129
+ if key_path.exists() and pub_path.exists():
130
+ return key_path
131
+
132
+ _download_ssh_keys(api_key=auth.api_key, ssh_home=ssh_dir, ssh_key_name="lightning_rsa", overwrite=False)
133
+ return key_path
134
+
135
+
136
+ def _split_ssh_config_blocks(lines: list[str]) -> tuple[list[str], list[list[str]]]:
137
+ """Split an SSH config into preamble and host blocks."""
138
+
139
+ preamble: list[str] = []
140
+ blocks: list[list[str]] = []
141
+ current: list[str] | None = None
142
+
143
+ for line in lines:
144
+ if line.strip().startswith("Host "):
145
+ if current is not None:
146
+ blocks.append(current)
147
+ current = [line]
148
+ continue
149
+
150
+ if current is None:
151
+ preamble.append(line)
152
+ else:
153
+ current.append(line)
154
+
155
+ if current is not None:
156
+ blocks.append(current)
157
+
158
+ return preamble, blocks
159
+
160
+
161
+ def _is_lightning_host_block(block: list[str]) -> bool:
162
+ for line in block:
163
+ stripped = line.strip().lower()
164
+ if stripped.startswith("hostname ") and stripped.split(maxsplit=1)[1] == LIGHTNING_HOSTNAME:
165
+ return True
166
+ return False
167
+
168
+
169
+ def _render_lightning_host_block(host: str, studio_id: str, key_path: Path) -> list[str]:
170
+ config = _generate_ssh_config(key_path=str(key_path), host=host, user=f"s_{studio_id}")
171
+ return [line.rstrip() for line in config.strip("\n").splitlines()]
172
+
173
+
174
+ def lock_lightning_ssh_config(studios: Iterable[StudioSummary]) -> tuple[int, int]:
175
+ """Sync Lightning hosts in ~/.ssh/config and return (kept_non_lightning, synced_lightning)."""
176
+
177
+ auth = authenticate_lightning_from_env()
178
+ ssh_dir = Path.home() / ".ssh"
179
+ ssh_dir.mkdir(parents=True, exist_ok=True)
180
+
181
+ key_path = _ensure_lightning_ssh_keys(auth, ssh_dir)
182
+ config_path = ssh_dir / "config"
183
+
184
+ rows = list(studios)
185
+ rows_by_host: dict[str, StudioSummary] = {}
186
+ for row in rows:
187
+ if row.name and row.studio_id:
188
+ rows_by_host[row.name] = row
189
+
190
+ existing_lines = []
191
+ if config_path.exists():
192
+ existing_lines = config_path.read_text(encoding="utf-8").splitlines()
193
+
194
+ preamble, blocks = _split_ssh_config_blocks(existing_lines)
195
+ non_lightning_blocks = [block for block in blocks if not _is_lightning_host_block(block)]
196
+
197
+ out_lines: list[str] = []
198
+ out_lines.extend(preamble)
199
+
200
+ if out_lines and out_lines[-1].strip() != "":
201
+ out_lines.append("")
202
+
203
+ for index, block in enumerate(non_lightning_blocks):
204
+ if index > 0 and out_lines and out_lines[-1].strip() != "":
205
+ out_lines.append("")
206
+ out_lines.extend(block)
207
+
208
+ if rows_by_host:
209
+ if out_lines and out_lines[-1].strip() != "":
210
+ out_lines.append("")
211
+
212
+ for index, host in enumerate(sorted(rows_by_host)):
213
+ if index > 0 and out_lines and out_lines[-1].strip() != "":
214
+ out_lines.append("")
215
+ studio = rows_by_host[host]
216
+ out_lines.extend(_render_lightning_host_block(host=host, studio_id=studio.studio_id or "", key_path=key_path))
217
+
218
+ content = "\n".join(out_lines)
219
+ if content and not content.endswith("\n"):
220
+ content += "\n"
221
+ config_path.write_text(content, encoding="utf-8")
222
+
223
+ return len(non_lightning_blocks), len(rows_by_host)
224
+
225
+
@@ -0,0 +1,56 @@
1
+ """CLI for listing Lightning AI studios."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import sys
7
+
8
+ from take_me_cloud.base import format_studios, list_existing_studios, lock_lightning_ssh_config
9
+
10
+
11
+ def build_parser() -> argparse.ArgumentParser:
12
+ parser = argparse.ArgumentParser(
13
+ prog="take-me-cloud",
14
+ description="Manage Lightning AI studio access.",
15
+ epilog="Requires LIGHTNING_API_KEY and LIGHTNING_USER_ID to be set.",
16
+ )
17
+ parser.add_argument("--list", "-ls", action="store_true", help="List accessible studios")
18
+ parser.add_argument(
19
+ "--lock-ssh",
20
+ action="store_true",
21
+ help="Sync Lightning studio SSH entries in ~/.ssh/config while preserving non-Lightning hosts",
22
+ )
23
+ return parser
24
+
25
+
26
+ def main(argv: list[str] | None = None) -> int:
27
+ parser = build_parser()
28
+ args = parser.parse_args(argv)
29
+
30
+ if args.list:
31
+ try:
32
+ print(format_studios(list_existing_studios()))
33
+ return 0
34
+ except (ValueError, RuntimeError) as exc:
35
+ print(f"take-me-cloud: {exc}", file=sys.stderr)
36
+ return 1
37
+
38
+ if args.lock_ssh:
39
+ try:
40
+ studios = list_existing_studios()
41
+ kept_non_lightning, synced_lightning = lock_lightning_ssh_config(studios)
42
+ print(
43
+ "SSH config synchronized "
44
+ f"(lightning_hosts={synced_lightning}, non_lightning_hosts_preserved={kept_non_lightning})."
45
+ )
46
+ return 0
47
+ except (ValueError, RuntimeError, OSError) as exc:
48
+ print(f"take-me-cloud: {exc}", file=sys.stderr)
49
+ return 1
50
+
51
+ parser.print_help()
52
+ return 0
53
+
54
+
55
+ if __name__ == "__main__":
56
+ raise SystemExit(main())
@@ -0,0 +1,131 @@
1
+ Metadata-Version: 2.4
2
+ Name: take-me-cloud
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Requires-Python: >=3.13
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: lightning-sdk>=2026.4.23
8
+
9
+ # take-me-cloud
10
+
11
+ A CLI tool for seamless Lightning AI studio management and SSH configuration. Easily list all your accessible studios and automatically synchronize them with your `.ssh/config` file for quick SSH access.
12
+
13
+ ## Introduction
14
+
15
+ `take-me-cloud` simplifies working with Lightning AI studios by providing a unified command-line interface to:
16
+ - List all studios across your teamspaces and organizations
17
+ - View studio status and cluster information
18
+ - Automatically configure SSH access to your studios
19
+ - Preserve non-Lightning SSH hosts while keeping Lightning entries in sync
20
+
21
+ ## Features
22
+
23
+ 1. **Studio Discovery**: Connect to Lightning AI and discover all studios you have access to across teamspaces and organizations.
24
+ 2. **Studio Listing**: Display a formatted table of all accessible studios with their status, cluster, and metadata.
25
+ 3. **SSH Configuration**: Synchronize your Lightning studios with `~/.ssh/config`, enabling direct SSH access by studio name while preserving existing non-Lightning hosts.
26
+
27
+ ## Installation
28
+
29
+ ### Using `uv` (Recommended)
30
+
31
+ ```bash
32
+ uv env create --python 3.13
33
+ uv sync
34
+ uv run take-me-cloud --help
35
+ ```
36
+
37
+ ### Using `pip`
38
+
39
+ ```bash
40
+ pip install -e .
41
+ take-me-cloud --help
42
+ ```
43
+
44
+ ## Requirements
45
+
46
+ - Python >= 3.13
47
+ - `lightning-sdk >= 2026.4.23`
48
+
49
+ Set the following environment variables before using the CLI:
50
+ - `LIGHTNING_API_KEY`: Your Lightning AI API key
51
+ - `LIGHTNING_USER_ID`: Your Lightning AI user ID
52
+
53
+ ## Usage
54
+
55
+ ### List all accessible studios
56
+
57
+ ```bash
58
+ take-me-cloud --list
59
+ # or
60
+ take-me-cloud -ls
61
+ ```
62
+
63
+ Output:
64
+ ```
65
+ Studio Teamspace Owner Cluster State
66
+ ---------------------- --------------- ------------- ------------------------- -----------------------
67
+ modern-amaranth-ou1r myml vaishnavahari lightning-public-prod CLOUD_SPACE_STATE_READY
68
+ husky-coffee-72g7 myml vaishnavahari lightning-public-prod CLOUD_SPACE_STATE_READY
69
+ ```
70
+
71
+ ### Synchronize SSH configuration
72
+
73
+ ```bash
74
+ take-me-cloud --lock-ssh
75
+ ```
76
+
77
+ This command will:
78
+ - Ensure Lightning SSH keys exist in `~/.ssh/`
79
+ - Add all currently accessible studios to `~/.ssh/config` with proper SSH configuration
80
+ - Remove stale Lightning studio entries that are no longer accessible
81
+ - Preserve all non-Lightning hosts
82
+
83
+ Output:
84
+ ```
85
+ SSH config synchronized (lightning_hosts=12, non_lightning_hosts_preserved=1).
86
+ ```
87
+
88
+ ## SSH Configuration Details
89
+
90
+ Once `--lock-ssh` is run, you can SSH directly to any of your studios by name:
91
+
92
+ ```bash
93
+ ssh modern-amaranth-ou1r
94
+ ssh husky-coffee-72g7
95
+ ```
96
+
97
+ The SSH config uses:
98
+ - Lightning AI's standard SSH gateway: `ssh.lightning.ai`
99
+ - Automatic key-based authentication
100
+ - Studio-specific user credentials
101
+
102
+ ## Development
103
+
104
+ ### Run tests
105
+
106
+ ```bash
107
+ uv run python -m unittest discover -s tests -v
108
+ ```
109
+
110
+ ### Project structure
111
+
112
+ ```
113
+ take-me-cloud/
114
+ ├── take_me_cloud/
115
+ │ ├── __init__.py
116
+ │ ├── base.py # Core functionality (listing, SSH config)
117
+ │ ├── cli.py # CLI entry point and argument parsing
118
+ ├── tests/
119
+ │ ├── test_base.py # Core functionality tests
120
+ │ ├── test_cli.py # CLI tests
121
+ ├── doc/
122
+ │ ├── AGENT.md # Agent instructions
123
+ │ ├── FEATURES.md # Feature specifications
124
+ │ ├── TESTING.md # Testing requirements
125
+ ├── README.md
126
+ └── pyproject.toml
127
+ ```
128
+
129
+ ## License
130
+
131
+ MIT
@@ -0,0 +1,13 @@
1
+ README.md
2
+ pyproject.toml
3
+ take_me_cloud/__init__.py
4
+ take_me_cloud/base.py
5
+ take_me_cloud/cli.py
6
+ take_me_cloud.egg-info/PKG-INFO
7
+ take_me_cloud.egg-info/SOURCES.txt
8
+ take_me_cloud.egg-info/dependency_links.txt
9
+ take_me_cloud.egg-info/entry_points.txt
10
+ take_me_cloud.egg-info/requires.txt
11
+ take_me_cloud.egg-info/top_level.txt
12
+ tests/test_base.py
13
+ tests/test_cli.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ take-me-cloud = take_me_cloud.cli:main
@@ -0,0 +1 @@
1
+ lightning-sdk>=2026.4.23
@@ -0,0 +1 @@
1
+ take_me_cloud
@@ -0,0 +1,163 @@
1
+ from types import SimpleNamespace
2
+ from pathlib import Path
3
+ from tempfile import TemporaryDirectory
4
+ from unittest import TestCase
5
+ from unittest.mock import Mock, patch
6
+
7
+ from take_me_cloud.base import StudioSummary, authenticate_lightning_from_env, lock_lightning_ssh_config, list_existing_studios
8
+
9
+
10
+ class TestAuthentication(TestCase):
11
+ @patch("take_me_cloud.base.Auth")
12
+ def test_authenticate_lightning_from_env_success(self, auth_cls: Mock) -> None:
13
+ auth = auth_cls.return_value
14
+ auth.user_id = "user-123"
15
+ auth.api_key = "api-123"
16
+
17
+ resolved = authenticate_lightning_from_env()
18
+
19
+ auth.authenticate.assert_called_once_with()
20
+ self.assertIs(resolved, auth)
21
+
22
+
23
+ class TestStudioListing(TestCase):
24
+ @patch("take_me_cloud.base._collect_owned_teamspaces")
25
+ @patch("take_me_cloud.base.UserApi")
26
+ @patch("take_me_cloud.base.TeamspaceApi")
27
+ @patch("take_me_cloud.base._resolve_authed_user")
28
+ def test_list_existing_studios_success(
29
+ self,
30
+ resolve_authed_user: Mock,
31
+ teamspace_api_cls: Mock,
32
+ user_api_cls: Mock,
33
+ collect_owned_teamspaces: Mock,
34
+ ) -> None:
35
+ resolve_authed_user.return_value = ("user-123", "vaishnav")
36
+ teamspace_api = teamspace_api_cls.return_value
37
+ user_api = user_api_cls.return_value
38
+
39
+ ts1 = SimpleNamespace(id="ts-1", name="teamspace-one")
40
+ ts2 = SimpleNamespace(id="ts-2", name="teamspace-two")
41
+ collect_owned_teamspaces.return_value = [
42
+ ("vaishnav", ts1),
43
+ ("org-x", ts2),
44
+ ]
45
+
46
+ studio1 = SimpleNamespace(
47
+ name="studio-a",
48
+ cluster_id="cluster-a",
49
+ state="RUNNING",
50
+ description="primary",
51
+ id="st-1",
52
+ )
53
+ studio2 = SimpleNamespace(
54
+ name="studio-b",
55
+ cluster_id="cluster-b",
56
+ code_status="STOPPED",
57
+ description="secondary",
58
+ id="st-2",
59
+ )
60
+
61
+ def list_studios_side_effect(teamspace_id: str):
62
+ if teamspace_id == "ts-1":
63
+ return [studio1]
64
+ if teamspace_id == "ts-2":
65
+ return [studio2]
66
+ return []
67
+
68
+ teamspace_api.list_studios.side_effect = list_studios_side_effect
69
+
70
+ studios = list_existing_studios()
71
+
72
+ collect_owned_teamspaces.assert_called_once_with("user-123", "vaishnav", teamspace_api, user_api)
73
+ self.assertEqual(
74
+ studios,
75
+ [
76
+ StudioSummary(
77
+ name="studio-a",
78
+ teamspace="teamspace-one",
79
+ owner="vaishnav",
80
+ cluster="cluster-a",
81
+ state="RUNNING",
82
+ description="primary",
83
+ studio_id="st-1",
84
+ ),
85
+ StudioSummary(
86
+ name="studio-b",
87
+ teamspace="teamspace-two",
88
+ owner="org-x",
89
+ cluster="cluster-b",
90
+ state="STOPPED",
91
+ description="secondary",
92
+ studio_id="st-2",
93
+ ),
94
+ ],
95
+ )
96
+
97
+
98
+ class TestLockSsh(TestCase):
99
+ @patch("take_me_cloud.base._render_lightning_host_block")
100
+ @patch("take_me_cloud.base._ensure_lightning_ssh_keys")
101
+ @patch("take_me_cloud.base.authenticate_lightning_from_env")
102
+ def test_lock_lightning_ssh_config_replaces_only_lightning_hosts(
103
+ self,
104
+ authenticate_lightning_from_env: Mock,
105
+ ensure_lightning_ssh_keys: Mock,
106
+ render_lightning_host_block: Mock,
107
+ ) -> None:
108
+ authenticate_lightning_from_env.return_value = SimpleNamespace(api_key="api-123", user_id="user-123")
109
+
110
+ def render_side_effect(host: str, studio_id: str, key_path: Path) -> list[str]:
111
+ return [
112
+ f"Host {host}",
113
+ f" User s_{studio_id}",
114
+ " Hostname ssh.lightning.ai",
115
+ f" IdentityFile {key_path}",
116
+ ]
117
+
118
+ render_lightning_host_block.side_effect = render_side_effect
119
+
120
+ studios = [
121
+ StudioSummary(
122
+ name="studio-new",
123
+ teamspace="ts",
124
+ owner="owner",
125
+ cluster="cluster",
126
+ state="RUNNING",
127
+ description="desc",
128
+ studio_id="st-new",
129
+ )
130
+ ]
131
+
132
+ with TemporaryDirectory() as temp_home:
133
+ ssh_dir = Path(temp_home) / ".ssh"
134
+ ssh_dir.mkdir(parents=True, exist_ok=True)
135
+ config_path = ssh_dir / "config"
136
+ config_path.write_text(
137
+ "\n".join(
138
+ [
139
+ "Host github.com",
140
+ " Hostname github.com",
141
+ " User git",
142
+ "",
143
+ "Host old-lightning",
144
+ " User s_old",
145
+ " Hostname ssh.lightning.ai",
146
+ ]
147
+ )
148
+ + "\n",
149
+ encoding="utf-8",
150
+ )
151
+
152
+ ensure_lightning_ssh_keys.return_value = ssh_dir / "lightning_rsa"
153
+
154
+ with patch("take_me_cloud.base.Path.home", return_value=Path(temp_home)):
155
+ kept_non_lightning, synced_lightning = lock_lightning_ssh_config(studios)
156
+
157
+ updated = config_path.read_text(encoding="utf-8")
158
+
159
+ self.assertEqual(kept_non_lightning, 1)
160
+ self.assertEqual(synced_lightning, 1)
161
+ self.assertIn("Host github.com", updated)
162
+ self.assertIn("Host studio-new", updated)
163
+ self.assertNotIn("Host old-lightning", updated)
@@ -0,0 +1,51 @@
1
+ from unittest import TestCase
2
+ from unittest.mock import patch
3
+
4
+ from take_me_cloud.base import StudioSummary
5
+ from take_me_cloud.cli import main
6
+
7
+
8
+ class TestCLI(TestCase):
9
+ @patch("take_me_cloud.cli.format_studios")
10
+ @patch("take_me_cloud.cli.list_existing_studios")
11
+ def test_list_flag_success(self, list_existing_studios, format_studios) -> None:
12
+ list_existing_studios.return_value = [
13
+ StudioSummary(
14
+ name="studio-a",
15
+ teamspace="ts",
16
+ owner="owner",
17
+ cluster="cluster",
18
+ state="RUNNING",
19
+ description="desc",
20
+ studio_id="id-1",
21
+ )
22
+ ]
23
+ format_studios.return_value = "ok"
24
+
25
+ exit_code = main(["--list"])
26
+
27
+ self.assertEqual(exit_code, 0)
28
+ list_existing_studios.assert_called_once_with()
29
+ format_studios.assert_called_once()
30
+
31
+ @patch("take_me_cloud.cli.lock_lightning_ssh_config")
32
+ @patch("take_me_cloud.cli.list_existing_studios")
33
+ def test_lock_ssh_flag_success(self, list_existing_studios, lock_lightning_ssh_config) -> None:
34
+ list_existing_studios.return_value = [
35
+ StudioSummary(
36
+ name="studio-a",
37
+ teamspace="ts",
38
+ owner="owner",
39
+ cluster="cluster",
40
+ state="RUNNING",
41
+ description="desc",
42
+ studio_id="id-1",
43
+ )
44
+ ]
45
+ lock_lightning_ssh_config.return_value = (1, 1)
46
+
47
+ exit_code = main(["--lock-ssh"])
48
+
49
+ self.assertEqual(exit_code, 0)
50
+ list_existing_studios.assert_called_once_with()
51
+ lock_lightning_ssh_config.assert_called_once_with(list_existing_studios.return_value)