multicloud-cli 0.9.1__tar.gz → 0.10.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.9.1 → multicloud_cli-0.10.0}/PKG-INFO +1 -1
- multicloud_cli-0.10.0/multicloud_cli/__init__.py +1 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/cloud_account.py +121 -13
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_cloud_account.py +110 -1
- multicloud_cli-0.9.1/multicloud_cli/__init__.py +0 -1
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/.gitignore +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/LICENSE +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/README.md +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/account.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/api.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/auth.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/catalog.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/config.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/duration.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/exitcodes.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/extend.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/main.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/net.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/node.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/orgopt.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/output.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/pool.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/ssh.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/ssh_cert.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/sso.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/multicloud_cli/version_check.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/pyproject.toml +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/__init__.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/conftest.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/helpers.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_account_extend.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_apply.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_auth.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_catalog.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_conventions.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_net.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_pool.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_ssh.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_ssh_cert.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_sso.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_sso_session.py +0 -0
- {multicloud_cli-0.9.1 → multicloud_cli-0.10.0}/tests/test_version_check.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: multicloud-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.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.10.0"
|
|
@@ -39,7 +39,7 @@ _LOCATION_LINE = re.compile(r'^(\s*location\s*=\s*)"[^"\n]*"', re.M)
|
|
|
39
39
|
#: The API snippet has no provider block, and azurerm needs one (features {}, the subscription).
|
|
40
40
|
#: Same as deploy/customer-terraform/examples/azure/main.tf.
|
|
41
41
|
AZURE_HEADER = """terraform {{
|
|
42
|
-
required_version = ">= 1.
|
|
42
|
+
required_version = ">= 1.10.0"
|
|
43
43
|
|
|
44
44
|
required_providers {{
|
|
45
45
|
azurerm = {{
|
|
@@ -56,8 +56,10 @@ provider "azurerm" {{
|
|
|
56
56
|
|
|
57
57
|
subscription_id = "{subscription}"
|
|
58
58
|
|
|
59
|
-
#
|
|
59
|
+
# Register only the four resource providers that Multicloud needs. The provider registers a missing
|
|
60
|
+
# one and never unregisters one. Without "none" it would register a long list first.
|
|
60
61
|
resource_provider_registrations = "none"
|
|
62
|
+
resource_providers_to_register = ["Microsoft.Compute", "Microsoft.ManagedIdentity", "Microsoft.Network", "Microsoft.Quota"]
|
|
61
63
|
}}
|
|
62
64
|
|
|
63
65
|
"""
|
|
@@ -75,12 +77,12 @@ class CloudAccountError(exitcodes.CliError):
|
|
|
75
77
|
|
|
76
78
|
def call(method: str, org: Optional[str], tail: str = "", *, body: Optional[Dict[str, Any]] = None,
|
|
77
79
|
headers: Optional[Dict[str, str]] = None, accept=(200, 201, 202),
|
|
78
|
-
prefer_sso: bool = False) -> Dict[str, Any]:
|
|
80
|
+
prefer_sso: bool = False, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
79
81
|
"""One API call. Returns the JSON body with ``_status`` added; raises on other statuses.
|
|
80
82
|
``prefer_sso`` uses the sign-in even when ``MULTICLOUD_API_KEY`` is set (the owner-only routes)."""
|
|
81
83
|
try:
|
|
82
84
|
return api.call(method, org, "/cloud-accounts" + tail, body=body, headers=headers, accept=accept,
|
|
83
|
-
pass_codes=("VERIFY_FAILED",), prefer_sso=prefer_sso)
|
|
85
|
+
pass_codes=("VERIFY_FAILED",), prefer_sso=prefer_sso, params=params)
|
|
84
86
|
except api.ApiError as ex:
|
|
85
87
|
raise CloudAccountError(str(ex), ex.exit_code)
|
|
86
88
|
|
|
@@ -147,7 +149,7 @@ def _num(value):
|
|
|
147
149
|
|
|
148
150
|
|
|
149
151
|
#: Onboarding decision 28: the question ``create`` asks, default No.
|
|
150
|
-
QUOTA_QUESTION = "Allow Multicloud to request higher quotas in this account?"
|
|
152
|
+
QUOTA_QUESTION = "Allow Multicloud to request higher quotas in this account later?"
|
|
151
153
|
ALLOW_QUOTA_COMMAND = "mctl cloud-account allow-quota-requests {id}"
|
|
152
154
|
|
|
153
155
|
|
|
@@ -339,9 +341,9 @@ def create(ctx, cloud, account, location, new_email, regions, force, opt_in, all
|
|
|
339
341
|
--region stays the list of locations Multicloud may use. Run apply after 'az login' as an Owner of the
|
|
340
342
|
subscription.
|
|
341
343
|
|
|
342
|
-
Quota requests:
|
|
343
|
-
(--allow-quota-requests, or 'y' at
|
|
344
|
-
|
|
344
|
+
Quota requests: verify only reads the quotas and tells you what is low; it requests none. Requests are
|
|
345
|
+
made later through the quota dialogue, and only when you allow it (--allow-quota-requests, or 'y' at
|
|
346
|
+
the question). Change it later with allow-quota-requests or revoke-quota-requests."""
|
|
345
347
|
cloud = cloud.upper()
|
|
346
348
|
gce, azure = cloud == "GCE", cloud == "AZURE"
|
|
347
349
|
if location and not azure:
|
|
@@ -460,9 +462,9 @@ def _ask_quota(cloud: str) -> bool:
|
|
|
460
462
|
if not _stdin_is_tty():
|
|
461
463
|
return False
|
|
462
464
|
service = "Azure Microsoft.Quota" if cloud == "AZURE" else "AWS Service Quotas"
|
|
463
|
-
click.echo(f"
|
|
464
|
-
"
|
|
465
|
-
err=True)
|
|
465
|
+
click.echo(f"Verify only reads the quotas in this account ({service}); it requests none. Requests are made "
|
|
466
|
+
"later through the quota dialogue and need your consent. Until then, request higher quotas "
|
|
467
|
+
"yourself where verify shows quota LOW.", err=True)
|
|
466
468
|
return click.confirm(QUOTA_QUESTION, default=False, err=True)
|
|
467
469
|
|
|
468
470
|
|
|
@@ -483,7 +485,7 @@ def _create_quota_consent(ctx, acct_id, allow: bool, say) -> Optional[Dict[str,
|
|
|
483
485
|
A refusal (no owner sign-in) keeps the account and says so on stderr."""
|
|
484
486
|
command = ALLOW_QUOTA_COMMAND.format(id=acct_id)
|
|
485
487
|
if not allow:
|
|
486
|
-
say(f"Quota requests: not allowed. To allow
|
|
488
|
+
say(f"Quota requests: not allowed (verify requests none). To allow the quota dialogue to request later: {command}")
|
|
487
489
|
return None
|
|
488
490
|
try:
|
|
489
491
|
answer = call("PUT", ctx.obj.get("cloud_account_org"), f"/{acct_id}/quota-consent", prefer_sso=True)
|
|
@@ -492,7 +494,7 @@ def _create_quota_consent(ctx, acct_id, allow: bool, say) -> Optional[Dict[str,
|
|
|
492
494
|
f"allows them with: {command}", err=True)
|
|
493
495
|
return None
|
|
494
496
|
answer.pop("_status", None)
|
|
495
|
-
say(f"Quota requests allowed (by {answer.get('quota_consent_by')}).")
|
|
497
|
+
say(f"Quota requests allowed (by {answer.get('quota_consent_by')}). Verify still requests none; the quota dialogue uses this consent.")
|
|
496
498
|
return answer
|
|
497
499
|
|
|
498
500
|
|
|
@@ -768,6 +770,98 @@ def revoke_quota_requests(ctx, account_id):
|
|
|
768
770
|
f"filed stay open in the cloud.")
|
|
769
771
|
|
|
770
772
|
|
|
773
|
+
def quota_plan_lines(data: Dict[str, Any]) -> list:
|
|
774
|
+
"""Readable lines for the answer of ``GET .../quota-plan-data``."""
|
|
775
|
+
lines = []
|
|
776
|
+
budget = data.get("budget") or {}
|
|
777
|
+
if budget:
|
|
778
|
+
lines.append("request budget: " + ", ".join(f"{k}={v}" for k, v in sorted(budget.items())))
|
|
779
|
+
lines.append("quota requests: " + ("allowed" if data.get("consent") else "NOT allowed (allow-quota-requests)"))
|
|
780
|
+
for region in data.get("regions") or []:
|
|
781
|
+
lines.append(f"{region.get('region')}:")
|
|
782
|
+
if region.get("history_error"):
|
|
783
|
+
lines.append(f" history unreadable: {region['history_error']}")
|
|
784
|
+
for q in region.get("quotas") or []:
|
|
785
|
+
head = f" {q.get('key')} ({q.get('code')}): "
|
|
786
|
+
lines.append(head + (f"limit {_num(q.get('current_limit'))}" if q.get("error") is None
|
|
787
|
+
else f"unreadable: {q['error']}"))
|
|
788
|
+
o = q.get("open_request")
|
|
789
|
+
if o:
|
|
790
|
+
lines.append(f" OPEN request {o.get('id')}: {_num(o.get('desired'))} ({o.get('status')})")
|
|
791
|
+
d = q.get("latest_denial")
|
|
792
|
+
if d:
|
|
793
|
+
state = (f"wait until {d.get('cooldown_until')}; confirm with --confirm-denied {d.get('request_id')}"
|
|
794
|
+
if d.get("cooldown_active") else "wait is over")
|
|
795
|
+
reason = f" ({d['reason']})" if d.get("reason") else ""
|
|
796
|
+
lines.append(f" DENIED {d.get('date')}, request {d.get('request_id')}{reason}: {state}")
|
|
797
|
+
return lines
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
@cloud_account.command(name="quota-plan")
|
|
801
|
+
@click.argument("account_id", type=int)
|
|
802
|
+
@click.option("--region", "regions", multiple=True, help="Region to read (repeat; at most 10). Required")
|
|
803
|
+
@click.option("--code", "codes", multiple=True, help="Quota code to read (repeat). Default: the four spot and on-demand codes")
|
|
804
|
+
@json_option
|
|
805
|
+
@click.pass_context
|
|
806
|
+
def quota_plan(ctx, account_id, regions, codes, as_json):
|
|
807
|
+
"""Read the quota data for the quota dialogue: limits, open requests, denials, request budget (AWS).
|
|
808
|
+
|
|
809
|
+
Files nothing. Output per region and quota: current limit, an open request, the latest denial and
|
|
810
|
+
the end of its 30-day wait."""
|
|
811
|
+
regions = list(dict.fromkeys(r.strip() for r in regions if r.strip()))
|
|
812
|
+
if not regions:
|
|
813
|
+
raise click.UsageError("Name at least one --region, for example --region us-east-1.")
|
|
814
|
+
if len(regions) > 10:
|
|
815
|
+
raise click.UsageError("At most 10 regions per call.")
|
|
816
|
+
params = {"regions": ",".join(regions)}
|
|
817
|
+
codes = list(dict.fromkeys(c.strip() for c in codes if c.strip()))
|
|
818
|
+
if codes:
|
|
819
|
+
params["codes"] = ",".join(codes)
|
|
820
|
+
answer = _run(ctx, lambda org: call("GET", org, f"/{account_id}/quota-plan-data", params=params))
|
|
821
|
+
if as_json:
|
|
822
|
+
_dump(answer)
|
|
823
|
+
return
|
|
824
|
+
click.echo("\n".join(quota_plan_lines(answer)))
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
@cloud_account.command(name="quota-request")
|
|
828
|
+
@click.argument("account_id", type=int)
|
|
829
|
+
@click.option("--region", required=True, help="Region to file in, for example us-east-1")
|
|
830
|
+
@click.option("--code", required=True, help="Quota code, for example L-3819A6DF (spot G and VT vCPUs)")
|
|
831
|
+
@click.option("--desired", required=True, type=click.FloatRange(min=0, min_open=True, max=10_000_000),
|
|
832
|
+
help="New limit to ask for (above 0, at most 10000000)")
|
|
833
|
+
@click.option("--confirm-denied", "confirm_denied", default=None,
|
|
834
|
+
help="Request id of the denial shown by quota-plan: files again although AWS denied this quota in the last 30 days")
|
|
835
|
+
@json_option
|
|
836
|
+
@click.pass_context
|
|
837
|
+
def quota_request(ctx, account_id, region, code, desired, confirm_denied, as_json):
|
|
838
|
+
"""File one quota increase (AWS). Needs consent: mctl cloud-account allow-quota-requests ID.
|
|
839
|
+
|
|
840
|
+
A quota AWS denied in the last 30 days is not filed again until you pass --confirm-denied with the
|
|
841
|
+
denial's request id (shown by quota-plan and in the answer)."""
|
|
842
|
+
item = {"region": region, "code": code, "desired": desired}
|
|
843
|
+
if confirm_denied and confirm_denied.strip():
|
|
844
|
+
item["confirm_denied"] = confirm_denied.strip()
|
|
845
|
+
answer = _run(ctx, lambda org: call("POST", org, f"/{account_id}/quota-requests", body={"requests": [item]}))
|
|
846
|
+
if as_json:
|
|
847
|
+
_dump(answer)
|
|
848
|
+
return
|
|
849
|
+
lines = quota_lines(answer)
|
|
850
|
+
for d in answer.get("deferred") or []:
|
|
851
|
+
denial = d.get("denial") or {}
|
|
852
|
+
if denial.get("request_id"):
|
|
853
|
+
lines.append(f"quota NOTE denied {denial.get('date')} (request {denial['request_id']}); "
|
|
854
|
+
f"to file anyway add: --confirm-denied {denial['request_id']}")
|
|
855
|
+
for u in answer.get("unmatched_confirmations") or []:
|
|
856
|
+
lines.append(f"quota NOTE --confirm-denied {u.get('confirm_denied')} lifted nothing: {u.get('reason')}")
|
|
857
|
+
if answer.get("consent") is False:
|
|
858
|
+
lines.append("quota NOTE NOTHING FILED: quota requests are not allowed. Run: "
|
|
859
|
+
+ ALLOW_QUOTA_COMMAND.format(id=account_id))
|
|
860
|
+
click.echo("\n".join(lines) if lines else "Nothing filed.")
|
|
861
|
+
if answer.get("consent") is False:
|
|
862
|
+
sys.exit(exitcodes.ERROR)
|
|
863
|
+
|
|
864
|
+
|
|
771
865
|
WAIT_DEFAULT = "130m" # the cleanup job gives up after about two hours
|
|
772
866
|
WAIT_INTERVAL = 30
|
|
773
867
|
|
|
@@ -892,10 +986,24 @@ def disconnect(ctx, account_id, yes, wait, timeout):
|
|
|
892
986
|
click.echo("Next: remove the Multicloud managed identity and role from the subscription. Run 'tofu destroy' "
|
|
893
987
|
f"(or 'terraform destroy') in the folder with {TF_FILE}.")
|
|
894
988
|
return
|
|
989
|
+
if data.get("cloud") == "AWS" and _module_before_2(data.get("module_version")):
|
|
990
|
+
click.echo(f"First: in the folder with {TF_FILE}, change the module version to 2.0.0, run 'tofu init -upgrade' "
|
|
991
|
+
"(or 'terraform init -upgrade'), then plan and apply. The plan must show the three service-linked "
|
|
992
|
+
"roles as forgotten and nothing to destroy. Module " + str(data.get("module_version")) + " deletes "
|
|
993
|
+
"the EC2 Spot, EC2 Fleet and Service Quotas service-linked roles of the account on destroy; 2.0.0 "
|
|
994
|
+
"keeps them.")
|
|
895
995
|
click.echo("Next: remove the Multicloud role from the account. Run 'tofu destroy' (or 'terraform destroy') in "
|
|
896
996
|
f"the folder with {TF_FILE}, or 'mctl cloud-account destroy {account_id}' if mctl created the AWS account.")
|
|
897
997
|
|
|
898
998
|
|
|
999
|
+
def _module_before_2(version) -> bool:
|
|
1000
|
+
"""The AWS module before 2.0.0 deletes the account's service-linked roles on destroy. Unknown: False."""
|
|
1001
|
+
try:
|
|
1002
|
+
return int(str(version).strip().lstrip("vV").split(".")[0]) < 2
|
|
1003
|
+
except (TypeError, ValueError):
|
|
1004
|
+
return False
|
|
1005
|
+
|
|
1006
|
+
|
|
899
1007
|
def _find_tool(requested: Optional[str]) -> str:
|
|
900
1008
|
if requested:
|
|
901
1009
|
if not shutil.which(requested):
|
|
@@ -592,6 +592,8 @@ def test_create_azure_sends_the_subscription_and_writes_a_runnable_file(tmp_path
|
|
|
592
592
|
assert 'provider "azurerm" {' in tf and "features {}" in tf
|
|
593
593
|
assert f'subscription_id = "{AZ_SUB}"' in tf
|
|
594
594
|
assert 'resource_provider_registrations = "none"' in tf
|
|
595
|
+
assert ('resource_providers_to_register = ["Microsoft.Compute", "Microsoft.ManagedIdentity", '
|
|
596
|
+
'"Microsoft.Network", "Microsoft.Quota"]') in tf
|
|
595
597
|
assert 'source = "hashicorp/azurerm"' in tf
|
|
596
598
|
assert 'location = "westeurope"' in tf and "REPLACE-WITH" not in tf
|
|
597
599
|
assert tf.count('module "multicloud"') == 1
|
|
@@ -1053,6 +1055,35 @@ def test_disconnect_with_yes_uses_the_sign_in():
|
|
|
1053
1055
|
assert "X-API-Key" not in sent.kwargs["headers"]
|
|
1054
1056
|
assert f"Disconnected: AWS account {ACCT} is no longer connected to Multicloud." in r.stdout
|
|
1055
1057
|
assert "tofu destroy" in r.stdout and "mctl cloud-account destroy 5" in r.stdout
|
|
1058
|
+
assert "First:" not in r.stdout # module version unknown: no upgrade line
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
def test_disconnect_module_before_2_says_upgrade_before_destroy():
|
|
1062
|
+
old = {**VERIFIED_CONNECTED, "module_version": "1.3.1"}
|
|
1063
|
+
r, _ = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, old), reply(200, REVOKED)])
|
|
1064
|
+
assert r.exit_code == 0, r.output
|
|
1065
|
+
first, nxt = r.stdout.index("First: "), r.stdout.index("Next: remove the Multicloud role")
|
|
1066
|
+
assert first < nxt and "2.0.0" in r.stdout and "init -upgrade" in r.stdout and "nothing to destroy" in r.stdout and "service-linked roles" in r.stdout
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
def test_disconnect_v_prefixed_old_module_still_warns():
|
|
1070
|
+
old = {**VERIFIED_CONNECTED, "module_version": "v1.3.1"}
|
|
1071
|
+
r, _ = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, old), reply(200, REVOKED)])
|
|
1072
|
+
assert "First: " in r.stdout
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
def test_disconnect_gce_old_module_prints_no_aws_upgrade_line():
|
|
1076
|
+
gce = {**VERIFIED_CONNECTED, "cloud": "GCE", "module_version": "1.0.1"}
|
|
1077
|
+
r, _ = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, gce), reply(200, {**gce, "status": "revoked"})])
|
|
1078
|
+
assert r.exit_code == 0, r.output
|
|
1079
|
+
assert "First:" not in r.stdout
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
def test_disconnect_module_2_prints_no_upgrade_line():
|
|
1083
|
+
new = {**VERIFIED_CONNECTED, "module_version": "2.0.0"}
|
|
1084
|
+
r, _ = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, new), reply(200, REVOKED)])
|
|
1085
|
+
assert r.exit_code == 0, r.output
|
|
1086
|
+
assert "First:" not in r.stdout and "tofu destroy" in r.stdout
|
|
1056
1087
|
|
|
1057
1088
|
|
|
1058
1089
|
def test_disconnect_asks_first():
|
|
@@ -1220,7 +1251,7 @@ def test_create_asks_about_quota_requests_and_defaults_to_no(tmp_path, monkeypat
|
|
|
1220
1251
|
monkeypatch.chdir(tmp_path)
|
|
1221
1252
|
r, calls = _run_create([], monkeypatch, tty=True, stdin="\n")
|
|
1222
1253
|
assert r.exit_code == 0, r.output
|
|
1223
|
-
assert "Allow Multicloud to request higher quotas in this account? [y/N]" in r.stderr
|
|
1254
|
+
assert "Allow Multicloud to request higher quotas in this account later? [y/N]" in r.stderr
|
|
1224
1255
|
assert [c[0] for c in calls] == ["POST"]
|
|
1225
1256
|
assert "mctl cloud-account allow-quota-requests 5" in r.stdout
|
|
1226
1257
|
|
|
@@ -1299,3 +1330,81 @@ def test_create_json_prints_the_account_after_the_consent(tmp_path, monkeypatch)
|
|
|
1299
1330
|
assert r.exit_code == 0, r.output
|
|
1300
1331
|
printed = json.loads(r.stdout)
|
|
1301
1332
|
assert printed["quota_consent_on"] == "2026-11-12T10:00:00Z" and "_status" not in printed
|
|
1333
|
+
|
|
1334
|
+
|
|
1335
|
+
# --- quota-plan and quota-request (the quota dialogue's data and filing calls) ---
|
|
1336
|
+
|
|
1337
|
+
PLAN = {"consent": True, "budget": {"account_active": 3, "account_cap": 20},
|
|
1338
|
+
"regions": [{"region": "us-east-1", "quotas": [
|
|
1339
|
+
{"key": "spot-g", "code": "L-3819A6DF", "current_limit": 0.0,
|
|
1340
|
+
"open_request": {"id": "r-1", "desired": 8, "status": "PENDING"}},
|
|
1341
|
+
{"key": "spot-standard", "code": "L-34B43A08", "current_limit": 64.0,
|
|
1342
|
+
"latest_denial": {"request_id": "d-9", "status": "DENIED", "date": "2026-11-01",
|
|
1343
|
+
"cooldown_until": "2026-12-01", "cooldown_active": True}},
|
|
1344
|
+
{"key": "ondemand-g", "code": "L-DB2E81BA", "error": "ClientError: AccessDenied"}]},
|
|
1345
|
+
{"region": "eu-west-1", "quotas": [], "history_error": "ClientError: AccessDenied"}]}
|
|
1346
|
+
|
|
1347
|
+
|
|
1348
|
+
def test_quota_plan_prints_limits_open_requests_and_denials():
|
|
1349
|
+
r, req = invoke(["cloud-account", "quota-plan", "5", "--region", "us-east-1", "--region", "eu-west-1"],
|
|
1350
|
+
reply(200, PLAN))
|
|
1351
|
+
assert r.exit_code == 0, r.output
|
|
1352
|
+
method, url = req.call_args[0][:2]
|
|
1353
|
+
assert (method, url) == ("GET", "https://api.multicloud.io/api/v1/orgs/acme/cloud-accounts/5/quota-plan-data")
|
|
1354
|
+
assert req.call_args[1]["params"] == {"regions": "us-east-1,eu-west-1"} or "regions=us-east-1%2Ceu-west-1" in str(req.call_args)
|
|
1355
|
+
out = r.stdout
|
|
1356
|
+
assert "us-east-1" in out and "spot-g" in out and "L-3819A6DF" in out
|
|
1357
|
+
assert "OPEN" in out and "r-1" in out
|
|
1358
|
+
assert "DENIED" in out and "d-9" in out and "2026-12-01" in out
|
|
1359
|
+
assert "AccessDenied" in out
|
|
1360
|
+
assert "eu-west-1" in out and "history" in out.lower()
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
def test_quota_plan_json_prints_the_raw_answer():
|
|
1364
|
+
r, _ = invoke(["cloud-account", "quota-plan", "5", "--region", "us-east-1", "--json"], reply(200, PLAN))
|
|
1365
|
+
assert json.loads(r.stdout)["budget"]["account_cap"] == 20
|
|
1366
|
+
|
|
1367
|
+
|
|
1368
|
+
def test_quota_request_sends_one_item_and_prints_the_outcome():
|
|
1369
|
+
answer = {"filed": [{"quota": "AWS/us-east-1/spot-g", "desired": 8, "request_id": "r-7"}],
|
|
1370
|
+
"deferred": [], "refused": [], "already_open": [], "unmatched_confirmations": []}
|
|
1371
|
+
r, req = invoke(["cloud-account", "quota-request", "5", "--region", "us-east-1", "--code", "L-3819A6DF",
|
|
1372
|
+
"--desired", "8"], reply(200, answer))
|
|
1373
|
+
assert r.exit_code == 0, r.output
|
|
1374
|
+
assert req.call_args[0][:2] == ("POST", "https://api.multicloud.io/api/v1/orgs/acme/cloud-accounts/5/quota-requests")
|
|
1375
|
+
assert req.call_args[1]["json"] == {"requests": [{"region": "us-east-1", "code": "L-3819A6DF", "desired": 8.0}]}
|
|
1376
|
+
assert "quota FILED" in r.stdout and "r-7" in r.stdout
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
def test_quota_request_confirm_denied_is_sent_and_a_denial_is_shown():
|
|
1380
|
+
answer = {"deferred": [{"quota": "AWS/us-east-1/spot-g", "reason": "denied 2026-11-01",
|
|
1381
|
+
"denial": {"request_id": "d-9", "status": "DENIED", "date": "2026-11-01"}}],
|
|
1382
|
+
"unmatched_confirmations": [{"region": "us-east-1", "code": "L-3819A6DF", "confirm_denied": "x",
|
|
1383
|
+
"reason": "not the latest denial"}]}
|
|
1384
|
+
r, req = invoke(["cloud-account", "quota-request", "5", "--region", "us-east-1", "--code", "L-3819A6DF",
|
|
1385
|
+
"--desired", "8", "--confirm-denied", "x"], reply(200, answer))
|
|
1386
|
+
assert req.call_args[1]["json"]["requests"][0]["confirm_denied"] == "x"
|
|
1387
|
+
assert "quota LATER" in r.stdout and "d-9" in r.stdout and "--confirm-denied d-9" in r.stdout
|
|
1388
|
+
assert "not the latest denial" in r.stdout
|
|
1389
|
+
|
|
1390
|
+
|
|
1391
|
+
def test_quota_request_without_consent_names_the_allow_command():
|
|
1392
|
+
answer = {"consent": False, "filed": [], "planned": [{"quota": "AWS/us-east-1/spot-g", "current": 0, "required": 8}]}
|
|
1393
|
+
r, _ = invoke(["cloud-account", "quota-request", "5", "--region", "us-east-1", "--code", "L-3819A6DF",
|
|
1394
|
+
"--desired", "8"], reply(200, answer))
|
|
1395
|
+
assert "mctl cloud-account allow-quota-requests 5" in r.stdout
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
def test_quota_request_refuses_a_bad_desired_and_exits_nonzero_without_consent():
|
|
1399
|
+
r, req = invoke(["cloud-account", "quota-request", "5", "--region", "us-east-1", "--code", "C", "--desired", "0"],
|
|
1400
|
+
reply(200, {}))
|
|
1401
|
+
assert r.exit_code != 0 and not req.called
|
|
1402
|
+
r, _ = invoke(["cloud-account", "quota-request", "5", "--region", "us-east-1", "--code", "C", "--desired", "8"],
|
|
1403
|
+
reply(200, {"consent": False, "planned": []}))
|
|
1404
|
+
assert r.exit_code != 0 and "NOTHING FILED" in r.stdout
|
|
1405
|
+
|
|
1406
|
+
|
|
1407
|
+
def test_quota_plan_refuses_more_than_ten_regions():
|
|
1408
|
+
args = ["cloud-account", "quota-plan", "5"] + [a for i in range(11) for a in ("--region", f"r{i}")]
|
|
1409
|
+
r, req = invoke(args, reply(200, {}))
|
|
1410
|
+
assert r.exit_code != 0 and not req.called
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.9.1"
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|