bootstrapvz/plugins/docker_daemon: flake8

This commit is contained in:
Johan Euphrosine 2014-11-19 11:49:17 -08:00
parent f3a9a1b1ec
commit 962532065c
2 changed files with 26 additions and 36 deletions

View file

@ -1,43 +1,32 @@
import os import os
import subprocess import subprocess
import time import time
import logging
def pull(info, images, retries=10): def pull(info, images, retries=10):
if len(images) == 0: if len(images) == 0:
return return
bin_docker = os.path.join(info.root, 'usr/bin/docker') bin_docker = os.path.join(info.root, 'usr/bin/docker')
graph_dir = os.path.join(info.root, 'var/lib/docker') graph_dir = os.path.join(info.root, 'var/lib/docker')
socket = 'unix://' + os.path.join(info.workspace, 'docker.sock') socket = 'unix://' + os.path.join(info.workspace, 'docker.sock')
pidfile = os.path.join(info.workspace, 'docker.pid') pidfile = os.path.join(info.workspace, 'docker.pid')
try: try:
daemon = subprocess.Popen([bin_docker, '-d', '--graph', graph_dir, '-H', socket, '-p', pidfile]) daemon = subprocess.Popen([bin_docker, '-d', '--graph', graph_dir, '-H', socket, '-p', pidfile])
for _ in range(retries): for _ in range(retries):
if subprocess.call([bin_docker, '-H', socket, 'version']) == 0: if subprocess.call([bin_docker, '-H', socket, 'version']) == 0:
break break
time.sleep(1) time.sleep(1)
for img in images: for img in images:
if img.endswith('.tar.gz') or img.endswith('.tgz'): if img.endswith('.tar.gz') or img.endswith('.tgz'):
cmd = [bin_docker, '-H', socket, 'load', '-i', img] cmd = [bin_docker, '-H', socket, 'load', '-i', img]
logging.debug(' '.join(cmd)) if subprocess.call(cmd) != 0:
if subprocess.call(cmd) != 0: msg = 'error loading docker image {img}.'.format(img=img)
msg = 'error loading docker image {img}.'.format(img=img) raise Exception(msg)
raise Exception(msg) continue
continue cmd = [bin_docker, '-H', socket, 'pull', img]
cmd = [bin_docker, '-H', socket, 'pull', img] if subprocess.call(cmd) != 0:
logging.debug('running: %s', ' '.join(cmd)) msg = 'error pulling docker image {img}.'.format(img=img)
if subprocess.call(cmd) != 0: raise Exception(msg)
msg = 'error pulling docker image {img}.'.format(img=img) finally:
raise Exception(msg) daemon.terminate()
finally:
daemon.terminate()
if __name__ == '__main__':
class Info(object):
root = '/tmp/bootstrap-vz/root'
workspace = '/tmp/bootstrap-vz/workspace'
pull_images = ['/usr/local/google/home/proppy/bootstrap-vz/busybox.tar.gz', 'golang:1.3']
pull(Info(), pull_images)

View file

@ -67,6 +67,7 @@ class EnableMemoryCgroup(Task):
grub_config = os.path.join(info.root, 'etc/default/grub') grub_config = os.path.join(info.root, 'etc/default/grub')
sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1 cgroup_enable=memory"') sed_i(grub_config, r'^(GRUB_CMDLINE_LINUX*=".*)"\s*$', r'\1 cgroup_enable=memory"')
class PullDockerImages(Task): class PullDockerImages(Task):
description = 'Pull docker images' description = 'Pull docker images'
phase = phases.system_modification phase = phases.system_modification