Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flags for podman/conmon executables #3

Merged
merged 2 commits into from
Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Dependencies

Podman-dump requires `podman` und `Python >= 3.6`.

Note that `conmon` version < 2.0.26 is affected by containers/conmon#236.
Unfortunately, this bug affects `conmon` shipped in
[Debian 11 (Bullseye)][conmon bullseye] as well as
[Ubuntu 22.04 (Jammy Jellyfish][conmon jammy]).

Use the `--conmon` flag of `podman-dump` to specify a more recent `conmon`
version to be used during dumps.

[conmon bullseye]: https://packages.debian.org/bullseye/conmon
[conmon jammy]: https://packages.ubuntu.com/jammy/conmon

Install
-------
Expand Down Expand Up @@ -72,15 +82,19 @@ Usage

```
usage: podman-dump [-h] [-p] [-v] dumpdir schedule
usage: podman-dump [-h] [-p] [-v] [--podman PODMAN] [--conmon CONMON] dumpdir schedule

positional arguments:
dumpdir The destination directory for container dumps
schedule Name of the schedule to run
dumpdir The destination directory for container dumps
schedule Name of the schedule to run

optional arguments:
-h, --help show this help message and exit
-p, --prune Prune old backups after dumping a container
-v, --verbose Turn on verbose logging
-h, --help show this help message and exit
-p, --prune Prune old backups after dumping a container
-v, --verbose Turn on verbose logging
--podman PODMAN Path of the podman binary
--conmon CONMON Path of the conmon binary

```


Expand Down
33 changes: 25 additions & 8 deletions bin/podman-dump
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,15 @@ class PodmanContainer:
"""
Represents a podman container with podman-dump configuration.
"""
podman_executable: str = "podman"
podman_cmd: Sequence[str] = []
log = logging.getLogger("PodmanContainer")

cid: str
name: str
config: dict

def __init__(self, cid: str, name: str):
def __init__(self, podman_cmd: Sequence[str], cid: str, name: str):
self.podman_cmd = podman_cmd
self.cid = cid
self.name = name

Expand All @@ -309,7 +310,7 @@ class PodmanContainer:
"""
Return a list of jobs.
"""
cmd = [self.podman_executable, 'container', 'inspect', self.cid,
cmd = self.podman_cmd + ['container', 'inspect', self.cid,
'--format', '{{index .Config.Labels "ch.znerol.podman-dump"}}',
]
output = subprocess.check_output(cmd, text=True)
Expand All @@ -322,22 +323,30 @@ class PodmanSource:
"""
Represents a podman container data source.
"""
podman_executable: str = "podman"
podman_cmd: Sequence[str] = ["podman"]
log = logging.getLogger("PodmanSource")

def __init__(self, podman: Optional[str], conmon: Optional[str]):
if podman:
self.podman_cmd = [podman]
if conmon:
self.podman_cmd.append('--conmon')
self.podman_cmd.append(conmon)

def containers(self) -> Sequence[PodmanContainer]:
"""
List available containers with a ch.znerol.podman-dump label
"""
self.log.debug("Listing containers")

cmd = [self.podman_executable, 'ps',
cmd = self.podman_cmd + [
'ps',
'--filter', 'status=running',
'--filter', 'label=ch.znerol.podman-dump',
'--format', '{{.ID}} {{.Names}}',
]
lines = subprocess.check_output(cmd, text=True).splitlines()
result = [PodmanContainer(*line.split()) for line in lines]
result = [PodmanContainer(self.podman_cmd, *line.split()) for line in lines]

self.log.debug("Found %i containers", len(result))
return result
Expand All @@ -356,7 +365,7 @@ class PodmanSource:
self.log.debug("Start dumping %s", name)

if len(dumpcmd) > 0:
cmd = [self.podman_executable, 'exec'] + execargs + [cid] + dumpcmd
cmd = self.podman_cmd + ['exec'] + execargs + [cid] + dumpcmd
with subprocess.Popen(
cmd,
stdin=subprocess.DEVNULL,
Expand Down Expand Up @@ -393,6 +402,14 @@ def main(prog, args):
"-v", "--verbose", action="store_true", dest="verbose",
help="Turn on verbose logging"
)
parser.add_argument(
"--podman", dest="podman",
help="Path of the podman binary",
)
parser.add_argument(
"--conmon", dest="conmon",
help="Path of the conmon binary",
)
parser.add_argument(
"dumpdir", type=str,
help="The destination directory for container dumps"
Expand All @@ -407,7 +424,7 @@ def main(prog, args):
level = logging.DEBUG if options.verbose else logging.INFO
logging.basicConfig(level=level)

source = PodmanSource()
source = PodmanSource(podman=options.podman, conmon=options.conmon)

for container in source.containers():
datestamp = datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion doc/podman-dump.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ podman-dump
Synopsis
--------

**podman-dump** [*-p*] [*-v*] [*dumpdir*] [*schedule*]
**podman-dump** [*-p*] [*-v*] [*--podman PODMAN*] [*--conmon CONMON*] [*dumpdir*] [*schedule*]


Description
Expand Down