From dba45a13c0e1829fb08613fc51cd1099bc7c7d25 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 14 Nov 2018 06:46:59 -0500 Subject: Add version command to pypodman pypodman does not currently support the version command. We want to have as close to the same functionality between podman and pypodman, so adding this command. Also had to fix some validate errors. Signed-off-by: Daniel J Walsh --- .../pypodman/pypodman/lib/actions/__init__.py | 2 ++ .../pypodman/lib/actions/version_action.py | 41 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 contrib/python/pypodman/pypodman/lib/actions/version_action.py (limited to 'contrib/python') diff --git a/contrib/python/pypodman/pypodman/lib/actions/__init__.py b/contrib/python/pypodman/pypodman/lib/actions/__init__.py index 2668cd8ff..bc863ce6d 100644 --- a/contrib/python/pypodman/pypodman/lib/actions/__init__.py +++ b/contrib/python/pypodman/pypodman/lib/actions/__init__.py @@ -22,6 +22,7 @@ from pypodman.lib.actions.rm_action import Rm from pypodman.lib.actions.rmi_action import Rmi from pypodman.lib.actions.run_action import Run from pypodman.lib.actions.search_action import Search +from pypodman.lib.actions.version_action import Version __all__ = [ 'Attach', @@ -47,4 +48,5 @@ __all__ = [ 'Rmi', 'Run', 'Search', + 'Version', ] diff --git a/contrib/python/pypodman/pypodman/lib/actions/version_action.py b/contrib/python/pypodman/pypodman/lib/actions/version_action.py new file mode 100644 index 000000000..12b6dc576 --- /dev/null +++ b/contrib/python/pypodman/pypodman/lib/actions/version_action.py @@ -0,0 +1,41 @@ +"""Remote client command for reporting on Podman service.""" +import json +import sys + +import podman +import yaml +from pypodman.lib import AbstractActionBase + + +class Version(AbstractActionBase): + """Class for reporting on Podman Service.""" + + @classmethod + def subparser(cls, parent): + """Add Version command to parent parser.""" + parser = parent.add_parser( + 'version', help='report version on podman service') + parser.set_defaults(class_=cls, method='version') + + def __init__(self, args): + """Construct Version class.""" + super().__init__(args) + + def version(self): + """Report on Podman Service.""" + try: + info = self.client.system.info() + except podman.ErrorOccurred as e: + sys.stdout.flush() + print( + '{}'.format(e.reason).capitalize(), + file=sys.stderr, + flush=True) + return 1 + else: + version = info._asdict()['podman'] + host = info._asdict()['host'] + print("Version {}".format(version['podman_version'])) + print("Go Version {}".format(version['go_version'])) + print("Git Commit {}".format(version['git_commit'])) + print("OS/Arch {}/{}".format(host["os"], host["arch"])) -- cgit v1.2.3-54-g00ecf