From abbe2ead95fdee6a0d59da35ce3542439ec2abcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Thu, 13 Sep 2012 10:08:39 -0400 Subject: [PATCH] lxc-start-ephemeral: startup time improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-organize the code to only call get_ips() when we actually need the IP address of the container. Also bump the timeout for get_ips() from 5s to 10s to accomodate slower machines. Signed-off-by: Stéphane Graber --- src/lxc/lxc-start-ephemeral.in | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/lxc/lxc-start-ephemeral.in b/src/lxc/lxc-start-ephemeral.in index 85772563d..2eb6157d9 100644 --- a/src/lxc/lxc-start-ephemeral.in +++ b/src/lxc/lxc-start-ephemeral.in @@ -233,26 +233,27 @@ if not dest.start() or not dest.wait("RUNNING", timeout=5): dest.destroy() sys.exit(1) -# Try to get the IP addresses -ips = dest.get_ips(timeout=5) +# Deal with the case where we just attach to the container's console +if not args.command and not args.daemon: + dest.console(tty=1) + dest.shutdown(timeout=5) + sys.exit(0) -# Deal with the case where we don't start a command in the container -if not args.command: - if args.daemon: - print(_("""The ephemeral container is now started. +# Try to get the IP addresses +ips = dest.get_ips(timeout=10) + +# Deal with the case where we just print info about the container +if args.daemon: + print(_("""The ephemeral container is now started. You can enter it from the command line with: lxc-console -n %s The following IP addresses have be found in the container: %s""") % ( - dest.name, - "\n".join([" - %s" % entry for entry in ips] - or [" - %s" % _("No address could be found")]) - )) - sys.exit(0) - else: - dest.console(tty=1) - dest.shutdown(timeout=5) - sys.exit(0) + dest.name, + "\n".join([" - %s" % entry for entry in ips] + or [" - %s" % _("No address could be found")]) + )) + sys.exit(0) # Now deal with the case where we want to run a command in the container if not ips: