multicloud-cli 0.13.0__tar.gz → 0.14.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.13.0 → multicloud_cli-0.14.0}/PKG-INFO +10 -2
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/README.md +9 -1
- multicloud_cli-0.14.0/multicloud_cli/__init__.py +1 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/cloud_account.py +45 -1
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/db_access.py +8 -1
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/net.py +8 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/pool.py +367 -3
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/ssh.py +42 -14
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/ssh_cert.py +7 -4
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_cloud_account.py +59 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_db_access.py +9 -0
- multicloud_cli-0.14.0/tests/test_net.py +49 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_pool.py +291 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_ssh.py +36 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_ssh_cert.py +9 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_version_check.py +1 -1
- multicloud_cli-0.13.0/multicloud_cli/__init__.py +0 -1
- multicloud_cli-0.13.0/tests/test_net.py +0 -24
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/.gitignore +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/LICENSE +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/account.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/api.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/auth.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/catalog.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/config.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/duration.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/exitcodes.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/extend.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/kube.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/main.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/node.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/orgopt.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/output.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/sso.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/multicloud_cli/version_check.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/pyproject.toml +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/__init__.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/conftest.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/helpers.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_account_extend.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_apply.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_auth.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_catalog.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_conventions.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_proxy_key.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.0}/tests/test_sso.py +0 -0
- {multicloud_cli-0.13.0 → multicloud_cli-0.14.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.
|
|
3
|
+
Version: 0.14.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>
|
|
@@ -55,7 +55,7 @@ OpenTofu or Terraform 1.10 or later.
|
|
|
55
55
|
```bash
|
|
56
56
|
mctl auth login # opens your browser; sign in as you do on multicloud.io
|
|
57
57
|
mkdir multicloud-aws && cd multicloud-aws
|
|
58
|
-
mctl cloud-account create --cloud AWS --account 123456789012 --region
|
|
58
|
+
mctl cloud-account create --cloud AWS --account 123456789012 # every region; add --region to limit
|
|
59
59
|
export AWS_REGION=us-east-1 # Terraform needs a region when your AWS profile has none
|
|
60
60
|
mctl cloud-account apply 7 # init, plan, asks you, apply, then waits for "Ready"
|
|
61
61
|
```
|
|
@@ -159,6 +159,14 @@ mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6
|
|
|
159
159
|
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--max-servers`, `--classes`, `--spot-policy`, `--cpu-units-requests`, `--clouds` or settings: `--set NAME=VALUE` (repeat; VALUE is JSON, else text; the name lists `instance_types`, `excluded_instance_types`, `accelerator_names`, `excluded_accelerator_names`, `accelerator_vendors` and `excluded_accelerator_vendors` also take comma-separated names; `grant.cpu` for grant fields), `--reset NAME`, `--settings JSON\|@file`. Only the options you give change. `mctl pool show` prints the settings, or `default: X` where a setting is unset. On an Extend pool with a `PENDING` or `READY` peering, a change of `accelerator_names` or `excluded_accelerator_names` fails with 409 `POOL_HAS_PEERINGS`: revoke the peering first, or create a second pool. |
|
|
160
160
|
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
161
161
|
| `mctl pool diagnose <pool>` | Why a pool or its Extend bridge does not work: the pool's lifecycle and readiness gates, and for each bridge replica what the pool sees of its WireGuard handshake, with a hint. Reads only; it never wakes a hibernated pool. `--json` prints the raw answer. |
|
|
162
|
+
| `mctl pool cpu-sizing <pool>` | Recommended cpu-units request and burst limit per workload container, from the last 14 days of usage (72 qualifying hours needed), with the current request, observed P95/MAX and `clipped`. `--namespace`, `--owner-kind`, `--window-days`, `--clipped-only`, `--json`. Reads only. |
|
|
163
|
+
| `mctl pool cpu-sizing-history <pool> <namespace> <owner-kind> <owner-name>` | The hourly cpu-units of one workload, per container. `--window-days`, `--json`. |
|
|
164
|
+
| `mctl pool cpu-units-mode <pool>` | The cpu-units Auto mode (advise, selected, full). `--preview MODE` shows the change list; `--set MODE` shows it, asks, then applies it (`--yes` skips the question). `--convert-raw`, `--json`. Write access for `--set`. |
|
|
165
|
+
| `mctl pool cpu-units-select <pool> <namespace> <owner-kind> <owner-name>` | Choose how Auto treats one workload: follow (default), `--pin CONTAINER=UNITS[:LIMIT]` (repeat), or `--exclude`. `--convert-raw`, `--startup-units N`, `--json`. |
|
|
166
|
+
| `mctl pool cpu-units-unselect <pool> <namespace> <owner-kind> <owner-name>` | Remove the selection. In `selected` the workload leaves Auto; in `full` it follows the recommendation. |
|
|
167
|
+
| `mctl pool cpu-units-roll <pool> <namespace> <owner-kind> <owner-name>` | Roll now: evict the pods of one workload one at a time, so the new pods get the Auto value. Asks first (`--yes` skips it). `--allow-downtime` for a 1-replica workload, `--json`. Write access. |
|
|
168
|
+
| `mctl pool cpu-units-rolls <pool>` | The active Roll now requests (`--all`: finished ones too), `--json`. |
|
|
169
|
+
| `mctl pool cpu-units-roll-cancel <pool> <roll-id>` | Cancel a roll before its next eviction, `--json`. Write access. |
|
|
162
170
|
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
163
171
|
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
164
172
|
| `mctl pool rotate-credentials <pool>` / `rotation-status <pool>` | Renew the pool's access credentials; show the progress of the last renewal. |
|
|
@@ -24,7 +24,7 @@ OpenTofu or Terraform 1.10 or later.
|
|
|
24
24
|
```bash
|
|
25
25
|
mctl auth login # opens your browser; sign in as you do on multicloud.io
|
|
26
26
|
mkdir multicloud-aws && cd multicloud-aws
|
|
27
|
-
mctl cloud-account create --cloud AWS --account 123456789012 --region
|
|
27
|
+
mctl cloud-account create --cloud AWS --account 123456789012 # every region; add --region to limit
|
|
28
28
|
export AWS_REGION=us-east-1 # Terraform needs a region when your AWS profile has none
|
|
29
29
|
mctl cloud-account apply 7 # init, plan, asks you, apply, then waits for "Ready"
|
|
30
30
|
```
|
|
@@ -128,6 +128,14 @@ mctl pool wake ci --wait --timeout 15m # exit 0 ready, 5 timeout, 6
|
|
|
128
128
|
| `mctl pool update <pool>` | Change `--max-cost-per-hour`, `--max-servers`, `--classes`, `--spot-policy`, `--cpu-units-requests`, `--clouds` or settings: `--set NAME=VALUE` (repeat; VALUE is JSON, else text; the name lists `instance_types`, `excluded_instance_types`, `accelerator_names`, `excluded_accelerator_names`, `accelerator_vendors` and `excluded_accelerator_vendors` also take comma-separated names; `grant.cpu` for grant fields), `--reset NAME`, `--settings JSON\|@file`. Only the options you give change. `mctl pool show` prints the settings, or `default: X` where a setting is unset. On an Extend pool with a `PENDING` or `READY` peering, a change of `accelerator_names` or `excluded_accelerator_names` fails with 409 `POOL_HAS_PEERINGS`: revoke the peering first, or create a second pool. |
|
|
129
129
|
| `mctl pool show <pool>` / `cluster <pool>` | The pool, or its machines and their cost. |
|
|
130
130
|
| `mctl pool diagnose <pool>` | Why a pool or its Extend bridge does not work: the pool's lifecycle and readiness gates, and for each bridge replica what the pool sees of its WireGuard handshake, with a hint. Reads only; it never wakes a hibernated pool. `--json` prints the raw answer. |
|
|
131
|
+
| `mctl pool cpu-sizing <pool>` | Recommended cpu-units request and burst limit per workload container, from the last 14 days of usage (72 qualifying hours needed), with the current request, observed P95/MAX and `clipped`. `--namespace`, `--owner-kind`, `--window-days`, `--clipped-only`, `--json`. Reads only. |
|
|
132
|
+
| `mctl pool cpu-sizing-history <pool> <namespace> <owner-kind> <owner-name>` | The hourly cpu-units of one workload, per container. `--window-days`, `--json`. |
|
|
133
|
+
| `mctl pool cpu-units-mode <pool>` | The cpu-units Auto mode (advise, selected, full). `--preview MODE` shows the change list; `--set MODE` shows it, asks, then applies it (`--yes` skips the question). `--convert-raw`, `--json`. Write access for `--set`. |
|
|
134
|
+
| `mctl pool cpu-units-select <pool> <namespace> <owner-kind> <owner-name>` | Choose how Auto treats one workload: follow (default), `--pin CONTAINER=UNITS[:LIMIT]` (repeat), or `--exclude`. `--convert-raw`, `--startup-units N`, `--json`. |
|
|
135
|
+
| `mctl pool cpu-units-unselect <pool> <namespace> <owner-kind> <owner-name>` | Remove the selection. In `selected` the workload leaves Auto; in `full` it follows the recommendation. |
|
|
136
|
+
| `mctl pool cpu-units-roll <pool> <namespace> <owner-kind> <owner-name>` | Roll now: evict the pods of one workload one at a time, so the new pods get the Auto value. Asks first (`--yes` skips it). `--allow-downtime` for a 1-replica workload, `--json`. Write access. |
|
|
137
|
+
| `mctl pool cpu-units-rolls <pool>` | The active Roll now requests (`--all`: finished ones too), `--json`. |
|
|
138
|
+
| `mctl pool cpu-units-roll-cancel <pool> <roll-id>` | Cancel a roll before its next eviction, `--json`. Write access. |
|
|
131
139
|
| `mctl pool hibernate <pool>` / `wake <pool>` | Pause or resume a pool. |
|
|
132
140
|
| `mctl pool delete <pool> [-y]` | Delete a pool for good. It asks first; without a terminal, `-y` is required. To pause a pool, use `hibernate`. |
|
|
133
141
|
| `mctl pool rotate-credentials <pool>` / `rotation-status <pool>` | Renew the pool's access credentials; show the progress of the last renewal. |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.14.0"
|
|
@@ -314,7 +314,7 @@ def _file_exists(name: str):
|
|
|
314
314
|
@click.option("--new-account-email", "new_email", metavar="EMAIL",
|
|
315
315
|
help="AWS: create a new AWS account for Multicloud in your AWS Organizations, with this email "
|
|
316
316
|
"(not allowed with --account)")
|
|
317
|
-
@click.option("--region", "regions", multiple=True, help="Region to allow; repeat for several")
|
|
317
|
+
@click.option("--region", "regions", multiple=True, help="Region to allow; repeat for several (default: every region)")
|
|
318
318
|
@click.option("--force", is_flag=True, help="Overwrite an existing multicloud.tf")
|
|
319
319
|
@click.option("--opt-in-regions/--no-opt-in-regions", "opt_in", default=None,
|
|
320
320
|
help="AWS: turn on the opt-in regions of the account that are off (default: yes; "
|
|
@@ -537,6 +537,7 @@ def _readable(data: Dict[str, Any]) -> str:
|
|
|
537
537
|
f"Status: {status}",
|
|
538
538
|
("Account", data.get("native_id") or data.get("expected_native_id")),
|
|
539
539
|
("Regions", ", ".join(regions) if regions else "all"),
|
|
540
|
+
("Pending regions", ", ".join(data.get("regions_pending") or [])),
|
|
540
541
|
("Opt-in regions", None if data.get("enable_opt_in_regions") is None
|
|
541
542
|
else "turn on" if data["enable_opt_in_regions"] else "leave off"),
|
|
542
543
|
("Role", data.get("role_arn")),
|
|
@@ -862,6 +863,49 @@ def quota_request(ctx, account_id, region, code, desired, confirm_denied, as_jso
|
|
|
862
863
|
sys.exit(exitcodes.ERROR)
|
|
863
864
|
|
|
864
865
|
|
|
866
|
+
@cloud_account.command(name="set-regions")
|
|
867
|
+
@click.argument("account_id", type=int)
|
|
868
|
+
@click.argument("regions", nargs=-1)
|
|
869
|
+
@click.option("--all", "every", is_flag=True, help="Allow every region of the cloud")
|
|
870
|
+
@json_option
|
|
871
|
+
@click.pass_context
|
|
872
|
+
def set_regions(ctx, account_id, regions, every, as_json):
|
|
873
|
+
"""Add or remove regions of a cloud account: set-regions ID (--all | REGION...).
|
|
874
|
+
|
|
875
|
+
REGION... is the new full list: a region the account has now and the list lacks is removed (refused with
|
|
876
|
+
REGIONS_IN_USE when a pool would keep no region). GCE and Azure: applied at once. AWS: a removal applies at
|
|
877
|
+
once; an added region is pending until the role allows it. The answer prints the step to run: put the
|
|
878
|
+
regions of the snippet into multicloud.tf, then 'mctl cloud-account apply ID' (it applies the module with a
|
|
879
|
+
new connect token and verifies), or update the CloudFormation stack; a verify moves each region that passes
|
|
880
|
+
into the account. After a removal the step is optional: it only tightens the role."""
|
|
881
|
+
names = list(dict.fromkeys(r.strip() for r in regions if r.strip()))
|
|
882
|
+
if every == bool(names):
|
|
883
|
+
raise click.UsageError("Give --all, or one or more REGION names, not both and not neither.")
|
|
884
|
+
answer = _run(ctx, lambda org: call("PUT", org, f"/{account_id}/regions",
|
|
885
|
+
body={"regions": None if every else names}))
|
|
886
|
+
if as_json:
|
|
887
|
+
_dump(answer)
|
|
888
|
+
return
|
|
889
|
+
current = answer.get("regions")
|
|
890
|
+
lines = [f"Cloud account {account_id} regions: {', '.join(current) if current else 'all'}"]
|
|
891
|
+
pending = answer.get("regions_pending") or []
|
|
892
|
+
if pending:
|
|
893
|
+
lines.append(f"Pending (the role does not allow them yet): {', '.join(pending)}")
|
|
894
|
+
apply_step = answer.get("apply") or {}
|
|
895
|
+
if apply_step.get("terraform"):
|
|
896
|
+
# `apply` applies multicloud.tf as it is (it does not render the regions) and verifies after the apply.
|
|
897
|
+
command = apply_step.get("command") or f"mctl cloud-account apply {account_id}"
|
|
898
|
+
optional = "" if pending else " Optional: it only tightens the role; the removal is already in force."
|
|
899
|
+
lines.append("First set `regions` in multicloud.tf to the list in the snippet below (the snippet is "
|
|
900
|
+
f"for reference).\nRun: {command} (it applies the module with the new regions and "
|
|
901
|
+
f"verifies){optional}\n{apply_step['terraform'].rstrip()}")
|
|
902
|
+
if apply_step.get("cloudformation"):
|
|
903
|
+
then = ("Optional: it only tightens the role; the removal is already in force." if not pending
|
|
904
|
+
else f"Then run: mctl cloud-account verify {account_id}")
|
|
905
|
+
lines.append(f"{apply_step['cloudformation']} {then}")
|
|
906
|
+
click.echo("\n".join(lines))
|
|
907
|
+
|
|
908
|
+
|
|
865
909
|
WAIT_DEFAULT = "130m" # the cleanup job gives up after about two hours
|
|
866
910
|
WAIT_INTERVAL = 30
|
|
867
911
|
|
|
@@ -80,13 +80,20 @@ def db_access():
|
|
|
80
80
|
@click.option("--ttl", "ttl", default="12h", show_default=True, callback=duration_option,
|
|
81
81
|
help="How long the access lasts: 5m to 24h (30m, 12h, 90s)")
|
|
82
82
|
@click.option("--ipv4-only", is_flag=True, help="Open only your IPv4 address (use it on a shared network)")
|
|
83
|
+
@click.option("--reason", default=None, metavar="TEXT", help="Why you open DB access (audit log)")
|
|
84
|
+
@click.option("--ticket", default=None, metavar="REF", help="Support ticket of this action (audit log)")
|
|
83
85
|
@json_option
|
|
84
|
-
def allow(ttl, ipv4_only, as_json):
|
|
86
|
+
def allow(ttl, ipv4_only, reason, ticket, as_json):
|
|
85
87
|
"""Open DB access for your current public IPs, or extend it."""
|
|
86
88
|
def go():
|
|
87
89
|
if not MIN_TTL_S <= ttl <= MAX_TTL_S:
|
|
88
90
|
raise DbAccessError(f"--ttl must be between 5m and 24h, not {ttl} seconds.", exitcodes.USAGE)
|
|
89
91
|
body = {"ttl_seconds": ttl}
|
|
92
|
+
# Sent only when given: a new mctl works against a server that does not know the fields yet.
|
|
93
|
+
if reason is not None:
|
|
94
|
+
body["reason"] = reason
|
|
95
|
+
if ticket is not None:
|
|
96
|
+
body["ticket_ref"] = ticket
|
|
90
97
|
results: List[Dict[str, Any]] = []
|
|
91
98
|
notes: List[str] = []
|
|
92
99
|
try:
|
|
@@ -11,6 +11,11 @@ from requests.adapters import HTTPAdapter
|
|
|
11
11
|
from . import __version__, exitcodes
|
|
12
12
|
|
|
13
13
|
USER_AGENT = f"mctl/{__version__}"
|
|
14
|
+
# The connect timeout of each address. api. and auth.multicloud.io resolve to several A and AAAA records, and
|
|
15
|
+
# urllib3 tries them one at a time (no Happy Eyeballs): with the read timeout as the connect timeout, one address
|
|
16
|
+
# that drops SYNs cost 30 s per request. The connect timeout also bounds the TLS handshake (urllib3 sets the read
|
|
17
|
+
# timeout only after it): TCP connect plus TLS to the API takes about 0.45 s, so 5 s leaves room for a slow link.
|
|
18
|
+
CONNECT_TIMEOUT_S = 5
|
|
14
19
|
UPGRADE = "uv tool upgrade multicloud-cli (or pipx upgrade multicloud-cli)"
|
|
15
20
|
|
|
16
21
|
|
|
@@ -53,6 +58,9 @@ def request(method: str, url: str, ipv4_only: bool = False, ipv6_only: bool = Fa
|
|
|
53
58
|
"""One request. ``ipv4_only`` / ``ipv6_only`` connect over one address family only: the grant routes read the
|
|
54
59
|
address of the caller as the API sees it, and ``api.multicloud.io`` has A and AAAA records."""
|
|
55
60
|
kw["headers"] = {"User-Agent": USER_AGENT, **(kw.get("headers") or {})}
|
|
61
|
+
timeout = kw.get("timeout")
|
|
62
|
+
if isinstance(timeout, (int, float)) and not isinstance(timeout, bool) and timeout > 0: # a pair is kept as given
|
|
63
|
+
kw["timeout"] = (min(CONNECT_TIMEOUT_S, timeout), timeout)
|
|
56
64
|
if ipv4_only or ipv6_only:
|
|
57
65
|
adapter = IPv6Adapter if ipv6_only else IPv4Adapter
|
|
58
66
|
with requests.Session() as session:
|
|
@@ -272,6 +272,360 @@ def diagnose(ctx, pool_ref, as_json):
|
|
|
272
272
|
click.echo(json.dumps(_plain(data), indent=2, sort_keys=True) if as_json else _diagnose_text(data))
|
|
273
273
|
|
|
274
274
|
|
|
275
|
+
#: GET /pools/{id}/cpu-sizing keeps 35 days of usage; the recommendation always uses 14.
|
|
276
|
+
CPU_SIZING_WINDOW = click.IntRange(1, 35)
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _units(value) -> str:
|
|
280
|
+
return "-" if value is None else str(value)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def _cpu_now(w: Dict[str, Any]) -> str:
|
|
284
|
+
"""The current request/limit: cpu-units when the pod spec sets them, else raw millicores."""
|
|
285
|
+
cur = w.get("current") or {}
|
|
286
|
+
if w.get("setting_status") == "manifest_units":
|
|
287
|
+
return f"{_units(cur.get('request_units'))}/{_units(cur.get('limit_units'))}u"
|
|
288
|
+
if w.get("setting_status") == "manifest_raw":
|
|
289
|
+
return f"{_units(cur.get('request_mcpu'))}/{_units(cur.get('limit_mcpu'))}m"
|
|
290
|
+
return "-"
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _cpu_recommended(rec: Dict[str, Any]) -> str:
|
|
294
|
+
if rec.get("status") == "ok":
|
|
295
|
+
return f"{rec.get('request_units')}/{rec.get('limit_units')}u"
|
|
296
|
+
return f"wait ({rec.get('qualifying_hours')}/{rec.get('required_hours')}h)"
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def format_cpu_sizing(data: Dict[str, Any], headers: bool = True) -> str:
|
|
300
|
+
rows = []
|
|
301
|
+
for w in data.get("workloads", []):
|
|
302
|
+
obs, rec = w.get("observed") or {}, w.get("recommendation") or {}
|
|
303
|
+
rows.append((f"{w.get('namespace')}/{w.get('owner_kind')}/{w.get('owner_name')}", str(w.get("container")),
|
|
304
|
+
_cpu_now(w), _units(obs.get("p95_units")), _units(obs.get("max_units")),
|
|
305
|
+
_cpu_recommended(rec), "yes" if w.get("clipped") else "no"))
|
|
306
|
+
return _table(("WORKLOAD", "CONTAINER", "NOW (REQ/LIM)", "P95", "MAX", "RECOMMENDED (REQ/LIM)", "CLIPPED"),
|
|
307
|
+
rows, headers)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
@pool.command(name="cpu-sizing")
|
|
311
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
312
|
+
@click.option("--namespace", default=None, help="Only this namespace")
|
|
313
|
+
@click.option("--owner-kind", default=None, help="Only this owner kind, e.g. Deployment")
|
|
314
|
+
@click.option("--window-days", type=CPU_SIZING_WINDOW, default=None,
|
|
315
|
+
help="Days for the observed P95 and MAX (1-35, default 14). Never changes the recommendation")
|
|
316
|
+
@click.option("--clipped-only", is_flag=True, default=False, help="Only workloads whose CPU limit clipped the peak")
|
|
317
|
+
@json_option
|
|
318
|
+
@no_headers_option
|
|
319
|
+
@click.pass_context
|
|
320
|
+
def cpu_sizing(ctx, pool_ref, namespace, owner_kind, window_days, clipped_only, as_json, no_headers):
|
|
321
|
+
"""Show cpu-units recommendations per workload of a pool (id or name).
|
|
322
|
+
|
|
323
|
+
NOW is the current request/limit from the pod spec (u = cpu-units, m = raw millicores); P95 (the 95th
|
|
324
|
+
percentile of the hourly P95 values) and MAX are the observed cpu-units; RECOMMENDED is the request/limit from the last 14 days, or "wait" with the
|
|
325
|
+
qualifying hours so far (72 are needed). Reads only: nothing is applied."""
|
|
326
|
+
params = {k: v for k, v in (("namespace", namespace), ("owner_kind", owner_kind),
|
|
327
|
+
("window_days", window_days)) if v is not None}
|
|
328
|
+
if clipped_only:
|
|
329
|
+
params["clipped_only"] = "true"
|
|
330
|
+
|
|
331
|
+
def go(org):
|
|
332
|
+
return _call(org, "GET", f"/pools/{resolve(org, pool_ref)}/cpu-sizing", READ, params=params or None)
|
|
333
|
+
data = _run(ctx, go)
|
|
334
|
+
if as_json:
|
|
335
|
+
return _dump(data)
|
|
336
|
+
_echo(format_cpu_sizing(data, not no_headers))
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _history_text(d: Dict[str, Any]) -> str:
|
|
340
|
+
out = [f"{d.get('namespace')}/{d.get('owner_kind')}/{d.get('owner_name')} in pool {d.get('pool_id')}, "
|
|
341
|
+
f"last {d.get('window_days')} days"]
|
|
342
|
+
for c in d.get("containers", []):
|
|
343
|
+
rec = c.get("recommendation") or {}
|
|
344
|
+
out += ["", f"Container {c.get('container')}: recommended {_cpu_recommended(rec)}"
|
|
345
|
+
+ (", CLIPPED: the CPU limit cut the peak" if c.get("clipped") else "")]
|
|
346
|
+
out.append(_table(("HOUR", "SAMPLES", "AVG", "P95", "MAX", "REQ", "LIM"), [
|
|
347
|
+
(str(p.get("hour")), str(p.get("samples")), _units(p.get("avg_units")), _units(p.get("p95_units")),
|
|
348
|
+
_units(p.get("max_units")), _units(p.get("request_units")), _units(p.get("limit_units")))
|
|
349
|
+
for p in c.get("points", [])], True))
|
|
350
|
+
return "\n".join(out)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
@pool.command(name="cpu-sizing-history")
|
|
354
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
355
|
+
@click.argument("namespace")
|
|
356
|
+
@click.argument("owner_kind", metavar="OWNER_KIND")
|
|
357
|
+
@click.argument("owner_name", metavar="OWNER_NAME")
|
|
358
|
+
@click.option("--window-days", type=CPU_SIZING_WINDOW, default=None, help="Days of hourly points (1-35, default 14)")
|
|
359
|
+
@json_option
|
|
360
|
+
@click.pass_context
|
|
361
|
+
def cpu_sizing_history(ctx, pool_ref, namespace, owner_kind, owner_name, window_days, as_json):
|
|
362
|
+
"""Show the hourly cpu-units usage of one workload, per container (values in cpu-units)."""
|
|
363
|
+
from urllib.parse import quote
|
|
364
|
+
segments = "/".join(quote(s, safe="") for s in (namespace, owner_kind, owner_name))
|
|
365
|
+
params = {"window_days": window_days} if window_days is not None else None
|
|
366
|
+
|
|
367
|
+
def go(org):
|
|
368
|
+
return _call(org, "GET", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/workloads/{segments}/history", READ,
|
|
369
|
+
params=params)
|
|
370
|
+
data = _run(ctx, go)
|
|
371
|
+
if as_json:
|
|
372
|
+
return _dump(data)
|
|
373
|
+
_echo(_history_text(data))
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
# --- cpu-units Auto: mode, preview and per-workload selections ---
|
|
377
|
+
|
|
378
|
+
CPU_UNITS_MODES = click.Choice(["advise", "selected", "full"])
|
|
379
|
+
RESTART_NOTE = "Values apply when pods are created: run kubectl rollout restart <kind>/<name> -n <ns>"
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def _wl_path(namespace: str, owner_kind: str, owner_name: str) -> str:
|
|
383
|
+
from urllib.parse import quote
|
|
384
|
+
return "/".join(quote(s, safe="") for s in (namespace, owner_kind, owner_name))
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def _cpu_pair(units, limit, req_mcpu=None, lim_mcpu=None) -> str:
|
|
388
|
+
if units is not None or limit is not None:
|
|
389
|
+
return f"{_units(units)}/{_units(limit)}u"
|
|
390
|
+
if req_mcpu is not None or lim_mcpu is not None:
|
|
391
|
+
return f"{_units(req_mcpu)}/{_units(lim_mcpu)}m"
|
|
392
|
+
return "-"
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def _mode_line(d: Dict[str, Any]) -> str:
|
|
396
|
+
return f"mode {d.get('mode')}, convert raw requests: {'yes' if d.get('full_convert_raw') else 'no'}"
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def _preview_text(d: Dict[str, Any]) -> str:
|
|
400
|
+
cur, tgt = d.get("current") or {}, d.get("target") or {}
|
|
401
|
+
out = [f"Pool {d.get('pool_id')}: {_mode_line(cur)} -> {_mode_line(tgt)} ({d.get('direction')})"]
|
|
402
|
+
rows = []
|
|
403
|
+
for w in d.get("workloads", []):
|
|
404
|
+
name = f"{w.get('namespace')}/{w.get('owner_kind')}/{w.get('owner_name')}"
|
|
405
|
+
for c in w.get("containers", []):
|
|
406
|
+
rows.append((name, str(c.get("container")),
|
|
407
|
+
_cpu_pair(c.get("current_units"), c.get("current_limit_units"),
|
|
408
|
+
c.get("current_request_mcpu"), c.get("current_limit_mcpu"))
|
|
409
|
+
+ " -> " + _cpu_pair(c.get("target_units"), c.get("target_limit_units")),
|
|
410
|
+
str(c.get("status"))))
|
|
411
|
+
out.append(_table(("WORKLOAD", "CONTAINER", "CURRENT -> TARGET", "STATUS"), rows, True) if rows
|
|
412
|
+
else "No workload changes.")
|
|
413
|
+
for key, label in (("excluded", "Excluded"), ("released", "Released")):
|
|
414
|
+
names = [f"{w.get('namespace')}/{w.get('owner_kind')}/{w.get('owner_name')}" for w in d.get(key) or []]
|
|
415
|
+
if names:
|
|
416
|
+
out.append(f"{label}: " + ", ".join(names))
|
|
417
|
+
out.append(f"Raw kept: {d.get('raw_kept', 0)}. Raw converted: {d.get('raw_converted', 0)}. "
|
|
418
|
+
f"Waiting for data: {d.get('waiting_for_data', 0)}.")
|
|
419
|
+
return "\n".join(out)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
@pool.command(name="cpu-units-mode")
|
|
423
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
424
|
+
@click.option("--preview", "preview_mode", type=CPU_UNITS_MODES, default=None,
|
|
425
|
+
help="Show what a change to this mode would do. Changes nothing")
|
|
426
|
+
@click.option("--set", "set_mode", type=CPU_UNITS_MODES, default=None,
|
|
427
|
+
help="Change the mode: shows the preview, asks, then applies it")
|
|
428
|
+
@click.option("--convert-raw", is_flag=True, default=False, help="With --preview or --set: also convert raw CPU requests")
|
|
429
|
+
@click.option("-y", "--yes", is_flag=True, help="With --set: apply without asking")
|
|
430
|
+
@json_option
|
|
431
|
+
@click.pass_context
|
|
432
|
+
def cpu_units_mode(ctx, pool_ref, preview_mode, set_mode, convert_raw, yes, as_json):
|
|
433
|
+
"""Show, preview or set the cpu-units Auto mode of a pool (advise, selected, full).
|
|
434
|
+
|
|
435
|
+
Without options it shows the current mode. --set always fetches the preview first, shows it, and applies
|
|
436
|
+
it only after you confirm (or --yes). It needs Write access."""
|
|
437
|
+
if preview_mode and set_mode:
|
|
438
|
+
raise click.UsageError("Use --preview or --set, not both.")
|
|
439
|
+
if convert_raw and not (preview_mode or set_mode):
|
|
440
|
+
raise click.UsageError("--convert-raw needs --preview or --set.")
|
|
441
|
+
if set_mode and not yes and not _stdin_is_tty():
|
|
442
|
+
click.echo("Error: Refusing to change the mode without confirmation. Run again with --yes.", err=True)
|
|
443
|
+
sys.exit(exitcodes.ERROR)
|
|
444
|
+
target = preview_mode or set_mode
|
|
445
|
+
|
|
446
|
+
def go(org):
|
|
447
|
+
base = f"/pools/{resolve(org, pool_ref)}/cpu-sizing/mode"
|
|
448
|
+
if not target:
|
|
449
|
+
data = _call(org, "GET", base, READ)
|
|
450
|
+
_dump(data) if as_json else click.echo(f"Pool {data.get('pool_id')}: {_mode_line(data)}")
|
|
451
|
+
return 0
|
|
452
|
+
params = {"mode": target, "full_convert_raw": "true" if convert_raw else "false"}
|
|
453
|
+
plan = _call(org, "GET", base + "/preview", READ, params=params)
|
|
454
|
+
if not set_mode:
|
|
455
|
+
_dump(plan) if as_json else click.echo(_preview_text(plan))
|
|
456
|
+
return 0
|
|
457
|
+
if not as_json:
|
|
458
|
+
click.echo(_preview_text(plan))
|
|
459
|
+
if not yes and not click.confirm("Apply this change?", default=False):
|
|
460
|
+
click.echo("Nothing changed.", err=True)
|
|
461
|
+
return exitcodes.ERROR
|
|
462
|
+
body = {"mode": set_mode, "full_convert_raw": convert_raw, "plan_hash": plan.get("plan_hash")}
|
|
463
|
+
try:
|
|
464
|
+
data = api.call("PUT", org, base, body=body, scope=WRITE)
|
|
465
|
+
except api.ApiError as ex:
|
|
466
|
+
if ex.status == 409:
|
|
467
|
+
raise PoolError(f"The plan changed; run again. ({ex})", ex.exit_code)
|
|
468
|
+
raise _fail(ex)
|
|
469
|
+
if as_json:
|
|
470
|
+
_dump(data)
|
|
471
|
+
else:
|
|
472
|
+
click.echo(f"Pool {data.get('pool_id')}: {_mode_line(data)}")
|
|
473
|
+
click.echo(RESTART_NOTE)
|
|
474
|
+
return 0
|
|
475
|
+
sys.exit(_run(ctx, go) or 0)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def _pin(ctx, param, values):
|
|
479
|
+
"""``CONTAINER=UNITS[:LIMIT]`` -> {container, units, limit_units}; LIMIT defaults to UNITS."""
|
|
480
|
+
out = []
|
|
481
|
+
for v in values:
|
|
482
|
+
name, sep, rest = v.partition("=")
|
|
483
|
+
units, _, limit = rest.partition(":")
|
|
484
|
+
try:
|
|
485
|
+
u = int(units)
|
|
486
|
+
lim = int(limit) if limit else u
|
|
487
|
+
except ValueError:
|
|
488
|
+
u = lim = 0
|
|
489
|
+
if not name or not sep or u < 1 or lim < 1:
|
|
490
|
+
raise click.BadParameter(f"'{v}' is not CONTAINER=UNITS[:LIMIT] with whole numbers above 0.")
|
|
491
|
+
out.append({"container": name, "units": u, "limit_units": lim})
|
|
492
|
+
return out
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
@pool.command(name="cpu-units-select")
|
|
496
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
497
|
+
@click.argument("namespace")
|
|
498
|
+
@click.argument("owner_kind", metavar="OWNER_KIND")
|
|
499
|
+
@click.argument("owner_name", metavar="OWNER_NAME")
|
|
500
|
+
@click.option("--pin", "pins", multiple=True, callback=_pin, metavar="CONTAINER=UNITS[:LIMIT]",
|
|
501
|
+
help="Fix the units of a container (repeat per container). LIMIT defaults to UNITS")
|
|
502
|
+
@click.option("--exclude", is_flag=True, default=False, help="Leave this workload alone")
|
|
503
|
+
@click.option("--convert-raw", is_flag=True, default=False, help="Also convert the workload's raw CPU requests")
|
|
504
|
+
@click.option("--startup-units", type=click.IntRange(min=1), default=None, help="Units for the startup phase")
|
|
505
|
+
@json_option
|
|
506
|
+
@click.pass_context
|
|
507
|
+
def cpu_units_select(ctx, pool_ref, namespace, owner_kind, owner_name, pins, exclude, convert_raw, startup_units,
|
|
508
|
+
as_json):
|
|
509
|
+
"""Choose how cpu-units Auto treats one workload: follow (default), pinned (--pin) or excluded (--exclude)."""
|
|
510
|
+
if pins and exclude:
|
|
511
|
+
raise click.UsageError("Use --pin or --exclude, not both.")
|
|
512
|
+
body = {"choice": "excluded" if exclude else "pinned" if pins else "follow", "convert_raw": convert_raw,
|
|
513
|
+
"containers": list(pins) if pins else None, "startup_units": startup_units}
|
|
514
|
+
|
|
515
|
+
def go(org):
|
|
516
|
+
return _call(org, "PUT", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/workloads/"
|
|
517
|
+
f"{_wl_path(namespace, owner_kind, owner_name)}/selection", WRITE, body=body)
|
|
518
|
+
data = _run(ctx, go)
|
|
519
|
+
if as_json:
|
|
520
|
+
return _dump(data)
|
|
521
|
+
click.echo(f"{namespace}/{owner_kind}/{owner_name}: {data.get('choice')}")
|
|
522
|
+
click.echo(RESTART_NOTE)
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
@pool.command(name="cpu-units-unselect")
|
|
526
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
527
|
+
@click.argument("namespace")
|
|
528
|
+
@click.argument("owner_kind", metavar="OWNER_KIND")
|
|
529
|
+
@click.argument("owner_name", metavar="OWNER_NAME")
|
|
530
|
+
@click.pass_context
|
|
531
|
+
def cpu_units_unselect(ctx, pool_ref, namespace, owner_kind, owner_name):
|
|
532
|
+
"""Remove the selection of one workload. In selected mode it leaves Auto; in full mode it follows the recommendation."""
|
|
533
|
+
def go(org):
|
|
534
|
+
return _call(org, "DELETE", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/workloads/"
|
|
535
|
+
f"{_wl_path(namespace, owner_kind, owner_name)}/selection", WRITE,
|
|
536
|
+
accept=(200, 204))
|
|
537
|
+
_run(ctx, go)
|
|
538
|
+
click.echo(f"{namespace}/{owner_kind}/{owner_name}: selection removed")
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
# --- cpu-units Roll now ---
|
|
542
|
+
|
|
543
|
+
def _roll_line(r: Dict[str, Any]) -> str:
|
|
544
|
+
"""One line: roll id, workload, state (with the progress and reason), and the last error."""
|
|
545
|
+
state = str(r.get("state"))
|
|
546
|
+
if r.get("pods_total") is not None:
|
|
547
|
+
state += f" ({r.get('pods_rolled', 0)} of {r.get('pods_total')})"
|
|
548
|
+
if r.get("reason"):
|
|
549
|
+
state += f", {r.get('reason')}"
|
|
550
|
+
line = f"Roll {r.get('roll_id')}: {r.get('namespace')}/{r.get('owner_kind')}/{r.get('owner_name')}: {state}"
|
|
551
|
+
return line + (f". {r.get('message')}" if r.get("message") else "")
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
@pool.command(name="cpu-units-roll")
|
|
555
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
556
|
+
@click.argument("namespace")
|
|
557
|
+
@click.argument("owner_kind", metavar="OWNER_KIND")
|
|
558
|
+
@click.argument("owner_name", metavar="OWNER_NAME")
|
|
559
|
+
@click.option("--allow-downtime", is_flag=True, default=False,
|
|
560
|
+
help="Accept downtime for a workload with 1 replica (it is down until the new pod is Ready)")
|
|
561
|
+
@click.option("-y", "--yes", is_flag=True, help="Roll without asking")
|
|
562
|
+
@json_option
|
|
563
|
+
@click.pass_context
|
|
564
|
+
def cpu_units_roll(ctx, pool_ref, namespace, owner_kind, owner_name, allow_downtime, yes, as_json):
|
|
565
|
+
"""Roll now: replace the pods of one workload, one at a time, so the new pods get the Auto value.
|
|
566
|
+
|
|
567
|
+
It evicts the pods through the Eviction API (PDBs apply). The workload object does not change. It asks for
|
|
568
|
+
confirmation first (--yes skips it). Check progress with: mctl pool cpu-units-rolls POOL. Needs Write access."""
|
|
569
|
+
name = f"{namespace}/{owner_kind}/{owner_name}"
|
|
570
|
+
if not yes and not _stdin_is_tty():
|
|
571
|
+
click.echo("Error: Refusing to roll without confirmation. Run again with --yes.", err=True)
|
|
572
|
+
sys.exit(exitcodes.ERROR)
|
|
573
|
+
if not yes and not click.confirm(f"Evict the pods of {name} one at a time?"
|
|
574
|
+
+ (" It is down until the new pod is Ready." if allow_downtime else ""),
|
|
575
|
+
default=False):
|
|
576
|
+
click.echo("Nothing changed.", err=True)
|
|
577
|
+
sys.exit(exitcodes.ERROR)
|
|
578
|
+
|
|
579
|
+
def go(org):
|
|
580
|
+
return _call(org, "POST", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/workloads/"
|
|
581
|
+
f"{_wl_path(namespace, owner_kind, owner_name)}/roll", WRITE,
|
|
582
|
+
body={"allow_downtime": allow_downtime})
|
|
583
|
+
data = _run(ctx, go)
|
|
584
|
+
if as_json:
|
|
585
|
+
return _dump(data)
|
|
586
|
+
click.echo(_roll_line(data))
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
@pool.command(name="cpu-units-rolls")
|
|
590
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
591
|
+
@click.option("--all", "show_all", is_flag=True, default=False, help="Also the finished rolls")
|
|
592
|
+
@json_option
|
|
593
|
+
@click.pass_context
|
|
594
|
+
def cpu_units_rolls(ctx, pool_ref, show_all, as_json):
|
|
595
|
+
"""List the Roll now requests of a pool, newest first. Default: the active ones (queued, rolling, blocked)."""
|
|
596
|
+
def go(org):
|
|
597
|
+
return _call(org, "GET", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/rolls", READ,
|
|
598
|
+
params={"state": "all" if show_all else "active"})
|
|
599
|
+
data = _run(ctx, go)
|
|
600
|
+
if as_json:
|
|
601
|
+
return _dump(data)
|
|
602
|
+
items = data.get("items") or []
|
|
603
|
+
if not items:
|
|
604
|
+
click.echo("No rolls." if show_all else "No active rolls. Use --all to list finished ones.")
|
|
605
|
+
return
|
|
606
|
+
click.echo(_table(("ID", "WORKLOAD", "STATE", "PODS", "REASON", "MESSAGE"), [
|
|
607
|
+
(str(r.get("roll_id")), f"{r.get('namespace')}/{r.get('owner_kind')}/{r.get('owner_name')}",
|
|
608
|
+
str(r.get("state")),
|
|
609
|
+
f"{r.get('pods_rolled', 0)}/{r.get('pods_total')}" if r.get("pods_total") is not None else "-",
|
|
610
|
+
str(r.get("reason") or "-"), str(r.get("message") or "")) for r in items], True))
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
@pool.command(name="cpu-units-roll-cancel")
|
|
614
|
+
@click.argument("pool_ref", metavar="POOL")
|
|
615
|
+
@click.argument("roll_id", type=click.IntRange(min=1))
|
|
616
|
+
@json_option
|
|
617
|
+
@click.pass_context
|
|
618
|
+
def cpu_units_roll_cancel(ctx, pool_ref, roll_id, as_json):
|
|
619
|
+
"""Cancel a Roll now request. The roller stops before its next eviction; replaced pods keep their new values."""
|
|
620
|
+
def go(org):
|
|
621
|
+
return _call(org, "DELETE", f"/pools/{resolve(org, pool_ref)}/cpu-sizing/rolls/{roll_id}", WRITE,
|
|
622
|
+
accept=(200, 202))
|
|
623
|
+
data = _run(ctx, go)
|
|
624
|
+
if as_json:
|
|
625
|
+
return _dump(data)
|
|
626
|
+
click.echo(_roll_line(data))
|
|
627
|
+
|
|
628
|
+
|
|
275
629
|
def _json_value(ctx, param, value):
|
|
276
630
|
"""A JSON value, or ``@path`` to read it from a file (``@-``: standard input)."""
|
|
277
631
|
if value is None:
|
|
@@ -425,6 +779,11 @@ def _settings_body(sets, resets, settings_json) -> Dict[str, Any]:
|
|
|
425
779
|
help="Runner classes of the pool; repeat or separate with commas")
|
|
426
780
|
@click.option("--clouds", callback=_json_value, default=None,
|
|
427
781
|
help="JSON list of {type, regions, exclude_regions, use} for clouds the pool has (use false turns one cloud off), or @file.json")
|
|
782
|
+
@click.option("--cloud-account", "cloud_accounts", type=int, multiple=True, metavar="ID",
|
|
783
|
+
help="Replace the pool's connected cloud accounts with these (see: mctl cloud-account list). "
|
|
784
|
+
"Repeat for more (one per cloud); an account you leave out is removed (409 ACCOUNT_HAS_NODES "
|
|
785
|
+
"while the pool has nodes on it). Not with --clouds. The API key needs the Infrastructure "
|
|
786
|
+
"(infra) scope")
|
|
428
787
|
@click.option("--max-servers", type=int, default=None, help="Most nodes the pool may run (1-100)")
|
|
429
788
|
@click.option("--set", "sets", multiple=True, metavar="NAME=VALUE",
|
|
430
789
|
help="Set one setting; VALUE is JSON, else a string (a name list may be comma separated); grant.cpu for grant fields. Repeat")
|
|
@@ -433,8 +792,8 @@ def _settings_body(sets, resets, settings_json) -> Dict[str, Any]:
|
|
|
433
792
|
help="JSON object of settings (null resets one), or @file.json")
|
|
434
793
|
@json_option
|
|
435
794
|
@click.pass_context
|
|
436
|
-
def update(ctx, pool_ref, spot_policy, cpu_units_requests, max_cost_per_hour, classes_, clouds,
|
|
437
|
-
sets, resets, settings_json, as_json):
|
|
795
|
+
def update(ctx, pool_ref, spot_policy, cpu_units_requests, max_cost_per_hour, classes_, clouds, cloud_accounts,
|
|
796
|
+
max_servers, sets, resets, settings_json, as_json):
|
|
438
797
|
"""Change a pool. Only the options you give are sent."""
|
|
439
798
|
if max_servers is not None and not 1 <= max_servers <= 100:
|
|
440
799
|
raise click.UsageError("--max-servers must be a whole number from 1 to 100.")
|
|
@@ -442,13 +801,18 @@ def update(ctx, pool_ref, spot_policy, cpu_units_requests, max_cost_per_hour, cl
|
|
|
442
801
|
body = _collect(spot_policy=spot_policy, cpu_units_requests=cpu_units_requests,
|
|
443
802
|
max_cost_per_hour=max_cost_per_hour, classes=classes_, clouds=clouds,
|
|
444
803
|
max_servers=max_servers)
|
|
804
|
+
if cloud_accounts:
|
|
805
|
+
if clouds is not None:
|
|
806
|
+
raise click.UsageError("Use --cloud-account or --clouds, not both.")
|
|
807
|
+
body["cloud_accounts"] = [{"id": i} for i in cloud_accounts]
|
|
445
808
|
if settings:
|
|
446
809
|
body["settings"] = settings
|
|
447
810
|
if not body:
|
|
448
811
|
raise click.UsageError("Give at least one option to change.")
|
|
449
812
|
|
|
450
813
|
def go(org):
|
|
451
|
-
return _call(org, "PATCH", f"/pools/{resolve(org, pool_ref)}",
|
|
814
|
+
return _call(org, "PATCH", f"/pools/{resolve(org, pool_ref)}",
|
|
815
|
+
"infra" if "cloud_accounts" in body else WRITE, body=body)
|
|
452
816
|
data = _run(ctx, go)
|
|
453
817
|
if as_json:
|
|
454
818
|
return _dump(data)
|