~adam-collard/charms/trusty/swift-proxy/lib-in-python-package

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/context.py

  • Committer: Liam Young
  • Date: 2015-08-19 13:49:37 UTC
  • Revision ID: liam.young@canonical.com-20150819134937-ej73qeyjve2enth8
[gnuoy,trivial] Charmhelper sync (+1'd by mojo)

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
from charmhelpers.core.strutils import bool_from_string
51
51
 
52
52
from charmhelpers.core.host import (
 
53
    get_bond_master,
 
54
    is_phy_iface,
53
55
    list_nics,
54
56
    get_nic_hwaddr,
55
57
    mkdir,
923
925
 
924
926
 
925
927
class NeutronPortContext(OSContextGenerator):
926
 
    NIC_PREFIXES = ['eth', 'bond']
927
928
 
928
929
    def resolve_ports(self, ports):
929
930
        """Resolve NICs not yet bound to bridge(s)
935
936
 
936
937
        hwaddr_to_nic = {}
937
938
        hwaddr_to_ip = {}
938
 
        for nic in list_nics(self.NIC_PREFIXES):
 
939
        for nic in list_nics():
 
940
            # Ignore virtual interfaces (bond masters will be identified from
 
941
            # their slaves)
 
942
            if not is_phy_iface(nic):
 
943
                continue
 
944
 
 
945
            _nic = get_bond_master(nic)
 
946
            if _nic:
 
947
                log("Replacing iface '%s' with bond master '%s'" % (nic, _nic),
 
948
                    level=DEBUG)
 
949
                nic = _nic
 
950
 
939
951
            hwaddr = get_nic_hwaddr(nic)
940
952
            hwaddr_to_nic[hwaddr] = nic
941
953
            addresses = get_ipv4_addr(nic, fatal=False)
961
973
                # trust it to be the real external network).
962
974
                resolved.append(entry)
963
975
 
964
 
        return resolved
 
976
        # Ensure no duplicates
 
977
        return list(set(resolved))
965
978
 
966
979
 
967
980
class OSConfigFlagContext(OSContextGenerator):
1280
1293
    def __call__(self):
1281
1294
        ports = config('data-port')
1282
1295
        if ports:
 
1296
            # Map of {port/mac:bridge}
1283
1297
            portmap = parse_data_port_mappings(ports)
1284
 
            ports = portmap.values()
 
1298
            ports = portmap.keys()
 
1299
            # Resolve provided ports or mac addresses and filter out those
 
1300
            # already attached to a bridge.
1285
1301
            resolved = self.resolve_ports(ports)
 
1302
            # FIXME: is this necessary?
1286
1303
            normalized = {get_nic_hwaddr(port): port for port in resolved
1287
1304
                          if port not in ports}
1288
1305
            normalized.update({port: port for port in resolved
1289
1306
                               if port in ports})
1290
1307
            if resolved:
1291
 
                return {bridge: normalized[port] for bridge, port in
 
1308
                return {bridge: normalized[port] for port, bridge in
1292
1309
                        six.iteritems(portmap) if port in normalized.keys()}
1293
1310
 
1294
1311
        return None