コード例 #1
0
ファイル: tasks.py プロジェクト: alemic/spin-docker
def start_container(container_id):
    """Starts a container. Never actually invoked asynchronously."""
    client.start(container_id, publish_all_ports=True)

    container_details = client.inspect_container(container_id)

    # Gather info about the new container
    container = {'container_id': container_id,
                 'name': container_details['Name'],
                 'image': container_details['Config']['Image'],
                 'status': RUNNING,
                 'active': 0}

    # Get new container's ports
    ports = get_container_ports(container_details['NetworkSettings']['Ports'])
    container.update(ports)

    r.hmset('containers:%s' % container_id, container)

    container_ip = container_details['NetworkSettings']['IPAddress']
    r.set('ips:%s' % container_ip, container_id)

    if not DISABLE_TIMEOUTS:
        check_container_activity.apply_async(
            args=(container_id,), countdown=INITIAL_TIMEOUT_INTERVAL)

    return container
コード例 #2
0
ファイル: tasks.py プロジェクト: alemic/spin-docker
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 start_container(container_id):
    """Starts a container. Never actually invoked asynchronously."""
    client.start(container_id, publish_all_ports=True)

    container_details = client.inspect_container(container_id)

    # Gather info about the new container
    container = {
        'container_id': container_id,
        'name': container_details['Name'],
        'image': container_details['Config']['Image'],
        'status': RUNNING,
        'active': 0
    }

    # Get new container's ports
    ports = get_container_ports(container_details['NetworkSettings']['Ports'])
    container.update(ports)

    r.hmset('containers:%s' % container_id, container)

    container_ip = container_details['NetworkSettings']['IPAddress']
    r.set('ips:%s' % container_ip, container_id)

    if not DISABLE_TIMEOUTS:
        check_container_activity.apply_async(
            args=(container_id, ), countdown=INITIAL_TIMEOUT_INTERVAL)

    return container
コード例 #4
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': ''
            })
コード例 #5
0
ファイル: tasks.py プロジェクト: alemic/spin-docker
def stop_container(self, container_id):
    """Stops a container asynchronously."""
    delete_container_ip(container_id)

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

    r.hmset('containers:%s' % container_id, {
            'status': STOPPED, 'active': 0, 'ssh_port': '', 'app_port': ''})
コード例 #6
0
def stop_container(self, container_id):
    """Stops a container asynchronously."""
    delete_container_ip(container_id)

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

    r.hmset('containers:%s' % container_id, {
            'status': STOPPED, 'active': 0, 'ssh_port': '', 'app_port': ''})