3lc-compute-plugin-azure 0.1.1__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.
- 3lc_compute_plugin_azure-0.1.1.dist-info/METADATA +221 -0
- 3lc_compute_plugin_azure-0.1.1.dist-info/RECORD +13 -0
- 3lc_compute_plugin_azure-0.1.1.dist-info/WHEEL +4 -0
- 3lc_compute_plugin_azure-0.1.1.dist-info/entry_points.txt +2 -0
- tlc_plugin_azure/__init__.py +17 -0
- tlc_plugin_azure/bootstrap.py +148 -0
- tlc_plugin_azure/config.py +150 -0
- tlc_plugin_azure/plugin.py +524 -0
- tlc_plugin_azure/plugin.toml +21 -0
- tlc_plugin_azure/provider.py +2031 -0
- tlc_plugin_azure/routes.py +37 -0
- tlc_plugin_azure/ui.html +707 -0
- tlc_plugin_azure/validate.py +219 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: 3lc-compute-plugin-azure
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Microsoft Azure infrastructure plugin for the 3LC compute service: disposable GPU virtual machines and Blob containers as storage.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: 3lc-compute-plugin-sdk<0.6.0,>=0.5.0
|
|
8
|
+
Requires-Dist: 3lc<4.0.0,>=3.5.0.dev149866
|
|
9
|
+
Provides-Extra: azure
|
|
10
|
+
Requires-Dist: azure-identity>=1.17; extra == 'azure'
|
|
11
|
+
Requires-Dist: azure-mgmt-compute>=30; extra == 'azure'
|
|
12
|
+
Requires-Dist: azure-mgmt-network>=25; extra == 'azure'
|
|
13
|
+
Requires-Dist: azure-mgmt-resource-subscriptions>=1.0.0; extra == 'azure'
|
|
14
|
+
Requires-Dist: azure-mgmt-resource>=23; extra == 'azure'
|
|
15
|
+
Requires-Dist: azure-mgmt-storage>=21; extra == 'azure'
|
|
16
|
+
Requires-Dist: azure-storage-blob>=12.19; extra == 'azure'
|
|
17
|
+
Requires-Dist: requests>=2.31; extra == 'azure'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# 3lc-compute-plugin-azure
|
|
21
|
+
|
|
22
|
+
Microsoft Azure infrastructure plugin for the 3LC compute service (`kind = "infrastructure"`). It creates
|
|
23
|
+
disposable **GPU virtual machines** in your Azure subscription for the Hub and tears them down, and it
|
|
24
|
+
offers **Azure Blob containers** as storage. It answers the plugin SDK's typed `InfrastructurePlugin`
|
|
25
|
+
contract, so the Hub drives it as it drives every other provider.
|
|
26
|
+
|
|
27
|
+
- **GPU nodes** — Azure VMs (`Standard_NC…`, `ND…`, `NV…` sizes) running the 3LC node agent; the host
|
|
28
|
+
dispatches training jobs to them and deletes them when idle. The image is the Data Science VM (Ubuntu
|
|
29
|
+
22.04, NVIDIA drivers and CUDA preinstalled), `image` in the settings overrides it (a URN or an image id).
|
|
30
|
+
Each node gets a static public IP, a NIC and an OS disk that are deleted with the VM, a system-assigned
|
|
31
|
+
managed identity, no password and a throwaway SSH key (port 22 is never opened). A managed network
|
|
32
|
+
security group (`3lc-gpu-nodes`) opens the agent port 8800 and the app ports the host asks for (8888) to this
|
|
33
|
+
controller's current egress IP only; SDK workers listen on the node's loopback and are reached through the
|
|
34
|
+
agent's proxy, so no worker port is opened. There is one rule per controller (replaced on every launch, so a
|
|
35
|
+
moved controller never locks itself out and two controllers sharing a group leave each other alone).
|
|
36
|
+
Azure's default rules deny everything else inbound. Nodes attach to a managed VNet (`3lc-gpu-nodes`,
|
|
37
|
+
10.42.0.0/16) unless `subnet_id` names one of yours.
|
|
38
|
+
- **Storage** — one storage account (`storage_account`); its containers are the plugin's storage, as
|
|
39
|
+
`abfs://<container>/<path>` URLs, which is the form `tlc` reads (it takes the account from
|
|
40
|
+
`AZURE_STORAGE_ACCOUNT_NAME`). Nodes land in the storage account's region.
|
|
41
|
+
|
|
42
|
+
**Credentials.** The plugin keeps no credential in its settings and acts in Azure only through the
|
|
43
|
+
**Connection** a call names (the host sends its binding; the SDK resolves it before the plugin runs).
|
|
44
|
+
`AMBIENT` is the one kind honoured today: this deployment's own identity through `DefaultAzureCredential` —
|
|
45
|
+
`az login`, a managed identity or the `AZURE_*` environment on the controller. The plugin never falls back to
|
|
46
|
+
that identity for a call that names no Connection: such a call is answered with "No Connection named — Azure
|
|
47
|
+
acts only through a Connection, and this deployment's own identity (AMBIENT) is the one kind honoured today"
|
|
48
|
+
— capabilities with `ready: false` and that sentence as `not_ready_reason`, every management route with 409,
|
|
49
|
+
and the catalogs and preflight in their answer, as they carry every failure. Cached Azure clients are keyed
|
|
50
|
+
by the Connection's kind and id, so one Connection never reuses another's. The one other path is the legacy
|
|
51
|
+
owner-credentials facet: a request that carries a service principal
|
|
52
|
+
(`credentials: {tenant_id, client_id, client_secret, subscription_id}`) acts in that subscription with it,
|
|
53
|
+
and nothing it carries is stored. `subscription_id` names the plugin's subscription
|
|
54
|
+
(`AZURE_SUBSCRIPTION_ID` in the environment when empty); `resource_group` (default `3lc-compute`) is created
|
|
55
|
+
in `location` when missing.
|
|
56
|
+
|
|
57
|
+
A settings file saved by an earlier version that kept credentials (`tlc_api_key`, `tenant_id`, `client_id`,
|
|
58
|
+
`client_secret`, `sign_in_client_id`, `storage_account_key`, `node_storage_credential`, `node_sas_hours`)
|
|
59
|
+
still loads: those keys are ignored. Their old values — plaintext secrets among them — stay in
|
|
60
|
+
`~/.3lc-plugin-configs/azure/default.json` until the settings are next saved (a save writes only the current
|
|
61
|
+
fields) or you remove them by hand. The browser sign-in is gone too: `signin.json` next to the settings and
|
|
62
|
+
azure-identity's `3lc-azure` token cache (kept by msal-extensions: under `~/.IdentityService/` as a plain file
|
|
63
|
+
on a headless Linux controller, in the OS keyring elsewhere) are no longer read; delete them to forget that
|
|
64
|
+
sign-in.
|
|
65
|
+
|
|
66
|
+
**Upgrading.** GPU nodes created by an earlier version may not be deletable from the Hub without a
|
|
67
|
+
Connection: delete your Azure nodes before upgrading, or remove the leftovers (VM, NIC, public IP, OS disk,
|
|
68
|
+
all named `3lc-<node id>…`) in the Azure portal.
|
|
69
|
+
|
|
70
|
+
**What the plugin's identity needs.** To run nodes: `Microsoft.Compute/*`, `Microsoft.Network/*` on the
|
|
71
|
+
resource group (Contributor on the group is the simple answer), `Microsoft.Compute/skus/read` and
|
|
72
|
+
`Microsoft.Compute/locations/usages/read` for the size table. For storage: Storage Account Contributor on the
|
|
73
|
+
account (or `listKeys`), or Storage Blob Data Contributor plus Storage Blob Delegator when the plugin signs
|
|
74
|
+
links with a user delegation key instead of the account key. The plugin never assigns roles itself.
|
|
75
|
+
|
|
76
|
+
## Trust model
|
|
77
|
+
|
|
78
|
+
- The node's environment carries no credential: the storage account name, `extra_env` (not for secrets) and
|
|
79
|
+
the agent's own control values (`TLC_NODE_*`) from the host. It is the same trust class as the VM itself:
|
|
80
|
+
anything running on the VM can read its own environment, and Azure's Instance Metadata Service hands custom
|
|
81
|
+
data back to any process on the VM. The agent gives its workers everything but its own control secrets.
|
|
82
|
+
- **A node has no 3LC identity and no Blob credential.** It acts in Azure only as its own system-assigned
|
|
83
|
+
managed identity, which is created with the VM and has no role until one is granted to it; the plugin grants
|
|
84
|
+
none. Until node credentials arrive with the Config Service, a node cannot sign in to 3LC, and it reads and
|
|
85
|
+
writes Blob storage only if its identity has been given Storage Blob Data Contributor on the account.
|
|
86
|
+
- **Self-termination.** When idle, the agent runs `/opt/3lc-agent/terminate.py`: IMDS names the VM, and
|
|
87
|
+
`DefaultAzureCredential` — the VM's own system-assigned managed identity — asks Compute to delete it
|
|
88
|
+
(`force_deletion`; disk, NIC and IP go with it). That needs **Virtual Machine Contributor** on the resource
|
|
89
|
+
group for the VM's identity. Without it the agent exits and the VM keeps billing, which is why the
|
|
90
|
+
controller's idle teardown and heartbeat handling are the other two layers.
|
|
91
|
+
- Browser uploads and downloads use per-blob SAS links (one hour; upload links allow create + write only,
|
|
92
|
+
download links read only). Server-side copies pass the source as a URL with a one-hour read SAS.
|
|
93
|
+
- Error text shown to people has subscription, tenant and object ids, resource scopes, principals, request
|
|
94
|
+
ids and endpoints removed; the code and the action stay. The plugin's `describe_error` does this for every
|
|
95
|
+
failure the SDK answers, a transfer or bundle job's included. Request values (container and account names,
|
|
96
|
+
locations, GUIDs, VM sizes and names, resource ids, environment keys and values) are checked before they
|
|
97
|
+
reach Azure and answer 400 with what to change.
|
|
98
|
+
|
|
99
|
+
## Routes
|
|
100
|
+
|
|
101
|
+
`AzurePlugin` is an `InfrastructurePlugin` with the SDK's **storage**, **catalog** and legacy
|
|
102
|
+
**owner-credentials** facets (`capabilities.facets: ["storage", "catalog", "legacy-owner-credentials"]`). The
|
|
103
|
+
SDK mounts the `/infra/*` routes and `/settings` from its typed methods and its settings dataclass; the plugin
|
|
104
|
+
adds its own region route. A call that names no Connection is answered 409 with the sentence under
|
|
105
|
+
*Credentials* by every route below except these: `GET /infra/capabilities` and `GET /ui` (200; capabilities
|
|
106
|
+
report `ready: false` with `not_ready_reason`), `/settings`, the catalogs and preflight (200 with the sentence
|
|
107
|
+
in their answer), `/infra/datacenters`, and the legacy owner-credentials calls
|
|
108
|
+
(`POST /infra/nodes/{id}/terminate`, `POST /infra/storage/discover`, and `POST /infra/storage` with
|
|
109
|
+
`credentials`), which act with the service principal they carry. Everything is mounted under `/api/plugins/azure/`; the host forwards
|
|
110
|
+
storage routes as `/api/infra/storage/azure/...`.
|
|
111
|
+
|
|
112
|
+
| Route | What it does |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `GET /infra/capabilities` | `provider: "azure"`, `ready` (never true for a call that names no Connection; `not_ready_reason` then says so), `node_types` (and `gpu_types`) = the configured VM sizes, `flavors: ["gpu"]`, `pricing: ["on_demand", "spot"]`, `region`, `credential_keys`, `missing_fields` (each with `help` and `href`), `facets`, and `storage` (`kind: "bucket"`, `label: "Azure Blob container"`, `creatable/upload/browse/download/bundle/delete/transfer/rename`) |
|
|
115
|
+
| `POST /infra/nodes` | Create a VM: `{node_id, node_type (or gpu_type; a VM size), token, env, ports, idle_ttl_s, pricing?, owner?, project_storage?}` → `{provider_id, agent_url, pricing}`; `agent_url` is `http://<public ip>:8800`; `ports` are the browser-facing app ports opened next to the agent port. A request whose `credentials` carry any value is refused: nodes run in the plugin's own subscription |
|
|
116
|
+
| `GET /infra/nodes/{id}` | `{state, detail}` with state `pending`, `running`, `exited`, `gone` (from the instance view); `?diagnostics=true` answers the same |
|
|
117
|
+
| `DELETE /infra/nodes/{id}` | Delete the VM (not found counts as done) → `{state: "terminated"}`; leftovers are removed once the VM is gone |
|
|
118
|
+
| `POST /infra/nodes/{id}/terminate` | Delete a VM in another subscription with the `credentials` in the body (a service principal and its `subscription_id`) |
|
|
119
|
+
| `GET /infra/gpu-catalog` | GPU VM sizes in the location with vCPUs, RAM, GPU model and VRAM, family quota, restrictions, pay-as-you-go and spot prices (`?region=` overrides); a failure is an empty list with `error` |
|
|
120
|
+
| `GET /infra/cpu-catalog` | CPU sizes with live prices (`?region=` overrides); a failure is an empty list with `error` |
|
|
121
|
+
| `GET /infra/datacenters` | Always empty: Azure places a VM in the location |
|
|
122
|
+
| `GET /infra/preflight` | Credential, offering and family quota checks before a VM is requested (`?node_type=` or `?gpu_type=`) |
|
|
123
|
+
| `GET /infra/storage` | The account's containers with region, by name; `account`; `regions` = the account's region (every region when no account exists yet) |
|
|
124
|
+
| `POST /infra/storage` | Create a container `{name, region?}` in the plugin's storage account; the first container creates the account (StorageV2, LRS, HTTPS only, no public access) and sets the plugin's account and location. With `credentials` (a service principal and its `subscription_id`; an all-empty object counts as none) the container is created in the requester's subscription, in a storage account this plugin tagged `3lc=storage` in the resource group there, else a new one; the answer's `account` and `https_url` address it, and nothing is saved. The request's `owner` goes into the container's metadata when it can be written as ASCII |
|
|
125
|
+
| `DELETE /infra/storage/{container}` | Delete an empty container; one with blobs is a 409 |
|
|
126
|
+
| `POST /infra/storage/discover` | The containers in the requester's subscription, with the `credentials` in the request (a service principal and its `subscription_id`) |
|
|
127
|
+
| `GET /infra/storage/list?url=abfs://c/prefix` | One level: sub-folders and blobs (`truncated` past 500) |
|
|
128
|
+
| `POST /infra/storage/presign` | `mode: "upload"` (default): PUT URLs for `files: [{path, size, content_type}]` with the `x-ms-blob-type: BlockBlob` header the browser must send; `mode: "download"`: GET URLs saved as attachments |
|
|
129
|
+
| `POST /infra/storage/delete` | Delete files and folders under a prefix, counted first (`dry_run`); the open folder and `..` paths are refused |
|
|
130
|
+
| `POST /infra/storage/transfer`, `GET/DELETE …/transfer/{id}` | Copy, move or rename inside the account as a job (server-side Copy Blob; SDK `TransferRegistry`) |
|
|
131
|
+
| `POST /infra/storage/bundle`, `GET/DELETE …/bundle/{id}` | Zip a folder in the background to `.3lc/downloads/` with a 24-hour link (SDK `BundleRegistry`) |
|
|
132
|
+
| `GET/POST /settings` | The plugin page's settings (no secrets; `extra_env` as `extra_env_keys`) |
|
|
133
|
+
| `GET /infra/regions` | Private: the subscription's regions `[{id, name}]` and the current one |
|
|
134
|
+
|
|
135
|
+
**Settings.** One `AzureSettings` dataclass behind the SDK's `PluginSettings`, with no secret field. The
|
|
136
|
+
location, resource group, image, pricing model and spot eviction policy are checked before they are saved and
|
|
137
|
+
an empty value keeps the current one; the subscription id, the storage account, subnet and network security
|
|
138
|
+
group ids are checked and may be cleared. `extra_env` keys must be environment variable names, and its values
|
|
139
|
+
are not for secrets (they ride the VM's custom data). Capabilities prompt for what is missing in the
|
|
140
|
+
dataclass's field order: the subscription id, the storage account. A node's idle teardown is the host's `idle_ttl_s`; the
|
|
141
|
+
plugin keeps no setting for it. A settings file that exists but does not parse answers 409 instead of being
|
|
142
|
+
read as defaults.
|
|
143
|
+
|
|
144
|
+
## Pricing
|
|
145
|
+
|
|
146
|
+
A GPU node is pay-as-you-go or spot: `pricing: "on_demand" | "spot"` on `POST /infra/nodes`, the `pricing`
|
|
147
|
+
setting when the request names none, and `capabilities.pricing` tells the host it may offer spot. A spot VM is
|
|
148
|
+
created with `priority: Spot`, the configured eviction policy (`Delete` by default — nothing keeps billing;
|
|
149
|
+
`Deallocate` keeps the disk, billed) and `max_price: -1`, which means the current spot price with the
|
|
150
|
+
pay-as-you-go price as the only cap. Azure may evict a spot VM with thirty seconds' notice; the node dies, the
|
|
151
|
+
job running on it fails, and it has to be started again. A launch that finds no capacity (`AllocationFailed`,
|
|
152
|
+
`SkuNotAvailable`, `OverconstrainedAllocationRequest`) fails with a sentence naming the size, the location and
|
|
153
|
+
the code; a quota refusal points at Subscriptions → Usage + quotas. Prices come from the public
|
|
154
|
+
[Retail Prices API](https://prices.azure.com/api/retail/prices) (Linux meters; Windows and Low Priority meters
|
|
155
|
+
skipped; the `Spot` meter is the spot price), cached an hour per size and region.
|
|
156
|
+
|
|
157
|
+
## Dev setup
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
uv sync --extra azure
|
|
161
|
+
uv run pytest
|
|
162
|
+
uvx --from 'ruff>=0.15,<0.16' ruff check . && uvx --from 'ruff>=0.15,<0.16' ruff format --check .
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Every Azure client, the Blob service, the Retail Prices API and the IP echo are fakes in the tests; nothing
|
|
166
|
+
reaches Azure. The SDK's conformance kit (`assert_conformant`) runs against the plugin with and without the
|
|
167
|
+
node lifecycle.
|
|
168
|
+
|
|
169
|
+
Point a dev compute service at this checkout via `TLC_COMPUTE_EXTERNAL_PLUGIN_DIRS=.../src`, open the Azure
|
|
170
|
+
page in the Hub and enter the subscription id. The plugin page's own calls name no Connection, so it shows the
|
|
171
|
+
sentence above and its management calls answer 409; nodes created through the Hub with this deployment's own
|
|
172
|
+
identity (AMBIENT) act through `az login` on the controller. The tests stand an AMBIENT Connection in to
|
|
173
|
+
exercise the provider.
|
|
174
|
+
|
|
175
|
+
## Host changes needed
|
|
176
|
+
|
|
177
|
+
None for the routes and shapes: the Hub reads `storage.label`, the capability flags, `regions`, node records
|
|
178
|
+
and `pricing` exactly as the AWS plugin reports them. One cosmetic gap noticed while mirroring:
|
|
179
|
+
|
|
180
|
+
- The Data page's upload progress and error text say "bucket"; with `storage.label` it could say "container".
|
|
181
|
+
|
|
182
|
+
## Phase 2
|
|
183
|
+
|
|
184
|
+
1. **Workspaces on Azure** — a CPU VM running the person's Object Service and compute service (Caddy, TLS
|
|
185
|
+
under sslip.io names), the `flavor: "workspace"` branch, `workspace_credentials`, and the workspace wizard's
|
|
186
|
+
storage step; `cpu-catalog` and `regions` exist for it already.
|
|
187
|
+
2. **Automatic role assignment for nodes** — grant the VM's managed identity Virtual Machine Contributor on
|
|
188
|
+
the resource group and Storage Blob Data Contributor on the storage account at launch
|
|
189
|
+
(`azure-mgmt-authorization`), so idle nodes delete themselves and reach Blob storage with no credential
|
|
190
|
+
on the VM.
|
|
191
|
+
3. **More than one storage account** — list containers across the 3LC-tagged accounts of the resource group
|
|
192
|
+
and resolve `abfs://` URLs to their account; today one account per plugin.
|
|
193
|
+
4. **Marketplace image plans and the NVIDIA driver extension** — `plan` on the VM for images that need one, and
|
|
194
|
+
the `NvidiaGpuDriverLinux` extension for plain Ubuntu images.
|
|
195
|
+
5. **Spot eviction notice** — read the Scheduled Events endpoint on the node so the agent can fail the job
|
|
196
|
+
cleanly before Azure evicts the VM.
|
|
197
|
+
6. **Placement scores and zone selection** — Azure's Spot Placement Scores API for the "availability" column,
|
|
198
|
+
and zonal placement for sizes that require it.
|
|
199
|
+
7. **Multipart browser uploads** — block uploads for files above the single-request ceiling (5000 MiB), and
|
|
200
|
+
Blob Batch for large deletes across containers.
|
|
201
|
+
8. **Live e2e** — run the plugin against a real subscription (the API-drift gate the fakes cannot be).
|
|
202
|
+
|
|
203
|
+
## Staging development and publishing
|
|
204
|
+
|
|
205
|
+
The plugin SDK 0.5 and the 3.5 core it is locked against are not on PyPI yet; `pyproject.toml` routes both
|
|
206
|
+
to the private `staging` index
|
|
207
|
+
(CloudRepo `prereleases`). Set that index's credentials in your shell (keep them out of source files):
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
export UV_INDEX_STAGING_USERNAME="<account email>"
|
|
211
|
+
export UV_INDEX_STAGING_PASSWORD="<read token>"
|
|
212
|
+
uv sync --locked --group dev --extra azure
|
|
213
|
+
uv run --no-sync pytest
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The Release workflow builds verified artifacts on manual runs. `publish=true` uploads them
|
|
217
|
+
to the private staging index; publishing is disabled by default. The timestamp, run and
|
|
218
|
+
attempt suffix stamps the distribution and manifest together.
|
|
219
|
+
|
|
220
|
+
The separate `v*` tag path provides PyPI Trusted Publishing plumbing. Configure the PyPI
|
|
221
|
+
project's trusted publisher before using that path; no public release is needed while the SDK is staged.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
tlc_plugin_azure/__init__.py,sha256=eynmKqRfG2WRD1VtSWOgO_d2ewz3ANGpa3g8Aw6zMxk,819
|
|
2
|
+
tlc_plugin_azure/bootstrap.py,sha256=FoZsFvMxR6ODe9OxQREu_1_TwcxfLmhRqmqhk_0WQ5Y,7632
|
|
3
|
+
tlc_plugin_azure/config.py,sha256=ARvIj6KipknHdYLSRIMTUuoFvghepsUkpB1v49XWBF8,6868
|
|
4
|
+
tlc_plugin_azure/plugin.py,sha256=6UgujY0UNqhNgk_Hid9JW0zOZg1Vkl8qAyzxnmxAINA,25332
|
|
5
|
+
tlc_plugin_azure/plugin.toml,sha256=hsIk3N3tC6k6abZvffgVP1TqeWY_8wCEuEM7pwKqCSU,933
|
|
6
|
+
tlc_plugin_azure/provider.py,sha256=ipXlpl-DdxH9_9cKFANhweeiX4Ng3iBwhXiD0VHIbIw,91191
|
|
7
|
+
tlc_plugin_azure/routes.py,sha256=L6OpIPLV3Pug4gKtSBnc9z7Wah7URIJoS5BwBompenw,1394
|
|
8
|
+
tlc_plugin_azure/ui.html,sha256=vjdUB_MyxuMFeHSiwFaOWiST9gkGt6v0AQUu1xiVEnw,38192
|
|
9
|
+
tlc_plugin_azure/validate.py,sha256=z8Y6_Lpee-kLRhVIqiAfOfqavvJRcTW7bNhAzR9HtiM,8925
|
|
10
|
+
3lc_compute_plugin_azure-0.1.1.dist-info/METADATA,sha256=ZWOuIf8twcNXSUvd2t9BBv7At0259Ru8fGZEsZtkEVI,18179
|
|
11
|
+
3lc_compute_plugin_azure-0.1.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
12
|
+
3lc_compute_plugin_azure-0.1.1.dist-info/entry_points.txt,sha256=jOt6xrVNLUFMO_zyuZPrew2OUdr8OO6l55Wqe1iKTVE,47
|
|
13
|
+
3lc_compute_plugin_azure-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Copyright 2026 3LC Inc.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Azure infrastructure plugin — GPU virtual machines and Blob containers for the 3LC Hub.
|
|
4
|
+
|
|
5
|
+
``kind = "infrastructure"``: this plugin computes nothing. It answers the SDK's typed
|
|
6
|
+
``InfrastructurePlugin`` contract with the storage, catalog and legacy owner-credentials facets
|
|
7
|
+
(:mod:`tlc_plugin_azure.plugin`): create, watch and delete GPU virtual machines that run the 3LC
|
|
8
|
+
node agent, Azure Blob containers as storage, the VM size catalog with retail prices, and the
|
|
9
|
+
pre-start checks. The host's InfraManager owns every other concern — node registry, heartbeats,
|
|
10
|
+
idle teardown, dispatch, data staging — identically for every provider.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from tlc_plugin_azure.plugin import AzurePlugin
|
|
16
|
+
|
|
17
|
+
__all__ = ["AzurePlugin"]
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Copyright 2026 3LC Inc.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Render the VM's boot script: uv + 3lc-compute + the node agent, and the self-terminate program.
|
|
4
|
+
|
|
5
|
+
Azure has one channel for this: ``custom_data`` on the VM's OS profile, which cloud-init runs once at
|
|
6
|
+
first boot (Ubuntu and Data Science VM images ship cloud-init). The environment the agent needs rides
|
|
7
|
+
inside the script, shell-quoted, and is the same trust class as the VM itself: anything running on
|
|
8
|
+
the VM can read its own environment, and the Instance Metadata Service hands custom data back to
|
|
9
|
+
any process on the VM. That is why it carries no cloud credential: the VM acts in Azure as its own
|
|
10
|
+
system-assigned managed identity. The one credential it may carry is a package index's read
|
|
11
|
+
credential, when the compute service sends one (a staged host does, for its staging index, until a
|
|
12
|
+
release), so the agent and its plugin venvs can install builds that only that index has.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
import shlex
|
|
19
|
+
|
|
20
|
+
from tlc_plugin_azure import validate
|
|
21
|
+
|
|
22
|
+
AGENT_PORT = 8800
|
|
23
|
+
# The uv release the bootstrap installs. Pinned: the installer is fetched over the network and runs as root.
|
|
24
|
+
UV_VERSION = "0.8.22"
|
|
25
|
+
_UV_INSTALL = f"curl -LsSf https://astral.sh/uv/{UV_VERSION}/install.sh | sh"
|
|
26
|
+
AGENT_VENV = "/opt/3lc-agent"
|
|
27
|
+
TERMINATE_SCRIPT_PATH = f"{AGENT_VENV}/terminate.py"
|
|
28
|
+
# The two packages the self-terminate program needs, installed next to 3lc-compute in the agent venv so
|
|
29
|
+
# the idle watchdog never waits on a cold install (the AWS node pays that with `uvx awscli`).
|
|
30
|
+
_TERMINATE_DISTS = ("azure-identity>=1.17", "azure-mgmt-compute>=30")
|
|
31
|
+
_SCRIPT_EOF = "__3LC_TERMINATE__"
|
|
32
|
+
|
|
33
|
+
# Runs on the VM when the agent's idle TTL fires. The Instance Metadata Service names the VM, the
|
|
34
|
+
# subscription and the resource group; the credential is the VM's own system-assigned managed identity
|
|
35
|
+
# (``DefaultAzureCredential`` finds it through IMDS), which needs the Virtual Machine Contributor role
|
|
36
|
+
# on the resource group (see the README). ``force_deletion`` skips the graceful shutdown: the disk,
|
|
37
|
+
# NIC and public IP were created with delete-on-VM-delete, so nothing is left billing.
|
|
38
|
+
TERMINATE_SCRIPT = """\
|
|
39
|
+
import json, sys, urllib.request
|
|
40
|
+
req = urllib.request.Request(
|
|
41
|
+
"http://169.254.169.254/metadata/instance/compute?api-version=2021-02-01", headers={"Metadata": "true"}
|
|
42
|
+
)
|
|
43
|
+
meta = json.load(urllib.request.urlopen(req, timeout=10))
|
|
44
|
+
from azure.identity import DefaultAzureCredential
|
|
45
|
+
from azure.mgmt.compute import ComputeManagementClient
|
|
46
|
+
cred = DefaultAzureCredential(exclude_interactive_browser_credential=True, exclude_shared_token_cache_credential=True)
|
|
47
|
+
client = ComputeManagementClient(cred, meta["subscriptionId"])
|
|
48
|
+
client.virtual_machines.begin_delete(meta["resourceGroupName"], meta["name"], force_deletion=True)
|
|
49
|
+
print("delete requested for", meta["name"])
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
#: Installed beside the agent pin when the host sent extra indexes: a staged ``3lc-compute`` may floor a core with
|
|
54
|
+
#: no release yet (``3lc>=X.Y.Z.devN``), and uv admits a pre-release only for a package whose *direct* requirement
|
|
55
|
+
#: names one. This admits them for ``3lc`` alone; ``UV_PRERELEASE=allow`` would admit every third-party one too.
|
|
56
|
+
CORE_PRERELEASES = "3lc>=0.0.0.dev0"
|
|
57
|
+
_NODE_INDEX_PREFIX = "TLC_NODE_PIP_INDEX_"
|
|
58
|
+
_NODE_INDEX_URL_RE = re.compile(rf"^{_NODE_INDEX_PREFIX}([A-Z0-9_]+)_URL$")
|
|
59
|
+
#: The compute service's own strategy: every index is searched, not just the first that answers (a
|
|
60
|
+
#: private index answers an empty page for names it does not carry).
|
|
61
|
+
INDEX_STRATEGY = "unsafe-first-match"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _index_install_flags(env: dict[str, str]) -> tuple[str, str]:
|
|
65
|
+
"""The uv index flags for the node's extra indexes, and the exports that authenticate them.
|
|
66
|
+
|
|
67
|
+
What the node agent does for its own installs: each URL in ``TLC_NODE_PIP_INDEX_URLS``
|
|
68
|
+
(comma-separated) is an extra index searched before PyPI under :data:`INDEX_STRATEGY`. A URL the
|
|
69
|
+
compute service sent read credentials for (``TLC_NODE_PIP_INDEX_<NAME>_URL`` naming it, with
|
|
70
|
+
``_USERNAME`` and ``_PASSWORD``) becomes uv's named ``--index <name>=<url>``, which uv
|
|
71
|
+
authenticates from ``UV_INDEX_<NAME>_USERNAME`` / ``_PASSWORD``; the export lines set those from
|
|
72
|
+
the variables the script already exported, so no value is written twice and none rides a URL.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
``(flags, exports)``: the flags for the ``uv pip install`` line (``""`` without indexes) and
|
|
76
|
+
the ``export UV_INDEX_…`` lines (``""`` without credentials).
|
|
77
|
+
"""
|
|
78
|
+
urls = [url.strip() for url in env.get("TLC_NODE_PIP_INDEX_URLS", "").split(",") if url.strip()]
|
|
79
|
+
if not urls:
|
|
80
|
+
return "", ""
|
|
81
|
+
credentialed: dict[str, str] = {} # url -> NAME
|
|
82
|
+
for key, value in env.items():
|
|
83
|
+
match = _NODE_INDEX_URL_RE.match(key)
|
|
84
|
+
if not match:
|
|
85
|
+
continue
|
|
86
|
+
name = match.group(1)
|
|
87
|
+
if (
|
|
88
|
+
value.strip()
|
|
89
|
+
and env.get(f"{_NODE_INDEX_PREFIX}{name}_USERNAME")
|
|
90
|
+
and env.get(f"{_NODE_INDEX_PREFIX}{name}_PASSWORD")
|
|
91
|
+
):
|
|
92
|
+
credentialed[value.strip()] = name
|
|
93
|
+
flags = [f"--index-strategy {INDEX_STRATEGY}"]
|
|
94
|
+
exports: list[str] = []
|
|
95
|
+
for url in urls:
|
|
96
|
+
name = credentialed.get(url)
|
|
97
|
+
if name is None:
|
|
98
|
+
flags.append(f"--extra-index-url {shlex.quote(url)}")
|
|
99
|
+
continue
|
|
100
|
+
flags.append(f"--index {shlex.quote(f'{name.lower()}={url}')}")
|
|
101
|
+
exports += [
|
|
102
|
+
f'export UV_INDEX_{name}_{field}="${_NODE_INDEX_PREFIX}{name}_{field}"'
|
|
103
|
+
for field in ("USERNAME", "PASSWORD")
|
|
104
|
+
]
|
|
105
|
+
return " ".join(flags), "\n".join(exports)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def render_user_data(*, env: dict[str, str], compute_dist_spec: str, compute_spec: str = "") -> str:
|
|
109
|
+
"""The VM's ``#!/bin/bash`` custom-data script (cloud-init runs it once, as root).
|
|
110
|
+
|
|
111
|
+
``compute_spec`` is the compute service's pinned requirement for the agent's distribution, from
|
|
112
|
+
the create request (``3lc-compute==1.2.0``): the node runs that service's build, so it is what
|
|
113
|
+
gets installed, from the extra indexes the request names too (:func:`_index_install_flags`). The
|
|
114
|
+
``compute_dist_spec`` setting is the fallback for a request that carries none.
|
|
115
|
+
"""
|
|
116
|
+
exports = "\n".join(
|
|
117
|
+
f"export {validate.env_key(key)}={shlex.quote(validate.env_value(key, str(value)))}"
|
|
118
|
+
for key, value in sorted(env.items())
|
|
119
|
+
)
|
|
120
|
+
spec = compute_spec.strip() or compute_dist_spec
|
|
121
|
+
index_flags, index_exports = _index_install_flags(env)
|
|
122
|
+
core = (CORE_PRERELEASES,) if index_flags else ()
|
|
123
|
+
dists = " ".join(shlex.quote(item) for item in (spec, *core, *_TERMINATE_DISTS))
|
|
124
|
+
authenticate = index_exports + "\n" if index_exports else ""
|
|
125
|
+
install_flags = index_flags + " " if index_flags else ""
|
|
126
|
+
return f"""#!/bin/bash
|
|
127
|
+
set -e
|
|
128
|
+
export HOME=/root
|
|
129
|
+
exec > /var/log/3lc-node-agent-boot.log 2>&1
|
|
130
|
+
{exports}
|
|
131
|
+
command -v uv >/dev/null 2>&1 || ({_UV_INSTALL})
|
|
132
|
+
export PATH="$HOME/.local/bin:$PATH"
|
|
133
|
+
uv venv {AGENT_VENV} --python 3.12
|
|
134
|
+
{authenticate}uv pip install --python {AGENT_VENV}/bin/python {install_flags}{dists}
|
|
135
|
+
cat > {TERMINATE_SCRIPT_PATH} <<'{_SCRIPT_EOF}'
|
|
136
|
+
{TERMINATE_SCRIPT}{_SCRIPT_EOF}
|
|
137
|
+
nohup {AGENT_VENV}/bin/python -m tlc_compute.node_agent --host 0.0.0.0 --port {AGENT_PORT} \\
|
|
138
|
+
>> /var/log/3lc-node-agent.log 2>&1 &
|
|
139
|
+
"""
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def terminate_cmd() -> str:
|
|
143
|
+
"""Self-destruct command the node agent runs on idle TTL (see :data:`TERMINATE_SCRIPT`).
|
|
144
|
+
|
|
145
|
+
If this fails — the managed identity has no role that may delete the VM — the agent exits and the
|
|
146
|
+
VM keeps billing, which is why the controller-side teardown matters as well.
|
|
147
|
+
"""
|
|
148
|
+
return f"{AGENT_VENV}/bin/python {TERMINATE_SCRIPT_PATH}"
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Copyright 2026 3LC Inc.
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""The Azure plugin's single persisted settings record.
|
|
4
|
+
|
|
5
|
+
One record (fixed id ``default``) in the SDK's per-plugin config store: where nodes go (subscription,
|
|
6
|
+
resource group, location), what they are (VM sizes, image, disk, network, pricing), the storage account
|
|
7
|
+
whose containers are the plugin's storage, and extra node environment. The record holds no credential:
|
|
8
|
+
the plugin's Azure identity comes from a Connection (see ``provider._connection_credential``), and a
|
|
9
|
+
settings file saved when the plugin kept keys of its own still loads — the SDK drops keys the dataclass
|
|
10
|
+
no longer has. The plugin keeps no project root either: the root a job writes to is carried by the job,
|
|
11
|
+
resolved by the host.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from collections.abc import Callable
|
|
17
|
+
from dataclasses import dataclass, field
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from tlc_plugin_sdk.shared.config_store import PluginConfigStore
|
|
21
|
+
from tlc_plugin_sdk.shared.settings import PluginSettings, option
|
|
22
|
+
|
|
23
|
+
from tlc_plugin_azure import validate
|
|
24
|
+
|
|
25
|
+
SETTINGS_ID = "default"
|
|
26
|
+
PLUGIN_ID = "azure"
|
|
27
|
+
|
|
28
|
+
# The Data Science VM image (Ubuntu 22.04, NVIDIA drivers, CUDA and Docker preinstalled) — the closest Azure
|
|
29
|
+
# has to AWS's Deep Learning Base AMI. A URN ``publisher:offer:sku:version``; ``image`` in the settings overrides.
|
|
30
|
+
DEFAULT_IMAGE = "microsoft-dsvm:ubuntu-2204:2204-gen2:latest"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _text(value: Any) -> str:
|
|
34
|
+
"""A saved value as stripped text; ``None`` and blanks become ``""`` (which keeps, or clears, the field)."""
|
|
35
|
+
return str(value or "").strip()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _resource_id(what: str) -> Callable[[str], str]:
|
|
39
|
+
return lambda value: validate.resource_id(value, what=what)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _env(value: Any) -> Any:
|
|
43
|
+
"""``extra_env`` with every key checked; anything that is not an object is left for the merge to ignore."""
|
|
44
|
+
if not isinstance(value, dict):
|
|
45
|
+
return value
|
|
46
|
+
return {validate.env_key(str(k)): str(v) for k, v in value.items()}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class AzureSettings:
|
|
51
|
+
"""Everything the plugin needs to create a working Azure GPU node."""
|
|
52
|
+
|
|
53
|
+
id: str = SETTINGS_ID
|
|
54
|
+
created: str = ""
|
|
55
|
+
last_run: str | None = None
|
|
56
|
+
|
|
57
|
+
# Field order is prompt order.
|
|
58
|
+
# ── where ──
|
|
59
|
+
# Empty = AZURE_SUBSCRIPTION_ID in the plugin's environment.
|
|
60
|
+
subscription_id: str = option(
|
|
61
|
+
"",
|
|
62
|
+
label="Azure subscription id",
|
|
63
|
+
required=True,
|
|
64
|
+
placeholder="12345678-1234-1234-1234-123456789abc",
|
|
65
|
+
help="The subscription nodes and storage are billed to. Azure portal → Subscriptions → the id column.",
|
|
66
|
+
href="https://portal.azure.com/#view/Microsoft_Azure_Billing/SubscriptionsBladeV2",
|
|
67
|
+
validate=validate.subscription_id,
|
|
68
|
+
clearable=True,
|
|
69
|
+
coerce=_text,
|
|
70
|
+
)
|
|
71
|
+
resource_group: str = option("3lc-compute", validate=validate.resource_group, coerce=_text) # created when missing
|
|
72
|
+
location: str = option("eastus", validate=validate.location, coerce=_text)
|
|
73
|
+
|
|
74
|
+
# ── GPU nodes ──
|
|
75
|
+
vm_sizes: list[str] = field(default_factory=lambda: ["Standard_NC4as_T4_v3"])
|
|
76
|
+
image: str = option("", validate=validate.image, coerce=_text) # empty = DEFAULT_IMAGE (a URN or an image id)
|
|
77
|
+
disk_gb: int = 128
|
|
78
|
+
# Empty = the managed VNet "3lc-gpu-nodes" in the resource group.
|
|
79
|
+
subnet_id: str = option("", validate=_resource_id("subnet id"), clearable=True, coerce=_text)
|
|
80
|
+
# Empty = find-or-create the "3lc-gpu-nodes" security group, pinned to the controller IP.
|
|
81
|
+
nsg_id: str = option("", validate=_resource_id("network security group id"), clearable=True, coerce=_text)
|
|
82
|
+
# How a GPU node is billed when the request names no pricing: "on_demand" (runs until stopped) or "spot"
|
|
83
|
+
# (the current spot price, at most the on-demand price; Azure may evict it with thirty seconds' notice).
|
|
84
|
+
pricing: str = option("on_demand", validate=validate.pricing, coerce=_text)
|
|
85
|
+
# An evicted spot VM is deleted (nothing keeps billing) or deallocated (its disk stays, and is billed).
|
|
86
|
+
spot_eviction_policy: str = option("Delete", validate=validate.eviction_policy, coerce=_text)
|
|
87
|
+
|
|
88
|
+
# ── storage: one storage account; its containers are the plugin's storage ──
|
|
89
|
+
# Created as "3lc<random>" by the first container when empty.
|
|
90
|
+
storage_account: str = option(
|
|
91
|
+
"",
|
|
92
|
+
label="Storage account",
|
|
93
|
+
required=True,
|
|
94
|
+
placeholder="3lcyourname",
|
|
95
|
+
help="The storage account whose containers hold your data. Create a container below and one is made "
|
|
96
|
+
"for you, or pick an existing account under Storage accounts in the portal.",
|
|
97
|
+
href="https://portal.azure.com/#browse/Microsoft.Storage%2FStorageAccounts",
|
|
98
|
+
validate=validate.storage_account,
|
|
99
|
+
clearable=True,
|
|
100
|
+
coerce=_text,
|
|
101
|
+
)
|
|
102
|
+
# More node environment — not for secrets: it is written into the VM's custom data, which any process on
|
|
103
|
+
# the VM can read back.
|
|
104
|
+
extra_env: dict[str, str] = option(default_factory=dict, coerce=_env)
|
|
105
|
+
|
|
106
|
+
# ── bootstrap ──
|
|
107
|
+
compute_dist_spec: str = "3lc-compute"
|
|
108
|
+
|
|
109
|
+
def node_env(self) -> dict[str, str]:
|
|
110
|
+
"""The environment a node's agent + workers inherit (empty values dropped).
|
|
111
|
+
|
|
112
|
+
The storage account name and ``extra_env``; no credential of any kind. Whatever a node reaches in Azure
|
|
113
|
+
it reaches through its own system-assigned managed identity and the roles granted to it.
|
|
114
|
+
"""
|
|
115
|
+
env = {
|
|
116
|
+
"AZURE_STORAGE_ACCOUNT_NAME": self.storage_account,
|
|
117
|
+
**{str(k): str(v) for k, v in self.extra_env.items()},
|
|
118
|
+
}
|
|
119
|
+
return {k: v for k, v in env.items() if v}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def get_store() -> PluginConfigStore[AzureSettings]:
|
|
123
|
+
"""The plugin's config store (``~/.3lc-plugin-configs/azure/``)."""
|
|
124
|
+
return PluginConfigStore(AzureSettings, PLUGIN_ID)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
#: The settings layer: ``GET/POST /settings`` are mounted from it, and every module reads through it.
|
|
128
|
+
SETTINGS: PluginSettings[AzureSettings] = PluginSettings(AzureSettings, PLUGIN_ID, record_id=SETTINGS_ID)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def load_settings() -> AzureSettings:
|
|
132
|
+
"""The single settings record (defaults when never saved).
|
|
133
|
+
|
|
134
|
+
Keys the dataclass does not have — a removed credential in a file saved by an older version — are
|
|
135
|
+
ignored, and the file is left as it is.
|
|
136
|
+
|
|
137
|
+
Raises:
|
|
138
|
+
SettingsUnreadable: When the file exists but does not parse; it is never read as defaults.
|
|
139
|
+
"""
|
|
140
|
+
return SETTINGS.load()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def save_settings(update: dict[str, Any]) -> AzureSettings:
|
|
144
|
+
"""Merge ``update`` onto the stored record (see :class:`AzureSettings` for what is checked).
|
|
145
|
+
|
|
146
|
+
Locations, GUIDs, names and the pricing model are checked (:class:`validate.InvalidInput`) before they
|
|
147
|
+
are written; an empty value keeps the current one, except for the ids and names that may be cleared.
|
|
148
|
+
Keys the dataclass does not have are ignored.
|
|
149
|
+
"""
|
|
150
|
+
return SETTINGS.save(update)
|