예제 #1
0
파일: loader.py 프로젝트: rmoorman/ship
def load(repo_file, tag_file, target_file):

    # Verify that tag file content matches our own tag
    tag = get_tag()
    with open(tag_file) as f:
        tag_from_file = f.read().strip()
        # Use no tag if the provided file is empty
        if not tag_from_file:
            tag = ''
        if tag != tag_from_file:
            raise Exception("ERROR: Tag file content '{}' differs from the Loader's tag '{}'."
                            " Please check sanity of the sail script.".format(tag_from_file, tag))

    with open(repo_file) as f:
        repo = f.read().strip()
    with open(target_file) as f:
        target = f.read().strip()

    modify_yaml(repo, tag)
    call_crane('run', target)
    start(repo, target, repo_file, tag_file, target_file, tag)
예제 #2
0
def load(repo_file, tag_file, target_file):

    # Verify that tag file content matches our own tag
    tag = get_tag()
    with open(tag_file) as f:
        tag_from_file = f.read().strip()
        # Use no tag if the provided file is empty
        if not tag_from_file:
            tag = ''
        if tag != tag_from_file:
            raise Exception(
                "ERROR: Tag file content '{}' differs from the Loader's tag '{}'."
                " Please check sanity of the sail script.".format(
                    tag_from_file, tag))

    with open(repo_file) as f:
        repo = f.read().strip()
    with open(target_file) as f:
        target = f.read().strip()

    modify_yaml(repo, tag)
    call_crane('run', target)
    start(repo, target, repo_file, tag_file, target_file, tag)
예제 #3
0
파일: main.py 프로젝트: rmoorman/ship
def main():
    if len(argv) == 1:
        raise Exception('Please specify a command')

    elif argv[1] == 'images':
        for i in loader.get_images():
            print i

    elif argv[1] == 'containers':
        with open(CRANE_YML_PATH) as f:
            y = yaml.load(f)

        for key in y['containers']:
            print key

    elif argv[1] == 'tag':
        print loader.get_tag()

    elif argv[1] == 'verify':
        loader.verify(argv[2])

    elif argv[1] == 'load':
        if len(argv) != 5:
            print >> stderr, "Usage: {} {} repo_file tag_file target_file".format(
                argv[0], argv[1])
            print >> stderr, "       Provide an empty repo file to use the default Docker repo."
            print >> stderr, "       Provide an empty target file to launch the default Crane target."
            print >>stderr, "       Provide an empty tag file to use the 'latest' tag and override " \
                            "the Loader's own tag file. Otherwise content of the two files must be identical."
            raise Exception('Wrong arguments for command {}'.format(argv[1]))
        loader.load(argv[2], argv[3], argv[4])

    elif argv[1] == 'install-getty':
        install_getty(argv[2])

    elif argv[1] == 'modified-yml':
        if len(argv) != 4:
            print >> stderr, "Usage: {} {} <repo> <tag>".format(
                argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3])
        with open(MODIFIED_YML_PATH) as f:
            print f.read()

    elif argv[1] == 'modified-containers':
        if len(argv) != 4:
            print >> stderr, "Usage: {} {} <repo> <tag>".format(
                argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3])
        with open(MODIFIED_YML_PATH) as f:
            y = yaml.load(f)
        for key in y['containers']:
            print key

    elif argv[1] == 'modified-images':
        if len(argv) != 4:
            print >> stderr, "Usage: {} {} <repo> <tag>".format(
                argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3])
        with open(MODIFIED_YML_PATH) as f:
            y = yaml.load(f)
        for value in y['containers'].itervalues():
            print value['image']

    elif argv[1] == 'create-containers':
        if len(argv) <= 5:
            print >> stderr, "Usage: {} {} <repo> <tag> <loader-container> container ...".format(
                argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3], argv[4], False)
        for i in argv[5:]:
            call_crane('create', i)

    elif argv[1] == 'simulate-getty':
        install_getty('/tmp')
        subprocess.call('/tmp/run')

    else:
        raise Exception('Unknown command: {}'.format(argv[1]))
예제 #4
0
파일: main.py 프로젝트: rmoorman/ship
def main():
    if len(argv) == 1:
        raise Exception('Please specify a command')

    elif argv[1] == 'images':
        for i in loader.get_images():
            print i

    elif argv[1] == 'containers':
        with open(CRANE_YML_PATH) as f:
            y = yaml.load(f)

        for key in y['containers']:
            print key

    elif argv[1] == 'tag':
        print loader.get_tag()

    elif argv[1] == 'verify':
        loader.verify(argv[2])

    elif argv[1] == 'load':
        if len(argv) != 5:
            print >>stderr, "Usage: {} {} repo_file tag_file target_file".format(argv[0], argv[1])
            print >>stderr, "       Provide an empty repo file to use the default Docker repo."
            print >>stderr, "       Provide an empty target file to launch the default Crane target."
            print >>stderr, "       Provide an empty tag file to use the 'latest' tag and override " \
                            "the Loader's own tag file. Otherwise content of the two files must be identical."
            raise Exception('Wrong arguments for command {}'.format(argv[1]))
        loader.load(argv[2], argv[3], argv[4])

    elif argv[1] == 'install-getty':
        install_getty(argv[2])

    elif argv[1] == 'modified-yml':
        if len(argv) != 4:
            print >>stderr, "Usage: {} {} <repo> <tag>".format(argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3])
        with open(MODIFIED_YML_PATH) as f:
            print f.read()

    elif argv[1] == 'modified-containers':
        if len(argv) != 4:
            print >>stderr, "Usage: {} {} <repo> <tag>".format(argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3])
        with open(MODIFIED_YML_PATH) as f:
            y = yaml.load(f)
        for key in y['containers']:
            print key

    elif argv[1] == 'modified-images':
        if len(argv) != 4:
            print >>stderr, "Usage: {} {} <repo> <tag>".format(argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3])
        with open(MODIFIED_YML_PATH) as f:
            y = yaml.load(f)
        for value in y['containers'].itervalues():
            print value['image']

    elif argv[1] == 'create-containers':
        if len(argv) <= 5:
            print >>stderr, "Usage: {} {} <repo> <tag> <loader-container> container ...".format(argv[0], argv[1])
            exit(11)
        modify_yaml(argv[2], argv[3], argv[4], False)
        for i in argv[5:]:
            call_crane('create', i)

    elif argv[1] == 'simulate-getty':
        install_getty('/tmp')
        subprocess.call('/tmp/run')

    else:
        raise Exception('Unknown command: {}'.format(argv[1]))