~james-page/charms/trusty/nova-cloud-controller/tox

« back to all changes in this revision

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

Add unit status support

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU Lesser General Public License
15
15
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
 
17
import glob
17
18
import json
18
19
import os
19
20
import re
1363
1364
            normalized.update({port: port for port in resolved
1364
1365
                               if port in ports})
1365
1366
            if resolved:
1366
 
                return {bridge: normalized[port] for port, bridge in
 
1367
                return {normalized[port]: bridge for port, bridge in
1367
1368
                        six.iteritems(portmap) if port in normalized.keys()}
1368
1369
 
1369
1370
        return None
1374
1375
    def __call__(self):
1375
1376
        ctxt = {}
1376
1377
        mappings = super(PhyNICMTUContext, self).__call__()
1377
 
        if mappings and mappings.values():
1378
 
            ports = mappings.values()
 
1378
        if mappings and mappings.keys():
 
1379
            ports = sorted(mappings.keys())
1379
1380
            napi_settings = NeutronAPIContext()()
1380
1381
            mtu = napi_settings.get('network_device_mtu')
 
1382
            all_ports = set()
 
1383
            # If any of ports is a vlan device, its underlying device must have
 
1384
            # mtu applied first.
 
1385
            for port in ports:
 
1386
                for lport in glob.glob("/sys/class/net/%s/lower_*" % port):
 
1387
                    lport = os.path.basename(lport)
 
1388
                    all_ports.add(lport.split('_')[1])
 
1389
 
 
1390
            all_ports = list(all_ports)
 
1391
            all_ports.extend(ports)
1381
1392
            if mtu:
1382
 
                ctxt["devs"] = '\\n'.join(ports)
 
1393
                ctxt["devs"] = '\\n'.join(all_ports)
1383
1394
                ctxt['mtu'] = mtu
1384
1395
 
1385
1396
        return ctxt