summaryrefslogtreecommitdiff
path: root/cloudinit/distros/__init__.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-24 20:17:10 -0400
committerScott Moser <smoser@ubuntu.com>2012-09-24 20:17:10 -0400
commit314530b519814af4b19b4f7cbcb9a35a6cd68e2d (patch)
tree50351bd64ecb401adde972bc47d1d7b28de7ad0f /cloudinit/distros/__init__.py
parent70cc7536f45a8d7052617ad88e2816291db0a309 (diff)
parente055c795581c2846aa6ae128de8cfd0b2c5d3f32 (diff)
downloadvyos-cloud-init-314530b519814af4b19b4f7cbcb9a35a6cd68e2d.tar.gz
vyos-cloud-init-314530b519814af4b19b4f7cbcb9a35a6cd68e2d.zip
handle ifup on RH distros by iterating over 'ifup devname'
Fix the ifup so that if a list of devices is provided then each interface is brought up individually instead of using the '--all' which isn't on rhel. The default debian behavior will be to use this still though as it overrides the new bring up interfaces function for this case.
Diffstat (limited to 'cloudinit/distros/__init__.py')
-rw-r--r--cloudinit/distros/__init__.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 612d44af..549c1612 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -34,12 +34,6 @@ from cloudinit import log as logging
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 @@ class Distro(object):
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 @@ class Distro(object):
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 @@ class Distro(object):
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):