Gestion de l'image de base

This commit is contained in:
2017-01-24 17:32:19 +01:00
parent 487c97e88c
commit 82fb9d31e1
3 changed files with 58 additions and 30 deletions

37
lib/rkt.py Normal file
View File

@ -0,0 +1,37 @@
import system, subprocess, os, tamarin, json, re
def run(args, as_root = False, capture_output=False):
"""Run rkt with the specified args (use the local copy if rkt is not found in the $PATH)"""
rkt_bin = system.which('rkt', tamarin.get_workspace_subdir('rkt'))
cmd = ( ["sudo", "-E", rkt_bin] if os.geteuid() != 0 and as_root == True else [rkt_bin] ) + args
print(" ".join(cmd))
if capture_output:
return subprocess.check_output(cmd, stdin=subprocess.PIPE)
else:
return subprocess.call(cmd, stdin=subprocess.PIPE)
def get_images_list(rkt_flags = []):
output = run([
"image",
"list",
"--format=json"
] + rkt_flags, capture_output=True)
# Fetch the list of installed images
return json.loads(output.decode('utf-8'))
def find_image_by_name(name_pattern, rkt_flags = []):
if type(name_pattern) is str:
name_pattern = re.compile(name_pattern)
images_list = get_images_list(rkt_flags = rkt_flags)
for image in images_list:
if name_pattern.search(image['name']):
return image
return None
def export_image(image_id, dest_file, rkt_flags = []):
output = run([
"image",
"export",
image_id,
dest_file,
] + rkt_flags)

View File

@ -59,16 +59,6 @@ def download_acbuild():
web.download_file(file_url=url, dest_path=file_path)
return file_path
def run_rkt(args, asRoot = False, captureOutput=False):
"""Run rkt with the specified args (use the local copy if rkt is not found in the $PATH)"""
rkt_bin = system.which('rkt', get_workspace_subdir('rkt'))
cmd = ( ["sudo", "-E", rkt_bin] if os.geteuid() != 0 and asRoot == True else [rkt_bin] ) + args
print(" ".join(cmd))
if captureOutput:
return subprocess.check_output(cmd, stdin=subprocess.PIPE)
else:
return subprocess.call(cmd, stdin=subprocess.PIPE)
def run_acbuild(args, captureOutput=False):
"""Run acbuild with the specified args (use the local copy if acbuild is not found in the $PATH)"""
acbuild_bin = system.which('acbuild', get_workspace_subdir('acbuild'))