From fd296ad0634808ef0e5733b764e93b9978abc518 Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Wed, 6 Jan 2021 13:27:19 +0200 Subject: [PATCH] dev-container: Add command to print container IP address Add './container ip' command to print current IP address of the container. Useful when running container related scripts on host machine. Signed-off-by: Veiko Aasa --- container | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/container b/container index 034cf4341..189dc3408 100755 --- a/container +++ b/container @@ -262,6 +262,13 @@ def parse_arguments(): subparser.add_argument('--image-size', default='12G', help='Disk image size to resize to after download') + # Print IP address + subparser = subparsers.add_parser( + 'ip', help='Print the IP address of the container.') + subparser.add_argument( + '--distribution', choices=distributions, default='testing', + help='Distribution of the container to print IP address') + # ssh subparser = subparsers.add_parser('ssh', help='SSH into the container') subparser.add_argument('--distribution', choices=distributions, @@ -926,6 +933,11 @@ def subcommand_up(arguments): _print_banner(arguments.distribution) +def subcommand_ip(arguments): + """Print the IP address of the container.""" + print(_get_ip_address(arguments.distribution) or '') + + def subcommand_ssh(arguments): """Open an SSH shell into the container.""" ip_address = _wait_for(lambda: _get_ip_address(arguments.distribution))