Comment 15 for bug 1225922

Revision history for this message
Kenneth Burger (burgerk) wrote :

Following with the thought process of the proposal by smoser in #3, I have made the following change in cloudinit/distros/__init__.py to work around this in my environment. ( doesn't go through the complexity of taking down only the auto interfaces )

def apply_network(self, settings, bring_up=True):
        # Write it out
        dev_names = self._write_network(settings)
        # Now try to bring them up
        if bring_up:
            self._bring_down_interfaces(dev_names) <---- new method
            return self._bring_up_interfaces(dev_names)
        return False

Then added these default implementations:

    def _bring_down_interface(self, device_name):
        cmd = ['ifdown', device_name]
        LOG.debug("Attempting to run bring down interface %s using command %s",
                   device_name, cmd)
        try:
            (_out, err) = util.subp(cmd)
            if len(err):
                LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
            return True
        except util.ProcessExecutionError:
            util.logexc(LOG, "Running interface command %s failed", cmd)
            return False

    def _bring_down_interfaces(self, device_names):
        am_failed = 0
        for d in device_names:
            if not self._bring_down_interface(d):
                am_failed += 1
        if am_failed == 0:
            return True
        return False

Since Ubuntu always returns --all for device_names, so implement in debian.py as:

    def _bring_down_interfaces(self, device_names):
        use_all = False
        for d in device_names:
            if d == 'all':
                use_all = True
        if use_all:
            return distros.Distro._bring_down_interface(self, '--all')
        else:
            return distros.Distro._bring_down_interfaces(self, device_names)