multicloud-cli 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.
- multicloud_cli-0.1.0/.gitignore +5 -0
- multicloud_cli-0.1.0/LICENSE +202 -0
- multicloud_cli-0.1.0/PKG-INFO +148 -0
- multicloud_cli-0.1.0/README.md +133 -0
- multicloud_cli-0.1.0/multicloud_cli/__init__.py +1 -0
- multicloud_cli-0.1.0/multicloud_cli/api.py +152 -0
- multicloud_cli-0.1.0/multicloud_cli/auth.py +547 -0
- multicloud_cli-0.1.0/multicloud_cli/catalog.py +311 -0
- multicloud_cli-0.1.0/multicloud_cli/cloud_account.py +401 -0
- multicloud_cli-0.1.0/multicloud_cli/config.py +114 -0
- multicloud_cli-0.1.0/multicloud_cli/duration.py +30 -0
- multicloud_cli-0.1.0/multicloud_cli/exitcodes.py +30 -0
- multicloud_cli-0.1.0/multicloud_cli/main.py +90 -0
- multicloud_cli-0.1.0/multicloud_cli/orgopt.py +28 -0
- multicloud_cli-0.1.0/multicloud_cli/output.py +40 -0
- multicloud_cli-0.1.0/multicloud_cli/pool.py +454 -0
- multicloud_cli-0.1.0/multicloud_cli/sso.py +265 -0
- multicloud_cli-0.1.0/pyproject.toml +37 -0
- multicloud_cli-0.1.0/tests/__init__.py +0 -0
- multicloud_cli-0.1.0/tests/conftest.py +36 -0
- multicloud_cli-0.1.0/tests/helpers.py +29 -0
- multicloud_cli-0.1.0/tests/test_apply.py +222 -0
- multicloud_cli-0.1.0/tests/test_auth.py +213 -0
- multicloud_cli-0.1.0/tests/test_catalog.py +325 -0
- multicloud_cli-0.1.0/tests/test_cloud_account.py +294 -0
- multicloud_cli-0.1.0/tests/test_conventions.py +304 -0
- multicloud_cli-0.1.0/tests/test_pool.py +333 -0
- multicloud_cli-0.1.0/tests/test_sso.py +384 -0
- multicloud_cli-0.1.0/tests/test_sso_session.py +599 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: multicloud-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: mctl: sign in to Multicloud and connect your cloud account
|
|
5
|
+
Author-email: Multicloud Team <info@multicloud.io>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: click>=8.1
|
|
10
|
+
Requires-Dist: keyring>=24
|
|
11
|
+
Requires-Dist: requests>=2.31
|
|
12
|
+
Provides-Extra: test
|
|
13
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# multicloud-cli
|
|
17
|
+
|
|
18
|
+
`mctl` connects your AWS account to [Multicloud](https://multicloud.io).
|
|
19
|
+
Multicloud then starts machines in your account, and AWS bills you directly.
|
|
20
|
+
You give Multicloud no password and no access key: you create one IAM role with the public
|
|
21
|
+
Terraform module [multicloud/multicloud/aws](https://registry.terraform.io/modules/multicloud/multicloud/aws).
|
|
22
|
+
|
|
23
|
+
The package is not on PyPI yet, so these commands do not work today. When it is published, install it with:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pipx install multicloud-cli # or: uv tool install multicloud-cli
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
If `mctl` is not found after the install, run `uv tool update-shell` (or `pipx ensurepath`) and open a new shell.
|
|
30
|
+
|
|
31
|
+
## Connect an AWS account
|
|
32
|
+
|
|
33
|
+
You need to be an owner of your team on multicloud.io, an AWS login that can create IAM roles, and
|
|
34
|
+
OpenTofu or Terraform 1.5 or later.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
mctl auth login # opens your browser; sign in as you do on multicloud.io
|
|
38
|
+
mkdir multicloud-aws && cd multicloud-aws
|
|
39
|
+
mctl cloud-account create --cloud AWS --account 123456789012 --region us-east-1
|
|
40
|
+
mctl cloud-account apply 7 # init, plan, asks you, apply, then waits for "Ready"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Keep the folder: it holds the Terraform state of the role.
|
|
44
|
+
|
|
45
|
+
To run OpenTofu or Terraform yourself, get a one-time connect code instead of `apply`:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
mctl cloud-account token 7 # prints one "export TF_VAR_multicloud_connect_token=..." line
|
|
49
|
+
tofu init && tofu apply
|
|
50
|
+
mctl cloud-account verify 7 --wait
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Commands
|
|
54
|
+
|
|
55
|
+
| Command | What it does |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `mctl auth login` | Sign in with your browser (SSO). `--no-browser` prints a code to enter on another device (SSH, containers). `--api-key` stores an API key instead (hidden prompt or `--key-stdin`). |
|
|
58
|
+
| `mctl auth status` / `logout` | Show how you are signed in and check it works; end the session and remove the stored sign-in and key. |
|
|
59
|
+
| `mctl cloud-account create` | Declare an AWS account and write `multicloud.tf`. |
|
|
60
|
+
| `mctl cloud-account apply <id>` | `init`, `plan`, a question (`--yes` skips it, `--plan-only` stops after the plan), then `apply` with a fresh connect code and a wait for the check. |
|
|
61
|
+
| `mctl cloud-account token <id>` | A new one-time connect code, for a manual `terraform apply`. |
|
|
62
|
+
| `mctl cloud-account verify <id> [--wait]` | Check the role again: `Ready` (exit 0), the missing permissions (exit 1) or pending (exit 5). |
|
|
63
|
+
| `mctl cloud-account list` / `show <id> [--json]` | The connections of your team. |
|
|
64
|
+
|
|
65
|
+
The connect code reaches Terraform only through the environment of the `apply` process.
|
|
66
|
+
`mctl` never prints a key or a token, and only `mctl cloud-account token` prints a connect code.
|
|
67
|
+
|
|
68
|
+
## Sign in
|
|
69
|
+
|
|
70
|
+
`mctl auth login` opens your browser on `auth.multicloud.io` (authorization code with PKCE, on a temporary
|
|
71
|
+
port of `127.0.0.1`). `mctl auth login --no-browser` uses the device flow instead: it prints a web address and a
|
|
72
|
+
code, and you sign in on any device. Both give a short-lived access token (15 minutes) and a refresh token.
|
|
73
|
+
`mctl` keeps them in the OS key store, else in `~/.config/multicloud/credentials` (mode 0600), and refreshes the
|
|
74
|
+
access token by itself. A session ends after at most 10 hours; then run `mctl auth login` again.
|
|
75
|
+
|
|
76
|
+
- **Organization.** The sign-in holds the organizations you belong to. With one, no `--org` is needed. With
|
|
77
|
+
several, name one: `--org <team-id>` or `MULTICLOUD_ORG`.
|
|
78
|
+
- **Order of credentials.** `MULTICLOUD_API_KEY` (for CI), then the SSO sign-in, then a stored API key.
|
|
79
|
+
- **Roles.** Pool reads need membership. Everything that changes a pool, and every `cloud-account` command, needs the
|
|
80
|
+
owner role of the team (an API key with the matching scope works too).
|
|
81
|
+
- **Logout.** `mctl auth logout` ends the session at Keycloak and deletes the local copy. Because `mctl` shares
|
|
82
|
+
your Keycloak browser session, it signs you out of Keycloak in your browser too.
|
|
83
|
+
- **Settings.** `MULTICLOUD_ISSUER_URL` (or `issuer` in `~/.config/multicloud/cli.json`) overrides the Keycloak
|
|
84
|
+
realm URL `https://auth.multicloud.io/realms/multicloud`. Like the API URL it must be `https://`.
|
|
85
|
+
- **Other environments.** The defaults point to production (`auth.multicloud.io`, `api.multicloud.io`). For
|
|
86
|
+
another environment, set `MULTICLOUD_ISSUER_URL` (for example `https://auth.example.com/realms/multicloud`) and
|
|
87
|
+
`MULTICLOUD_API_URL` (for example `https://api.example.com`) to that environment's hosts before `mctl auth login`. Set both: the sign-in server (issuer) and the API must belong
|
|
88
|
+
to the same environment, or the API rejects the token.
|
|
89
|
+
- **API key (CI, scripts).** `mctl auth login --api-key --org <team-id>`, or `MULTICLOUD_API_KEY` in the environment.
|
|
90
|
+
|
|
91
|
+
## Manage CI pools
|
|
92
|
+
|
|
93
|
+
A pool is a group of build machines that Multicloud starts for you and stops when they are idle.
|
|
94
|
+
With an API key, reading needs **Read** access, create and update need **Write**, and delete, hibernate and wake need **Admin**.
|
|
95
|
+
With an SSO sign-in, reading needs team membership and the rest needs the owner role.
|
|
96
|
+
Every command takes `--org <team-id>` (also before the command: `mctl --org acme pool list`) and, where it makes
|
|
97
|
+
sense, `--json` for the raw answer. `pool list` and `cloud-account list` take `-q` (only the IDs) and
|
|
98
|
+
`--no-headers`. Data goes to stdout; progress and questions go to stderr.
|
|
99
|
+
`<pool>` is the number from `mctl pool list` or the exact pool name.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
mctl pool classes # the machine sizes you can ask for
|
|
103
|
+
mctl pool create ci --github-org my-gh-org --max-cost-per-hour 2 --classes cpu-4 \
|
|
104
|
+
--clouds '[{"type":"AWS","regions":["us-east-1"]}]'
|
|
105
|
+
mctl pool list
|
|
106
|
+
mctl pool hibernate ci # pause: no machines, no cost, the name stays
|
|
107
|
+
mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6 pool deleted, 1 other error
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
| Command | What it does |
|
|
111
|
+
|---|---|
|
|
112
|
+
| `mctl pool create <name>` | Make a pool. Use `--from-file pool.json` for the full request, or the flags `--github-org`, `--clouds`, `--classes`, `--max-cost-per-hour`, `--spot-policy`, `--cpu-units-requests`, `--image-by-class`, `--egress-by-class`, `--class-headroom`. A repeated run with the same `--idempotency-key` makes one pool. Put cloud keys in the file, not on the command line. |
|
|
113
|
+
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--classes`, `--spot-policy`, `--cpu-units-requests` or `--clouds`. Only the options you give change. |
|
|
114
|
+
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
115
|
+
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
116
|
+
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
117
|
+
| `mctl pool rotate-credentials <pool>` / `rotation-status <pool>` | Renew the pool's access credentials; show the progress of the last renewal. |
|
|
118
|
+
|
|
119
|
+
## Find servers and prices
|
|
120
|
+
|
|
121
|
+
The catalog lists the servers of AWS, Azure and Google Cloud with prices. An API key needs the **Catalog** access
|
|
122
|
+
(`catalog` scope); `MULTICLOUD_API_KEY` needs no `--org`. Filter names are the API names: `--min-vcpus` and
|
|
123
|
+
`--min_vcpus` both work. Data goes to stdout; the page line (`Page 1 of 3, 42 results.`) goes to stderr.
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
mctl catalog search --provider aws --min-vcpus 8 --max-price-per-hour 0.5 --sort-by vcpus
|
|
127
|
+
mctl catalog search --has-accelerator --accelerator-name 'A100.*' --price-type SPOT -q # only the IDs
|
|
128
|
+
mctl catalog show 11
|
|
129
|
+
mctl catalog compare 11 12 13
|
|
130
|
+
mctl catalog locations --provider aws
|
|
131
|
+
mctl catalog providers
|
|
132
|
+
mctl catalog field-values # the values the filters accept
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Every command takes `--json`. See [docs/reference.md](docs/reference.md) for all options.
|
|
136
|
+
|
|
137
|
+
## Use it from an AI agent
|
|
138
|
+
|
|
139
|
+
The skill `multicloud-connect-aws` in [multicloud/skills](https://github.com/multicloud/skills) teaches an agent
|
|
140
|
+
such as Claude Code to run these commands. The agent asks you before each apply and never sees the key or the code.
|
|
141
|
+
|
|
142
|
+
## More
|
|
143
|
+
|
|
144
|
+
Every command shows its options with `--help` or `-h`, for example `mctl pool create -h`.
|
|
145
|
+
The exit codes, shell completion and all options are in the [command reference](docs/reference.md):
|
|
146
|
+
0 ok, 1 error, 2 usage, 3 sign-in or access, 4 not found, 5 still pending or wait timeout, 6 pool gone.
|
|
147
|
+
|
|
148
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# multicloud-cli
|
|
2
|
+
|
|
3
|
+
`mctl` connects your AWS account to [Multicloud](https://multicloud.io).
|
|
4
|
+
Multicloud then starts machines in your account, and AWS bills you directly.
|
|
5
|
+
You give Multicloud no password and no access key: you create one IAM role with the public
|
|
6
|
+
Terraform module [multicloud/multicloud/aws](https://registry.terraform.io/modules/multicloud/multicloud/aws).
|
|
7
|
+
|
|
8
|
+
The package is not on PyPI yet, so these commands do not work today. When it is published, install it with:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pipx install multicloud-cli # or: uv tool install multicloud-cli
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
If `mctl` is not found after the install, run `uv tool update-shell` (or `pipx ensurepath`) and open a new shell.
|
|
15
|
+
|
|
16
|
+
## Connect an AWS account
|
|
17
|
+
|
|
18
|
+
You need to be an owner of your team on multicloud.io, an AWS login that can create IAM roles, and
|
|
19
|
+
OpenTofu or Terraform 1.5 or later.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
mctl auth login # opens your browser; sign in as you do on multicloud.io
|
|
23
|
+
mkdir multicloud-aws && cd multicloud-aws
|
|
24
|
+
mctl cloud-account create --cloud AWS --account 123456789012 --region us-east-1
|
|
25
|
+
mctl cloud-account apply 7 # init, plan, asks you, apply, then waits for "Ready"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Keep the folder: it holds the Terraform state of the role.
|
|
29
|
+
|
|
30
|
+
To run OpenTofu or Terraform yourself, get a one-time connect code instead of `apply`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
mctl cloud-account token 7 # prints one "export TF_VAR_multicloud_connect_token=..." line
|
|
34
|
+
tofu init && tofu apply
|
|
35
|
+
mctl cloud-account verify 7 --wait
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Commands
|
|
39
|
+
|
|
40
|
+
| Command | What it does |
|
|
41
|
+
|---|---|
|
|
42
|
+
| `mctl auth login` | Sign in with your browser (SSO). `--no-browser` prints a code to enter on another device (SSH, containers). `--api-key` stores an API key instead (hidden prompt or `--key-stdin`). |
|
|
43
|
+
| `mctl auth status` / `logout` | Show how you are signed in and check it works; end the session and remove the stored sign-in and key. |
|
|
44
|
+
| `mctl cloud-account create` | Declare an AWS account and write `multicloud.tf`. |
|
|
45
|
+
| `mctl cloud-account apply <id>` | `init`, `plan`, a question (`--yes` skips it, `--plan-only` stops after the plan), then `apply` with a fresh connect code and a wait for the check. |
|
|
46
|
+
| `mctl cloud-account token <id>` | A new one-time connect code, for a manual `terraform apply`. |
|
|
47
|
+
| `mctl cloud-account verify <id> [--wait]` | Check the role again: `Ready` (exit 0), the missing permissions (exit 1) or pending (exit 5). |
|
|
48
|
+
| `mctl cloud-account list` / `show <id> [--json]` | The connections of your team. |
|
|
49
|
+
|
|
50
|
+
The connect code reaches Terraform only through the environment of the `apply` process.
|
|
51
|
+
`mctl` never prints a key or a token, and only `mctl cloud-account token` prints a connect code.
|
|
52
|
+
|
|
53
|
+
## Sign in
|
|
54
|
+
|
|
55
|
+
`mctl auth login` opens your browser on `auth.multicloud.io` (authorization code with PKCE, on a temporary
|
|
56
|
+
port of `127.0.0.1`). `mctl auth login --no-browser` uses the device flow instead: it prints a web address and a
|
|
57
|
+
code, and you sign in on any device. Both give a short-lived access token (15 minutes) and a refresh token.
|
|
58
|
+
`mctl` keeps them in the OS key store, else in `~/.config/multicloud/credentials` (mode 0600), and refreshes the
|
|
59
|
+
access token by itself. A session ends after at most 10 hours; then run `mctl auth login` again.
|
|
60
|
+
|
|
61
|
+
- **Organization.** The sign-in holds the organizations you belong to. With one, no `--org` is needed. With
|
|
62
|
+
several, name one: `--org <team-id>` or `MULTICLOUD_ORG`.
|
|
63
|
+
- **Order of credentials.** `MULTICLOUD_API_KEY` (for CI), then the SSO sign-in, then a stored API key.
|
|
64
|
+
- **Roles.** Pool reads need membership. Everything that changes a pool, and every `cloud-account` command, needs the
|
|
65
|
+
owner role of the team (an API key with the matching scope works too).
|
|
66
|
+
- **Logout.** `mctl auth logout` ends the session at Keycloak and deletes the local copy. Because `mctl` shares
|
|
67
|
+
your Keycloak browser session, it signs you out of Keycloak in your browser too.
|
|
68
|
+
- **Settings.** `MULTICLOUD_ISSUER_URL` (or `issuer` in `~/.config/multicloud/cli.json`) overrides the Keycloak
|
|
69
|
+
realm URL `https://auth.multicloud.io/realms/multicloud`. Like the API URL it must be `https://`.
|
|
70
|
+
- **Other environments.** The defaults point to production (`auth.multicloud.io`, `api.multicloud.io`). For
|
|
71
|
+
another environment, set `MULTICLOUD_ISSUER_URL` (for example `https://auth.example.com/realms/multicloud`) and
|
|
72
|
+
`MULTICLOUD_API_URL` (for example `https://api.example.com`) to that environment's hosts before `mctl auth login`. Set both: the sign-in server (issuer) and the API must belong
|
|
73
|
+
to the same environment, or the API rejects the token.
|
|
74
|
+
- **API key (CI, scripts).** `mctl auth login --api-key --org <team-id>`, or `MULTICLOUD_API_KEY` in the environment.
|
|
75
|
+
|
|
76
|
+
## Manage CI pools
|
|
77
|
+
|
|
78
|
+
A pool is a group of build machines that Multicloud starts for you and stops when they are idle.
|
|
79
|
+
With an API key, reading needs **Read** access, create and update need **Write**, and delete, hibernate and wake need **Admin**.
|
|
80
|
+
With an SSO sign-in, reading needs team membership and the rest needs the owner role.
|
|
81
|
+
Every command takes `--org <team-id>` (also before the command: `mctl --org acme pool list`) and, where it makes
|
|
82
|
+
sense, `--json` for the raw answer. `pool list` and `cloud-account list` take `-q` (only the IDs) and
|
|
83
|
+
`--no-headers`. Data goes to stdout; progress and questions go to stderr.
|
|
84
|
+
`<pool>` is the number from `mctl pool list` or the exact pool name.
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
mctl pool classes # the machine sizes you can ask for
|
|
88
|
+
mctl pool create ci --github-org my-gh-org --max-cost-per-hour 2 --classes cpu-4 \
|
|
89
|
+
--clouds '[{"type":"AWS","regions":["us-east-1"]}]'
|
|
90
|
+
mctl pool list
|
|
91
|
+
mctl pool hibernate ci # pause: no machines, no cost, the name stays
|
|
92
|
+
mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6 pool deleted, 1 other error
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
| Command | What it does |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `mctl pool create <name>` | Make a pool. Use `--from-file pool.json` for the full request, or the flags `--github-org`, `--clouds`, `--classes`, `--max-cost-per-hour`, `--spot-policy`, `--cpu-units-requests`, `--image-by-class`, `--egress-by-class`, `--class-headroom`. A repeated run with the same `--idempotency-key` makes one pool. Put cloud keys in the file, not on the command line. |
|
|
98
|
+
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--classes`, `--spot-policy`, `--cpu-units-requests` or `--clouds`. Only the options you give change. |
|
|
99
|
+
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
100
|
+
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
101
|
+
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
102
|
+
| `mctl pool rotate-credentials <pool>` / `rotation-status <pool>` | Renew the pool's access credentials; show the progress of the last renewal. |
|
|
103
|
+
|
|
104
|
+
## Find servers and prices
|
|
105
|
+
|
|
106
|
+
The catalog lists the servers of AWS, Azure and Google Cloud with prices. An API key needs the **Catalog** access
|
|
107
|
+
(`catalog` scope); `MULTICLOUD_API_KEY` needs no `--org`. Filter names are the API names: `--min-vcpus` and
|
|
108
|
+
`--min_vcpus` both work. Data goes to stdout; the page line (`Page 1 of 3, 42 results.`) goes to stderr.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
mctl catalog search --provider aws --min-vcpus 8 --max-price-per-hour 0.5 --sort-by vcpus
|
|
112
|
+
mctl catalog search --has-accelerator --accelerator-name 'A100.*' --price-type SPOT -q # only the IDs
|
|
113
|
+
mctl catalog show 11
|
|
114
|
+
mctl catalog compare 11 12 13
|
|
115
|
+
mctl catalog locations --provider aws
|
|
116
|
+
mctl catalog providers
|
|
117
|
+
mctl catalog field-values # the values the filters accept
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Every command takes `--json`. See [docs/reference.md](docs/reference.md) for all options.
|
|
121
|
+
|
|
122
|
+
## Use it from an AI agent
|
|
123
|
+
|
|
124
|
+
The skill `multicloud-connect-aws` in [multicloud/skills](https://github.com/multicloud/skills) teaches an agent
|
|
125
|
+
such as Claude Code to run these commands. The agent asks you before each apply and never sees the key or the code.
|
|
126
|
+
|
|
127
|
+
## More
|
|
128
|
+
|
|
129
|
+
Every command shows its options with `--help` or `-h`, for example `mctl pool create -h`.
|
|
130
|
+
The exit codes, shell completion and all options are in the [command reference](docs/reference.md):
|
|
131
|
+
0 ok, 1 error, 2 usage, 3 sign-in or access, 4 not found, 5 still pending or wait timeout, 6 pool gone.
|
|
132
|
+
|
|
133
|
+
License: Apache-2.0.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""One HTTP call to the Multicloud API, shared by the command groups.
|
|
2
|
+
|
|
3
|
+
The URL is ``{api_url}/api/v1/orgs/{slug}{path}``, or ``{api_url}/api/v1{path}`` for an ``org_scoped=False`` call
|
|
4
|
+
(the catalog). The credential is, in this order: ``MULTICLOUD_API_KEY``,
|
|
5
|
+
the SSO session (``Authorization: Bearer``), the stored API key (``X-API-Key``). It travels only to the https
|
|
6
|
+
URL that ``config.get_api_url`` accepted.
|
|
7
|
+
"""
|
|
8
|
+
import os
|
|
9
|
+
from typing import Any, Dict, Iterable, Optional, Tuple
|
|
10
|
+
from urllib.parse import quote
|
|
11
|
+
|
|
12
|
+
import requests
|
|
13
|
+
|
|
14
|
+
from . import auth, config, exitcodes, sso
|
|
15
|
+
|
|
16
|
+
TIMEOUT_S = 30
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ApiError(Exception):
|
|
20
|
+
"""The call failed. ``status`` is the HTTP status, or None when there was no answer.
|
|
21
|
+
``exit_code`` is the exit code of ``mctl`` for it (see ``exitcodes``)."""
|
|
22
|
+
|
|
23
|
+
def __init__(self, message: str, status: Optional[int] = None, exit_code: Optional[int] = None):
|
|
24
|
+
super().__init__(message)
|
|
25
|
+
self.status = status
|
|
26
|
+
self.exit_code = exit_code if exit_code is not None else exitcodes.for_status(status)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _detail_text(data: Any) -> Optional[str]:
|
|
30
|
+
"""The text of a Multicloud API error body: ``detail: {code, message}``, ``detail: {error: {message}}``,
|
|
31
|
+
``detail: "<text>"`` or the list of a 422 validation error."""
|
|
32
|
+
detail = data.get("detail") if isinstance(data, dict) else None
|
|
33
|
+
if isinstance(detail, str):
|
|
34
|
+
return detail or None
|
|
35
|
+
if isinstance(detail, dict):
|
|
36
|
+
inner = detail.get("error")
|
|
37
|
+
if isinstance(inner, dict):
|
|
38
|
+
detail = inner
|
|
39
|
+
if detail.get("message"):
|
|
40
|
+
code = detail.get("code")
|
|
41
|
+
return f"{code}: {detail['message']}" if code else str(detail["message"])
|
|
42
|
+
if detail.get("code"):
|
|
43
|
+
return str(detail["code"])
|
|
44
|
+
if isinstance(detail, list):
|
|
45
|
+
parts = []
|
|
46
|
+
for item in detail:
|
|
47
|
+
if isinstance(item, dict) and item.get("msg"):
|
|
48
|
+
where = ".".join(str(p) for p in item.get("loc", []) if p != "body")
|
|
49
|
+
parts.append(f"{where}: {item['msg']}" if where else str(item["msg"]))
|
|
50
|
+
return "; ".join(parts) or None
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _send(method: str, url: str, body: Optional[Dict[str, Any]], headers: Dict[str, str],
|
|
55
|
+
params: Optional[Dict[str, Any]] = None) -> requests.Response:
|
|
56
|
+
extra = {"params": params} if params else {} # a list value becomes one repeated key
|
|
57
|
+
try:
|
|
58
|
+
# No redirects: requests would carry the credential header to another host.
|
|
59
|
+
return requests.request(method, url, json=body, timeout=TIMEOUT_S, allow_redirects=False, headers=headers,
|
|
60
|
+
**extra)
|
|
61
|
+
except requests.RequestException as ex:
|
|
62
|
+
raise ApiError(f"Could not reach the API: {ex}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _sso_org(slug: Optional[str], token: str, explicit: bool = True) -> str:
|
|
66
|
+
"""The organization of this call: ``--org`` (or env, or saved) when it is in the token, else the only one.
|
|
67
|
+
A SAVED org that the token lacks (left from an API-key login) is ignored; an explicit one is an error."""
|
|
68
|
+
orgs = sso.orgs_in_token(token)
|
|
69
|
+
if slug and not explicit and slug not in orgs:
|
|
70
|
+
slug = None
|
|
71
|
+
if not orgs:
|
|
72
|
+
raise auth.AuthError("Your sign-in holds no organization. Ask an owner of your organization to add you, "
|
|
73
|
+
"then run: mctl auth login")
|
|
74
|
+
if slug:
|
|
75
|
+
if slug not in orgs:
|
|
76
|
+
raise auth.AuthError(f"You are not a member of '{slug}'. Your organizations: {', '.join(orgs)}.")
|
|
77
|
+
return slug
|
|
78
|
+
if len(orgs) > 1:
|
|
79
|
+
raise auth.AuthError(f"You belong to several organizations ({', '.join(orgs)}). "
|
|
80
|
+
"Name one with --org or MULTICLOUD_ORG.")
|
|
81
|
+
return orgs[0]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def call(method: str, org: Optional[str], path: str = "", *, body: Optional[Dict[str, Any]] = None,
|
|
85
|
+
headers: Optional[Dict[str, str]] = None, accept: Iterable[int] = (200, 201, 202),
|
|
86
|
+
scope: Optional[str] = None, pass_codes: Iterable[str] = (),
|
|
87
|
+
params: Optional[Dict[str, Any]] = None, org_scoped: bool = True) -> Dict[str, Any]:
|
|
88
|
+
"""One API call. Returns the JSON body with ``_status`` added; raises ``ApiError`` on other statuses.
|
|
89
|
+
|
|
90
|
+
``scope`` names the API key scope this call needs; a 401 or 403 then says that it may be missing.
|
|
91
|
+
A failed answer whose error code is in ``pass_codes`` is returned like a success.
|
|
92
|
+
``params`` are query parameters. ``org_scoped=False`` calls ``/api/v1{path}`` with no organization in the URL:
|
|
93
|
+
an SSO call then needs no organization, and ``MULTICLOUD_API_KEY`` needs none either (a stored key still
|
|
94
|
+
needs one to be found)."""
|
|
95
|
+
slug = config.get_org(org)
|
|
96
|
+
try:
|
|
97
|
+
use_sso = False
|
|
98
|
+
if not os.environ.get("MULTICLOUD_API_KEY"): # the key path needs no issuer
|
|
99
|
+
issuer = config.get_issuer()
|
|
100
|
+
use_sso = auth.load_sso(issuer) is not None
|
|
101
|
+
if use_sso and not org_scoped and slug and auth.get_key(slug)[0]:
|
|
102
|
+
# A stored key of the named org wins for the platform routes (the catalog): it holds its scope
|
|
103
|
+
# explicitly, while an SSO token may not reach them.
|
|
104
|
+
use_sso = False
|
|
105
|
+
base = config.get_api_url()
|
|
106
|
+
if use_sso:
|
|
107
|
+
token = auth.fresh_access_token(issuer)
|
|
108
|
+
if org_scoped:
|
|
109
|
+
slug = _sso_org(slug, token, explicit=config.org_is_explicit(org))
|
|
110
|
+
credential = {"Authorization": f"Bearer {token}"}
|
|
111
|
+
else:
|
|
112
|
+
env_key = os.environ.get("MULTICLOUD_API_KEY")
|
|
113
|
+
if not slug and not org_scoped and not env_key:
|
|
114
|
+
raise ApiError("No sign-in. Run: mctl auth login (or set MULTICLOUD_API_KEY, or name the "
|
|
115
|
+
"organization of a stored key with --org).", exit_code=exitcodes.AUTH)
|
|
116
|
+
if not slug and org_scoped:
|
|
117
|
+
raise ApiError("Name the organization with --org or MULTICLOUD_ORG.")
|
|
118
|
+
key = auth.get_key(slug)[0] if slug else env_key
|
|
119
|
+
if not key:
|
|
120
|
+
raise ApiError(f"No sign-in for {slug}. Run: mctl auth login", exit_code=exitcodes.AUTH)
|
|
121
|
+
credential = {"X-API-Key": key}
|
|
122
|
+
except auth.AuthError as ex:
|
|
123
|
+
raise ApiError(str(ex), exit_code=exitcodes.AUTH)
|
|
124
|
+
except config.ConfigError as ex:
|
|
125
|
+
raise ApiError(str(ex))
|
|
126
|
+
url = f"{base}/api/v1/orgs/{quote(slug, safe='')}{path}" if org_scoped else f"{base}/api/v1{path}"
|
|
127
|
+
r = _send(method, url, body, {**credential, **(headers or {})}, params)
|
|
128
|
+
if r.status_code == 401 and use_sso:
|
|
129
|
+
# The access token was refused (the session may have ended on the server): refresh once and retry once.
|
|
130
|
+
try:
|
|
131
|
+
token = auth.fresh_access_token(issuer, rejected=token)
|
|
132
|
+
except auth.AuthError as ex:
|
|
133
|
+
raise ApiError(str(ex), 401)
|
|
134
|
+
r = _send(method, url, body, {"Authorization": f"Bearer {token}", **(headers or {})}, params)
|
|
135
|
+
try:
|
|
136
|
+
data = r.json() if r.text else {}
|
|
137
|
+
except ValueError:
|
|
138
|
+
data = {}
|
|
139
|
+
if r.status_code not in accept:
|
|
140
|
+
detail = data.get("detail") if isinstance(data, dict) else None
|
|
141
|
+
if isinstance(detail, dict) and detail.get("code") in set(pass_codes):
|
|
142
|
+
data = dict(data)
|
|
143
|
+
data["_status"] = r.status_code
|
|
144
|
+
return data
|
|
145
|
+
text = _detail_text(data) or f"HTTP {r.status_code}"
|
|
146
|
+
# A 401 is a bad or expired credential, not a missing scope.
|
|
147
|
+
if r.status_code == 403 and scope and not use_sso:
|
|
148
|
+
text += f" (HTTP {r.status_code}. The API key may lack the '{scope}' scope.)"
|
|
149
|
+
raise ApiError(text, r.status_code)
|
|
150
|
+
data = dict(data) if isinstance(data, dict) else {"body": data}
|
|
151
|
+
data["_status"] = r.status_code
|
|
152
|
+
return data
|