def audit_containers(): """Reviews all known containers and updates their information in redis.""" for ip_address in r.keys('ips:*'): r.delete(ip_address) containers = [r.hgetall(container) for container in r.keys('containers:*')] for container in containers: container_id = container['container_id'] try: docker_info = client.inspect_container(container_id) except APIError: r.delete('containers:%s' % container_id) break if docker_info['State']['Running']: ports = get_container_ports(docker_info['NetworkSettings']['Ports']) r.hmset('containers:%s' % container_id, { 'status': RUNNING, 'active': 0, 'ssh_port': ports['ssh_port'], 'app_port': ports['app_port']}) r.set('ips:%s' % docker_info['NetworkSettings']['IPAddress'], container_id) else: r.hmset('containers:%s' % container_id, { 'status': STOPPED, 'active': 0, 'ssh_port': '', 'app_port': ''})
def audit_containers(): """Reviews all known containers and updates their information in redis.""" for ip_address in r.keys('ips:*'): r.delete(ip_address) containers = [r.hgetall(container) for container in r.keys('containers:*')] for container in containers: container_id = container['container_id'] try: docker_info = client.inspect_container(container_id) except APIError: r.delete('containers:%s' % container_id) break if docker_info['State']['Running']: ports = get_container_ports( docker_info['NetworkSettings']['Ports']) r.hmset( 'containers:%s' % container_id, { 'status': RUNNING, 'active': 0, 'ssh_port': ports['ssh_port'], 'app_port': ports['app_port'] }) r.set('ips:%s' % docker_info['NetworkSettings']['IPAddress'], container_id) else: r.hmset('containers:%s' % container_id, { 'status': STOPPED, 'active': 0, 'ssh_port': '', 'app_port': '' })
def get(self): """Returns all containers for the /containers endpoint.""" self.reqparse.add_argument('audit', type=types.boolean, default=False,) args = self.reqparse.parse_args() if args['audit']: audit_containers() containers = [r.hgetall(container) for container in r.keys('containers:*')] return [marshal(c, container_fields) for c in containers]