mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-14 11:39:56 +00:00
python: Re-introduce timeout in get_ips
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>
This commit is contained in:
parent
18efb001a4
commit
b0f9616f62
@ -36,7 +36,6 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
|
||||||
|
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
gettext.textdomain("lxc-start-ephemeral")
|
gettext.textdomain("lxc-start-ephemeral")
|
||||||
@ -260,12 +259,7 @@ if not args.command and not args.daemon:
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Try to get the IP addresses
|
# Try to get the IP addresses
|
||||||
ips = None
|
ips = dest.get_ips(timeout=5)
|
||||||
timeout = 5
|
|
||||||
while not ips and timeout != 0:
|
|
||||||
ips = dest.get_ips()
|
|
||||||
time.sleep(1)
|
|
||||||
timeout -= 1
|
|
||||||
|
|
||||||
# Deal with the case where we just print info about the container
|
# Deal with the case where we just print info about the container
|
||||||
if args.daemon:
|
if args.daemon:
|
||||||
|
@ -26,6 +26,7 @@ import glob
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import stat
|
import stat
|
||||||
|
import time
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
warnings.warn("The python-lxc API isn't yet stable "
|
warnings.warn("The python-lxc API isn't yet stable "
|
||||||
@ -353,6 +354,31 @@ class Container(_lxc.Container):
|
|||||||
else:
|
else:
|
||||||
return value
|
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):
|
def set_config_item(self, key, value):
|
||||||
"""
|
"""
|
||||||
Set a config key to a provided value.
|
Set a config key to a provided value.
|
||||||
|
Loading…
Reference in New Issue
Block a user