~wesley-wiedenmeier/curtin/vmtest-webhook-delay

« back to all changes in this revision

Viewing changes to curtin/net/__init__.py

net: introduce 'control' field to network configuration

Allow users to specify how they want ifupdown to treat the
interface.  The default value for control is 'auto' which
results in an auto $iface line in eni.  If control is
'manual', then we emit a comment instead, # control-manual $iface
Any other value of control will emit a an allow-$control value.

These lines control whether ifupdown will ensure the interfaces are
up during boot.  auto and hotplug ifaces will be considered a requirement
for network to be "up".  

The 'manual' setting is useful for things like iscsiroot which
will configure networking in initramfs and when the root filesystem
runs, we do not want ifupdown to bring the interface used to connect
to the iscsi target up or down.

Show diffs side-by-side

added added

removed removed

Lines of Context:
178
178
                        "_source_path": src_path
179
179
                    }
180
180
                ifaces[iface]['auto'] = True
 
181
                ifaces[iface]['control'] = 'auto'
 
182
        elif option.startswith('allow-'):
 
183
            for iface in split[1:]:
 
184
                if iface not in ifaces:
 
185
                    ifaces[iface] = {
 
186
                        # Include the source path this interface was found in.
 
187
                        "_source_path": src_path
 
188
                    }
 
189
                ifaces[iface]['auto'] = False
 
190
                ifaces[iface]['control'] = option.split('allow-')[-1]
181
191
        elif option == "iface":
182
192
            iface, family, method = split[1:4]
183
193
            if iface not in ifaces:
326
336
def iface_add_attrs(iface):
327
337
    content = ""
328
338
    ignore_map = [
329
 
        'type',
330
 
        'name',
 
339
        'control',
 
340
        'index',
331
341
        'inet',
332
342
        'mode',
333
 
        'index',
 
343
        'name',
334
344
        'subnets',
 
345
        'type',
335
346
    ]
336
347
    if iface['type'] not in ['bond', 'bridge']:
337
348
        ignore_map.append('mac_address')
361
372
    return content
362
373
 
363
374
 
 
375
def iface_start_entry(iface, index):
 
376
    fullname = iface['name']
 
377
    if index != 0:
 
378
        fullname += ":%s" % index
 
379
 
 
380
    control = iface['control']
 
381
    if control == "auto":
 
382
        cverb = "auto"
 
383
    elif control in ("hotplug",):
 
384
        cverb = "allow-" + control
 
385
    else:
 
386
        cverb = "# control-" + control
 
387
 
 
388
    subst = iface.copy()
 
389
    subst.update({'fullname': fullname, 'cverb': cverb})
 
390
 
 
391
    return ("{cverb} {fullname}\n"
 
392
            "iface {fullname} {inet} {mode}\n").format(**subst)
 
393
 
 
394
 
364
395
def render_interfaces(network_state):
365
396
    ''' Given state, emit etc/network/interfaces content '''
366
397
 
393
424
                    content += "\n"
394
425
                iface['index'] = index
395
426
                iface['mode'] = subnet['type']
 
427
                iface['control'] = subnet.get('control', 'auto')
396
428
                if iface['mode'].endswith('6'):
397
429
                    iface['inet'] += '6'
398
430
                elif iface['mode'] == 'static' and ":" in subnet['address']:
400
432
                if iface['mode'].startswith('dhcp'):
401
433
                    iface['mode'] = 'dhcp'
402
434
 
403
 
                if index == 0:
404
 
                    if subnet['type'] != 'manual':
405
 
                        content += "auto {name}\n".format(**iface)
406
 
                    content += "iface {name} {inet} {mode}\n".format(**iface)
407
 
                else:
408
 
                    if subnet['type'] != 'manual':
409
 
                        content += "auto {name}:{index}\n".format(**iface)
410
 
                    content += \
411
 
                        "iface {name}:{index} {inet} {mode}\n".format(**iface)
412
 
 
 
435
                content += iface_start_entry(iface, index)
413
436
                content += iface_add_subnet(iface, subnet)
414
437
                content += iface_add_attrs(iface)
415
438
        else:
 
439
            # ifenslave docs say to auto the slave devices
416
440
            if 'bond-master' in iface:
417
441
                content += "auto {name}\n".format(**iface)
418
442
            content += "iface {name} {inet} {mode}\n".format(**iface)