コード例 #1
0
def docker_pull_image(docker_url):
    """Pull an image via ``docker pull``. Uses the actual pull command instead of the python
    bindings due to the docker auth/registry transition. Once we are past Docker 1.6
    we can use better credential management, but for now this function assumes the
    user running the command has already been authorized for the registry"""
    paasta_print("Please wait while the image (%s) is pulled (times out after 30m)..." % docker_url, file=sys.stderr)
    DEVNULL = open(os.devnull, 'wb')
    with open('/tmp/paasta-local-run-pull.lock', 'w') as f:
        with timed_flock(f, seconds=1800):
            ret, output = _run('docker pull %s' % docker_url, stream=True, stdin=DEVNULL)
            if ret != 0:
                paasta_print(
                    "\nPull failed. Are you authorized to run docker commands?",
                    file=sys.stderr,
                )
                sys.exit(ret)
コード例 #2
0
def firewall_flock(flock_path=DEFAULT_FIREWALL_FLOCK_PATH):
    """ Grab an exclusive flock to avoid concurrent iptables updates
    """
    with io.FileIO(flock_path, 'w') as f:
        with timed_flock(f, seconds=DEFAULT_FIREWALL_FLOCK_TIMEOUT_SECS):
            yield