示例#1
0
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': ''})
示例#2
0
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': ''
            })
示例#3
0
def remove_container(self, container_id):
    """Deletes a container asynchronously."""
    delete_container_ip(container_id)

    try:
        client.stop(container_id)
        client.remove_container(container_id)
    except APIError as exception:
        raise self.retry(exc=exception)

    r.delete('containers:%s' % container_id)
示例#4
0
def remove_container(self, container_id):
    """Deletes a container asynchronously."""
    delete_container_ip(container_id)

    try:
        client.stop(container_id)
        client.remove_container(container_id)
    except APIError as exception:
        raise self.retry(exc=exception)

    r.delete('containers:%s' % container_id)
示例#5
0
def delete_container_ip(container_id):
    """Deletes a container's IP mapping in redis."""
    container_ip = client.inspect_container(
        container_id)['NetworkSettings']['IPAddress']
    r.delete('ips:%s' % container_ip)
示例#6
0
def delete_container_ip(container_id):
    """Deletes a container's IP mapping in redis."""
    container_ip = client.inspect_container(
        container_id)['NetworkSettings']['IPAddress']
    r.delete('ips:%s' % container_ip)