multicloud-cli 0.6.0__tar.gz → 0.7.1__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.
Files changed (40) hide show
  1. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/PKG-INFO +1 -1
  2. multicloud_cli-0.7.1/multicloud_cli/__init__.py +1 -0
  3. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/cloud_account.py +117 -8
  4. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/pool.py +12 -1
  5. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_cloud_account.py +155 -3
  6. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_conventions.py +2 -1
  7. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_pool.py +42 -0
  8. multicloud_cli-0.6.0/multicloud_cli/__init__.py +0 -1
  9. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/.gitignore +0 -0
  10. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/LICENSE +0 -0
  11. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/README.md +0 -0
  12. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/account.py +0 -0
  13. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/api.py +0 -0
  14. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/auth.py +0 -0
  15. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/catalog.py +0 -0
  16. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/config.py +0 -0
  17. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/duration.py +0 -0
  18. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/exitcodes.py +0 -0
  19. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/extend.py +0 -0
  20. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/main.py +0 -0
  21. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/net.py +0 -0
  22. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/node.py +0 -0
  23. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/orgopt.py +0 -0
  24. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/output.py +0 -0
  25. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/ssh.py +0 -0
  26. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/ssh_cert.py +0 -0
  27. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/multicloud_cli/sso.py +0 -0
  28. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/pyproject.toml +0 -0
  29. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/__init__.py +0 -0
  30. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/conftest.py +0 -0
  31. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/helpers.py +0 -0
  32. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_account_extend.py +0 -0
  33. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_apply.py +0 -0
  34. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_auth.py +0 -0
  35. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_catalog.py +0 -0
  36. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_net.py +0 -0
  37. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_ssh.py +0 -0
  38. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_ssh_cert.py +0 -0
  39. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/tests/test_sso.py +0 -0
  40. {multicloud_cli-0.6.0 → multicloud_cli-0.7.1}/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.6.0
3
+ Version: 0.7.1
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.1"
@@ -60,6 +60,14 @@ def call(method: str, org: Optional[str], tail: str = "", *, body: Optional[Dict
60
60
  _NOUN = {"AWS": "AWS account", "GCE": "GCP project", "AZURE": "Azure subscription"}
61
61
 
62
62
 
63
+ # The cloud's own id of an account (what accept-shared-account wants typed), and what it looks like.
64
+ _NATIVE_ID = {
65
+ "AWS": ("AWS account ID", "12 digits, for example 123456789012"),
66
+ "GCE": ("GCP project ID", "lower-case letters, digits and hyphens, for example my-project-123"),
67
+ "AZURE": ("Azure subscription ID", "a GUID, for example 0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0"),
68
+ }
69
+
70
+
63
71
  def noun_of(cloud: Optional[str]) -> str:
64
72
  return _NOUN.get(str(cloud or "").upper(), "cloud account")
65
73
 
@@ -105,6 +113,22 @@ def describe_verify(answer: Dict[str, Any]) -> str:
105
113
  return out
106
114
 
107
115
 
116
+ def _num(value):
117
+ """8.0 -> 8; anything else as it is."""
118
+ return int(value) if isinstance(value, float) and value.is_integer() else value
119
+
120
+
121
+ #: Onboarding decision 28: the question ``create`` asks, default No.
122
+ QUOTA_QUESTION = "Allow Multicloud to request higher quotas in this account?"
123
+ ALLOW_QUOTA_COMMAND = "mctl cloud-account allow-quota-requests {id}"
124
+
125
+
126
+ def quota_consent_label(account: Dict[str, Any]) -> str:
127
+ if account.get("quota_consent_on"):
128
+ return f"allowed by {account.get('quota_consent_by')} on {account.get('quota_consent_on')}"
129
+ return "not allowed"
130
+
131
+
108
132
  def quota_lines(quota: Optional[Dict[str, Any]]) -> list:
109
133
  """One line per item of the ``quota`` block of a verify answer."""
110
134
  quota = quota or {}
@@ -117,6 +141,9 @@ def quota_lines(quota: Optional[Dict[str, Any]]) -> list:
117
141
  lines.append(f"quota LATER {d.get('quota')}: {d.get('reason')}")
118
142
  for r in quota.get("refused") or []:
119
143
  lines.append(f"quota NO {r.get('quota')}: {r.get('error')}")
144
+ for p in quota.get("planned") or []:
145
+ lines.append(f"quota LOW {p.get('quota')}: {_num(p.get('current'))} -> {_num(p.get('required'))} "
146
+ f"(not requested)")
120
147
  for label in quota.get("sufficient") or []:
121
148
  lines.append(f"quota OK {label}")
122
149
  for u in quota.get("unknown") or []:
@@ -242,7 +269,8 @@ def _file_exists(name: str):
242
269
 
243
270
 
244
271
  @cloud_account.command()
245
- @click.option("--cloud", required=True, type=click.Choice(["AWS", "GCE"], case_sensitive=False))
272
+ @click.option("--cloud", required=True, type=click.Choice(["AWS", "GCE"], case_sensitive=False),
273
+ help="AWS or GCE (Google Cloud). Azure: not available in mctl yet")
246
274
  @click.option("--account", help="AWS: pin the 12-digit AWS account id (optional; not allowed for GCE)")
247
275
  @click.option("--new-account-email", "new_email", metavar="EMAIL",
248
276
  help="AWS: create a new AWS account for Multicloud in your AWS Organizations, with this email "
@@ -252,9 +280,12 @@ def _file_exists(name: str):
252
280
  @click.option("--opt-in-regions/--no-opt-in-regions", "opt_in", default=None,
253
281
  help="AWS: turn on the opt-in regions of the account that are off (default: yes; "
254
282
  "asks when stdin is a terminal)")
283
+ @click.option("--allow-quota-requests/--no-allow-quota-requests", "allow_quota", default=None,
284
+ help="AWS: allow Multicloud to request higher quotas in this account (default: no; asks when "
285
+ "stdin is a terminal). Needs an organization owner's sign-in")
255
286
  @json_option
256
287
  @click.pass_context
257
- def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
288
+ def create(ctx, cloud, account, new_email, regions, force, opt_in, allow_quota, as_json):
258
289
  """Register an account and write multicloud.tf. No token is printed.
259
290
 
260
291
  An existing multicloud.tf is kept: a new external id in it would cut off a connected account.
@@ -265,7 +296,11 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
265
296
 
266
297
  AWS opt-in regions (for example af-south-1) are off in a new account. With the default, Multicloud
267
298
  turns them on (only the --region ones when you give --region). That takes minutes to hours; verify
268
- again to add them."""
299
+ again to add them.
300
+
301
+ Quota requests: Multicloud files a quota increase request in the account only when you allow it
302
+ (--allow-quota-requests, or 'y' at the question). Without it, verify only reads the quotas and tells
303
+ you what to request. Change it later with allow-quota-requests or revoke-quota-requests."""
269
304
  gce = cloud.upper() == "GCE"
270
305
  if gce and account:
271
306
  raise click.UsageError("--account is not allowed for GCE: Multicloud generates the project id.")
@@ -276,6 +311,9 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
276
311
  "has no ID yet.")
277
312
  if gce and opt_in is not None:
278
313
  raise click.UsageError("--opt-in-regions applies to AWS only.")
314
+ if gce and allow_quota is not None:
315
+ raise click.UsageError("--allow-quota-requests applies to AWS only: Multicloud files no GCP quota "
316
+ "request.")
279
317
  if new_email:
280
318
  new_email = new_email.strip()
281
319
  if not _EMAIL.match(new_email):
@@ -301,6 +339,14 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
301
339
  opt_in = (click.confirm("Turn on the AWS opt-in regions in this account?", default=True, err=True)
302
340
  if _stdin_is_tty() else True)
303
341
  body["enable_opt_in_regions"] = bool(opt_in)
342
+ if allow_quota is None:
343
+ if _stdin_is_tty():
344
+ click.echo("Multicloud can request higher spot quotas in this account (AWS Service Quotas) when "
345
+ "they are too low for your pools. Without it, Multicloud only reads the quotas and "
346
+ "tells you what to request.", err=True)
347
+ allow_quota = click.confirm(QUOTA_QUESTION, default=False, err=True)
348
+ else:
349
+ allow_quota = False
304
350
  if regions:
305
351
  body["regions"] = list(regions)
306
352
  made = _run(ctx, lambda org: call("POST", org, body=body))
@@ -316,9 +362,12 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
316
362
  except FileExistsError:
317
363
  _file_exists(TFVARS_FILE)
318
364
  acct_id = made["account"]["id"]
319
- if as_json: # the created account; the Terraform file is in multicloud.tf
320
- _dump(made["account"])
321
365
  say = lambda text: click.echo(text, err=as_json) # noqa: E731
366
+ shown, consent_lines = made["account"], []
367
+ if not gce:
368
+ shown = _create_quota_consent(ctx, acct_id, allow_quota, consent_lines.append) or shown
369
+ if as_json: # the created account (after the consent call); the Terraform file is in multicloud.tf
370
+ _dump(shown)
322
371
  if gce:
323
372
  target = f"GCP project {made['account'].get('expected_native_id')}"
324
373
  elif account:
@@ -335,10 +384,30 @@ def create(ctx, cloud, account, new_email, regions, force, opt_in, as_json):
335
384
  elif not gce and not account:
336
385
  say("The AWS account ID is read when the module connects. The account should be a new AWS account "
337
386
  "made for Multicloud.")
387
+ for line in consent_lines:
388
+ say(line)
338
389
  say(f"Next: mctl cloud-account apply {acct_id}")
339
390
  say(f"By hand: mctl cloud-account token {acct_id}, then tofu apply (or terraform apply).")
340
391
 
341
392
 
393
+ def _create_quota_consent(ctx, acct_id, allow: bool, say) -> Optional[Dict[str, Any]]:
394
+ """After create: allow quota requests when asked to. Returns the account the allow call answered, else None.
395
+ A refusal (no owner sign-in) keeps the account and says so on stderr."""
396
+ command = ALLOW_QUOTA_COMMAND.format(id=acct_id)
397
+ if not allow:
398
+ say(f"Quota requests: not allowed. To allow them later: {command}")
399
+ return None
400
+ try:
401
+ answer = call("PUT", ctx.obj.get("cloud_account_org"), f"/{acct_id}/quota-consent", prefer_sso=True)
402
+ except CloudAccountError as ex:
403
+ click.echo(f"Quota requests are not allowed: {ex}. The account was created. An organization owner "
404
+ f"allows them with: {command}", err=True)
405
+ return None
406
+ answer.pop("_status", None)
407
+ say(f"Quota requests allowed (by {answer.get('quota_consent_by')}).")
408
+ return answer
409
+
410
+
342
411
  @cloud_account.command()
343
412
  @click.argument("account_id", type=int)
344
413
  @click.pass_context
@@ -392,6 +461,7 @@ def _readable(data: Dict[str, Any]) -> str:
392
461
  ("Dedicated", dedicated_label(data)),
393
462
  ("Shared account approved by", data.get("shared_risk_accepted_by")),
394
463
  ("Shared account approved on", data.get("shared_risk_accepted_on")),
464
+ ("Quota requests", quota_consent_label(data)),
395
465
  ]
396
466
  if data.get("approval_required"):
397
467
  lines += approval_lines(data.get("cloud"), data.get("id"))
@@ -540,6 +610,10 @@ def accept_shared_account(ctx, account_id):
540
610
  click.echo(f"Error: cloud account {account_id} needs no approval ({describe_verify(data)}; "
541
611
  f"dedicated: {dedicated_label(data)}).", err=True)
542
612
  sys.exit(exitcodes.ERROR)
613
+ if not native:
614
+ click.echo(f"Error: cloud account {account_id} has no cloud id yet, so there is nothing to approve. "
615
+ f"Run: mctl cloud-account verify {account_id}", err=True)
616
+ sys.exit(exitcodes.ERROR)
543
617
  noun = noun_of(cloud)
544
618
  for line in shared_warning(cloud):
545
619
  click.echo(line)
@@ -547,9 +621,17 @@ def accept_shared_account(ctx, account_id):
547
621
  if not _stdin_is_tty():
548
622
  click.echo("Error: the approval needs a person at a terminal: type the id when asked.", err=True)
549
623
  sys.exit(exitcodes.ERROR)
550
- typed = click.prompt(f"To connect {noun} {native} anyway, type its id", default="", show_default=False)
551
- if not native or not typed.strip() or typed.strip().lower() != str(native).lower():
552
- click.echo("The id does not match. Nothing approved.", err=True)
624
+ kind, example = _NATIVE_ID.get(str(cloud or "").upper(), ("cloud id", "the id your cloud shows"))
625
+ click.echo(f"To connect it anyway, type the {kind} ({native}). The {kind} is {example}. "
626
+ f"It is not the Multicloud cloud account id {account_id}.")
627
+ typed = click.prompt(kind, default="", show_default=False).strip()
628
+ if not native or not typed or typed.lower() != str(native).lower():
629
+ if typed == str(account_id):
630
+ click.echo(f"You typed the Multicloud cloud account id {account_id}. Type the {kind} {native} "
631
+ f"instead.", err=True)
632
+ else:
633
+ click.echo(f"The id does not match the {kind} {native}.", err=True)
634
+ click.echo("Nothing approved.", err=True)
553
635
  sys.exit(exitcodes.ERROR)
554
636
  answer = _run(ctx, lambda org: call("POST", org, f"/{account_id}/accept-shared-account",
555
637
  body={"account_id": typed.strip()}, prefer_sso=True))
@@ -567,6 +649,33 @@ def accept_shared_account(ctx, account_id):
567
649
  sys.exit(exitcodes.ERROR)
568
650
 
569
651
 
652
+ @cloud_account.command(name="allow-quota-requests")
653
+ @click.argument("account_id", type=int)
654
+ @click.pass_context
655
+ def allow_quota_requests(ctx, account_id):
656
+ """Allow Multicloud to request higher quotas in this account (organization owners only).
657
+
658
+ Multicloud then files quota increase requests (AWS Service Quotas, Azure Microsoft.Quota) when the spot
659
+ quota is too low for your pools, at most a few per day. Needs a sign-in (mctl auth login), not an API key.
660
+ Undo with revoke-quota-requests."""
661
+ answer = _run(ctx, lambda org: call("PUT", org, f"/{account_id}/quota-consent", prefer_sso=True))
662
+ click.echo(f"Multicloud may now request higher quotas in cloud account {account_id} "
663
+ f"({quota_consent_label(answer)}). The next verify files what is needed: "
664
+ f"mctl cloud-account verify {account_id}")
665
+
666
+
667
+ @cloud_account.command(name="revoke-quota-requests")
668
+ @click.argument("account_id", type=int)
669
+ @click.pass_context
670
+ def revoke_quota_requests(ctx, account_id):
671
+ """Stop Multicloud from requesting higher quotas in this account (organization owners only).
672
+
673
+ Requests already filed stay open in the cloud; cancel them in the cloud console if you want."""
674
+ _run(ctx, lambda org: call("DELETE", org, f"/{account_id}/quota-consent", prefer_sso=True))
675
+ click.echo(f"Multicloud no longer requests higher quotas in cloud account {account_id}. Requests already "
676
+ f"filed stay open in the cloud.")
677
+
678
+
570
679
  IN_USE = "ACCOUNT_IN_USE"
571
680
 
572
681
 
@@ -285,7 +285,18 @@ def create(ctx, name, github_org, clouds, cloud_accounts, classes_, max_cost_per
285
285
  made = _run(ctx, go)
286
286
  if as_json:
287
287
  return _dump(made)
288
- click.echo(f"Pool {made.get('pool_id')} ({made.get('name')}) created. Status: {_status(made)}")
288
+ pool_id = made.get("pool_id")
289
+
290
+ def view(org):
291
+ # The 201 body has no name and no status: read them from the pool. The pool exists either way.
292
+ try:
293
+ return api.call("GET", org, f"/pools/{pool_id}", scope=READ)
294
+ except api.ApiError:
295
+ return None
296
+ shown = _run(ctx, view) if pool_id is not None else None
297
+ text = f"Pool {pool_id} ({(shown or {}).get('name') or body['name']}) created."
298
+ click.echo(text + (f" Status: {_status(shown)}" if shown and shown.get("status")
299
+ else " Status: not read yet (see the next command)."))
289
300
  for line in quota_lines(made.get("quota")) if "cloud_accounts" in body else ():
290
301
  click.echo(line)
291
302
  click.echo(f"Next: mctl pool show {made.get('pool_id')}")
@@ -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
 
@@ -535,6 +535,42 @@ def test_accept_shared_account_wrong_id_approves_nothing():
535
535
  assert "Nothing approved" in r.stderr
536
536
 
537
537
 
538
+ @pytest.mark.parametrize("cloud,native,kind,example", [
539
+ ("AWS", "123456789012", "AWS account ID", "12 digits"),
540
+ ("GCE", "mc-acme-1a2b", "GCP project ID", "my-project-123"),
541
+ ("AZURE", SUB, "Azure subscription ID", "GUID"),
542
+ ])
543
+ def test_accept_shared_account_prompt_names_the_native_id_not_the_row_id(cloud, native, kind, example):
544
+ # Live run 2026-11-12: the operator typed the Multicloud row id at "type its id".
545
+ shared = {**SHARED, "cloud": cloud, "expected_native_id": native}
546
+ r, req = invoke_seq(["cloud-account", "accept-shared-account", "7"], [reply(200, shared)], input="7\n")
547
+ assert r.exit_code == 1 and req.call_count == 1 # nothing posted
548
+ assert f"type the {kind} ({native})" in r.output and example in r.output
549
+ assert "not the Multicloud cloud account id 7" in r.output
550
+ assert "You typed the Multicloud cloud account id 7" in r.stderr
551
+ assert "Nothing approved" in r.stderr
552
+
553
+
554
+ def test_accept_shared_account_without_a_cloud_id_stops_before_the_prompt():
555
+ bare = {**SHARED, "expected_native_id": None, "native_id": None}
556
+ r, req = invoke_seq(["cloud-account", "accept-shared-account", "7"], [reply(200, bare)], input="x\n")
557
+ assert r.exit_code == 1 and req.call_count == 1
558
+ assert "has no cloud id yet" in r.stderr and "This Azure subscription" not in r.output
559
+
560
+
561
+ def test_accept_shared_account_wrong_id_says_what_was_expected():
562
+ r, _ = invoke_seq(["cloud-account", "accept-shared-account", "7"], [reply(200, SHARED)], input="nope\n")
563
+ assert r.exit_code == 1
564
+ assert f"does not match the Azure subscription ID {SUB}" in r.stderr
565
+
566
+
567
+ def test_create_cloud_choice_says_azure_is_not_available_yet():
568
+ r, req = invoke(["cloud-account", "create", "--cloud", "AZURE"], reply(200, {}))
569
+ assert r.exit_code == 2 and not req.called
570
+ r, _ = invoke(["cloud-account", "create", "--help"], reply(200, {}))
571
+ assert "Azure: not available in mctl yet" in " ".join(r.output.split())
572
+
573
+
538
574
  def test_accept_shared_account_has_no_yes_and_needs_a_terminal():
539
575
  r, _ = invoke_seq(["cloud-account", "accept-shared-account", "7", "--yes"], [])
540
576
  assert r.exit_code == 2
@@ -637,7 +673,7 @@ def test_create_new_account_email_retype_mismatch_is_refused(tmp_path, monkeypat
637
673
  def test_create_new_account_email_retype_match_works(tmp_path, monkeypatch):
638
674
  monkeypatch.chdir(tmp_path)
639
675
  r, req = _create_a(["--cloud", "AWS", "--new-account-email", EMAIL, "--opt-in-regions"], tty=True,
640
- typed=EMAIL + "\n", monkeypatch=monkeypatch)
676
+ typed=EMAIL + "\n\n", monkeypatch=monkeypatch)
641
677
  assert r.exit_code == 0, r.output
642
678
  assert (tmp_path / "multicloud.auto.tfvars").exists()
643
679
 
@@ -923,3 +959,119 @@ def test_disconnect_a_never_connected_account_has_no_next_step():
923
959
  r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, pending), reply(200, REVOKED)])
924
960
  assert r.exit_code == 0 and "Disconnected:" in r.stdout
925
961
  assert "Next:" not in r.stdout
962
+
963
+
964
+ # --- quota request consent (onboarding decision 28) -----------------------------------------
965
+
966
+ def _record_calls(monkeypatch, answers):
967
+ """Replace ``cmds.call``; ``answers`` maps (method, tail) to a body or an exception."""
968
+ calls = []
969
+
970
+ def fake(method, org, tail="", *, body=None, headers=None, accept=(200, 201, 202), prefer_sso=False):
971
+ calls.append((method, tail, body, prefer_sso))
972
+ answer = answers[(method, tail)]
973
+ if isinstance(answer, Exception):
974
+ raise answer
975
+ return {**answer, "_status": 201 if method == "POST" else 200}
976
+ monkeypatch.setattr(cmds, "call", fake)
977
+ return calls
978
+
979
+
980
+ def _run_create(args, monkeypatch, tty, stdin="", answers=None):
981
+ monkeypatch.setattr(cmds, "_stdin_is_tty", lambda: tty)
982
+ calls = _record_calls(monkeypatch, answers or {
983
+ ("POST", ""): CREATED, ("PUT", "/5/quota-consent"): {"id": 5, "quota_consent_by": "bearer u1",
984
+ "quota_consent_on": "2026-11-12T10:00:00Z"}})
985
+ with patch.dict("os.environ", {"MULTICLOUD_API_KEY": "fake-key-0000", "MULTICLOUD_ORG": "acme"}):
986
+ try:
987
+ runner = CliRunner(mix_stderr=False)
988
+ except TypeError:
989
+ runner = CliRunner()
990
+ r = runner.invoke(mctl, ["cloud-account", "create", "--cloud", "AWS", "--account", ACCT,
991
+ "--no-opt-in-regions", *args], input=stdin)
992
+ return r, calls
993
+
994
+
995
+ def test_create_asks_about_quota_requests_and_defaults_to_no(tmp_path, monkeypatch):
996
+ monkeypatch.chdir(tmp_path)
997
+ r, calls = _run_create([], monkeypatch, tty=True, stdin="\n")
998
+ assert r.exit_code == 0, r.output
999
+ assert "Allow Multicloud to request higher quotas in this account? [y/N]" in r.stderr
1000
+ assert [c[0] for c in calls] == ["POST"]
1001
+ assert "mctl cloud-account allow-quota-requests 5" in r.stdout
1002
+
1003
+
1004
+ def test_create_yes_allows_quota_requests_with_the_sign_in(tmp_path, monkeypatch):
1005
+ monkeypatch.chdir(tmp_path)
1006
+ r, calls = _run_create([], monkeypatch, tty=True, stdin="y\n")
1007
+ assert r.exit_code == 0, r.output
1008
+ assert calls[-1] == ("PUT", "/5/quota-consent", None, True)
1009
+ assert "Quota requests allowed (by bearer u1)." in r.stdout
1010
+
1011
+
1012
+ def test_create_without_a_terminal_never_allows(tmp_path, monkeypatch):
1013
+ monkeypatch.chdir(tmp_path)
1014
+ r, calls = _run_create([], monkeypatch, tty=False)
1015
+ assert r.exit_code == 0, r.output
1016
+ assert [c[0] for c in calls] == ["POST"]
1017
+
1018
+
1019
+ def test_create_flag_allows_without_asking(tmp_path, monkeypatch):
1020
+ monkeypatch.chdir(tmp_path)
1021
+ r, calls = _run_create(["--allow-quota-requests"], monkeypatch, tty=False)
1022
+ assert r.exit_code == 0, r.output
1023
+ assert "higher quotas" not in r.stderr
1024
+ assert calls[-1][:2] == ("PUT", "/5/quota-consent")
1025
+
1026
+
1027
+ def test_create_keeps_the_account_when_the_consent_is_refused(tmp_path, monkeypatch):
1028
+ monkeypatch.chdir(tmp_path)
1029
+ refused = cmds.CloudAccountError("403: An organization owner must approve this", 1)
1030
+ r, calls = _run_create(["--allow-quota-requests"], monkeypatch, tty=False,
1031
+ answers={("POST", ""): CREATED, ("PUT", "/5/quota-consent"): refused})
1032
+ assert r.exit_code == 0, r.output
1033
+ assert (tmp_path / "multicloud.tf").exists()
1034
+ assert "Quota requests are not allowed" in r.stderr
1035
+ assert "mctl cloud-account allow-quota-requests 5" in r.stderr
1036
+
1037
+
1038
+ def test_allow_and_revoke_quota_requests(monkeypatch):
1039
+ calls = _record_calls(monkeypatch, {
1040
+ ("PUT", "/5/quota-consent"): {"id": 5, "quota_consent_by": "bearer u1", "quota_consent_on": "t"},
1041
+ ("DELETE", "/5/quota-consent"): {"id": 5, "quota_consent_by": None, "quota_consent_on": None}})
1042
+ with patch.dict("os.environ", {"MULTICLOUD_ORG": "acme"}):
1043
+ runner = CliRunner()
1044
+ r = runner.invoke(mctl, ["cloud-account", "allow-quota-requests", "5"])
1045
+ assert r.exit_code == 0, r.output
1046
+ assert "Multicloud may now request higher quotas in cloud account 5" in r.output
1047
+ r = runner.invoke(mctl, ["cloud-account", "revoke-quota-requests", "5"])
1048
+ assert r.exit_code == 0, r.output
1049
+ assert "Multicloud no longer requests higher quotas in cloud account 5" in r.output
1050
+ assert [(c[0], c[1], c[3]) for c in calls] == [("PUT", "/5/quota-consent", True),
1051
+ ("DELETE", "/5/quota-consent", True)]
1052
+
1053
+
1054
+ def test_verify_prints_planned_quota_lines(monkeypatch):
1055
+ quota = {"consent": False, "planned": [{"quota": "AWS/us-east-1/spot-g", "code": "L-3819A6DF",
1056
+ "region": "us-east-1", "current": 8.0, "required": 40.0}],
1057
+ "notes": ["Multicloud does not request higher quotas in this account. An organization owner allows "
1058
+ "that with: mctl cloud-account allow-quota-requests 5"]}
1059
+ r, _, _ = run_verify(["5"], [reply(200, {**VERIFIED, "quota": quota})], monkeypatch)
1060
+ assert r.exit_code == 0, r.output
1061
+ assert "quota LOW AWS/us-east-1/spot-g: 8 -> 40 (not requested)" in r.stdout
1062
+ assert "mctl cloud-account allow-quota-requests 5" in r.stdout
1063
+
1064
+
1065
+ def test_show_prints_the_quota_consent():
1066
+ text = cmds._readable({"id": 5, "cloud": "AWS", "status": "verified", "quota_consent_by": "bearer u1",
1067
+ "quota_consent_on": "2026-11-12T10:00:00Z"})
1068
+ assert "Quota requests: allowed by bearer u1 on 2026-11-12T10:00:00Z" in text
1069
+ assert "Quota requests: not allowed" in cmds._readable({"id": 5, "cloud": "AWS", "status": "verified"})
1070
+
1071
+
1072
+ def test_create_json_prints_the_account_after_the_consent(tmp_path, monkeypatch):
1073
+ monkeypatch.chdir(tmp_path)
1074
+ r, calls = _run_create(["--allow-quota-requests", "--json"], monkeypatch, tty=False)
1075
+ assert r.exit_code == 0, r.output
1076
+ printed = json.loads(r.stdout)
1077
+ assert printed["quota_consent_on"] == "2026-11-12T10:00:00Z" and "_status" not in printed
@@ -239,7 +239,8 @@ def test_create_from_stdin_and_json_option_from_stdin(net):
239
239
  r = runner().invoke(mctl, ["pool", "create", "ci", "--github-org", "g", "--clouds", "@-", "--classes", "cpu-4",
240
240
  "--max-cost-per-hour", "2"], input=json.dumps([{"type": "AWS"}]))
241
241
  assert r.exit_code == 0, r.stderr
242
- assert net["calls"][1][2]["json"]["clouds"] == [{"type": "AWS"}]
242
+ posts = [c for c in net["calls"] if c[0] == "POST"] # each create also reads the new pool (GET)
243
+ assert posts[1][2]["json"]["clouds"] == [{"type": "AWS"}]
243
244
 
244
245
 
245
246
  def test_rotation_status_and_deprecated_flag(net):
@@ -132,6 +132,48 @@ def test_pool_create_cloud_account_option_builds_body(monkeypatch):
132
132
  assert "quota NOTE" in r.stdout and "quota FILED" not in r.stdout
133
133
 
134
134
 
135
+ def created_body(pool_id=7):
136
+ """The 201 body of POST /pools (pools_service.onboard): no name and no status, unlike a PoolView."""
137
+ return {"pool_id": pool_id, "cluster_slug": "acme-ci", "github_app_manifest_url": "https://github.test/m",
138
+ "github_app_manifest": {}, "cache_bucket": {}, "clouds": [],
139
+ "quota": {"filed": [], "notes": ["spot quota is not checked or filed for pools on connected "
140
+ "cloud accounts"]},
141
+ "cloud_accounts": [{"id": 9, "cloud": "AWS", "regions": [], "via": "own"}], "grants": [], "notes": []}
142
+
143
+
144
+ def test_pool_create_prints_name_and_status_from_the_pool(monkeypatch):
145
+ # Live run 2026-11-12 printed "Pool 7 (None) created. Status: unknown".
146
+ r, calls, _ = run(["create", "ci", "--github-org", "acme-gh", "--cloud-account", "9", "--classes", "cpu-4",
147
+ "--max-cost-per-hour", "0.05"],
148
+ [reply(201, created_body()), reply(200, pool_view(7, "ci", status="provisioning",
149
+ status_message="TCP_NOT_READY"))],
150
+ monkeypatch)
151
+ assert r.exit_code == 0, r.output
152
+ assert [c[:2] for c in calls] == [("POST", f"{BASE}/pools"), ("GET", f"{BASE}/pools/7")]
153
+ assert "Pool 7 (ci) created. Status: provisioning (TCP_NOT_READY)" in r.stdout
154
+ assert "None" not in r.stdout and "unknown" not in r.stdout
155
+ assert "quota NOTE" in r.stdout
156
+ assert "Next: mctl pool show 7" in r.stdout
157
+
158
+
159
+ def test_pool_create_still_succeeds_when_the_status_read_fails(monkeypatch):
160
+ r, calls, _ = run(["create", "ci", "--github-org", "acme-gh", "--cloud-account", "9", "--classes", "cpu-4",
161
+ "--max-cost-per-hour", "0.05"],
162
+ [reply(201, created_body()), reply(503, {"detail": "busy"})], monkeypatch)
163
+ assert r.exit_code == 0, r.output
164
+ assert len(calls) == 2
165
+ assert "Pool 7 (ci) created." in r.stdout and "None" not in r.stdout
166
+ assert "Status: unknown" not in r.stdout and "Status: not read yet" in r.stdout
167
+ assert "Next: mctl pool show 7" in r.stdout
168
+
169
+
170
+ def test_pool_create_json_is_the_raw_create_body(monkeypatch):
171
+ r, calls, _ = run(["create", "ci", "--github-org", "acme-gh", "--cloud-account", "9", "--classes", "cpu-4",
172
+ "--max-cost-per-hour", "0.05", "--json"], [reply(201, created_body())], monkeypatch)
173
+ assert r.exit_code == 0, r.output
174
+ assert len(calls) == 1 and json.loads(r.stdout) == created_body()
175
+
176
+
135
177
  def test_pool_create_cloud_account_and_clouds_are_exclusive(monkeypatch, tmp_path):
136
178
  base = ["create", "ci", "--github-org", "g", "--classes", "cpu-4", "--max-cost-per-hour", "1"]
137
179
  r, calls, _ = run(base + ["--cloud-account", "7", "--clouds", '[{"type":"AWS"}]'],
@@ -1 +0,0 @@
1
- __version__ = "0.6.0"
File without changes
File without changes