Skip to content

Commit efe7602

Browse files
authored
Docker version (#610)
This expose docker server and local version as well as a method to get specific informations from "docker version".
1 parent aff008d commit efe7602

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

testinfra/modules/docker.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ def id(self):
4949
def name(self):
5050
return self.inspect()["Name"][1:] # get rid of slash in front
5151

52+
@classmethod
53+
def client_version(cls):
54+
"""Docker client version"""
55+
return cls.version("{{.Client.Version}}")
56+
57+
@classmethod
58+
def server_version(cls):
59+
"""Docker server version"""
60+
return cls.version("{{.Server.Version}}")
61+
62+
@classmethod
63+
def version(cls, format=None):
64+
"""Docker version_ with an optional format (Go template).
65+
66+
>>> host.docker.version()
67+
Client: Docker Engine - Community
68+
...
69+
>>> host.docker.version("{{.Client.Context}}"))
70+
default
71+
72+
.. _version: https://docs.docker.com/engine/reference/commandline/version/
73+
"""
74+
cmd = "docker version"
75+
if format:
76+
cmd = "{} --format '{}'".format(cmd, format)
77+
return cls.check_output(cmd)
78+
5279
@classmethod
5380
def get_containers(cls, **filters):
5481
"""Return a list of containers

0 commit comments

Comments
 (0)