multicloud-cli 0.9.0__tar.gz → 0.9.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.
Files changed (42) hide show
  1. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/PKG-INFO +2 -2
  2. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/README.md +1 -1
  3. multicloud_cli-0.9.2/multicloud_cli/__init__.py +1 -0
  4. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/cloud_account.py +18 -2
  5. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/main.py +12 -2
  6. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_cloud_account.py +31 -0
  7. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_version_check.py +29 -2
  8. multicloud_cli-0.9.0/multicloud_cli/__init__.py +0 -1
  9. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/.gitignore +0 -0
  10. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/LICENSE +0 -0
  11. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/account.py +0 -0
  12. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/api.py +0 -0
  13. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/auth.py +0 -0
  14. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/catalog.py +0 -0
  15. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/config.py +0 -0
  16. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/duration.py +0 -0
  17. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/exitcodes.py +0 -0
  18. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/extend.py +0 -0
  19. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/net.py +0 -0
  20. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/node.py +0 -0
  21. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/orgopt.py +0 -0
  22. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/output.py +0 -0
  23. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/pool.py +0 -0
  24. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/ssh.py +0 -0
  25. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/ssh_cert.py +0 -0
  26. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/sso.py +0 -0
  27. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/multicloud_cli/version_check.py +0 -0
  28. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/pyproject.toml +0 -0
  29. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/__init__.py +0 -0
  30. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/conftest.py +0 -0
  31. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/helpers.py +0 -0
  32. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_account_extend.py +0 -0
  33. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_apply.py +0 -0
  34. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_auth.py +0 -0
  35. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_catalog.py +0 -0
  36. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_conventions.py +0 -0
  37. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_net.py +0 -0
  38. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_pool.py +0 -0
  39. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_ssh.py +0 -0
  40. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_ssh_cert.py +0 -0
  41. {multicloud_cli-0.9.0 → multicloud_cli-0.9.2}/tests/test_sso.py +0 -0
  42. {multicloud_cli-0.9.0 → multicloud_cli-0.9.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.9.0
3
+ Version: 0.9.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>
@@ -43,7 +43,7 @@ pipx install multicloud-cli # or: uv tool install multicloud-cli
43
43
  ```
44
44
 
45
45
  If `mctl` is not found after the install, run `uv tool update-shell` (or `pipx ensurepath`) and open a new shell.
46
- Upgrade with `uv tool upgrade multicloud-cli` (or `pipx upgrade multicloud-cli`). Check the version with `mctl --version`.
46
+ Upgrade with `uv tool upgrade multicloud-cli` (or `pipx upgrade multicloud-cli`). Check the version with `mctl version` (or `mctl --version`).
47
47
  Once a day, `mctl` asks PyPI for the latest version and prints one line when a newer version exists. It never
48
48
  upgrades itself. Turn the check off with `MCTL_NO_UPDATE_CHECK=1`.
49
49
 
@@ -12,7 +12,7 @@ pipx install multicloud-cli # or: uv tool install multicloud-cli
12
12
  ```
13
13
 
14
14
  If `mctl` is not found after the install, run `uv tool update-shell` (or `pipx ensurepath`) and open a new shell.
15
- Upgrade with `uv tool upgrade multicloud-cli` (or `pipx upgrade multicloud-cli`). Check the version with `mctl --version`.
15
+ Upgrade with `uv tool upgrade multicloud-cli` (or `pipx upgrade multicloud-cli`). Check the version with `mctl version` (or `mctl --version`).
16
16
  Once a day, `mctl` asks PyPI for the latest version and prints one line when a newer version exists. It never
17
17
  upgrades itself. Turn the check off with `MCTL_NO_UPDATE_CHECK=1`.
18
18
 
@@ -0,0 +1 @@
1
+ __version__ = "0.9.2"
@@ -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.6.0"
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
- # The module registers the resource providers that it needs.
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
  """
@@ -892,10 +894,24 @@ def disconnect(ctx, account_id, yes, wait, timeout):
892
894
  click.echo("Next: remove the Multicloud managed identity and role from the subscription. Run 'tofu destroy' "
893
895
  f"(or 'terraform destroy') in the folder with {TF_FILE}.")
894
896
  return
897
+ if data.get("cloud") == "AWS" and _module_before_2(data.get("module_version")):
898
+ click.echo(f"First: in the folder with {TF_FILE}, change the module version to 2.0.0, run 'tofu init -upgrade' "
899
+ "(or 'terraform init -upgrade'), then plan and apply. The plan must show the three service-linked "
900
+ "roles as forgotten and nothing to destroy. Module " + str(data.get("module_version")) + " deletes "
901
+ "the EC2 Spot, EC2 Fleet and Service Quotas service-linked roles of the account on destroy; 2.0.0 "
902
+ "keeps them.")
895
903
  click.echo("Next: remove the Multicloud role from the account. Run 'tofu destroy' (or 'terraform destroy') in "
896
904
  f"the folder with {TF_FILE}, or 'mctl cloud-account destroy {account_id}' if mctl created the AWS account.")
897
905
 
898
906
 
907
+ def _module_before_2(version) -> bool:
908
+ """The AWS module before 2.0.0 deletes the account's service-linked roles on destroy. Unknown: False."""
909
+ try:
910
+ return int(str(version).strip().lstrip("vV").split(".")[0]) < 2
911
+ except (TypeError, ValueError):
912
+ return False
913
+
914
+
899
915
  def _find_tool(requested: Optional[str]) -> str:
900
916
  if requested:
901
917
  if not shutil.which(requested):
@@ -26,6 +26,9 @@ def _broken_pipe() -> int:
26
26
  return exitcodes.BROKEN_PIPE
27
27
 
28
28
 
29
+ VERSION_LINE = f"mctl, version {__version__}" # one line for `mctl version` and `mctl --version`
30
+
31
+
29
32
  class Root(click.Group):
30
33
  def invoke(self, ctx):
31
34
  # click itself turns EPIPE into exit 1, so this catches it first.
@@ -36,7 +39,7 @@ class Root(click.Group):
36
39
 
37
40
 
38
41
  @click.group(cls=Root, context_settings={"help_option_names": ["-h", "--help"]})
39
- @click.version_option(__version__, prog_name="mctl")
42
+ @click.version_option(__version__, message=VERSION_LINE)
40
43
  @org_option()
41
44
  @click.option("--api-url", default=None, help="API URL (default: MULTICLOUD_API_URL)")
42
45
  @click.pass_context
@@ -50,6 +53,12 @@ def mctl(ctx, org, api_url):
50
53
  ctx.obj["root_api_url"] = api_url
51
54
 
52
55
 
56
+ @mctl.command("version")
57
+ def version_cmd():
58
+ """Print the mctl version (the same line as mctl --version)."""
59
+ click.echo(VERSION_LINE)
60
+
61
+
53
62
  mctl.add_command(auth)
54
63
  mctl.add_command(cloud_account)
55
64
  mctl.add_command(pool)
@@ -98,7 +107,8 @@ def _version_notice() -> None:
98
107
 
99
108
  def main():
100
109
  code = _run()
101
- if code not in (exitcodes.INTERRUPTED, exitcodes.BROKEN_PIPE): # the user or the pipe wants mctl gone
110
+ local_only = sys.argv[1:2] == ["version"] or "--version" in sys.argv[1:] # no network, no notice
111
+ if code not in (exitcodes.INTERRUPTED, exitcodes.BROKEN_PIPE) and not local_only: # the user or the pipe wants mctl gone
102
112
  _version_notice()
103
113
  try:
104
114
  sys.stdout.flush() # a closed pipe shows here, when the output was small and buffered
@@ -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():
@@ -134,7 +134,7 @@ def test_env_switch_skips_the_check(cache, pypi, monkeypatch):
134
134
  def test_main_prints_the_notice_and_keeps_the_exit_code(cache, pypi, monkeypatch, capsys):
135
135
  pypi["latest"] = "99.0.0"
136
136
  monkeypatch.setattr(version_check.sys, "stderr", TtyErr())
137
- monkeypatch.setattr(main.sys, "argv", ["mctl", "--version"])
137
+ monkeypatch.setattr(main.sys, "argv", ["mctl", "--help"])
138
138
  with pytest.raises(SystemExit) as ex:
139
139
  main.main()
140
140
  assert ex.value.code == 0
@@ -146,7 +146,7 @@ def test_main_survives_a_broken_check(monkeypatch):
146
146
  raise RuntimeError("bug in the check")
147
147
 
148
148
  monkeypatch.setattr(version_check, "notify", boom)
149
- monkeypatch.setattr(main.sys, "argv", ["mctl", "--version"])
149
+ monkeypatch.setattr(main.sys, "argv", ["mctl", "--help"])
150
150
  with pytest.raises(SystemExit) as ex:
151
151
  main.main()
152
152
  assert ex.value.code == 0
@@ -230,3 +230,30 @@ def test_ctrl_c_during_the_lookup_only_drops_the_notice(monkeypatch):
230
230
  with pytest.raises(SystemExit) as ex:
231
231
  main.main()
232
232
  assert ex.value.code == 0
233
+
234
+
235
+ # --- `mctl version` ------------------------------------------------------------------------------------------
236
+
237
+ def test_version_command_prints_the_same_line_as_the_flag():
238
+ from click.testing import CliRunner
239
+ from multicloud_cli import __version__
240
+ runner = CliRunner()
241
+ cmd = runner.invoke(main.mctl, ["version"])
242
+ flag = runner.invoke(main.mctl, ["--version"])
243
+ assert cmd.exit_code == 0
244
+ assert cmd.output == flag.output == f"mctl, version {__version__}\n"
245
+
246
+
247
+ @pytest.mark.parametrize("argv", [["mctl", "version"], ["mctl", "--version"]])
248
+ def test_version_forms_make_no_network_call_even_on_a_terminal(cache, monkeypatch, argv, capsys):
249
+ """Through main(), where the notice runs: both forms stay local and print only the version."""
250
+ monkeypatch.delenv("MCTL_NO_UPDATE_CHECK", raising=False)
251
+ calls = []
252
+ monkeypatch.setattr(requests, "request", lambda *a, **kw: calls.append(a) or FakeResponse(200, {"info": {"version": "99.0.0"}}))
253
+ monkeypatch.setattr(version_check.sys, "stderr", TtyErr())
254
+ monkeypatch.setattr(main.sys, "argv", argv)
255
+ with pytest.raises(SystemExit) as ex:
256
+ main.main()
257
+ assert ex.value.code == 0
258
+ assert calls == []
259
+ assert version_check.sys.stderr.getvalue() == ""
@@ -1 +0,0 @@
1
- __version__ = "0.9.0"
File without changes