multicloud-cli 0.5.1__tar.gz → 0.5.2__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.1 → multicloud_cli-0.5.2}/PKG-INFO +1 -1
- multicloud_cli-0.5.2/multicloud_cli/__init__.py +1 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/cloud_account.py +75 -4
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_cloud_account.py +95 -1
- multicloud_cli-0.5.1/multicloud_cli/__init__.py +0 -1
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/.gitignore +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/LICENSE +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/README.md +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/account.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/api.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/auth.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/catalog.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/config.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/duration.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/exitcodes.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/extend.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/main.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/net.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/node.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/orgopt.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/output.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/pool.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/ssh.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/ssh_cert.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/multicloud_cli/sso.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/pyproject.toml +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/__init__.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/conftest.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/helpers.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_account_extend.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_apply.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_auth.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_catalog.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_conventions.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_net.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_pool.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_ssh.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_ssh_cert.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/tests/test_sso.py +0 -0
- {multicloud_cli-0.5.1 → multicloud_cli-0.5.2}/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.5.
|
|
3
|
+
Version: 0.5.2
|
|
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.5.2"
|
|
@@ -567,6 +567,70 @@ def accept_shared_account(ctx, account_id):
|
|
|
567
567
|
sys.exit(exitcodes.ERROR)
|
|
568
568
|
|
|
569
569
|
|
|
570
|
+
IN_USE = "ACCOUNT_IN_USE"
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def _disconnect(org, account_id: int, again: str = "disconnect") -> Dict[str, Any]:
|
|
574
|
+
"""``DELETE /cloud-accounts/{id}`` with the sign-in. Returns the account; raises ``CloudAccountError`` with
|
|
575
|
+
calm text when a pool still uses it (nothing changed then)."""
|
|
576
|
+
try:
|
|
577
|
+
answer = api.call("DELETE", org, f"/cloud-accounts/{account_id}", pass_codes=(IN_USE,), prefer_sso=True)
|
|
578
|
+
except api.ApiError as ex:
|
|
579
|
+
raise CloudAccountError(str(ex), ex.exit_code)
|
|
580
|
+
status = answer.pop("_status", 200)
|
|
581
|
+
if status == 409:
|
|
582
|
+
detail = answer.get("detail") or {}
|
|
583
|
+
details = detail.get("details") or {}
|
|
584
|
+
lines = [f"Cloud account {account_id} is still in use, so it stays connected. Nothing changed."]
|
|
585
|
+
for name in details.get("pools") or []:
|
|
586
|
+
lines.append(f" Pool {name}: delete it with 'mctl pool delete {name}'.")
|
|
587
|
+
if details.get("other_organization_pools"):
|
|
588
|
+
lines.append(f" {details['other_organization_pools']} pool(s) of other organizations use it: "
|
|
589
|
+
"ask Multicloud support.")
|
|
590
|
+
if details.get("live_servers"):
|
|
591
|
+
lines.append(f" {details['live_servers']} server(s) still run in it. They stop a few minutes after "
|
|
592
|
+
"their pool is deleted.")
|
|
593
|
+
lines.append(f"Then run 'mctl cloud-account {again} {account_id}' again.")
|
|
594
|
+
raise CloudAccountError("\n".join(lines), exitcodes.ERROR)
|
|
595
|
+
return answer
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
@cloud_account.command()
|
|
599
|
+
@click.argument("account_id", type=int)
|
|
600
|
+
@click.option("-y", "--yes", is_flag=True, help="Disconnect without asking")
|
|
601
|
+
@click.pass_context
|
|
602
|
+
def disconnect(ctx, account_id, yes):
|
|
603
|
+
"""Disconnect a cloud account from the organization (organization owners only).
|
|
604
|
+
|
|
605
|
+
Multicloud stops using the account at once. Nothing in the account is deleted: remove the Multicloud role
|
|
606
|
+
afterwards with 'tofu destroy' (or 'mctl cloud-account destroy' for an AWS account that mctl created). A pool
|
|
607
|
+
that uses the account must be deleted first. Needs a sign-in (mctl auth login), not an API key."""
|
|
608
|
+
# The sign-in from the start: the API refuses an API key here, so fail before the prompt.
|
|
609
|
+
data = _run(ctx, lambda org: call("GET", org, f"/{account_id}", prefer_sso=True))
|
|
610
|
+
data.pop("_status", None)
|
|
611
|
+
noun = noun_of(data.get("cloud"))
|
|
612
|
+
native = data.get("native_id") or data.get("expected_native_id")
|
|
613
|
+
which = f"{noun} {native}" if native else f"cloud account {account_id}"
|
|
614
|
+
if data.get("status") == "revoked":
|
|
615
|
+
click.echo(f"Cloud account {account_id} is already disconnected.")
|
|
616
|
+
return
|
|
617
|
+
if not yes:
|
|
618
|
+
if not _stdin_is_tty():
|
|
619
|
+
click.echo("Error: Refusing to disconnect without confirmation. Run again with --yes.", err=True)
|
|
620
|
+
sys.exit(exitcodes.ERROR)
|
|
621
|
+
click.echo(f"This disconnects {which} from your organization. Multicloud stops using it at once.")
|
|
622
|
+
click.echo(f"Nothing in the {noun} is deleted. You can connect it again later with mctl cloud-account create.")
|
|
623
|
+
if not click.confirm(f"Disconnect {which}?", default=False):
|
|
624
|
+
click.echo("Nothing changed.", err=True)
|
|
625
|
+
sys.exit(exitcodes.ERROR)
|
|
626
|
+
_run(ctx, lambda org: _disconnect(org, account_id))
|
|
627
|
+
click.echo(f"Disconnected: {which} is no longer connected to Multicloud.")
|
|
628
|
+
if not data.get("connected_on"):
|
|
629
|
+
return # Terraform never connected it: there is no Multicloud role to remove
|
|
630
|
+
click.echo("Next: remove the Multicloud role from the account. Run 'tofu destroy' (or 'terraform destroy') in "
|
|
631
|
+
f"the folder with {TF_FILE}, or 'mctl cloud-account destroy {account_id}' if mctl created the AWS account.")
|
|
632
|
+
|
|
633
|
+
|
|
570
634
|
def _find_tool(requested: Optional[str]) -> str:
|
|
571
635
|
if requested:
|
|
572
636
|
if not shutil.which(requested):
|
|
@@ -631,10 +695,12 @@ def _aws_account_state(account_id: str) -> Optional[str]:
|
|
|
631
695
|
@click.option("-y", "--yes", is_flag=True, help="Destroy without asking")
|
|
632
696
|
@click.pass_context
|
|
633
697
|
def destroy(ctx, account_id, directory, tool, yes):
|
|
634
|
-
"""
|
|
698
|
+
"""Disconnect the AWS account that multicloud.tf created, then close it.
|
|
635
699
|
|
|
636
|
-
Only for a file made with 'create --new-account-email'.
|
|
637
|
-
|
|
700
|
+
Only for a file made with 'create --new-account-email'. The account is disconnected from your organization
|
|
701
|
+
first (organization owners only; needs mctl auth login), so a pool that still uses it stops the command before
|
|
702
|
+
anything is closed. AWS keeps a closed account for 90 days, and its email cannot be used for a new AWS
|
|
703
|
+
account again."""
|
|
638
704
|
text = _check_file(account_id, directory)
|
|
639
705
|
if not _PATH_A.search(text):
|
|
640
706
|
click.echo(f"{TF_FILE} did not create an AWS account, so there is no account for mctl to close.")
|
|
@@ -656,11 +722,16 @@ def destroy(ctx, account_id, directory, tool, yes):
|
|
|
656
722
|
if not _stdin_is_tty():
|
|
657
723
|
click.echo("Error: Refusing to destroy without confirmation. Run again with --yes.", err=True)
|
|
658
724
|
sys.exit(1)
|
|
659
|
-
click.echo(f"This removes the Multicloud role and closes
|
|
725
|
+
click.echo(f"This disconnects {which} from your organization, removes the Multicloud role and closes the "
|
|
726
|
+
f"account that {TF_FILE} created.")
|
|
660
727
|
click.echo("AWS keeps a closed account for 90 days. Its email cannot be used again for a new AWS account.")
|
|
661
728
|
if not click.confirm(f"Close {which}?", default=False):
|
|
662
729
|
click.echo("Nothing destroyed.", err=True)
|
|
663
730
|
sys.exit(exitcodes.ERROR)
|
|
731
|
+
# Disconnect first: a closed account must not stay connected, and a pool that still uses it stops us here,
|
|
732
|
+
# before anything is closed. An account that is already disconnected answers the same.
|
|
733
|
+
_run(ctx, lambda org: _disconnect(org, account_id, again="destroy"))
|
|
734
|
+
click.echo(f"Disconnected cloud account {account_id} from your organization.")
|
|
664
735
|
# The account closes with everything in it. Deleting the Spot service-linked role can be blocked
|
|
665
736
|
# for about 4 minutes after the last spot instance ends, so the destroy must not depend on it.
|
|
666
737
|
code, out = _run(ctx, lambda org: _tool_capture(tool, ["state", "rm", "module.multicloud"], directory, base_env))
|
|
@@ -685,10 +685,15 @@ class Tool:
|
|
|
685
685
|
return [" ".join(a[:3]) for _, a, _ in self.calls]
|
|
686
686
|
|
|
687
687
|
|
|
688
|
-
def _run_cmd(args, tool, tmp_path, monkeypatch, tty=False, tf=PATH_A_TF, answers=None, aws=True):
|
|
688
|
+
def _run_cmd(args, tool, tmp_path, monkeypatch, tty=False, tf=PATH_A_TF, answers=None, aws=True, sso=True):
|
|
689
689
|
(tmp_path / "multicloud.tf").write_text(tf)
|
|
690
690
|
monkeypatch.setenv("MULTICLOUD_API_KEY", "fake-key-0000")
|
|
691
691
|
monkeypatch.setenv("MULTICLOUD_ORG", "acme")
|
|
692
|
+
# destroy disconnects with the sign-in (an owner route); apply keeps using the API key.
|
|
693
|
+
monkeypatch.setenv("MULTICLOUD_ISSUER", "https://auth.example.test/realms/multicloud")
|
|
694
|
+
monkeypatch.setattr(auth, "load_sso", lambda issuer: {"session": "x"} if sso else None)
|
|
695
|
+
monkeypatch.setattr(auth, "fresh_access_token", lambda issuer: "sso-token")
|
|
696
|
+
monkeypatch.setattr(cmds.api, "_sso_org", lambda slug, token, explicit=True: slug)
|
|
692
697
|
monkeypatch.setenv("TF_LOG", "DEBUG")
|
|
693
698
|
monkeypatch.setattr(cmds, "_stdin_is_tty", lambda: tty)
|
|
694
699
|
monkeypatch.setattr(cmds, "_sleep", lambda s: None)
|
|
@@ -829,3 +834,92 @@ def test_destroy_for_another_cloud_account_is_refused(tmp_path, monkeypatch):
|
|
|
829
834
|
tool = Tool()
|
|
830
835
|
r, _ = _run_cmd(["destroy", "6", "--yes"], tool, tmp_path, monkeypatch)
|
|
831
836
|
assert r.exit_code == 1 and not tool.calls
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
# --- disconnect ---------------------------------------------------------------------------------
|
|
840
|
+
|
|
841
|
+
VERIFIED_CONNECTED = {**VERIFIED, "connected_on": "2026-11-11T10:00:00Z"}
|
|
842
|
+
REVOKED = {**VERIFIED, "status": "revoked", "status_reason": "disconnected by an organization owner"}
|
|
843
|
+
IN_USE = {"detail": {"code": "ACCOUNT_IN_USE", "message": "This AWS account is still in use",
|
|
844
|
+
"details": {"pools": ["ci-runners"], "other_organization_pools": 0, "live_servers": 2}}}
|
|
845
|
+
DELETE_URL = "https://api.multicloud.io/api/v1/orgs/acme/cloud-accounts/5"
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
def test_disconnect_with_yes_uses_the_sign_in():
|
|
849
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"],
|
|
850
|
+
[reply(200, VERIFIED_CONNECTED), reply(200, REVOKED)])
|
|
851
|
+
assert r.exit_code == 0, r.output
|
|
852
|
+
assert [c.args[:2] for c in req.call_args_list] == [("GET", DELETE_URL), ("DELETE", DELETE_URL)]
|
|
853
|
+
for sent in req.call_args_list: # the sign-in, never the API key
|
|
854
|
+
assert sent.kwargs["headers"]["Authorization"] == "Bearer sso-token"
|
|
855
|
+
assert "X-API-Key" not in sent.kwargs["headers"]
|
|
856
|
+
assert f"Disconnected: AWS account {ACCT} is no longer connected to Multicloud." in r.stdout
|
|
857
|
+
assert "tofu destroy" in r.stdout and "mctl cloud-account destroy 5" in r.stdout
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
def test_disconnect_asks_first():
|
|
861
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5"], [reply(200, VERIFIED)], input="n\n")
|
|
862
|
+
assert r.exit_code == 1 and req.call_count == 1 and "Nothing changed." in r.stderr
|
|
863
|
+
assert f"This disconnects AWS account {ACCT} from your organization." in r.stdout
|
|
864
|
+
assert "Nothing in the AWS account is deleted." in r.stdout
|
|
865
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5"], [reply(200, VERIFIED), reply(200, REVOKED)],
|
|
866
|
+
input="y\n")
|
|
867
|
+
assert r.exit_code == 0 and req.call_args_list[1].args[0] == "DELETE"
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
def test_disconnect_without_a_terminal_needs_yes():
|
|
871
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5"], [reply(200, VERIFIED)], tty=False)
|
|
872
|
+
assert r.exit_code == 1 and req.call_count == 1 and "--yes" in r.stderr
|
|
873
|
+
|
|
874
|
+
|
|
875
|
+
def test_disconnect_without_a_sign_in_names_the_login():
|
|
876
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, VERIFIED)], sso=False)
|
|
877
|
+
assert r.exit_code == 3 and not req.called and "mctl auth login" in r.stderr
|
|
878
|
+
|
|
879
|
+
|
|
880
|
+
def test_disconnect_in_use_lists_the_pools_and_changes_nothing():
|
|
881
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, VERIFIED), reply(409, IN_USE)])
|
|
882
|
+
assert r.exit_code == 1
|
|
883
|
+
assert "Cloud account 5 is still in use, so it stays connected. Nothing changed." in r.stderr
|
|
884
|
+
assert "Pool ci-runners: delete it with 'mctl pool delete ci-runners'." in r.stderr
|
|
885
|
+
assert "2 server(s) still run in it." in r.stderr
|
|
886
|
+
assert "mctl cloud-account disconnect 5' again" in r.stderr
|
|
887
|
+
assert "Disconnected" not in r.stdout
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def test_disconnect_an_already_disconnected_account_does_nothing():
|
|
891
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, REVOKED)])
|
|
892
|
+
assert r.exit_code == 0 and req.call_count == 1 and "already disconnected" in r.stdout
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
def test_destroy_disconnects_before_it_closes(tmp_path, monkeypatch):
|
|
896
|
+
tool = Tool()
|
|
897
|
+
r, fake = _run_cmd(["destroy", "5", "--yes"], tool, tmp_path, monkeypatch, answers=[reply(200, REVOKED)])
|
|
898
|
+
assert r.exit_code == 0, r.output + r.stderr
|
|
899
|
+
assert fake.calls == [("DELETE", DELETE_URL)]
|
|
900
|
+
assert "Disconnected cloud account 5 from your organization." in r.stdout
|
|
901
|
+
# the order: Multicloud first, then the account closes
|
|
902
|
+
out = r.stdout
|
|
903
|
+
assert out.index("Disconnected cloud account 5") < out.index("Closing AWS account 999999999999")
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
def test_destroy_stops_before_closing_when_a_pool_uses_the_account(tmp_path, monkeypatch):
|
|
907
|
+
tool = Tool()
|
|
908
|
+
r, fake = _run_cmd(["destroy", "5", "--yes"], tool, tmp_path, monkeypatch, answers=[reply(409, IN_USE)])
|
|
909
|
+
assert r.exit_code == 1
|
|
910
|
+
assert "mctl cloud-account destroy 5' again" in r.stderr
|
|
911
|
+
assert tool.seq() == ["output -json"] # nothing removed, nothing closed
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
def test_destroy_without_a_sign_in_closes_nothing(tmp_path, monkeypatch):
|
|
915
|
+
tool = Tool()
|
|
916
|
+
r, fake = _run_cmd(["destroy", "5", "--yes"], tool, tmp_path, monkeypatch, sso=False)
|
|
917
|
+
assert r.exit_code == 3 and "mctl auth login" in r.stderr
|
|
918
|
+
assert not fake.calls and tool.seq() == ["output -json"]
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
def test_disconnect_a_never_connected_account_has_no_next_step():
|
|
922
|
+
pending = {"id": 5, "cloud": "AWS", "status": "pending", "expected_native_id": ACCT}
|
|
923
|
+
r, req = invoke_seq(["cloud-account", "disconnect", "5", "--yes"], [reply(200, pending), reply(200, REVOKED)])
|
|
924
|
+
assert r.exit_code == 0 and "Disconnected:" in r.stdout
|
|
925
|
+
assert "Next:" not in r.stdout
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.5.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
|