import time
import urllib.parse
from pathlib import Path
-from typing import Union
+from typing import Dict, List, Union
+import ipaddress
import requests
def set_num_workers(self, n: int):
response = requests.post(self._create_url("/config/server/workers"), data=str(n))
print(response.text)
+
+ def set_static_hints(self, hints: Dict[str, List[Union[ipaddress.IPv4Address, ipaddress.IPv6Address]]]):
+ payload = [
+ {
+ "name": name,
+ "addresses": [str(a) for a in addrs]
+ }
+ for name, addrs in hints.items()
+ ]
+ response = requests.post(self._create_url("/config/static-hints/hints"), json=payload)
+ print(response.text)
+
+ def set_listen_ip_address(self, ip: Union[ipaddress.IPv4Address, ipaddress.IPv6Address], port: int):
+ payload = [
+ {
+ "listen": {
+ "ip": str(ip),
+ "port": port
+ }
+ }
+ ]
+ response = requests.post(self._create_url("/config/network/interfaces"), json=payload)
+ print(response)
def wait_for_initialization(self, timeout_sec: float = 5, time_step: float = 0.4):
started = time.time()
+import ipaddress
import sys
import click
client = KnotManagerClient(ctx.obj[BASE_URL])
client.set_num_workers(instances)
+@main.command("one-static-hint", help="Set one inline static-hint hints (replaces old static hints)")
+@click.argument("name", type=str, nargs=1)
+@click.argument("ip", type=str, nargs=1)
+@click.pass_context
+def one_static_hint(ctx: click.Context, name: str, ip: str):
+ client = KnotManagerClient(ctx.obj[BASE_URL])
+ client.set_static_hints({name: [ipaddress.ip_address(ip)]})
+
+@main.command("listen-ip", help="Configure where the resolver should listen (replaces all previous locations)")
+@click.argument("ip", type=str, nargs=1)
+@click.argument("port", type=int, nargs=1)
+@click.pass_context
+def listen_ip(ctx: click.Context, ip: str, port: int):
+ client = KnotManagerClient(ctx.obj[BASE_URL])
+ client.set_listen_ip_address(ipaddress.ip_address(ip), port)
+
@main.command(help="Wait for manager initialization")
@click.pass_context
_used: "weakref.WeakSet[KresID]" = weakref.WeakSet()
-def alloc() -> KresID:
+def alloc(_custom_name_id: bool=False) -> KresID:
for i in itertools.count(start=1):
- val = KresID(i)
+ val = KresID(i if not _custom_name_id else -i)
if val not in _used:
_used.add(val)
return val
_used.add(res)
return res
else:
- res = alloc()
+ # this would be for example 'gc'
+ # we want a special value, so that they do not clash with normal numerical values
+ res = alloc(_custom_name_id=True)
res.set_custom_str_representation(val)
return res
# we can't easily check, if the unit is transient or not without additional systemd call
# we ignore it for now and assume the default persistency state. It shouldn't cause any
# problems, because interactions with the process are done the same way in all cases
- res.append(SystemdSubprocess(SubprocessType.GC, alloc(), self._systemd_type))
+ res.append(SystemdSubprocess(SubprocessType.GC, alloc_from_string("gc"), self._systemd_type))
return res
async def initialize_controller(self) -> None:
await server.wait_for_shutdown()
- logger.info("Gracefull shutdown triggered. Cleaning up...")
+ logger.info("Gracefull shutdown triggered.")
+ logger.info("Stopping API service...")
await server.shutdown()
+ logger.info("Stopping kresd manager...")
await manager.stop()
logger.info(f"The manager run for {round(time() - start_time)} seconds... Hope it served well. Bye!")
echo API will be running on port 5000
echo ----------------------------------------
-poetry run python -m debugpy --listen 0.0.0.0:5678 --wait-for-client -m knot_resolver_manager 5000 $@
\ No newline at end of file
+poetry run python -m debugpy --listen 0.0.0.0:5678 --wait-for-client -m knot_resolver_manager $@
\ No newline at end of file