multicloud-cli 0.5.2__tar.gz → 0.6.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.
Files changed (40) hide show
  1. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/PKG-INFO +1 -1
  2. multicloud_cli-0.6.0/multicloud_cli/__init__.py +1 -0
  3. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/api.py +2 -1
  4. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/extend.py +11 -2
  5. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/pool.py +32 -7
  6. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_account_extend.py +25 -0
  7. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_pool.py +48 -0
  8. multicloud_cli-0.5.2/multicloud_cli/__init__.py +0 -1
  9. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/.gitignore +0 -0
  10. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/LICENSE +0 -0
  11. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/README.md +0 -0
  12. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/account.py +0 -0
  13. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/auth.py +0 -0
  14. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/catalog.py +0 -0
  15. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/cloud_account.py +0 -0
  16. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/config.py +0 -0
  17. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/duration.py +0 -0
  18. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/exitcodes.py +0 -0
  19. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/main.py +0 -0
  20. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/net.py +0 -0
  21. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/node.py +0 -0
  22. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/orgopt.py +0 -0
  23. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/output.py +0 -0
  24. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/ssh.py +0 -0
  25. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/ssh_cert.py +0 -0
  26. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/multicloud_cli/sso.py +0 -0
  27. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/pyproject.toml +0 -0
  28. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/__init__.py +0 -0
  29. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/conftest.py +0 -0
  30. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/helpers.py +0 -0
  31. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_apply.py +0 -0
  32. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_auth.py +0 -0
  33. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_catalog.py +0 -0
  34. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_cloud_account.py +0 -0
  35. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_conventions.py +0 -0
  36. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_net.py +0 -0
  37. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_ssh.py +0 -0
  38. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_ssh_cert.py +0 -0
  39. {multicloud_cli-0.5.2 → multicloud_cli-0.6.0}/tests/test_sso.py +0 -0
  40. {multicloud_cli-0.5.2 → multicloud_cli-0.6.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.5.2
3
+ Version: 0.6.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.6.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):
@@ -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, image_by_class, egress_by_class,
241
- class_headroom, spot_policy, cpu_units_requests, from_file, idempotency_key, as_json):
242
- """Create a CI pool."""
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
- missing = [f for f in ("name", "github_org", "clouds", "classes", "max_cost_per_hour") if f not in body]
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}, scope=WRITE)
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"}
@@ -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