示例#1
0
 def wrapper(*args):
     cache_key = cache_key_templ.format(":".join(args)).replace(
         "/", "%")
     container_id = utils.plash_call("map", cache_key)
     if not container_id:
         container_id = func(*args)
         utils.plash_call("map", cache_key, container_id)
     return hint("image", container_id)
示例#2
0
def from_github(user_repo_pair, file='plashfile'):
    "build and use a file (default 'plashfile') from github repo"
    from urllib.request import urlopen
    url = 'https://raw.githubusercontent.com/{}/master/{}'.format(
        user_repo_pair, file)
    with utils.catch_and_die([Exception], debug=url):
        resp = urlopen(url)
    plashstr = resp.read().decode()
    return utils.plash_call('build', '--eval-stdin', input=plashstr)
示例#3
0
def eval_github(user_repo_pair, file="plashfile"):
    "eval a file (default 'plashfile') from a github repo"
    from urllib.request import urlopen

    url = "https://raw.githubusercontent.com/{}/master/{}".format(
        user_repo_pair, file)
    with utils.catch_and_die([Exception], debug=url):
        resp = urlopen(url)
    plashstr = resp.read().decode()
    return utils.plash_call("eval", "--eval-stdin", input=plashstr)
示例#4
0
def eval_file(file):
    "evaluate file content as expressions"

    fname = os.path.realpath(os.path.expanduser(file))
    with open(fname) as f:
        inscript = f.read()

    sh = utils.plash_call("eval", "--eval-stdin", strip=False, input=inscript)

    # we remove an possibly existing newline
    # because else this macros would add one
    if sh.endswith("\n"):
        return sh[:-1]

    return sh
示例#5
0
def from_map(map_key):
    'use resolved map as image'
    image_id = utils.plash_call('map', map_key)
    if not image_id:
        raise MapDoesNotExist('map {} not found'.format(repr(map_key)))
    return hint('image', image_id)
示例#6
0
def from_url(url):
    'import image from an url'
    return utils.plash_call('import-url', url)
示例#7
0
def from_lxc(image):
    'use images from images.linuxcontainers.org'
    return utils.plash_call('import-lxc', image)
示例#8
0
def from_docker(image):
    'use image from local docker'
    utils.plash_call('import-docker', image)
示例#9
0
def eval_string(stri):
    "evaluate expressions passed as string"
    import shlex

    tokens = shlex.split(stri)
    return utils.plash_call("eval", *tokens, strip=False)
示例#10
0
def eval_stdin():
    "evaluate expressions read from stdin"
    tokens = [i.rstrip("\n") for i in sys.stdin.readlines()]
    return utils.plash_call("eval", *tokens, strip=False)
示例#11
0
def from_github(user_repo_pair, file="plashfile"):
    "build and use a file (default 'plashfile') from a github repo"
    return utils.plash_call("build", "--eval-github", user_repo_pair, file)
示例#12
0
def from_map(map_key):
    "use resolved map as image"
    image_id = utils.plash_call("map", map_key)
    if not image_id:
        raise MapDoesNotExist("map {} not found".format(repr(map_key)))
    return hint("image", image_id)
示例#13
0
def from_url(url):
    "import image from an url"
    return utils.plash_call("import-url", url)
示例#14
0
def from_lxc(image):
    "use images from images.linuxcontainers.org"
    return utils.plash_call("import-lxc", image)
示例#15
0
def from_docker(image):
    "use image from local docker"
    return utils.plash_call("import-docker", image)
示例#16
0
def eval_string(stri):
    'evaluate expressions passed as string'
    import shlex
    tokens = shlex.split(stri)
    return utils.plash_call('eval', input='\n'.join(tokens), strip=False)