~harlowja/cloud-init/cloud-init-net-refactor

« back to all changes in this revision

Viewing changes to cloudinit/net/eni.py

  • Committer: Joshua Harlow
  • Date: 2016-05-19 22:33:15 UTC
  • Revision ID: harlowja@gmail.com-20160519223315-2bylbhy01tocjpkx
Fix up tests and flake8 warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
258
258
        return content
259
259
 
260
260
    def _render_route(self, route, indent=""):
261
 
        """ When rendering routes for an iface, in some cases applying a route
 
261
        """When rendering routes for an iface, in some cases applying a route
262
262
        may result in the route command returning non-zero which produces
263
263
        some confusing output for users manually using ifup/ifdown[1].  To
264
264
        that end, we will optionally include an '|| true' postfix to each
302
302
        return content
303
303
 
304
304
    def _render_interfaces(self, network_state):
305
 
        ''' Given state, emit etc/network/interfaces content '''
 
305
        '''Given state, emit etc/network/interfaces content'''
306
306
 
307
307
        content = ""
308
308
        interfaces = network_state.get('interfaces')
336
336
                    iface['control'] = subnet.get('control', 'auto')
337
337
                    if iface['mode'].endswith('6'):
338
338
                        iface['inet'] += '6'
339
 
                    elif iface['mode'] == 'static' \
340
 
                         and ":" in subnet['address']:
 
339
                    elif (iface['mode'] == 'static'
 
340
                            and ":" in subnet['address']):
341
341
                        iface['inet'] += '6'
342
342
                    if iface['mode'].startswith('dhcp'):
343
343
                        iface['mode'] = 'dhcp'
359
359
        content = content.replace('mac_address', 'hwaddress')
360
360
        return content
361
361
 
362
 
    def render_network_state(self,
363
 
        target, network_state, eni="etc/network/interfaces",
364
 
        links_prefix=LINKS_FNAME_PREFIX,
365
 
        netrules='etc/udev/rules.d/70-persistent-net.rules'):
 
362
    def render_network_state(
 
363
            self, target, network_state,
 
364
            eni="etc/network/interfaces", links_prefix=LINKS_FNAME_PREFIX,
 
365
            netrules='etc/udev/rules.d/70-persistent-net.rules'):
366
366
 
367
367
        fpeni = os.path.join(target, eni)
368
368
        net.write_file(fpeni, self._render_interfaces(network_state))