fix local ip discovery on 15.04
This commit is contained in:
parent
5294a0cb50
commit
b188f702d6
1 changed files with 15 additions and 1 deletions
16
oml/utils.py
16
oml/utils.py
|
@ -271,7 +271,21 @@ def get_local_ipv4():
|
|||
dev = local[0].split(' ')[4]
|
||||
local_ip = [l for l in stdout.split('\n')
|
||||
if dev in l and not 'default' in l and 'src' in l]
|
||||
ip = [p for p in local_ip[0].split(' ')[1:] if '.' in p][0]
|
||||
if local_ip:
|
||||
local_ip = [p for p in local_ip[0].split(' ')[1:] if '.' in p]
|
||||
if local_ip:
|
||||
ip = local_ip[0]
|
||||
if not ip:
|
||||
cmd = ['ip', 'addr', 'show']
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True)
|
||||
stdout, stderr = p.communicate()
|
||||
stdout = stdout.decode('utf-8')
|
||||
parts = stdout.split(' ')
|
||||
local_ip = [p for p in parts if dev in p]
|
||||
if local_ip:
|
||||
local_ip = re.compile('inet (\d+\.\d+\.\d+.\d+)').findall(local_ip[0])
|
||||
if local_ip:
|
||||
ip = local_ip[0]
|
||||
return ip
|
||||
|
||||
def update_dict(root, data):
|
||||
|
|
Loading…
Reference in a new issue