dinemic-cli 0.0.19__py3-none-any.whl
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.
- dinemic_cli/__init__.py +1 -0
- dinemic_cli/__main__.py +16 -0
- dinemic_cli/client.py +75 -0
- dinemic_cli/commands/__init__.py +0 -0
- dinemic_cli/commands/auth.py +31 -0
- dinemic_cli/commands/caa.py +11 -0
- dinemic_cli/commands/cert.py +29 -0
- dinemic_cli/commands/cert_peer.py +37 -0
- dinemic_cli/commands/dns_entry.py +57 -0
- dinemic_cli/commands/dns_value.py +43 -0
- dinemic_cli/commands/dns_zone.py +98 -0
- dinemic_cli/commands/endpoint.py +39 -0
- dinemic_cli/commands/healthcheck.py +40 -0
- dinemic_cli/commands/loadbalancer.py +39 -0
- dinemic_cli/commands/loadbalancer_backend.py +44 -0
- dinemic_cli/commands/loadbalancer_host.py +37 -0
- dinemic_cli/commands/loadbalancer_route.py +42 -0
- dinemic_cli/commands/network.py +34 -0
- dinemic_cli/commands/node.py +29 -0
- dinemic_cli/commands/peer.py +33 -0
- dinemic_cli/commands/peer_config.py +33 -0
- dinemic_cli/commands/project.py +58 -0
- dinemic_cli/commands/quota.py +22 -0
- dinemic_cli/main.py +68 -0
- dinemic_cli/output.py +25 -0
- dinemic_cli-0.0.19.dist-info/METADATA +13 -0
- dinemic_cli-0.0.19.dist-info/RECORD +63 -0
- dinemic_cli-0.0.19.dist-info/WHEEL +5 -0
- dinemic_cli-0.0.19.dist-info/entry_points.txt +2 -0
- dinemic_cli-0.0.19.dist-info/licenses/LICENSE +696 -0
- dinemic_cli-0.0.19.dist-info/top_level.txt +2 -0
- tests/01-cli-fixes.patch +418 -0
- tests/02-tests-after-fixes.patch +208 -0
- tests/api_samples.py +214 -0
- tests/cert_peer.py +37 -0
- tests/cli_runner.py +113 -0
- tests/command_matrix.py +612 -0
- tests/conftest.py +235 -0
- tests/dns_entry.py +41 -0
- tests/dns_value.py +43 -0
- tests/dns_zone.py +38 -0
- tests/endpoint.py +39 -0
- tests/healthcheck.py +40 -0
- tests/loadbalancer.py +36 -0
- tests/loadbalancer_backend.py +44 -0
- tests/loadbalancer_host.py +37 -0
- tests/loadbalancer_route.py +42 -0
- tests/network.py +34 -0
- tests/network_node.py +74 -0
- tests/node.py +23 -0
- tests/peer.py +33 -0
- tests/project.py +58 -0
- tests/support.py +246 -0
- tests/test_auth.py +114 -0
- tests/test_columns.py +58 -0
- tests/test_commands.py +98 -0
- tests/test_confirmations.py +71 -0
- tests/test_envvars.py +119 -0
- tests/test_error_handling.py +83 -0
- tests/test_lifecycle.py +188 -0
- tests/test_network_node.py +116 -0
- tests/test_option_contract.py +335 -0
- tests/test_smoke.py +83 -0
tests/conftest.py
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""Fixtures for the CLI test suite — unit and integration.
|
|
2
|
+
|
|
3
|
+
Unit helpers live in ``support.py``, integration helpers (running the CLI, the
|
|
4
|
+
command-path map) in ``cli_runner.py``. This file holds fixtures ONLY.
|
|
5
|
+
|
|
6
|
+
The integration fixtures (``cli``, ``project``, ``unique_suffix``) are at the
|
|
7
|
+
bottom. Without ``DINEMIC_API_URL`` and ``DINEMIC_API_TOKEN`` the tests that use
|
|
8
|
+
them are skipped rather than failing.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import os
|
|
15
|
+
import re
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
import uuid
|
|
20
|
+
|
|
21
|
+
import pytest
|
|
22
|
+
from typer.testing import CliRunner
|
|
23
|
+
|
|
24
|
+
from cli_runner import API_TOKEN, API_URL, CLI_PATH, TIMEOUT, CliResult, extract_id, parse_json
|
|
25
|
+
from support import ( # noqa: F401 (re-exported for convenience in tests)
|
|
26
|
+
ApiError,
|
|
27
|
+
COMMAND_MODULES,
|
|
28
|
+
Call,
|
|
29
|
+
FakeClient,
|
|
30
|
+
RenderCall,
|
|
31
|
+
RenderRecorder,
|
|
32
|
+
all_output,
|
|
33
|
+
assert_ok,
|
|
34
|
+
load_command_module,
|
|
35
|
+
module_source,
|
|
36
|
+
mount,
|
|
37
|
+
typer_app_for,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# ---------------------------------------------------------------------------
|
|
41
|
+
# Unit fixtures
|
|
42
|
+
# ---------------------------------------------------------------------------
|
|
43
|
+
|
|
44
|
+
DINEMIC_ENV_VARS = (
|
|
45
|
+
"DINEMIC_API_URL",
|
|
46
|
+
"DINEMIC_API_TOKEN",
|
|
47
|
+
"DINEMIC_PROJECT",
|
|
48
|
+
"DINEMIC_ZONE",
|
|
49
|
+
"DINEMIC_LB",
|
|
50
|
+
"DINEMIC_HOST",
|
|
51
|
+
"DINEMIC_ROUTE",
|
|
52
|
+
"DINEMIC_NETWORK",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@pytest.fixture(autouse=True)
|
|
57
|
+
def clean_env(monkeypatch):
|
|
58
|
+
"""Unit tests must not depend on the developer's environment.
|
|
59
|
+
|
|
60
|
+
Without this, a ``DINEMIC_PROJECT`` exported in your shell silently
|
|
61
|
+
satisfies a required option and the test passes on your machine only.
|
|
62
|
+
"""
|
|
63
|
+
for var in DINEMIC_ENV_VARS:
|
|
64
|
+
monkeypatch.delenv(var, raising=False)
|
|
65
|
+
# headless CI has no keyring backend (section 7.7 of the doc)
|
|
66
|
+
monkeypatch.setenv("PYTHON_KEYRING_BACKEND", "keyring.backends.null.Keyring")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@pytest.fixture
|
|
70
|
+
def client() -> FakeClient:
|
|
71
|
+
return FakeClient()
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@pytest.fixture
|
|
75
|
+
def runner() -> CliRunner:
|
|
76
|
+
return CliRunner()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@pytest.fixture
|
|
80
|
+
def invoke(runner, client, monkeypatch):
|
|
81
|
+
"""Run a command with the fake client injected.
|
|
82
|
+
|
|
83
|
+
Returns ``(result, render_recorder)``. ``client`` is the same instance as the
|
|
84
|
+
``client`` fixture, so that is where the assertions go.
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
def _invoke(module_name: str, args: list[str], output: str = "table", input: str | None = None):
|
|
88
|
+
module = load_command_module(module_name)
|
|
89
|
+
recorder = RenderRecorder(getattr(module, "render", lambda *a, **k: None))
|
|
90
|
+
if hasattr(module, "render"):
|
|
91
|
+
monkeypatch.setattr(module, "render", recorder)
|
|
92
|
+
root = mount(module_name, {"client": client, "output": output})
|
|
93
|
+
result = runner.invoke(
|
|
94
|
+
root,
|
|
95
|
+
[module_name, *args],
|
|
96
|
+
input=input,
|
|
97
|
+
catch_exceptions=True,
|
|
98
|
+
)
|
|
99
|
+
return result, recorder
|
|
100
|
+
|
|
101
|
+
return _invoke
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@pytest.fixture
|
|
105
|
+
def json_invoke(invoke):
|
|
106
|
+
"""Like ``invoke`` but forces ``--output json`` and parses stdout."""
|
|
107
|
+
|
|
108
|
+
def _invoke(module_name: str, args: list[str], **kwargs):
|
|
109
|
+
result, recorder = invoke(module_name, args, output="json", **kwargs)
|
|
110
|
+
payload = None
|
|
111
|
+
if result.stdout.strip():
|
|
112
|
+
match = re.search(r"[\[{].*[\]}]", result.stdout, re.S)
|
|
113
|
+
if match:
|
|
114
|
+
try:
|
|
115
|
+
payload = json.loads(match.group(0))
|
|
116
|
+
except json.JSONDecodeError:
|
|
117
|
+
payload = None
|
|
118
|
+
return result, recorder, payload
|
|
119
|
+
|
|
120
|
+
return _invoke
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
# ---------------------------------------------------------------------------
|
|
124
|
+
# Integration fixtures (real CLI, real API)
|
|
125
|
+
# ---------------------------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@pytest.fixture(scope="session")
|
|
129
|
+
def api_url() -> str:
|
|
130
|
+
if not API_URL:
|
|
131
|
+
pytest.skip("DINEMIC_API_URL is not set")
|
|
132
|
+
return API_URL
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
@pytest.fixture(scope="session")
|
|
136
|
+
def api_token() -> str:
|
|
137
|
+
if not API_TOKEN:
|
|
138
|
+
pytest.skip("DINEMIC_API_TOKEN is not set")
|
|
139
|
+
return API_TOKEN
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@pytest.fixture(scope="session")
|
|
143
|
+
def cli_command() -> list[str]:
|
|
144
|
+
"""How to invoke the CLI: installed command, falling back to ``python -m``."""
|
|
145
|
+
override = os.environ.get("DINEMIC_CLI_BIN")
|
|
146
|
+
if override:
|
|
147
|
+
return override.split()
|
|
148
|
+
binary = shutil.which("dinemic")
|
|
149
|
+
if binary:
|
|
150
|
+
return [binary]
|
|
151
|
+
return [sys.executable, "-m", "dinemic_cli"]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@pytest.fixture(scope="session")
|
|
155
|
+
def authenticated(cli_command, api_url, api_token):
|
|
156
|
+
"""Check that the CLI authenticates with the supplied token at all.
|
|
157
|
+
|
|
158
|
+
If ``client.py`` only ever reads the token from the keyring and ignores
|
|
159
|
+
``DINEMIC_API_TOKEN``, everything else would fail with a 401 anyway — better
|
|
160
|
+
to say so once and clearly.
|
|
161
|
+
"""
|
|
162
|
+
env = dict(os.environ)
|
|
163
|
+
env["DINEMIC_API_URL"] = api_url
|
|
164
|
+
env["DINEMIC_API_TOKEN"] = api_token
|
|
165
|
+
env.setdefault("PYTHON_KEYRING_BACKEND", "keyring.backends.null.Keyring")
|
|
166
|
+
completed = subprocess.run(
|
|
167
|
+
[*cli_command, "--output", "json", *CLI_PATH["project"], "list"],
|
|
168
|
+
capture_output=True,
|
|
169
|
+
text=True,
|
|
170
|
+
env=env,
|
|
171
|
+
timeout=TIMEOUT,
|
|
172
|
+
)
|
|
173
|
+
if completed.returncode != 0:
|
|
174
|
+
pytest.skip(
|
|
175
|
+
"The CLI does not authenticate via DINEMIC_API_URL/DINEMIC_API_TOKEN.\n"
|
|
176
|
+
f"stdout: {completed.stdout}\nstderr: {completed.stderr}\n"
|
|
177
|
+
"If client.py reads the token from the keyring only, add an environment "
|
|
178
|
+
"variable fallback — otherwise the CLI is unusable in CI."
|
|
179
|
+
)
|
|
180
|
+
return True
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
@pytest.fixture(scope="session")
|
|
184
|
+
def cli(cli_command, api_url, api_token, authenticated):
|
|
185
|
+
"""Returns ``run(*args, output="json")``, which invokes the real CLI."""
|
|
186
|
+
|
|
187
|
+
def run(*args: str, output: str | None = "json", expect_ok: bool = True) -> CliResult:
|
|
188
|
+
argv = list(cli_command)
|
|
189
|
+
if output:
|
|
190
|
+
argv += ["--output", output]
|
|
191
|
+
argv += [str(a) for a in args]
|
|
192
|
+
|
|
193
|
+
env = dict(os.environ)
|
|
194
|
+
env["DINEMIC_API_URL"] = api_url
|
|
195
|
+
env["DINEMIC_API_TOKEN"] = api_token
|
|
196
|
+
# without this, headless CI dies on importing keyring (7.7)
|
|
197
|
+
env.setdefault("PYTHON_KEYRING_BACKEND", "keyring.backends.null.Keyring")
|
|
198
|
+
# context variables must come from the test, not the developer's shell
|
|
199
|
+
for var in ("DINEMIC_PROJECT", "DINEMIC_ZONE", "DINEMIC_LB", "DINEMIC_HOST",
|
|
200
|
+
"DINEMIC_ROUTE", "DINEMIC_NETWORK"):
|
|
201
|
+
env.pop(var, None)
|
|
202
|
+
|
|
203
|
+
completed = subprocess.run(
|
|
204
|
+
argv, capture_output=True, text=True, env=env, timeout=TIMEOUT
|
|
205
|
+
)
|
|
206
|
+
result = CliResult(
|
|
207
|
+
args=[str(a) for a in args],
|
|
208
|
+
exit_code=completed.returncode,
|
|
209
|
+
stdout=completed.stdout,
|
|
210
|
+
stderr=completed.stderr,
|
|
211
|
+
data=parse_json(completed.stdout),
|
|
212
|
+
)
|
|
213
|
+
if expect_ok:
|
|
214
|
+
result.ok()
|
|
215
|
+
return result
|
|
216
|
+
|
|
217
|
+
return run
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
@pytest.fixture
|
|
221
|
+
def unique_suffix() -> str:
|
|
222
|
+
"""Suffix that keeps this run's resources apart (unique_together on Config)."""
|
|
223
|
+
return uuid.uuid4().hex[:8]
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@pytest.fixture(scope="module")
|
|
227
|
+
def project(cli) -> str:
|
|
228
|
+
"""A fresh project for the duration of the module; cascade-deleted at the end."""
|
|
229
|
+
name = f"pytest-{uuid.uuid4().hex[:8]}"
|
|
230
|
+
created = cli(*CLI_PATH["project"], "create", "-n", name)
|
|
231
|
+
project_id = extract_id(created)
|
|
232
|
+
|
|
233
|
+
yield project_id
|
|
234
|
+
|
|
235
|
+
cli(*CLI_PATH["project"], "delete", "-p", project_id, "-y", expect_ok=False)
|
tests/dns_entry.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True, help="Entries for DNS zone")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_entries(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE")
|
|
12
|
+
):
|
|
13
|
+
data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/")
|
|
14
|
+
render(data, ctx.obj["output"], columns=["id", "record", "type", "ttl"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("create")
|
|
18
|
+
def create_entry(
|
|
19
|
+
ctx: typer.Context,
|
|
20
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
|
|
21
|
+
record: str = typer.Option(..., "--record", "-r", help="Record name, i.e. www (empty for zone apex)"),
|
|
22
|
+
type_: str = typer.Option(..., "--type", "-t", help="Record type, i.e. A, AAAA or MX"),
|
|
23
|
+
ttl: int = typer.Option(300, "--ttl", help="TTL value in seconds"),
|
|
24
|
+
):
|
|
25
|
+
data = ctx.obj["client"].post(
|
|
26
|
+
f"/zone/{zone_id}/entry/", {"record": record, "type": type_, "ttl": ttl}
|
|
27
|
+
)
|
|
28
|
+
typer.secho(f"Added record {data['record']} ({data['id']})", fg="green")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@app.command("delete")
|
|
32
|
+
def delete_entry(
|
|
33
|
+
ctx: typer.Context,
|
|
34
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
|
|
35
|
+
record_id: str = typer.Option(..., "--record", "-r", help="Record id"),
|
|
36
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
37
|
+
):
|
|
38
|
+
if not yes:
|
|
39
|
+
typer.confirm(f"Remove record {record_id} from zone {zone_id}?", abort=True)
|
|
40
|
+
ctx.obj["client"].delete(f"/zone/{zone_id}/entry/{record_id}/")
|
|
41
|
+
typer.secho("Removed.", fg="green")
|
tests/dns_value.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True, help="Values for entry in DNS zone")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_values(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
|
|
12
|
+
record_id: str = typer.Option(..., "--record", "-r", help="Record ID")
|
|
13
|
+
):
|
|
14
|
+
data = ctx.obj["client"].get(f"/zone/{zone_id}/entry/{record_id}/value/")
|
|
15
|
+
render(data, ctx.obj["output"], columns=["id", "value", "weight"])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.command("create")
|
|
19
|
+
def create_value(
|
|
20
|
+
ctx: typer.Context,
|
|
21
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
|
|
22
|
+
record_id: str = typer.Option(..., "--record", "-r", help="Record ID"),
|
|
23
|
+
value: str = typer.Option(..., "--value", "-v", help="Value for record"),
|
|
24
|
+
weight: int = typer.Option(1, "--weight", "-w", help="Weight"),
|
|
25
|
+
):
|
|
26
|
+
data = ctx.obj["client"].post(
|
|
27
|
+
f"/zone/{zone_id}/entry/{record_id}/value/", {"value": value, "weight": weight}
|
|
28
|
+
)
|
|
29
|
+
typer.secho(f"Added value {data['value']} ({data['id']})", fg="green")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@app.command("delete")
|
|
33
|
+
def delete_value(
|
|
34
|
+
ctx: typer.Context,
|
|
35
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
|
|
36
|
+
record_id: str = typer.Option(..., "--record", "-r", help="Record ID"),
|
|
37
|
+
value_id: str = typer.Option(..., "--value", "-v", help="Value ID"),
|
|
38
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
39
|
+
):
|
|
40
|
+
if not yes:
|
|
41
|
+
typer.confirm(f"Remove value {value_id} from record {record_id} in zone {zone_id}?", abort=True)
|
|
42
|
+
ctx.obj["client"].delete(f"/zone/{zone_id}/entry/{record_id}/value/{value_id}/")
|
|
43
|
+
typer.secho("Removed.", fg="green")
|
tests/dns_zone.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_zones(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
|
|
12
|
+
):
|
|
13
|
+
data = ctx.obj["client"].get("/zone/", project=project)
|
|
14
|
+
render(data, ctx.obj["output"], columns=["id", "domain", "project"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("create")
|
|
18
|
+
def create_zone(
|
|
19
|
+
ctx: typer.Context,
|
|
20
|
+
domain: str = typer.Option(..., "--domain", "-d", help="Domain name"),
|
|
21
|
+
project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
|
|
22
|
+
caa: str = typer.Option(..., "--caa", "-c", help="CAA ID"),
|
|
23
|
+
name: str = typer.Option(..., "--name", "-n", help="Zone name"),
|
|
24
|
+
):
|
|
25
|
+
data = ctx.obj["client"].post("/zone/", {"domain": domain, "project": project, "valid_caa": [caa], "name": name})
|
|
26
|
+
typer.secho(f"Created zone {data['domain']} ({data['id']})", fg="green")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@app.command("delete")
|
|
30
|
+
def delete_zone(
|
|
31
|
+
ctx: typer.Context,
|
|
32
|
+
zone_id: str = typer.Option(..., "--zone", "-z", help="Zone ID", envvar="DINEMIC_ZONE"),
|
|
33
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
34
|
+
):
|
|
35
|
+
if not yes:
|
|
36
|
+
typer.confirm(f"Remove DNS zone {zone_id} and all its records?", abort=True)
|
|
37
|
+
ctx.obj["client"].delete(f"/zone/{zone_id}/")
|
|
38
|
+
typer.secho("Removed.", fg="green")
|
tests/endpoint.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_endpoints(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
|
|
12
|
+
):
|
|
13
|
+
data = ctx.obj["client"].get("/endpoint/", project=project)
|
|
14
|
+
render(data, ctx.obj["output"], columns=["id", "project", "name", "scheme", "host", "port"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("create")
|
|
18
|
+
def create_endpoint(
|
|
19
|
+
ctx: typer.Context,
|
|
20
|
+
project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
|
|
21
|
+
name: str = typer.Option(..., "--name", "-n", help="Name"),
|
|
22
|
+
scheme: str = typer.Option(..., "--scheme", "-s", help="Scheme (HTTP or HTTPS)"),
|
|
23
|
+
host: str = typer.Option(..., "--host", "-H", help="Host name"),
|
|
24
|
+
port: int = typer.Option(..., "--port", "-P", help="Port number"),
|
|
25
|
+
):
|
|
26
|
+
data = ctx.obj["client"].post("/endpoint/", {"project": project, "name": name, "scheme": scheme, "host": host, "port": port, "tags": []})
|
|
27
|
+
typer.secho(f"Created endpoint {data['name']} ({data['id']})", fg="green")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@app.command("delete")
|
|
31
|
+
def delete_endpoint(
|
|
32
|
+
ctx: typer.Context,
|
|
33
|
+
endpoint_id: str = typer.Option(..., "--endpoint", "-e", help="Endpoint ID"),
|
|
34
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
35
|
+
):
|
|
36
|
+
if not yes:
|
|
37
|
+
typer.confirm(f"Remove Endpoint {endpoint_id} and all its records?", abort=True)
|
|
38
|
+
ctx.obj["client"].delete(f"/endpoint/{endpoint_id}/")
|
|
39
|
+
typer.secho("Removed.", fg="green")
|
tests/healthcheck.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_healthchecks(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
|
|
12
|
+
):
|
|
13
|
+
data = ctx.obj["client"].get("/healthcheck/", project=project)
|
|
14
|
+
render(data, ctx.obj["output"], columns=["id", "name", "project", "path", "period", "max_fail", "initial_delay"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("create")
|
|
18
|
+
def create_healthcheck(
|
|
19
|
+
ctx: typer.Context,
|
|
20
|
+
project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
|
|
21
|
+
name: str = typer.Option(..., "--name", "-n", help="Name"),
|
|
22
|
+
path: str = typer.Option(..., "--path", "-P", help="Path"),
|
|
23
|
+
period: int = typer.Option(..., "--period", "-d", help="Period (seconds)"),
|
|
24
|
+
max_fail: int = typer.Option(..., "--max-fail", "-m", help="Maximum fails before disabling"),
|
|
25
|
+
initial_delay: int = typer.Option(..., "--initial-delay", "-i", help="Initial delay (seconds)"),
|
|
26
|
+
):
|
|
27
|
+
data = ctx.obj["client"].post("/healthcheck/", {"project": project, "name": name, "path": path, "period": period, "max_fail": max_fail, "initial_delay": initial_delay})
|
|
28
|
+
typer.secho(f"Created healthcheck {data['id']}", fg="green")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@app.command("delete")
|
|
32
|
+
def delete_healthcheck(
|
|
33
|
+
ctx: typer.Context,
|
|
34
|
+
healthcheck_id: str = typer.Option(..., "--healthcheck", "-H", help="Healthcheck ID"),
|
|
35
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
36
|
+
):
|
|
37
|
+
if not yes:
|
|
38
|
+
typer.confirm(f"Remove healthcheck {healthcheck_id}?", abort=True)
|
|
39
|
+
ctx.obj["client"].delete(f"/healthcheck/{healthcheck_id}/")
|
|
40
|
+
typer.secho("Removed.", fg="green")
|
tests/loadbalancer.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_loadbalancers(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")
|
|
12
|
+
):
|
|
13
|
+
data = ctx.obj["client"].get("/loadbalancer/", project=project)
|
|
14
|
+
render(data, ctx.obj["output"], columns=["id", "name", "project"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("create")
|
|
18
|
+
def create_loadbalancer(
|
|
19
|
+
ctx: typer.Context,
|
|
20
|
+
project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
|
|
21
|
+
name: str = typer.Option(..., "--name", "-n", help="Name"),
|
|
22
|
+
):
|
|
23
|
+
data = ctx.obj["client"].post("/loadbalancer/", {"project": project, "name": name})
|
|
24
|
+
typer.secho(f"Created loadbalancer {data['name']} ({data['id']})", fg="green")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@app.command("delete")
|
|
28
|
+
def delete_loadbalancer(
|
|
29
|
+
ctx: typer.Context,
|
|
30
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID", envvar="DINEMIC_LB"),
|
|
31
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
32
|
+
):
|
|
33
|
+
if not yes:
|
|
34
|
+
typer.confirm(f"Remove loadbalancer {loadbalancer_id} and all its hosts, routes and backends?", abort=True)
|
|
35
|
+
ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/")
|
|
36
|
+
typer.secho("Removed.", fg="green")
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_backends(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
12
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
|
|
13
|
+
route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE")
|
|
14
|
+
):
|
|
15
|
+
data = ctx.obj["client"].get(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/backend/")
|
|
16
|
+
render(data, ctx.obj["output"], columns=["id", "endpoint", "weight", "route"])
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@app.command("create")
|
|
20
|
+
def create_backend(
|
|
21
|
+
ctx: typer.Context,
|
|
22
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
23
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
|
|
24
|
+
route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
|
|
25
|
+
endpoint_id: str = typer.Option(..., "--endpoint", "-e", help="Endpoint ID"),
|
|
26
|
+
weight: int = typer.Option(..., "--weight", "-w", help="Weight")
|
|
27
|
+
):
|
|
28
|
+
data = ctx.obj["client"].post(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/backend/", {"endpoint": endpoint_id, "weight": weight})
|
|
29
|
+
typer.secho(f"Created backend {data['id']} (for route {route_id} in host {host_id} in loadbalancer {loadbalancer_id})", fg="green")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@app.command("delete")
|
|
33
|
+
def delete_backend(
|
|
34
|
+
ctx: typer.Context,
|
|
35
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
36
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
|
|
37
|
+
route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
|
|
38
|
+
backend_id: str = typer.Option(..., "--backend", "-b", help="Backend ID"),
|
|
39
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
40
|
+
):
|
|
41
|
+
if not yes:
|
|
42
|
+
typer.confirm(f"Remove backend {backend_id}?", abort=True)
|
|
43
|
+
ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/backend/{backend_id}/")
|
|
44
|
+
typer.secho("Removed.", fg="green")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_hosts(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB")
|
|
12
|
+
):
|
|
13
|
+
data = ctx.obj["client"].get(f"/loadbalancer/{loadbalancer_id}/host/")
|
|
14
|
+
render(data, ctx.obj["output"], columns=["id", "domain"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@app.command("create")
|
|
18
|
+
def create_host(
|
|
19
|
+
ctx: typer.Context,
|
|
20
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
21
|
+
domain_id: str = typer.Option(..., "--domain", "-d", help="Route from DNS zone (domain)"),
|
|
22
|
+
):
|
|
23
|
+
data = ctx.obj["client"].post(f"/loadbalancer/{loadbalancer_id}/host/", {"domain": domain_id})
|
|
24
|
+
typer.secho(f"Created host {data['id']} (for loadbalancer {loadbalancer_id})", fg="green")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@app.command("delete")
|
|
28
|
+
def delete_host(
|
|
29
|
+
ctx: typer.Context,
|
|
30
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Load balancer ID", envvar="DINEMIC_LB"),
|
|
31
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
|
|
32
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
33
|
+
):
|
|
34
|
+
if not yes:
|
|
35
|
+
typer.confirm(f"Remove host {host_id} and all its routes?", abort=True)
|
|
36
|
+
ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/")
|
|
37
|
+
typer.secho("Removed.", fg="green")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_routes(
|
|
10
|
+
ctx: typer.Context,
|
|
11
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
12
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST")
|
|
13
|
+
):
|
|
14
|
+
data = ctx.obj["client"].get(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/")
|
|
15
|
+
render(data, ctx.obj["output"], columns=["id", "path", "host", "healthcheck", "priority"])
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.command("create")
|
|
19
|
+
def create_route(
|
|
20
|
+
ctx: typer.Context,
|
|
21
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
22
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
|
|
23
|
+
path: str = typer.Option(..., "--path", "-p", help="Path"),
|
|
24
|
+
priority: int = typer.Option(..., "--priority", "-P", help="Priority"),
|
|
25
|
+
healthcheck_id: str = typer.Option(..., "--healthcheck", "-k", help="Health check ID"),
|
|
26
|
+
):
|
|
27
|
+
data = ctx.obj["client"].post(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/", {"path": path, "priority": priority, "healthcheck": healthcheck_id})
|
|
28
|
+
typer.secho(f"Created route {data['id']} (for host {host_id} in loadbalancer {loadbalancer_id})", fg="green")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@app.command("delete")
|
|
32
|
+
def delete_route(
|
|
33
|
+
ctx: typer.Context,
|
|
34
|
+
loadbalancer_id: str = typer.Option(..., "--loadbalancer", "-l", help="Loadbalancer ID", envvar="DINEMIC_LB"),
|
|
35
|
+
host_id: str = typer.Option(..., "--host", "-H", help="Host ID", envvar="DINEMIC_HOST"),
|
|
36
|
+
route_id: str = typer.Option(..., "--route", "-r", help="Route ID", envvar="DINEMIC_ROUTE"),
|
|
37
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),
|
|
38
|
+
):
|
|
39
|
+
if not yes:
|
|
40
|
+
typer.confirm(f"Remove route {route_id} and all its backends?", abort=True)
|
|
41
|
+
ctx.obj["client"].delete(f"/loadbalancer/{loadbalancer_id}/host/{host_id}/route/{route_id}/")
|
|
42
|
+
typer.secho("Removed.", fg="green")
|
tests/network.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import typer
|
|
2
|
+
|
|
3
|
+
from dinemic_cli.output import render
|
|
4
|
+
|
|
5
|
+
app = typer.Typer(no_args_is_help=True)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@app.command("list")
|
|
9
|
+
def list_networks(ctx: typer.Context,
|
|
10
|
+
project: str = typer.Option(None, "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT")):
|
|
11
|
+
data = ctx.obj["client"].get("/network/", project=project)
|
|
12
|
+
render(data, ctx.obj["output"], columns=["id", "name", "project", "ip_address", "ip_netmask"])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@app.command("create")
|
|
16
|
+
def create_network(
|
|
17
|
+
ctx: typer.Context,
|
|
18
|
+
project: str = typer.Option(..., "--project", "-p", help="Project ID", envvar="DINEMIC_PROJECT"),
|
|
19
|
+
name: str = typer.Option(..., "--name", "-n", help="Network name"),
|
|
20
|
+
ip_address: str = typer.Option(..., "--ip", "-i", help="IPv4 address"),
|
|
21
|
+
ip_netmask: str = typer.Option(..., "--netmask", "-m", help="IPv4 netmask"),
|
|
22
|
+
):
|
|
23
|
+
data = ctx.obj["client"].post("/network/", {"project": project, "name": name, "ip_address": ip_address, "ip_netmask": ip_netmask})
|
|
24
|
+
typer.secho(f"Created network {data['name']} ({data['id']})", fg="green")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@app.command("delete")
|
|
28
|
+
def delete_network(ctx: typer.Context,
|
|
29
|
+
network_id: str = typer.Option(..., "--network", "-n", help="Network ID", envvar="DINEMIC_NETWORK"),
|
|
30
|
+
yes: bool = typer.Option(False, "--yes", "-y", help="Don't ask for confirmation"),):
|
|
31
|
+
if not yes:
|
|
32
|
+
typer.confirm(f"Remove network {network_id}?", abort=True)
|
|
33
|
+
ctx.obj["client"].delete(f"/network/{network_id}/")
|
|
34
|
+
typer.secho("Removed.", fg="green")
|