← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~harlowja/cloud-init/patch-ifup-names into lp:cloud-init

 

Joshua Harlow has proposed merging lp:~harlowja/cloud-init/patch-ifup-names into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1053185 in cloud-init: "RHEL doesn't have ifup --all but instead needs individual interfaces"
  https://bugs.launchpad.net/cloud-init/+bug/1053185

For more details, see:
https://code.launchpad.net/~harlowja/cloud-init/patch-ifup-names/+merge/125386
-- 
https://code.launchpad.net/~harlowja/cloud-init/patch-ifup-names/+merge/125386
Your team cloud init development team is requested to review the proposed merge of lp:~harlowja/cloud-init/patch-ifup-names into lp:cloud-init.
=== modified file 'cloudinit/distros/__init__.py'
--- cloudinit/distros/__init__.py	2012-09-18 17:27:41 +0000
+++ cloudinit/distros/__init__.py	2012-09-20 01:45:32 +0000
@@ -34,12 +34,6 @@
 from cloudinit import ssh_util
 from cloudinit import util
 
-# TODO(harlowja): Make this via config??
-IFACE_ACTIONS = {
-    'up': ['ifup', '--all'],
-    'down': ['ifdown', '--all'],
-}
-
 LOG = logging.getLogger(__name__)
 
 
@@ -134,10 +128,10 @@
 
     def apply_network(self, settings, bring_up=True):
         # Write it out
-        self._write_network(settings)
+        dev_names = self._write_network(settings)
         # Now try to bring them up
         if bring_up:
-            return self._interface_action('up')
+            return self._bring_up_interfaces(dev_names)
         return False
 
     @abc.abstractmethod
@@ -189,13 +183,11 @@
             util.write_file(self._paths.join(False, "/etc/hosts"),
                             contents, mode=0644)
 
-    def _interface_action(self, action):
-        if action not in IFACE_ACTIONS:
-            raise NotImplementedError("Unknown interface action %s" % (action))
-        cmd = IFACE_ACTIONS[action]
+    def _bring_up_interface(self, device_name):
+        cmd = ['ifup', device_name]
+        LOG.debug("Attempting to run bring up interface %s using command %s",
+                   device_name, cmd)
         try:
-            LOG.debug("Attempting to run %s interface action using command %s",
-                      action, cmd)
             (_out, err) = util.subp(cmd)
             if len(err):
                 LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
@@ -204,6 +196,15 @@
             util.logexc(LOG, "Running interface command %s failed", cmd)
             return False
 
+    def _bring_up_interfaces(self, device_names):
+        am_failed = 0
+        for d in device_names:
+            if not self._bring_up_interface(d):
+                am_failed += 1
+        if am_failed == 0:
+            return True
+        return False
+
     def isuser(self, name):
         try:
             if pwd.getpwnam(name):

=== modified file 'cloudinit/distros/debian.py'
--- cloudinit/distros/debian.py	2012-09-19 19:07:03 +0000
+++ cloudinit/distros/debian.py	2012-09-20 01:45:32 +0000
@@ -56,6 +56,12 @@
     def _write_network(self, settings):
         net_fn = self._paths.join(False, "/etc/network/interfaces")
         util.write_file(net_fn, settings)
+        return []
+
+    def _bring_up_interfaces(self, device_names):
+        if not device_names:
+            device_names = ['--all']
+        return distros.Distro._bring_up_interfaces(self, device_names)
 
     def set_hostname(self, hostname):
         out_fn = self._paths.join(False, "/etc/hostname")

=== modified file 'cloudinit/distros/fedora.py'
--- cloudinit/distros/fedora.py	2012-09-17 18:23:51 +0000
+++ cloudinit/distros/fedora.py	2012-09-20 01:45:32 +0000
@@ -28,5 +28,4 @@
 
 
 class Distro(rhel.Distro):
-    distro_name  = 'fedora'
     default_user = 'ec2-user'

=== modified file 'cloudinit/distros/rhel.py'
--- cloudinit/distros/rhel.py	2012-09-19 20:06:58 +0000
+++ cloudinit/distros/rhel.py	2012-09-20 01:45:32 +0000
@@ -88,6 +88,7 @@
         # Make the intermediate format as the rhel format...
         nameservers = []
         searchservers = []
+        dev_names = entries.keys()
         for (dev, info) in entries.iteritems():
             net_fn = NETWORK_FN_TPL % (dev)
             net_ro_fn = self._paths.join(True, net_fn)
@@ -127,6 +128,7 @@
             util.write_file(net_rw_fn, w_contents, 0644)
         if nameservers or searchservers:
             self._write_resolve(nameservers, searchservers)
+        return dev_names
 
     def set_hostname(self, hostname):
         out_fn = self._paths.join(False, '/etc/sysconfig/network')

=== modified file 'cloudinit/distros/ubuntu.py'
--- cloudinit/distros/ubuntu.py	2012-08-31 21:45:15 +0000
+++ cloudinit/distros/ubuntu.py	2012-09-20 01:45:32 +0000
@@ -29,7 +29,6 @@
 
 class Distro(debian.Distro):
 
-    distro_name = 'ubuntu'
     default_user = 'ubuntu'
     default_user_groups = ("adm,audio,cdrom,dialout,floppy,video,"
                             "plugdev,dip,netdev,sudo")


Follow ups