]> git.siccegge.de Git - forks/vmdebootstrap.git/blobdiff - vmdebootstrap
Update for systemd persistent interface mask
[forks/vmdebootstrap.git] / vmdebootstrap
index 4894bae7455d93e92003b973ea1f7ccabaaf91c5..51c2674f5d37c914a749a3a923e0cb2c53e6e83d 100755 (executable)
@@ -30,7 +30,7 @@ import time
 from distro_info import DebianDistroInfo, UbuntuDistroInfo
 
 
-__version__ = '0.10'
+__version__ = '0.11'
 
 # pylint: disable=invalid-name,line-too-long,missing-docstring,too-many-branches
 
@@ -784,20 +784,33 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
             else:
                 logging.debug('not removing non-existent %s', pathname)
 
+    def mask_udev_predictable_rules(self, rootdir):
+        """
+        This can be reset later but to get networking using immediately
+        on boot, the interface we're going to use must be kno
+        http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
+        """
+        self.message('Disabling systemd predictable interface names')
+        udev_path = os.path.join(
+            'etc', 'udev', 'rules.d', '80-net-setup-link.rules')
+        self.runcmd(['chroot', rootdir, 'ln', '-s', '/dev/null', udev_path])
+
     def setup_networking(self, rootdir):
         self.message('Setting up networking')
+        ifc_file = os.path.join(rootdir, 'etc', 'network', 'interfaces')
+        ifc_d = os.path.join(rootdir, 'etc', 'network', 'interfaces.d')
 
-        # unconditionally write for wheezy (which became oldstable on 04/25/2015)
+        # unconditionally write for wheezy (which became oldstable 2015.04.25)
         if self.was_oldstable(datetime.date(2015, 4, 26)):
-            with open(os.path.join(rootdir, 'etc', 'network', 'interfaces'), 'w') as netfile:
+            with open(ifc_file, 'w') as netfile:
                 netfile.write('source /etc/network/interfaces.d/*\n')
-            os.mkdir(os.path.join(rootdir, 'etc', 'network', 'interfaces.d'))
-
-        elif not os.path.exists(os.path.join(rootdir, 'etc', 'network', 'interfaces')):
-            iface_path = os.path.join(rootdir, 'etc', 'network', 'interfaces')
-            with open(iface_path, 'w') as netfile:
+        elif not os.path.exists(ifc_file):
+            with open(ifc_file, 'a') as netfile:
                 netfile.write('source-directory /etc/network/interfaces.d\n')
-        ethpath = os.path.join(rootdir, 'etc', 'network', 'interfaces.d', 'setup')
+
+        if not os.path.exists(ifc_d):
+            os.mkdir(ifc_d)
+        ethpath = os.path.join(ifc_d, 'setup')
         with open(ethpath, 'w') as eth:
             eth.write('auto lo\n')
             eth.write('iface lo inet loopback\n')
@@ -806,6 +819,8 @@ class VmDebootstrap(cliapp.Application):  # pylint: disable=too-many-public-meth
                 eth.write('\n')
                 eth.write('auto eth0\n')
                 eth.write('iface eth0 inet dhcp\n')
+                # force predictable interface names
+                self.mask_udev_predictable_rules(rootdir)
 
     def append_serial_console(self, rootdir):
         if self.settings['serial-console']: