multicloud-cli 0.5.2__tar.gz → 0.7.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.5.2 → multicloud_cli-0.7.0}/PKG-INFO +1 -1
- multicloud_cli-0.7.0/multicloud_cli/__init__.py +1 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/api.py +2 -1
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/cloud_account.py +92 -4
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/extend.py +11 -2
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/pool.py +32 -7
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_account_extend.py +25 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_cloud_account.py +119 -3
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_pool.py +48 -0
- multicloud_cli-0.5.2/multicloud_cli/__init__.py +0 -1
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/.gitignore +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/LICENSE +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/README.md +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/account.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/auth.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/catalog.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/config.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/duration.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/exitcodes.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/main.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/net.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/node.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/orgopt.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/output.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/ssh.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/ssh_cert.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/multicloud_cli/sso.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/pyproject.toml +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/__init__.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/conftest.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/helpers.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_apply.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_auth.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_catalog.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_conventions.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_net.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_ssh.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_ssh_cert.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_sso.py +0 -0
- {multicloud_cli-0.5.2 → multicloud_cli-0.7.0}/tests/test_sso_session.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: multicloud-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: mctl: the Multicloud command line: sign in, connect your cloud account, run pools
|
|
5
5
|
Project-URL: Homepage, https://multicloud.io
|
|
6
6
|
Author-email: Multicloud Team <info@multicloud.io>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.0"
|
|
@@ -15,7 +15,8 @@ from . import auth, config, exitcodes, net, sso
|
|
|
15
15
|
|
|
16
16
|
TIMEOUT_S = 30
|
|
17
17
|
# The name of each scope in the console key form (multicloud.io, Account, API keys).
|
|
18
|
-
CONSOLE_SCOPE_NAMES = {"org:read": "Pools: Read", "org:write": "Pools: Manage", "org:admin": "Pools: Full"
|
|
18
|
+
CONSOLE_SCOPE_NAMES = {"org:read": "Pools: Read", "org:write": "Pools: Manage", "org:admin": "Pools: Full",
|
|
19
|
+
"infra": "Infrastructure"}
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
class ApiError(Exception):
|
|
@@ -105,6 +105,22 @@ def describe_verify(answer: Dict[str, Any]) -> str:
|
|
|
105
105
|
return out
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
def _num(value):
|
|
109
|
+
"""8.0 -> 8; anything else as it is."""
|
|
110
|
+
return int(value) if isinstance(value, float) and value.is_integer() else value
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
#: Onboarding decision 28: the question ``create`` asks, default No.
|
|
114
|
+
QUOTA_QUESTION = "Allow Multicloud to request higher quotas in this account?"
|
|
115
|
+
ALLOW_QUOTA_COMMAND = "mctl cloud-account allow-quota-requests {id}"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def quota_consent_label(account: Dict[str, Any]) -> str:
|
|
119
|
+
if account.get("quota_consent_on"):
|
|
120
|
+
return f"allowed by {account.get('quota_consent_by')} on {account.get('quota_consent_on')}"
|
|
121
|
+
return "not allowed"
|
|
122
|
+
|
|
123
|
+
|
|
108
124
|
def quota_lines(quota: Optional[Dict[str, Any]]) -> list:
|
|
109
125
|
"""One line per item of the ``quota`` block of a verify answer."""
|
|
110
126
|
quota = quota or {}
|
|
@@ -117,6 +133,9 @@ def quota_lines(quota: Optional[Dict[str, Any]]) -> list:
|
|
|
117
133
|
lines.append(f"quota LATER {d.get('quota')}: {d.get('reason')}")
|
|
118
134
|
for r in quota.get("refused") or []:
|
|
119
135
|
lines.append(f"quota NO {r.get('quota')}: {r.get('error')}")
|
|
136
|
+
for p in quota.get("planned") or []:
|
|
137
|
+
lines.append(f"quota LOW {p.get('quota')}: {_num(p.get('current'))} -> {_num(p.get('required'))} "
|
|
138
|
+
f"(not requested)")
|
|
120
139
|
for label in quota.get("sufficient") or []:
|
|
121
140
|
lines.append(f"quota OK {label}")
|
|
122
141
|
for u in quota.get("unknown") or []:
|
|
@@ -252,9 +271,12 @@ def _file_exists(name: str):
|
|
|
252
271
|
@click.option("--opt-in-regions/--no-opt-in-regions", "opt_in", default=None,
|
|
253
272
|
help="AWS: turn on the opt-in regions of the account that are off (default: yes; "
|
|
254
273
|
"asks when stdin is a terminal)")
|
|
274
|
+
@click.option("--allow-quota-requests/--no-allow-quota-requests", "allow_quota", default=None,
|
|
275
|
+
help="AWS: allow Multicloud to request higher quotas in this account (default: no; asks when "
|
|
276
|
+
"stdin is a terminal). Needs an organization owner's sign-in")
|
|
255
277
|
@json_option
|
|
256
278
|
@click.pass_context
|
|
257
|
-
def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
|
|
279
|
+
def create(ctx, cloud, account, new_email, regions, force, opt_in, allow_quota, as_json):
|
|
258
280
|
"""Register an account and write multicloud.tf. No token is printed.
|
|
259
281
|
|
|
260
282
|
An existing multicloud.tf is kept: a new external id in it would cut off a connected account.
|
|
@@ -265,7 +287,11 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
|
|
|
265
287
|
|
|
266
288
|
AWS opt-in regions (for example af-south-1) are off in a new account. With the default, Multicloud
|
|
267
289
|
turns them on (only the --region ones when you give --region). That takes minutes to hours; verify
|
|
268
|
-
again to add them.
|
|
290
|
+
again to add them.
|
|
291
|
+
|
|
292
|
+
Quota requests: Multicloud files a quota increase request in the account only when you allow it
|
|
293
|
+
(--allow-quota-requests, or 'y' at the question). Without it, verify only reads the quotas and tells
|
|
294
|
+
you what to request. Change it later with allow-quota-requests or revoke-quota-requests."""
|
|
269
295
|
gce = cloud.upper() == "GCE"
|
|
270
296
|
if gce and account:
|
|
271
297
|
raise click.UsageError("--account is not allowed for GCE: Multicloud generates the project id.")
|
|
@@ -276,6 +302,9 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
|
|
|
276
302
|
"has no ID yet.")
|
|
277
303
|
if gce and opt_in is not None:
|
|
278
304
|
raise click.UsageError("--opt-in-regions applies to AWS only.")
|
|
305
|
+
if gce and allow_quota is not None:
|
|
306
|
+
raise click.UsageError("--allow-quota-requests applies to AWS only: Multicloud files no GCP quota "
|
|
307
|
+
"request.")
|
|
279
308
|
if new_email:
|
|
280
309
|
new_email = new_email.strip()
|
|
281
310
|
if not _EMAIL.match(new_email):
|
|
@@ -301,6 +330,14 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
|
|
|
301
330
|
opt_in = (click.confirm("Turn on the AWS opt-in regions in this account?", default=True, err=True)
|
|
302
331
|
if _stdin_is_tty() else True)
|
|
303
332
|
body["enable_opt_in_regions"] = bool(opt_in)
|
|
333
|
+
if allow_quota is None:
|
|
334
|
+
if _stdin_is_tty():
|
|
335
|
+
click.echo("Multicloud can request higher spot quotas in this account (AWS Service Quotas) when "
|
|
336
|
+
"they are too low for your pools. Without it, Multicloud only reads the quotas and "
|
|
337
|
+
"tells you what to request.", err=True)
|
|
338
|
+
allow_quota = click.confirm(QUOTA_QUESTION, default=False, err=True)
|
|
339
|
+
else:
|
|
340
|
+
allow_quota = False
|
|
304
341
|
if regions:
|
|
305
342
|
body["regions"] = list(regions)
|
|
306
343
|
made = _run(ctx, lambda org: call("POST", org, body=body))
|
|
@@ -316,9 +353,12 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
|
|
|
316
353
|
except FileExistsError:
|
|
317
354
|
_file_exists(TFVARS_FILE)
|
|
318
355
|
acct_id = made["account"]["id"]
|
|
319
|
-
if as_json: # the created account; the Terraform file is in multicloud.tf
|
|
320
|
-
_dump(made["account"])
|
|
321
356
|
say = lambda text: click.echo(text, err=as_json) # noqa: E731
|
|
357
|
+
shown, consent_lines = made["account"], []
|
|
358
|
+
if not gce:
|
|
359
|
+
shown = _create_quota_consent(ctx, acct_id, allow_quota, consent_lines.append) or shown
|
|
360
|
+
if as_json: # the created account (after the consent call); the Terraform file is in multicloud.tf
|
|
361
|
+
_dump(shown)
|
|
322
362
|
if gce:
|
|
323
363
|
target = f"GCP project {made['account'].get('expected_native_id')}"
|
|
324
364
|
elif account:
|
|
@@ -335,10 +375,30 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
|
|
|
335
375
|
elif not gce and not account:
|
|
336
376
|
say("The AWS account ID is read when the module connects. The account should be a new AWS account "
|
|
337
377
|
"made for Multicloud.")
|
|
378
|
+
for line in consent_lines:
|
|
379
|
+
say(line)
|
|
338
380
|
say(f"Next: mctl cloud-account apply {acct_id}")
|
|
339
381
|
say(f"By hand: mctl cloud-account token {acct_id}, then tofu apply (or terraform apply).")
|
|
340
382
|
|
|
341
383
|
|
|
384
|
+
def _create_quota_consent(ctx, acct_id, allow: bool, say) -> Optional[Dict[str, Any]]:
|
|
385
|
+
"""After create: allow quota requests when asked to. Returns the account the allow call answered, else None.
|
|
386
|
+
A refusal (no owner sign-in) keeps the account and says so on stderr."""
|
|
387
|
+
command = ALLOW_QUOTA_COMMAND.format(id=acct_id)
|
|
388
|
+
if not allow:
|
|
389
|
+
say(f"Quota requests: not allowed. To allow them later: {command}")
|
|
390
|
+
return None
|
|
391
|
+
try:
|
|
392
|
+
answer = call("PUT", ctx.obj.get("cloud_account_org"), f"/{acct_id}/quota-consent", prefer_sso=True)
|
|
393
|
+
except CloudAccountError as ex:
|
|
394
|
+
click.echo(f"Quota requests are not allowed: {ex}. The account was created. An organization owner "
|
|
395
|
+
f"allows them with: {command}", err=True)
|
|
396
|
+
return None
|
|
397
|
+
answer.pop("_status", None)
|
|
398
|
+
say(f"Quota requests allowed (by {answer.get('quota_consent_by')}).")
|
|
399
|
+
return answer
|
|
400
|
+
|
|
401
|
+
|
|
342
402
|
@cloud_account.command()
|
|
343
403
|
@click.argument("account_id", type=int)
|
|
344
404
|
@click.pass_context
|
|
@@ -392,6 +452,7 @@ def _readable(data: Dict[str, Any]) -> str:
|
|
|
392
452
|
("Dedicated", dedicated_label(data)),
|
|
393
453
|
("Shared account approved by", data.get("shared_risk_accepted_by")),
|
|
394
454
|
("Shared account approved on", data.get("shared_risk_accepted_on")),
|
|
455
|
+
("Quota requests", quota_consent_label(data)),
|
|
395
456
|
]
|
|
396
457
|
if data.get("approval_required"):
|
|
397
458
|
lines += approval_lines(data.get("cloud"), data.get("id"))
|
|
@@ -567,6 +628,33 @@ def accept_shared_account(ctx, account_id):
|
|
|
567
628
|
sys.exit(exitcodes.ERROR)
|
|
568
629
|
|
|
569
630
|
|
|
631
|
+
@cloud_account.command(name="allow-quota-requests")
|
|
632
|
+
@click.argument("account_id", type=int)
|
|
633
|
+
@click.pass_context
|
|
634
|
+
def allow_quota_requests(ctx, account_id):
|
|
635
|
+
"""Allow Multicloud to request higher quotas in this account (organization owners only).
|
|
636
|
+
|
|
637
|
+
Multicloud then files quota increase requests (AWS Service Quotas, Azure Microsoft.Quota) when the spot
|
|
638
|
+
quota is too low for your pools, at most a few per day. Needs a sign-in (mctl auth login), not an API key.
|
|
639
|
+
Undo with revoke-quota-requests."""
|
|
640
|
+
answer = _run(ctx, lambda org: call("PUT", org, f"/{account_id}/quota-consent", prefer_sso=True))
|
|
641
|
+
click.echo(f"Multicloud may now request higher quotas in cloud account {account_id} "
|
|
642
|
+
f"({quota_consent_label(answer)}). The next verify files what is needed: "
|
|
643
|
+
f"mctl cloud-account verify {account_id}")
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
@cloud_account.command(name="revoke-quota-requests")
|
|
647
|
+
@click.argument("account_id", type=int)
|
|
648
|
+
@click.pass_context
|
|
649
|
+
def revoke_quota_requests(ctx, account_id):
|
|
650
|
+
"""Stop Multicloud from requesting higher quotas in this account (organization owners only).
|
|
651
|
+
|
|
652
|
+
Requests already filed stay open in the cloud; cancel them in the cloud console if you want."""
|
|
653
|
+
_run(ctx, lambda org: call("DELETE", org, f"/{account_id}/quota-consent", prefer_sso=True))
|
|
654
|
+
click.echo(f"Multicloud no longer requests higher quotas in cloud account {account_id}. Requests already "
|
|
655
|
+
f"filed stay open in the cloud.")
|
|
656
|
+
|
|
657
|
+
|
|
570
658
|
IN_USE = "ACCOUNT_IN_USE"
|
|
571
659
|
|
|
572
660
|
|
|
@@ -14,6 +14,7 @@ from urllib.parse import quote
|
|
|
14
14
|
import click
|
|
15
15
|
|
|
16
16
|
from . import api, exitcodes
|
|
17
|
+
from .cloud_account import quota_lines
|
|
17
18
|
from .orgopt import org_group, org_option
|
|
18
19
|
from .output import (collect as _collect, dump as _dump, echo as _echo, json_option, load_body, no_headers_option, quiet_option,
|
|
19
20
|
run, table as _table)
|
|
@@ -70,6 +71,10 @@ def _run(ctx, key, fn):
|
|
|
70
71
|
|
|
71
72
|
@extend.command(name="create")
|
|
72
73
|
@click.argument("name", required=False)
|
|
74
|
+
@click.option("--cloud-account", "cloud_accounts", type=int, multiple=True, metavar="ID",
|
|
75
|
+
help="Run the pool on a connected cloud account (see: mctl cloud-account list). Repeat for more "
|
|
76
|
+
"(one per cloud). This command uses your SSO sign-in as owner; an API key that calls the "
|
|
77
|
+
"Extend API directly needs the Infrastructure (infra) scope")
|
|
73
78
|
@click.option("--max-servers", type=int, default=None, help="Most servers the pool may hold (1-50)")
|
|
74
79
|
@click.option("--max-cost-per-hour", type=float, default=None, help="Cost ceiling in USD per hour (up to 50)")
|
|
75
80
|
@click.option("--from-file", "from_file", type=click.Path(dir_okay=False, allow_dash=True), default=None,
|
|
@@ -78,10 +83,12 @@ def _run(ctx, key, fn):
|
|
|
78
83
|
help="Same key and body within 24 hours creates one pool (default: a new random key)")
|
|
79
84
|
@json_option
|
|
80
85
|
@click.pass_context
|
|
81
|
-
def create_pool(ctx, name, max_servers, max_cost_per_hour, from_file, idempotency_key, as_json):
|
|
82
|
-
"""Create an Extend pool."""
|
|
86
|
+
def create_pool(ctx, name, cloud_accounts, max_servers, max_cost_per_hour, from_file, idempotency_key, as_json):
|
|
87
|
+
"""Create an Extend pool, optionally on connected cloud accounts (--cloud-account)."""
|
|
83
88
|
body = load_body(from_file)
|
|
84
89
|
body.update(_collect(name=name, max_servers=max_servers, max_cost_per_hour=max_cost_per_hour))
|
|
90
|
+
if cloud_accounts:
|
|
91
|
+
body["cloud_accounts"] = [{"id": i} for i in cloud_accounts]
|
|
85
92
|
if "name" not in body:
|
|
86
93
|
raise click.UsageError("Missing: NAME")
|
|
87
94
|
key = idempotency_key or str(uuid.uuid4())
|
|
@@ -98,6 +105,8 @@ def create_pool(ctx, name, max_servers, max_cost_per_hour, from_file, idempotenc
|
|
|
98
105
|
if as_json:
|
|
99
106
|
return _dump(made)
|
|
100
107
|
click.echo(f"Pool {made.get('pool_id')} ({made.get('name')}) created. Status: {_status(made)}")
|
|
108
|
+
for line in quota_lines(made.get("quota")):
|
|
109
|
+
click.echo(line)
|
|
101
110
|
click.echo(f"Next: mctl peering create {made.get('name')}")
|
|
102
111
|
|
|
103
112
|
|
|
@@ -16,6 +16,7 @@ from typing import Any, Callable, Dict, Optional, Tuple
|
|
|
16
16
|
import click
|
|
17
17
|
|
|
18
18
|
from . import api, exitcodes
|
|
19
|
+
from .cloud_account import quota_lines
|
|
19
20
|
from .duration import duration_option, interval_option, parse_duration # noqa: F401 (parse_duration: tests)
|
|
20
21
|
from .orgopt import org_group, org_option
|
|
21
22
|
from .output import (collect as _collect, dump as _dump, echo as _echo, json_option, load_body, no_headers_option, plain as _plain,
|
|
@@ -221,10 +222,19 @@ def _classes_list(ctx, param, value):
|
|
|
221
222
|
@click.argument("name", required=False)
|
|
222
223
|
@click.option("--github-org", default=None, help="GitHub organization the runners serve")
|
|
223
224
|
@click.option("--clouds", callback=_json_value, default=None,
|
|
224
|
-
help="JSON list of clouds, or @file.json. Cloud keys belong in --from-file, not in a command line"
|
|
225
|
+
help="JSON list of clouds, or @file.json. Cloud keys belong in --from-file, not in a command line. "
|
|
226
|
+
"Not with --cloud-account")
|
|
227
|
+
@click.option("--cloud-account", "cloud_accounts", type=int, multiple=True, metavar="ID",
|
|
228
|
+
help="Run on a connected cloud account (see: mctl cloud-account list). Repeat for more "
|
|
229
|
+
"(one per cloud). Not with --clouds. The API key needs the Infrastructure (infra) scope")
|
|
225
230
|
@click.option("--classes", "classes_", multiple=True, callback=_classes_list,
|
|
226
231
|
help="Runner class; repeat or separate with commas (see: mctl pool classes)")
|
|
227
232
|
@click.option("--max-cost-per-hour", type=float, default=None, help="Cost ceiling in USD per hour")
|
|
233
|
+
@click.option("--set", "sets", multiple=True, metavar="NAME=VALUE",
|
|
234
|
+
help="Set one setting, e.g. regions=us-east-1,us-west-2 with --cloud-account (a flat list; "
|
|
235
|
+
"without it, every region of the accounts). Repeat")
|
|
236
|
+
@click.option("--settings", "settings_json", callback=_json_value, default=None,
|
|
237
|
+
help="JSON object of settings, or @file.json")
|
|
228
238
|
@click.option("--image-by-class", callback=_json_value, default=None, help="JSON object, or @file.json")
|
|
229
239
|
@click.option("--egress-by-class", callback=_json_value, default=None, help="JSON object, or @file.json")
|
|
230
240
|
@click.option("--class-headroom", callback=_json_value, default=None, help="JSON object, or @file.json")
|
|
@@ -237,15 +247,27 @@ def _classes_list(ctx, param, value):
|
|
|
237
247
|
help="Same key and body within 24 hours creates one pool (default: a new random key)")
|
|
238
248
|
@json_option
|
|
239
249
|
@click.pass_context
|
|
240
|
-
def create(ctx, name, github_org, clouds, classes_, max_cost_per_hour,
|
|
241
|
-
class_headroom, spot_policy, cpu_units_requests, from_file,
|
|
242
|
-
|
|
250
|
+
def create(ctx, name, github_org, clouds, cloud_accounts, classes_, max_cost_per_hour, sets, settings_json,
|
|
251
|
+
image_by_class, egress_by_class, class_headroom, spot_policy, cpu_units_requests, from_file,
|
|
252
|
+
idempotency_key, as_json):
|
|
253
|
+
"""Create a CI pool, on cloud keys (--clouds) or on connected cloud accounts (--cloud-account)."""
|
|
243
254
|
body = load_body(from_file)
|
|
244
255
|
body.update(_collect(name=name, github_org=github_org, clouds=clouds, classes=classes_,
|
|
245
256
|
max_cost_per_hour=max_cost_per_hour, image_by_class=image_by_class,
|
|
246
257
|
egress_by_class=egress_by_class, class_headroom=class_headroom,
|
|
247
258
|
spot_policy=spot_policy, cpu_units_requests=cpu_units_requests))
|
|
248
|
-
|
|
259
|
+
if cloud_accounts:
|
|
260
|
+
body["cloud_accounts"] = [{"id": i} for i in cloud_accounts]
|
|
261
|
+
settings = _settings_body(sets, (), settings_json)
|
|
262
|
+
if settings:
|
|
263
|
+
if not isinstance(body.get("settings", {}), dict):
|
|
264
|
+
raise click.UsageError("'settings' in --from-file must be a JSON object.")
|
|
265
|
+
body["settings"] = {**(body.get("settings") or {}), **settings}
|
|
266
|
+
if "clouds" in body and "cloud_accounts" in body:
|
|
267
|
+
raise click.UsageError("Use --cloud-account or --clouds, not both (also not both in --from-file).")
|
|
268
|
+
needed = ("name", "github_org", "classes", "max_cost_per_hour") if "cloud_accounts" in body else \
|
|
269
|
+
("name", "github_org", "clouds", "classes", "max_cost_per_hour")
|
|
270
|
+
missing = [f for f in needed if f not in body]
|
|
249
271
|
if missing:
|
|
250
272
|
raise click.UsageError("Missing: " + ", ".join("--" + m.replace("_", "-") if m != "name" else "NAME"
|
|
251
273
|
for m in missing))
|
|
@@ -253,7 +275,8 @@ def create(ctx, name, github_org, clouds, classes_, max_cost_per_hour, image_by_
|
|
|
253
275
|
|
|
254
276
|
def go(org):
|
|
255
277
|
try:
|
|
256
|
-
return api.call("POST", org, "/pools", body=body, headers={"Idempotency-Key": key},
|
|
278
|
+
return api.call("POST", org, "/pools", body=body, headers={"Idempotency-Key": key},
|
|
279
|
+
scope="infra" if "cloud_accounts" in body else WRITE)
|
|
257
280
|
except api.ApiError as ex:
|
|
258
281
|
if ex.status is None or ex.status >= 500:
|
|
259
282
|
# The pool may exist already: the same key and body make the retry safe.
|
|
@@ -263,6 +286,8 @@ def create(ctx, name, github_org, clouds, classes_, max_cost_per_hour, image_by_
|
|
|
263
286
|
if as_json:
|
|
264
287
|
return _dump(made)
|
|
265
288
|
click.echo(f"Pool {made.get('pool_id')} ({made.get('name')}) created. Status: {_status(made)}")
|
|
289
|
+
for line in quota_lines(made.get("quota")) if "cloud_accounts" in body else ():
|
|
290
|
+
click.echo(line)
|
|
266
291
|
click.echo(f"Next: mctl pool show {made.get('pool_id')}")
|
|
267
292
|
|
|
268
293
|
|
|
@@ -279,7 +304,7 @@ def _put(settings: Dict[str, Any], name: str, value: Any) -> None:
|
|
|
279
304
|
|
|
280
305
|
|
|
281
306
|
_LIST_SETTINGS = ("instance_types", "excluded_instance_types", "accelerator_names",
|
|
282
|
-
"excluded_accelerator_names")
|
|
307
|
+
"excluded_accelerator_names", "regions")
|
|
283
308
|
|
|
284
309
|
|
|
285
310
|
def _settings_body(sets, resets, settings_json) -> Dict[str, Any]:
|
|
@@ -125,6 +125,31 @@ def test_extend_create_flags(monkeypatch):
|
|
|
125
125
|
assert "Next: mctl peering create edge" in r.stdout
|
|
126
126
|
|
|
127
127
|
|
|
128
|
+
def test_extend_create_pool_cloud_account_option(monkeypatch):
|
|
129
|
+
r, calls = run(["extend", "create", "edge", "--cloud-account", "7", "--cloud-account", "9",
|
|
130
|
+
"--max-servers", "5", "--idempotency-key", "k1"], [reply(202, POOL_MADE)], monkeypatch)
|
|
131
|
+
assert r.exit_code == 0, r.output
|
|
132
|
+
method, url, kw = calls[0]
|
|
133
|
+
assert (method, url) == ("POST", f"{BASE}/extend-pools")
|
|
134
|
+
assert kw["json"] == {"name": "edge", "max_servers": 5, "cloud_accounts": [{"id": 7}, {"id": 9}]}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_extend_create_pool_from_file_may_carry_cloud_accounts(monkeypatch, tmp_path):
|
|
138
|
+
f = tmp_path / "p.json"
|
|
139
|
+
f.write_text(json.dumps({"name": "edge", "cloud_accounts": [{"id": 7}]}))
|
|
140
|
+
r, calls = run(["extend", "create", "--from-file", str(f)], [reply(202, POOL_MADE)], monkeypatch)
|
|
141
|
+
assert r.exit_code == 0, r.output
|
|
142
|
+
assert calls[0][2]["json"] == {"name": "edge", "cloud_accounts": [{"id": 7}]}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_extend_create_pool_prints_quota_lines_only_when_the_answer_has_them(monkeypatch):
|
|
146
|
+
r, _ = run(["extend", "create", "edge", "--cloud-account", "7"],
|
|
147
|
+
[reply(202, {**POOL_MADE, "quota": {"notes": ["later"]}})], monkeypatch)
|
|
148
|
+
assert "quota NOTE" in r.stdout
|
|
149
|
+
r, _ = run(["extend", "create", "edge"], [reply(202, POOL_MADE)], monkeypatch)
|
|
150
|
+
assert "quota" not in r.stdout
|
|
151
|
+
|
|
152
|
+
|
|
128
153
|
def test_extend_create_only_name_sends_only_name(monkeypatch):
|
|
129
154
|
r, calls = run(["extend", "create", "edge"], [reply(202, POOL_MADE)], monkeypatch)
|
|
130
155
|
assert calls[0][2]["json"] == {"name": "edge"}
|
|
@@ -416,12 +416,12 @@ def test_create_asks_on_a_terminal_and_defaults_to_yes(tmp_path, monkeypatch):
|
|
|
416
416
|
runner = CliRunner(mix_stderr=False)
|
|
417
417
|
except TypeError:
|
|
418
418
|
runner = CliRunner()
|
|
419
|
-
r = runner.invoke(mctl, ["cloud-account", "create", "--cloud", "AWS", "--account", ACCT], input="\n")
|
|
419
|
+
r = runner.invoke(mctl, ["cloud-account", "create", "--cloud", "AWS", "--account", ACCT], input="\n\n")
|
|
420
420
|
assert r.exit_code == 0, r.output
|
|
421
421
|
assert "Turn on the AWS opt-in regions in this account? [Y/n]" in r.stderr
|
|
422
422
|
assert req.call_args.kwargs["json"]["enable_opt_in_regions"] is True
|
|
423
423
|
(tmp_path / "multicloud.tf").unlink()
|
|
424
|
-
r = runner.invoke(mctl, ["cloud-account", "create", "--cloud", "AWS", "--account", ACCT], input="n\n")
|
|
424
|
+
r = runner.invoke(mctl, ["cloud-account", "create", "--cloud", "AWS", "--account", ACCT], input="n\n\n")
|
|
425
425
|
assert r.exit_code == 0, r.output
|
|
426
426
|
assert req.call_args.kwargs["json"]["enable_opt_in_regions"] is False
|
|
427
427
|
|
|
@@ -637,7 +637,7 @@ def test_create_new_account_email_retype_mismatch_is_refused(tmp_path, monkeypat
|
|
|
637
637
|
def test_create_new_account_email_retype_match_works(tmp_path, monkeypatch):
|
|
638
638
|
monkeypatch.chdir(tmp_path)
|
|
639
639
|
r, req = _create_a(["--cloud", "AWS", "--new-account-email", EMAIL, "--opt-in-regions"], tty=True,
|
|
640
|
-
typed=EMAIL + "\n", monkeypatch=monkeypatch)
|
|
640
|
+
typed=EMAIL + "\n\n", monkeypatch=monkeypatch)
|
|
641
641
|
assert r.exit_code == 0, r.output
|
|
642
642
|
assert (tmp_path / "multicloud.auto.tfvars").exists()
|
|
643
643
|
|
|
@@ -923,3 +923,119 @@ def test_disconnect_a_never_connected_account_has_no_next_step():
|
|
|
923
923
|
r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, pending), reply(200, REVOKED)])
|
|
924
924
|
assert r.exit_code == 0 and "Disconnected:" in r.stdout
|
|
925
925
|
assert "Next:" not in r.stdout
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
# --- quota request consent (onboarding decision 28) -----------------------------------------
|
|
929
|
+
|
|
930
|
+
def _record_calls(monkeypatch, answers):
|
|
931
|
+
"""Replace ``cmds.call``; ``answers`` maps (method, tail) to a body or an exception."""
|
|
932
|
+
calls = []
|
|
933
|
+
|
|
934
|
+
def fake(method, org, tail="", *, body=None, headers=None, accept=(200, 201, 202), prefer_sso=False):
|
|
935
|
+
calls.append((method, tail, body, prefer_sso))
|
|
936
|
+
answer = answers[(method, tail)]
|
|
937
|
+
if isinstance(answer, Exception):
|
|
938
|
+
raise answer
|
|
939
|
+
return {**answer, "_status": 201 if method == "POST" else 200}
|
|
940
|
+
monkeypatch.setattr(cmds, "call", fake)
|
|
941
|
+
return calls
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
def _run_create(args, monkeypatch, tty, stdin="", answers=None):
|
|
945
|
+
monkeypatch.setattr(cmds, "_stdin_is_tty", lambda: tty)
|
|
946
|
+
calls = _record_calls(monkeypatch, answers or {
|
|
947
|
+
("POST", ""): CREATED, ("PUT", "/5/quota-consent"): {"id": 5, "quota_consent_by": "bearer u1",
|
|
948
|
+
"quota_consent_on": "2026-11-12T10:00:00Z"}})
|
|
949
|
+
with patch.dict("os.environ", {"MULTICLOUD_API_KEY": "fake-key-0000", "MULTICLOUD_ORG": "acme"}):
|
|
950
|
+
try:
|
|
951
|
+
runner = CliRunner(mix_stderr=False)
|
|
952
|
+
except TypeError:
|
|
953
|
+
runner = CliRunner()
|
|
954
|
+
r = runner.invoke(mctl, ["cloud-account", "create", "--cloud", "AWS", "--account", ACCT,
|
|
955
|
+
"--no-opt-in-regions", *args], input=stdin)
|
|
956
|
+
return r, calls
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
def test_create_asks_about_quota_requests_and_defaults_to_no(tmp_path, monkeypatch):
|
|
960
|
+
monkeypatch.chdir(tmp_path)
|
|
961
|
+
r, calls = _run_create([], monkeypatch, tty=True, stdin="\n")
|
|
962
|
+
assert r.exit_code == 0, r.output
|
|
963
|
+
assert "Allow Multicloud to request higher quotas in this account? [y/N]" in r.stderr
|
|
964
|
+
assert [c[0] for c in calls] == ["POST"]
|
|
965
|
+
assert "mctl cloud-account allow-quota-requests 5" in r.stdout
|
|
966
|
+
|
|
967
|
+
|
|
968
|
+
def test_create_yes_allows_quota_requests_with_the_sign_in(tmp_path, monkeypatch):
|
|
969
|
+
monkeypatch.chdir(tmp_path)
|
|
970
|
+
r, calls = _run_create([], monkeypatch, tty=True, stdin="y\n")
|
|
971
|
+
assert r.exit_code == 0, r.output
|
|
972
|
+
assert calls[-1] == ("PUT", "/5/quota-consent", None, True)
|
|
973
|
+
assert "Quota requests allowed (by bearer u1)." in r.stdout
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
def test_create_without_a_terminal_never_allows(tmp_path, monkeypatch):
|
|
977
|
+
monkeypatch.chdir(tmp_path)
|
|
978
|
+
r, calls = _run_create([], monkeypatch, tty=False)
|
|
979
|
+
assert r.exit_code == 0, r.output
|
|
980
|
+
assert [c[0] for c in calls] == ["POST"]
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
def test_create_flag_allows_without_asking(tmp_path, monkeypatch):
|
|
984
|
+
monkeypatch.chdir(tmp_path)
|
|
985
|
+
r, calls = _run_create(["--allow-quota-requests"], monkeypatch, tty=False)
|
|
986
|
+
assert r.exit_code == 0, r.output
|
|
987
|
+
assert "higher quotas" not in r.stderr
|
|
988
|
+
assert calls[-1][:2] == ("PUT", "/5/quota-consent")
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
def test_create_keeps_the_account_when_the_consent_is_refused(tmp_path, monkeypatch):
|
|
992
|
+
monkeypatch.chdir(tmp_path)
|
|
993
|
+
refused = cmds.CloudAccountError("403: An organization owner must approve this", 1)
|
|
994
|
+
r, calls = _run_create(["--allow-quota-requests"], monkeypatch, tty=False,
|
|
995
|
+
answers={("POST", ""): CREATED, ("PUT", "/5/quota-consent"): refused})
|
|
996
|
+
assert r.exit_code == 0, r.output
|
|
997
|
+
assert (tmp_path / "multicloud.tf").exists()
|
|
998
|
+
assert "Quota requests are not allowed" in r.stderr
|
|
999
|
+
assert "mctl cloud-account allow-quota-requests 5" in r.stderr
|
|
1000
|
+
|
|
1001
|
+
|
|
1002
|
+
def test_allow_and_revoke_quota_requests(monkeypatch):
|
|
1003
|
+
calls = _record_calls(monkeypatch, {
|
|
1004
|
+
("PUT", "/5/quota-consent"): {"id": 5, "quota_consent_by": "bearer u1", "quota_consent_on": "t"},
|
|
1005
|
+
("DELETE", "/5/quota-consent"): {"id": 5, "quota_consent_by": None, "quota_consent_on": None}})
|
|
1006
|
+
with patch.dict("os.environ", {"MULTICLOUD_ORG": "acme"}):
|
|
1007
|
+
runner = CliRunner()
|
|
1008
|
+
r = runner.invoke(mctl, ["cloud-account", "allow-quota-requests", "5"])
|
|
1009
|
+
assert r.exit_code == 0, r.output
|
|
1010
|
+
assert "Multicloud may now request higher quotas in cloud account 5" in r.output
|
|
1011
|
+
r = runner.invoke(mctl, ["cloud-account", "revoke-quota-requests", "5"])
|
|
1012
|
+
assert r.exit_code == 0, r.output
|
|
1013
|
+
assert "Multicloud no longer requests higher quotas in cloud account 5" in r.output
|
|
1014
|
+
assert [(c[0], c[1], c[3]) for c in calls] == [("PUT", "/5/quota-consent", True),
|
|
1015
|
+
("DELETE", "/5/quota-consent", True)]
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
def test_verify_prints_planned_quota_lines(monkeypatch):
|
|
1019
|
+
quota = {"consent": False, "planned": [{"quota": "AWS/us-east-1/spot-g", "code": "L-3819A6DF",
|
|
1020
|
+
"region": "us-east-1", "current": 8.0, "required": 40.0}],
|
|
1021
|
+
"notes": ["Multicloud does not request higher quotas in this account. An organization owner allows "
|
|
1022
|
+
"that with: mctl cloud-account allow-quota-requests 5"]}
|
|
1023
|
+
r, _, _ = run_verify(["5"], [reply(200, {**VERIFIED, "quota": quota})], monkeypatch)
|
|
1024
|
+
assert r.exit_code == 0, r.output
|
|
1025
|
+
assert "quota LOW AWS/us-east-1/spot-g: 8 -> 40 (not requested)" in r.stdout
|
|
1026
|
+
assert "mctl cloud-account allow-quota-requests 5" in r.stdout
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
def test_show_prints_the_quota_consent():
|
|
1030
|
+
text = cmds._readable({"id": 5, "cloud": "AWS", "status": "verified", "quota_consent_by": "bearer u1",
|
|
1031
|
+
"quota_consent_on": "2026-11-12T10:00:00Z"})
|
|
1032
|
+
assert "Quota requests: allowed by bearer u1 on 2026-11-12T10:00:00Z" in text
|
|
1033
|
+
assert "Quota requests: not allowed" in cmds._readable({"id": 5, "cloud": "AWS", "status": "verified"})
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
def test_create_json_prints_the_account_after_the_consent(tmp_path, monkeypatch):
|
|
1037
|
+
monkeypatch.chdir(tmp_path)
|
|
1038
|
+
r, calls = _run_create(["--allow-quota-requests", "--json"], monkeypatch, tty=False)
|
|
1039
|
+
assert r.exit_code == 0, r.output
|
|
1040
|
+
printed = json.loads(r.stdout)
|
|
1041
|
+
assert printed["quota_consent_on"] == "2026-11-12T10:00:00Z" and "_status" not in printed
|
|
@@ -116,6 +116,54 @@ def test_create_body_equals_flags(monkeypatch):
|
|
|
116
116
|
assert "Pool 7 (ci) created" in r.stdout
|
|
117
117
|
|
|
118
118
|
|
|
119
|
+
def test_pool_create_cloud_account_option_builds_body(monkeypatch):
|
|
120
|
+
quota = {"filed": [], "notes": ["spot quota is not checked or filed for pools on connected cloud accounts"]}
|
|
121
|
+
r, calls, _ = run(["create", "ci", "--github-org", "acme-gh", "--cloud-account", "7", "--cloud-account", "9",
|
|
122
|
+
"--classes", "cpu-4", "--max-cost-per-hour", "2.5", "--set", "regions=us-east-1,us-west-2",
|
|
123
|
+
"--idempotency-key", "k1"],
|
|
124
|
+
[reply(201, {**pool_view(), "quota": quota})], monkeypatch)
|
|
125
|
+
assert r.exit_code == 0, r.output
|
|
126
|
+
method, url, kw = calls[0]
|
|
127
|
+
assert (method, url) == ("POST", f"{BASE}/pools")
|
|
128
|
+
# CreatePoolRequest with cloud_accounts: no clouds key, regions in settings (H5)
|
|
129
|
+
assert kw["json"] == {"name": "ci", "github_org": "acme-gh", "cloud_accounts": [{"id": 7}, {"id": 9}],
|
|
130
|
+
"classes": ["cpu-4"], "max_cost_per_hour": 2.5,
|
|
131
|
+
"settings": {"regions": ["us-east-1", "us-west-2"]}}
|
|
132
|
+
assert "quota NOTE" in r.stdout and "quota FILED" not in r.stdout
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_pool_create_cloud_account_and_clouds_are_exclusive(monkeypatch, tmp_path):
|
|
136
|
+
base = ["create", "ci", "--github-org", "g", "--classes", "cpu-4", "--max-cost-per-hour", "1"]
|
|
137
|
+
r, calls, _ = run(base + ["--cloud-account", "7", "--clouds", '[{"type":"AWS"}]'],
|
|
138
|
+
[reply(201, pool_view())], monkeypatch)
|
|
139
|
+
assert r.exit_code == 2 and not calls and "not both" in r.stderr
|
|
140
|
+
f = tmp_path / "p.json"
|
|
141
|
+
f.write_text(json.dumps({"clouds": [{"type": "AWS"}]}))
|
|
142
|
+
r, calls, _ = run(base + ["--cloud-account", "7", "--from-file", str(f)], [reply(201, pool_view())], monkeypatch)
|
|
143
|
+
assert r.exit_code == 2 and not calls
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_pool_create_from_file_may_carry_cloud_accounts(monkeypatch, tmp_path):
|
|
147
|
+
body = {"name": "ci", "github_org": "g", "cloud_accounts": [{"id": 7}], "classes": ["cpu-4"],
|
|
148
|
+
"max_cost_per_hour": 1.0, "settings": {"regions": ["us-east-1"]}}
|
|
149
|
+
f = tmp_path / "pool.json"
|
|
150
|
+
f.write_text(json.dumps(body))
|
|
151
|
+
r, calls, _ = run(["create", "--from-file", str(f)], [reply(201, pool_view())], monkeypatch)
|
|
152
|
+
assert r.exit_code == 0, r.output
|
|
153
|
+
assert calls[0][2]["json"] == body
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_pool_create_without_any_cloud_names_both_options(monkeypatch):
|
|
157
|
+
r, calls, _ = run(["create", "ci", "--github-org", "g", "--classes", "cpu-4", "--max-cost-per-hour", "1"],
|
|
158
|
+
[reply(201, pool_view())], monkeypatch)
|
|
159
|
+
assert r.exit_code == 2 and not calls and "--clouds" in r.stderr
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_pool_create_help_names_the_infra_scope():
|
|
163
|
+
r = CliRunner().invoke(mctl, ["pool", "create", "--help"])
|
|
164
|
+
assert "--cloud-account" in r.output and "infra" in r.output
|
|
165
|
+
|
|
166
|
+
|
|
119
167
|
def test_create_from_file_and_flag_override(monkeypatch, tmp_path):
|
|
120
168
|
# CreatePoolRequest
|
|
121
169
|
body = {"name": "ci", "github_org": "acme-gh", "clouds": [{"type": "AWS"}], "classes": ["cpu-4"],
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.5.2"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|