in container_agent/docker_client.py [0:0]
def list_containers(self, needle=''):
"""List running containers.
Note: When specifying a needle, 'docker ps' is invoked without the
'-q' flag in order to be able to match on container names.
Any string in 'docker ps' output that contains the needle is
then returned and may as such not actually be a real container
id or name.
Args:
needle: keyword to filter docker ps output on.
Returns:
A list of container id's and/or names.
Example:
list_containers()
list_containers('deadbeef-namespace')
"""
if not needle:
return self.cli_check('ps', '-q').splitlines()
else:
lines = self.cli_check('ps').splitlines()[1:]
matches = [word for line in lines
for word in line.split() if needle in word]
log.debug('list_containers: needle=%s, matches=%s',
needle, matches)
return matches