add
This commit is contained in:
		| @@ -1,4 +1,6 @@ | ||||
| import sys | ||||
| from subprocess import Popen, PIPE | ||||
|  | ||||
| import gentooimgr.chroot | ||||
|  | ||||
| def command(config, *args): | ||||
|   | ||||
| @@ -15,9 +15,8 @@ def older_than_a_day(fullpath): | ||||
|     return time.time() - filetime > (gentooimgr.config.DAY_IN_SECONDS * | ||||
|                                      gentooimgr.config.DAYS) | ||||
|  | ||||
|  | ||||
|  | ||||
| def find_iso(download_dir): | ||||
|     LOG.info(f"Looking for iso in {download_dir}") | ||||
|     name = None | ||||
|     ext = None | ||||
|     found = [] | ||||
| @@ -34,9 +33,10 @@ def make_iso_from_dir(mydir): | ||||
|         path to iso that was created or NoneType if mydir is not found | ||||
|     """ | ||||
|     if not os.path.exists(mydir): | ||||
|         LOG.warn(f"\t:: dir not found {mydir}") | ||||
|         return | ||||
|  | ||||
|     print(f"\t:: Making ISO with dir of {mydir}") | ||||
|     LOG.info(f"\t:: Making ISO with dir of {mydir}") | ||||
|     path = os.path.join(mydir, "..", "cloudgen.iso") | ||||
|     proc = Popen(["mkisofs", | ||||
|         "--input-charset", "utf-8", | ||||
| @@ -52,15 +52,17 @@ def make_iso_from_dir(mydir): | ||||
|  | ||||
|     return path | ||||
|  | ||||
| def portage_from_dir(d, filename=None): | ||||
| def portage_from_dir(download_dir, filename=None): | ||||
|     """Find portage file from directory. Will do a check in os.listdir() for portage*.tar.bz2. | ||||
|  | ||||
|     If a filename is provided, this function either returns that filename assuming it exists in d, | ||||
|     or return None. If filename is None, this looks through all entries for portage files and if | ||||
|     only one exists, returns it, otherwise None. | ||||
|     """ | ||||
|     assert download_dir, f"empty {download_dir} for  for portage" | ||||
|     LOG.info(f"Looking for portage in {download_dir}") | ||||
|     found = [] | ||||
|     for f in os.listdir(d): | ||||
|     for f in os.listdir(download_dir): | ||||
|         if filename is not None: | ||||
|             if filename == f: | ||||
|                 found.append(f) | ||||
| @@ -70,7 +72,7 @@ def portage_from_dir(d, filename=None): | ||||
|     if len(found) > 1: | ||||
|         LOG.error("\tEE: More than one portage file exists, please specify the exact portage file with --portage [file]  or remove all others\n") | ||||
|         LOG.error(''.join([f"\t{f}\n" for f in found])) | ||||
|         LOG.error(f"in {d}\n") | ||||
|         LOG.error(f"in {download_dir}\n") | ||||
|         sys.exit(1) | ||||
|  | ||||
|     return found[0] if found else None | ||||
|   | ||||
| @@ -72,7 +72,7 @@ | ||||
|         "syslog-ng": "default", | ||||
|         "cronie": "default", | ||||
|         "acpid": "default", | ||||
|         "ntp": "default" | ||||
|         "ntp": "default", | ||||
|         "qemu-guest-agent": "default" | ||||
|     }, | ||||
|     "iso": null, | ||||
|   | ||||
| @@ -151,7 +151,7 @@ def step10_emerge_pkgs(args, cfg): | ||||
|         proc = Popen(["emerge", "-j1", single]) | ||||
|         proc.communicate() | ||||
|  | ||||
|     LOG.info("KERNEL PACKAGES", packages.get("kernel")) | ||||
|     LOG.info(f"KERNEL PACKAGES {packages.get('kernel')}") | ||||
|     if packages.get("kernel", []): | ||||
|         cmd = ["emerge", "-j", str(args.threads)] + packages.get("kernel", []) | ||||
|         proc = Popen(cmd) | ||||
|   | ||||
| @@ -3,6 +3,8 @@ import os | ||||
| import sys | ||||
| import argparse | ||||
| from subprocess import Popen, PIPE | ||||
|  | ||||
| from gentooimgr import LOG | ||||
| import gentooimgr.config | ||||
| import gentooimgr.common | ||||
| def create_image(args, config: dict, overwrite: bool = False) -> str: | ||||
| @@ -36,6 +38,8 @@ def run_image( | ||||
|         - mount_isos: list of iso paths to mount in qemu as disks. | ||||
|     """ | ||||
|     iso = config.get("iso") | ||||
|     prefix = args.temporary_dir | ||||
|     LOG.info(f"iso from config {iso}") | ||||
|     if iso is None: | ||||
|         iso = gentooimgr.common.find_iso( | ||||
|             os.path.join( | ||||
| @@ -43,6 +47,13 @@ def run_image( | ||||
|                 ".." | ||||
|             ) | ||||
|         ) | ||||
|         LOG.info(f"iso from cwd {iso}") | ||||
|     if not iso: | ||||
|         prefix = config.get('temporary_dir') | ||||
|         iso = gentooimgr.common.find_iso(prefix) | ||||
|         LOG.info(f"iso from {prefix} {iso}") | ||||
|  | ||||
|     assert iso, f"iso not found {iso}" | ||||
|  | ||||
|     if isinstance(iso, list): | ||||
|         assert len(iso), f"iso list is empty {iso}" | ||||
| @@ -55,6 +66,11 @@ def run_image( | ||||
|         qmounts.append("-drive") | ||||
|         qmounts.append(f"file={i},media=cdrom") | ||||
|  | ||||
|     assert image, f"image is empty {image}" | ||||
|     if not os.path.exists(image): | ||||
|         if os.path.exists(os.path.join(prefix, image)): | ||||
|             image = os.path.join(prefix, image) | ||||
|     assert os.path.exists(image), f"image not found {image}" | ||||
|     threads = args.threads | ||||
|     cmd = [ | ||||
|         "qemu-system-x86_64", | ||||
| @@ -65,7 +81,6 @@ def run_image( | ||||
|         "-drive", f"file={image},if=virtio,index=0", | ||||
|         "-cdrom", iso, | ||||
|         "-net", "nic,model=virtio", | ||||
|         "-net", "user", | ||||
|         "-vga", "virtio", | ||||
|         "-cpu", "kvm64", | ||||
|         "-chardev", "file,id=charserial0,path=gentoo.log", | ||||
| @@ -73,12 +88,14 @@ def run_image( | ||||
|         "-chardev", "pty,id=charserial1", | ||||
|         "-device", "isa-serial,chardev=charserial1,id=serial1" | ||||
|     ] | ||||
|     # "-net", "user", | ||||
|     # -net user: network backend 'user' is not compiled into this binary" | ||||
|  | ||||
|     cmd += qmounts | ||||
|     print(cmd) | ||||
|     LOG.info(cmd) | ||||
|     proc = Popen(cmd, stderr=PIPE, stdout=PIPE) | ||||
|     stdout, stderr = proc.communicate() | ||||
|     if stderr: | ||||
|         sys.stderr.write(str(stderr)) | ||||
|         sys.stderr.write("\n") | ||||
|         LOG.error(str(stderr)) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -23,6 +23,11 @@ def run(args, config: dict) -> None: | ||||
|     assert os.path.isfile(main_iso), f"iso not found {main_iso}" | ||||
|     LOG.info(args) | ||||
|     LOG.info(f'iso={args.iso}') | ||||
|     if args.iso != config['iso']: | ||||
|         LOG.warn(f'iso={args.iso}') | ||||
|         config['iso'] = args.iso | ||||
|     else: | ||||
|         LOG.info(f'iso={args.iso}') | ||||
|     gentooimgr.qemu.run_image( | ||||
|         args, | ||||
|         config, | ||||
|   | ||||
| @@ -17,14 +17,17 @@ Step 16: Sysconfig | ||||
| Step 17: fstab | ||||
| """ | ||||
| import os | ||||
| import sys | ||||
| import json | ||||
|  | ||||
| # from gentooimgr import LOG | ||||
| import gentooimgr.config | ||||
| import gentooimgr.configs | ||||
| from gentooimgr import install | ||||
|  | ||||
| def print_template(args, configjson): | ||||
| def print_template(args, configjson, prefix='/tmp'): | ||||
|     print(__doc__) | ||||
|     sys.stderr.write(f"the last step to succeed is {install.getlaststep(prefix)}\n") | ||||
|     print(f"the last step to succeed is {install.getlaststep(prefix)}\n") | ||||
|     print(f"""------------------------ STATUS ------------------------ | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user