~harlowja/cloud-init/cloud-init-net-sysconfig

« back to all changes in this revision

Viewing changes to cloudinit/net/eni.py

  • Committer: Joshua Harlow
  • Date: 2016-06-13 20:10:07 UTC
  • Revision ID: harlowja@gmail.com-20160613201007-hbiso1uectg3rw6g
Refactor some of sysconfig changes -> network_state module

Show diffs side-by-side

added added

removed removed

Lines of Context:
360
360
        '''Given state, emit etc/network/interfaces content.'''
361
361
 
362
362
        content = ""
363
 
        interfaces = network_state.get('interfaces')
 
363
        content += "auto lo\niface lo inet loopback\n"
 
364
 
 
365
        nameservers = network_state.dns_nameservers
 
366
        if nameservers:
 
367
            content += "    dns-nameservers %s\n" % (" ".join(nameservers))
 
368
        searchdomains = network_state.dns_searchdomains
 
369
        if searchdomains:
 
370
            content += "    dns-search %s\n" % (" ".join(searchdomains))
 
371
 
364
372
        ''' Apply a sort order to ensure that we write out
365
373
            the physical interfaces first; this is critical for
366
374
            bonding
371
379
            'bridge': 2,
372
380
            'vlan': 3,
373
381
        }
374
 
        content += "auto lo\niface lo inet loopback\n"
375
 
        for dnskey, value in network_state.get('dns', {}).items():
376
 
            if len(value):
377
 
                content += "    dns-{} {}\n".format(dnskey, " ".join(value))
378
 
 
379
 
        for iface in sorted(interfaces.values(),
 
382
        for iface in sorted(network_state.iter_interfaces(),
380
383
                            key=lambda k: (order[k['type']], k['name'])):
381
384
 
382
385
            if content[-2:] != "\n\n":
409
412
                content += "iface {name} {inet} {mode}\n".format(**iface)
410
413
                content += _iface_add_attrs(iface)
411
414
 
412
 
        for route in network_state.get('routes'):
 
415
        for route in network_state.iter_routes():
413
416
            content += self._render_route(route)
414
417
 
415
418
        # global replacements until v2 format
441
444
        fp_prefix = os.path.sep.join((target, links_prefix))
442
445
        for f in glob.glob(fp_prefix + "*"):
443
446
            os.unlink(f)
444
 
        interfaces = network_state.get('interfaces')
445
 
        for iface in interfaces.values():
 
447
        for iface in network_state.iter_interfaces():
446
448
            if (iface['type'] == 'physical' and 'name' in iface and
447
449
                    iface.get('mac_address')):
448
450
                fname = fp_prefix + iface['name'] + ".link"