It turns out that most API users want some kind of timeout option for
get_ips, so instead of re-implementing it in every single client
software, let's just have it as a python overlay upstream.
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
import sys
import subprocess
import tempfile
-import time
_ = gettext.gettext
gettext.textdomain("lxc-start-ephemeral")
sys.exit(0)
# Try to get the IP addresses
-ips = None
-timeout = 5
-while not ips and timeout != 0:
- ips = dest.get_ips()
- time.sleep(1)
- timeout -= 1
+ips = dest.get_ips(timeout=5)
# Deal with the case where we just print info about the container
if args.daemon:
import os
import subprocess
import stat
+import time
import warnings
warnings.warn("The python-lxc API isn't yet stable "
else:
return value
+ def get_ips(self, interface=None, family=None, scope=None, timeout=0):
+ """
+ Get a tuple of IPs for the container.
+ """
+
+ kwargs = {}
+ if interface:
+ kwargs['interface'] = interface
+ if family:
+ kwargs['family'] = family
+ if scope:
+ kwargs['scope'] = scope
+
+ ips = None
+
+ while not ips:
+ ips = _lxc.Container.get_ips(self, **kwargs)
+ if timeout == 0:
+ break
+
+ timeout -= 1
+ time.sleep(1)
+
+ return ips
+
def set_config_item(self, key, value):
"""
Set a config key to a provided value.