Skip to content

Commit

Permalink
Docker version (#610)
Browse files Browse the repository at this point in the history
This expose docker server and local version as well as a method to get specific informations from "docker version".
  • Loading branch information
romainx committed Apr 18, 2021
1 parent aff008d commit efe7602
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions testinfra/modules/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@ def id(self):
def name(self):
return self.inspect()["Name"][1:] # get rid of slash in front

@classmethod
def client_version(cls):
"""Docker client version"""
return cls.version("{{.Client.Version}}")

@classmethod
def server_version(cls):
"""Docker server version"""
return cls.version("{{.Server.Version}}")

@classmethod
def version(cls, format=None):
"""Docker version_ with an optional format (Go template).
>>> host.docker.version()
Client: Docker Engine - Community
...
>>> host.docker.version("{{.Client.Context}}"))
default
.. _version: https://docs.docker.com/engine/reference/commandline/version/
"""
cmd = "docker version"
if format:
cmd = "{} --format '{}'".format(cmd, format)
return cls.check_output(cmd)

@classmethod
def get_containers(cls, **filters):
"""Return a list of containers
Expand Down

0 comments on commit efe7602

Please sign in to comment.