File: reload.py

package info (click to toggle)
knot-resolver 6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,392 kB
  • sloc: javascript: 42,732; ansic: 40,312; python: 12,616; cpp: 2,121; sh: 1,997; xml: 193; makefile: 181
file content (42 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import argparse
import sys
from typing import List, Tuple, Type

from knot_resolver.client.command import Command, CommandArgs, CompWords, register_command
from knot_resolver.utils.requests import request


@register_command
class ReloadCommand(Command):
    def __init__(self, namespace: argparse.Namespace) -> None:
        super().__init__(namespace)
        self.force: bool = namespace.force

    @staticmethod
    def register_args_subparser(
        subparser: "argparse._SubParsersAction[argparse.ArgumentParser]",
    ) -> Tuple[argparse.ArgumentParser, "Type[Command]"]:
        reload = subparser.add_parser(
            "reload",
            help="Tells the resolver to reload YAML configuration file."
            " Old processes are replaced by new ones (with updated configuration) using rolling restarts."
            " So there will be no DNS service unavailability during reload operation.",
        )
        reload.add_argument(
            "--force",
            help="Force a reload, even if the configuration hasn't changed.",
            action="store_true",
            default=False,
        )
        return reload, ReloadCommand

    @staticmethod
    def completion(args: List[str], parser: argparse.ArgumentParser) -> CompWords:
        return {}

    def run(self, args: CommandArgs) -> None:
        response = request(args.socket, "POST", "reload/force" if self.force else "reload")

        if response.status != 200:
            print(response, file=sys.stderr)
            sys.exit(1)