-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
207f69c
commit 9d9c173
Showing
6 changed files
with
154 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# coding:utf-8 | ||
|
||
from typing import Iterable | ||
|
||
from xarg import add_command | ||
from xarg import argp | ||
from xarg import commands | ||
from xarg import run_command | ||
|
||
from ...utils import podman_container | ||
|
||
|
||
def add_pos_containers(_arg: argp): | ||
_arg.add_argument(dest="containers", type=str, nargs="*", | ||
metavar="CONTAINER", action="extend", | ||
choices=list(podman_container.list()) + [[]], | ||
help="Specify containers, default ALL") | ||
|
||
|
||
@add_command("guard", help="Guard podman container") | ||
def add_cmd_container_guard(_arg: argp): | ||
add_pos_containers(_arg) | ||
|
||
|
||
@run_command(add_cmd_container_guard) | ||
def run_cmd_container_guard(cmds: commands) -> int: | ||
containers: Iterable[str] = cmds.args.containers or podman_container.list() | ||
for container_name in containers: | ||
cmds.logger.info(f"guard container {container_name}") | ||
podman_container(container_name).guard() | ||
return 0 | ||
|
||
|
||
@add_command("container", help="Manage podman containers") | ||
def add_cmd_container(_arg: argp): | ||
pass | ||
|
||
|
||
@run_command(add_cmd_container, add_cmd_container_guard) | ||
def run_cmd_container(cmds: commands) -> int: | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# coding:utf-8 | ||
|
||
from typing import List | ||
|
||
from xarg import add_command | ||
from xarg import argp | ||
from xarg import commands | ||
from xarg import run_command | ||
|
||
from ...utils import assemble_file | ||
from ...utils import podman_container | ||
from ..service import add_pos_services | ||
|
||
|
||
@add_command("generate", help="Generate container guard crontab") | ||
def add_cmd_guard_generate(_arg: argp): | ||
add_pos_services(_arg) | ||
|
||
|
||
@run_command(add_cmd_guard_generate) | ||
def run_cmd_guard_generate(cmds: commands) -> int: | ||
assemble: assemble_file = cmds.args.assemble_file | ||
assert isinstance(assemble, assemble_file) | ||
services: List[str] = cmds.args.services | ||
for service in assemble.template.services: | ||
cmds.logger.debug(f"{service.title}: {service.container_name}") | ||
if len(services) > 0 and service.title not in services: | ||
continue | ||
container_name = assemble.safe_substitute(service.container_name) | ||
cmds.logger.info(f"generate container {container_name} guard") | ||
podman_container(container_name).generate_guard_task() | ||
return 0 | ||
|
||
|
||
@add_command("guard", help="Manage containers guard") | ||
def add_cmd_guard(_arg: argp): | ||
pass | ||
|
||
|
||
@run_command(add_cmd_guard, add_cmd_guard_generate) | ||
def run_cmd_guard(cmds: commands) -> int: | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters