add services function
@@ -92,3 +92,30 @@ def Tools(**kargs):
template = Template(template=manifest)
tools = template.sections()
return tools[1]
+
+def Services(vent=True):
+ """
+ Get services that have exposed ports, by default limit to vent containers
+ """
+ services = []
+ try:
+ d_client = docker.from_env()
+ if vent:
+ containers = d_client.containers.list(filters={'label':'vent'})
+ else:
+ containers = d_client.containers.list()
+ for container in containers:
+ if vent:
+ name = container.attrs['Config']['Labels']['vent.name']
+ else:
+ name = container.name
+ ports = container.attrs['NetworkSettings']['Ports']
+ p = []
+ for port in ports:
+ if ports[port]:
+ p.append(ports[port][0]['HostIp']+":"+ports[port][0]['HostPort'])
+ if p:
+ services.append((name, p))
+ except Exception as e: # pragma: no cover
+ pass
+ return services
