listing available and running containers

This commit is contained in:
Eike 2023-02-28 12:17:35 +01:00
parent dbb1c5f719
commit 5e0726f9f1
1 changed files with 15 additions and 0 deletions

View File

@ -630,6 +630,16 @@ def delete_jail(jail_name):
else: else:
eprint("Wrong name, nothing happens.") eprint("Wrong name, nothing happens.")
def list_jails():
"""
List all running jails.
"""
jail_path = os.path.join(JAILS_DIR_PATH)
eprint("\nAvailable containers:\n")
os.system(f"ls -l {jail_path} | grep '^d' | awk '{{print $NF}}'")
eprint("\nCurrently running containers:\n")
os.system(f"machinectl list")
def main(): def main():
if os.stat(__file__).st_uid != 0: if os.stat(__file__).st_uid != 0:
@ -650,6 +660,8 @@ def main():
start_parser = subparsers.add_parser(name='delete', epilog=DISCLAIMER) start_parser = subparsers.add_parser(name='delete', epilog=DISCLAIMER)
start_parser.add_argument('name', help='name of the jail') start_parser.add_argument('name', help='name of the jail')
start_parser = subparsers.add_parser(name='list', epilog=DISCLAIMER)
parser.usage = f"{parser.format_usage()[7:]}{create_parser.format_usage()}{start_parser.format_usage()}" parser.usage = f"{parser.format_usage()[7:]}{create_parser.format_usage()}{start_parser.format_usage()}"
if os.getuid() != 0: if os.getuid() != 0:
@ -674,6 +686,9 @@ def main():
elif args.subcommand == 'delete': elif args.subcommand == 'delete':
delete_jail(args.name) delete_jail(args.name)
elif args.subcommand == 'list':
list_jails()
elif args.subcommand: elif args.subcommand:
parser.print_usage() parser.print_usage()