[niedbalski] charm helpers sync , mostly for support the fix for LP: #1382050

This commit is contained in:
Jorge Niedbalski 2014-10-16 14:42:14 -03:00
parent 841806a0ed
commit 933270dbbf
2 changed files with 15 additions and 4 deletions

View File

@ -140,7 +140,8 @@ def _get_for_address(address, key):
if address.version == 4 and netifaces.AF_INET in addresses: if address.version == 4 and netifaces.AF_INET in addresses:
addr = addresses[netifaces.AF_INET][0]['addr'] addr = addresses[netifaces.AF_INET][0]['addr']
netmask = addresses[netifaces.AF_INET][0]['netmask'] netmask = addresses[netifaces.AF_INET][0]['netmask']
cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) network = netaddr.IPNetwork("%s/%s" % (addr, netmask))
cidr = network.cidr
if address in cidr: if address in cidr:
if key == 'iface': if key == 'iface':
return iface return iface
@ -149,11 +150,14 @@ def _get_for_address(address, key):
if address.version == 6 and netifaces.AF_INET6 in addresses: if address.version == 6 and netifaces.AF_INET6 in addresses:
for addr in addresses[netifaces.AF_INET6]: for addr in addresses[netifaces.AF_INET6]:
if not addr['addr'].startswith('fe80'): if not addr['addr'].startswith('fe80'):
cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'], network = netaddr.IPNetwork("%s/%s" % (addr['addr'],
addr['netmask'])) addr['netmask']))
cidr = network.cidr
if address in cidr: if address in cidr:
if key == 'iface': if key == 'iface':
return iface return iface
elif key == 'netmask' and cidr:
return str(cidr).split('/')[1]
else: else:
return addr[key] return addr[key]
return None return None

View File

@ -6,6 +6,7 @@
# Matthew Wedgwood <matthew.wedgwood@canonical.com> # Matthew Wedgwood <matthew.wedgwood@canonical.com>
import os import os
import re
import pwd import pwd
import grp import grp
import random import random
@ -317,7 +318,13 @@ def list_nics(nic_type):
ip_output = (line for line in ip_output if line) ip_output = (line for line in ip_output if line)
for line in ip_output: for line in ip_output:
if line.split()[1].startswith(int_type): if line.split()[1].startswith(int_type):
interfaces.append(line.split()[1].replace(":", "")) matched = re.search('.*: (bond[0-9]+\.[0-9]+)@.*', line)
if matched:
interface = matched.groups()[0]
else:
interface = line.split()[1].replace(":", "")
interfaces.append(interface)
return interfaces return interfaces