Ubuntu Pastebin

Paste from smoser at Thu, 14 Apr 2016 15:27:55 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
=== modified file 'cloudinit/net/__init__.py'
--- cloudinit/net/__init__.py	2016-04-13 15:48:38 +0000
+++ cloudinit/net/__init__.py	2016-04-14 15:23:47 +0000
@@ -303,7 +303,7 @@
     return data
 
 
-def _klibc_to_config_entry(content, mac_addrs=None):
+def _klibc_to_config_entry(content, mac_addrs=None, control="manual"):
     """Convert a klibc writtent shell content file to a 'config' entry
     When ip= is seen on the kernel command line in debian initramfs
     and networking is brought up, ipconfig will populate
@@ -341,6 +341,8 @@
         'name': name,
         'subnets': [],
     }
+    if control:
+        iface['control'] = control
 
     if name in mac_addrs:
         iface['mac_address'] = mac_addrs[name]
@@ -379,7 +381,8 @@
     return name, iface
 
 
-def config_from_klibc_net_cfg(files=None, mac_addrs=None):
+def config_from_klibc_net_cfg(files=None, mac_addrs=None,
+                              control="manual"):
     if files is None:
         files = glob.glob('/run/net*.conf')
 
@@ -387,7 +390,8 @@
     names = {}
     for cfg_file in files:
         name, entry = _klibc_to_config_entry(util.load_file(cfg_file),
-                                             mac_addrs=mac_addrs)
+                                             mac_addrs=mac_addrs,
+                                             control=control)
         if name in names:
             raise ValueError(
                 "device '%s' defined multiple times: %s and %s" % (
@@ -531,7 +535,11 @@
     content += "\n"
     for iface in sorted(interfaces.values(),
                         key=lambda k: (order[k['type']], k['name'])):
-        content += "auto {name}\n".format(**iface)
+
+        # valid values for 'control' would be: 'auto', 'hotplug', None
+        control = iface.get('control', 'auto')
+        if control and control != 'manual':
+            content += "allow-{control} {name}\n".format(**iface)
 
         subnets = iface.get('subnets', {})
         if subnets:

=== modified file 'tests/unittests/test_net.py'
--- tests/unittests/test_net.py	2016-03-24 19:46:52 +0000
+++ tests/unittests/test_net.py	2016-04-14 15:27:36 +0000
@@ -32,6 +32,7 @@
 DHCP_EXPECTED_1 = {
     'name': 'eth0',
     'type': 'physical',
+    'control': 'manual',
     'subnets': [{'broadcast': '192.168.122.255',
                  'gateway': '192.168.122.1',
                  'dns_search': ['foo.com'],
@@ -58,6 +59,7 @@
 
 STATIC_EXPECTED_1 = {
     'name': 'eth1',
+    'control': 'manual',
     'type': 'physical',
     'subnets': [{'broadcast': '10.0.0.255', 'gateway': '10.0.0.1',
                  'dns_search': ['foo.com'], 'type': 'static',
Download as text