def child_test(iocroot, name, _type, force=False, recursive=False): """Tests for dependent children""" path = None children = [] paths = [ f"{iocroot}/jails/{name}/root", f"{iocroot}/releases/{name}", f"{iocroot}/templates/{name}/root" ] for p in paths: if os.path.isdir(p): path = p children = Dataset(path).snapshots_recursive() break if path is None: if not force: ioc_common.logit({ "level": "WARNING", "message": "Partial UUID/NAME supplied, cannot check for " "dependant jails." }) if not click.confirm("\nProceed?"): exit() else: return _children = [] for child in children: _name = child.name _children.append(f" {_name}\n") sort = ioc_common.ioc_sort("", "name", data=_children) _children.sort(key=sort) if len(_children) != 0: if not force and not recursive: ioc_common.logit({ "level": "WARNING", "message": f"\n{name} has dependent jails" " (who may also have dependents)," " use --recursive to destroy: " }) ioc_common.logit({ "level": "WARNING", "message": "".join(_children) }) exit(1) else: return _children
def child_test(zfs, iocroot, name, _type, force=False, recursive=False): """Tests for dependent children""" path = None children = [] paths = [f"{iocroot}/jails/{name}/root", f"{iocroot}/releases/{name}", f"{iocroot}/templates/{name}/root"] for p in paths: if os.path.isdir(p): path = p children = zfs.get_dataset_by_path(path).snapshots_recursive break if path is None: if not force: ioc_common.logit({ "level": "WARNING", "message": "Partial UUID/NAME supplied, cannot check for " "dependant jails." }) if not click.confirm("\nProceed?"): exit() else: return _children = [] for child in children: _name = child.name.rsplit("@", 1)[-1] _children.append(f" {_name}\n") sort = ioc_common.ioc_sort("", "name", data=_children) _children.sort(key=sort) if len(_children) != 0: if not force and not recursive: ioc_common.logit({ "level": "WARNING", "message": f"\n{name} has dependent jails" " (who may also have dependents)," " use --recursive to destroy: " }) ioc_common.logit({ "level": "WARNING", "message": "".join(_children) }) exit(1) else: return
def cli(header, _long, _sort): """Allows a user to show resource usage of all jails.""" table = texttable.Texttable(max_width=0) jail_list = ioc.IOCage().df() sort = ioc_common.ioc_sort("df", _sort) jail_list.sort(key=sort) if header: jail_list.insert(0, ["NAME", "CRT", "RES", "QTA", "USE", "AVA"]) # We get an infinite float otherwise. table.set_cols_dtype(["t", "t", "t", "t", "t", "t"]) table.add_rows(jail_list) ioc_common.logit({"level": "INFO", "message": table.draw()}) else: for jail in jail_list: ioc_common.logit({"level": "INFO", "message": "\t".join(jail)})