def cli(force, release, download, jails, recursive): """Destroys the jail's 2 datasets and the snapshot from the RELEASE.""" # Want these here, otherwise they're reinstanced for each jail. zfs = libzfs.ZFS(history=True, history_prefix="<iocage>") iocroot = ioc.PoolAndDataset().get_iocroot() if download and not release: ioc_common.logit({ "level": "EXCEPTION", "message": "--release (-r) must be specified as well!" }) if jails and not release: for jail in jails: if not force: ioc_common.logit({ "level": "WARNING", "message": f"\nThis will destroy jail {jail}" }) if not click.confirm("\nAre you sure?"): continue # no, continue to next jail child_test(zfs, iocroot, jail, "jail", force=force, recursive=recursive) ioc.IOCage(jail=jail, skip_jails=True).destroy_jail() elif jails and release: for release in jails: if not force: ioc_common.logit({ "level": "WARNING", "message": f"\nThis will destroy RELEASE: {release}" }) if not click.confirm("\nAre you sure?"): continue child_test(zfs, iocroot, release, "release", force=force, recursive=recursive) ioc.IOCage(jail=release, skip_jails=True).destroy_release(download) elif not jails and release: ioc_common.logit({ "level": "EXCEPTION", "message": "Please specify one or more RELEASEs!" }) else: ioc_common.logit({ "level": "EXCEPTION", "message": "Please specify one or more jails!" })
def cli(force, release, download, jails, recursive): """Destroys the jail's 2 datasets and the snapshot from the RELEASE.""" # Want these here, otherwise they're reinstanced for each jail. iocroot = ioc.PoolAndDataset().get_iocroot() if download and not release: ioc_common.logit({ "level": "EXCEPTION", "message": "--release (-r) must be specified as well!" }) if jails and not release: for jail in jails: iocage = ioc.IOCage(jail=jail, skip_jails=True) # If supplied a partial, we want the real match we got. jail, _ = iocage.__check_jail_existence__() if not force: ioc_common.logit({ "level": "WARNING", "message": f"\nThis will destroy jail {jail}" }) if not click.confirm("\nAre you sure?"): continue # no, continue to next jail child_test(iocroot, jail, "jail", force=force, recursive=recursive) iocage.destroy_jail(force=force) elif jails and release: for release in jails: if not force: ioc_common.logit({ "level": "WARNING", "message": f"\nThis will destroy RELEASE: {release}" }) if not click.confirm("\nAre you sure?"): continue children = child_test(iocroot, release, "release", force=force, recursive=recursive) if children: for child in children: ioc.IOCage(jail=child).destroy_jail(force) ioc.IOCage(jail=release, skip_jails=True).destroy_release(download) elif not jails and release: ioc_common.logit({ "level": "EXCEPTION", "message": "Please specify one or more RELEASEs!" }) else: ioc_common.logit({ "level": "EXCEPTION", "message": "Please specify one or more jails!" })
def cli(release, template, count, props, pkglist, basejail, clone_basejail, thickjail, empty, short, name, _uuid, thickconfig): if _uuid: try: uuid.UUID(_uuid, version=4) except ValueError: ioc_common.logit({ "level": "EXCEPTION", "message": "Please provide a valid UUID" }) else: if count > 1: ioc_common.logit({ "level": "EXCEPTION", "message": "Flag --count cannot be used with --uuid" }) if name: # noinspection Annotator valid = True if re.match(r"^[a-zA-Z0-9\._-]+$", name) else False if not valid: ioc_common.logit({ "level": "EXCEPTION", "message": f"Invalid character in {name}, please remove it." }) # At this point we don't care _uuid = name if release and "=" in release: ioc_common.logit({ "level": "EXCEPTION", "message": "Please supply a valid RELEASE!" }) elif release and release.lower() == "latest": release = ioc_common.parse_latest_release() if release: try: ioc_common.check_release_newer(release) except ValueError: # We're assuming they understand the implications of a custom # scheme iocroot = ioc.PoolAndDataset().get_iocroot() path = f'{iocroot}/releases/{release}/root' _release = ioc_common.get_jail_freebsd_version(path, release) try: ioc_common.check_release_newer(_release) except ValueError: # We tried pass # We don't really care it's not a RELEASE at this point. release = template if template else release if pkglist: _pkgformat = """ { "pkgs": [ "foo", "bar" ] }""" if not os.path.isfile(pkglist): ioc_common.logit({ "level": "EXCEPTION", "message": f"{pkglist} does not exist!\n" "Please supply a JSON file with the format:" f" {_pkgformat}" }) else: try: # Just try to open the JSON with the right key. with open(pkglist, "r") as p: json.load(p)["pkgs"] # noqa except json.JSONDecodeError: ioc_common.logit({ "level": "EXCEPTION", "message": "Please supply a valid" f" JSON file with the format:{_pkgformat}" }) if empty: release = "EMPTY" if clone_basejail: # We want to still create a basejail basejail = True iocage = ioc.IOCage(skip_jails=True) try: iocage.create(release, props, count, pkglist=pkglist, template=template, short=short, _uuid=_uuid, basejail=basejail, thickjail=thickjail, empty=empty, thickconfig=thickconfig, clone_basejail=clone_basejail) except (RuntimeError, ioc_exceptions.JailMissingConfiguration) as err: if template and "Dataset" in str(err) or str(err).startswith( 'Template'): # We want to list the available templates first ioc_common.logit({ "level": "ERROR", "message": f"Template: {release} not found!" }) templates = ioc.IOCage(silent=True).list('template') template_names = '' for temp in templates: template_names += '\n ' + temp[1] ioc_common.logit({ 'level': 'EXCEPTION', 'message': f'Created Templates:{template_names}' }) exit(1) else: # Standard errors ioc_common.logit({"level": "EXCEPTION", "message": err})