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 <veiko17@disroot.org>
This commit is contained in:
Veiko Aasa 2021-01-06 13:27:19 +02:00 committed by Fioddor Superconcentrado
parent fc7696d181
commit fd296ad063

View File

@ -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))