summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-09-24 17:41:56 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-09-24 17:41:56 -0700
commitebd83a036cd94d856c2cd100202c6fb4ca287ce1 (patch)
tree2502a4464ae60d5a821ed9040f13241e8dce284b /cloudinit/distros
parentf59369d1bb0eac874dcd2fa91abfad9186b22810 (diff)
parent314530b519814af4b19b4f7cbcb9a35a6cd68e2d (diff)
downloadvyos-cloud-init-ebd83a036cd94d856c2cd100202c6fb4ca287ce1.tar.gz
vyos-cloud-init-ebd83a036cd94d856c2cd100202c6fb4ca287ce1.zip
Bring up to date with trunk.
Diffstat (limited to 'cloudinit/distros')
-rw-r--r--cloudinit/distros/__init__.py31
-rw-r--r--cloudinit/distros/debian.py11
-rw-r--r--cloudinit/distros/fedora.py1
-rw-r--r--cloudinit/distros/rhel.py2
-rw-r--r--cloudinit/distros/ubuntu.py1
5 files changed, 29 insertions, 17 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 3e9d934d..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):
@@ -339,7 +340,7 @@ class Distro(object):
content += "\n"
if not os.path.exists(sudo_file):
- util.write_file(sudo_file, content, 0644)
+ util.write_file(sudo_file, content, 0440)
else:
try:
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 5b4aa9f8..88f4e978 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -56,6 +56,17 @@ class Distro(distros.Distro):
def _write_network(self, settings):
net_fn = self._paths.join(False, "/etc/network/interfaces")
util.write_file(net_fn, settings)
+ return ['all']
+
+ def _bring_up_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_up_interface(self, '--all')
+ else:
+ return distros.Distro._bring_up_interfaces(self, device_names)
def set_hostname(self, hostname):
out_fn = self._paths.join(False, "/etc/hostname")
diff --git a/cloudinit/distros/fedora.py b/cloudinit/distros/fedora.py
index 9f76a116..f65a820d 100644
--- a/cloudinit/distros/fedora.py
+++ b/cloudinit/distros/fedora.py
@@ -28,5 +28,4 @@ LOG = logging.getLogger(__name__)
class Distro(rhel.Distro):
- distro_name = 'fedora'
default_user = 'ec2-user'
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index 1ea7952b..67d80bf4 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -144,6 +144,8 @@ class Distro(distros.Distro):
if not exists:
lines.insert(0, _make_header())
util.write_file(fn, "\n".join(lines), 0644)
+=======
+>>>>>>> MERGE-SOURCE
def set_hostname(self, hostname):
self._write_hostname(hostname, '/etc/sysconfig/network')
diff --git a/cloudinit/distros/ubuntu.py b/cloudinit/distros/ubuntu.py
index 22f8c2c5..4e697f82 100644
--- a/cloudinit/distros/ubuntu.py
+++ b/cloudinit/distros/ubuntu.py
@@ -29,7 +29,6 @@ LOG = logging.getLogger(__name__)
class Distro(debian.Distro):
- distro_name = 'ubuntu'
default_user = 'ubuntu'
default_user_groups = ("adm,audio,cdrom,dialout,floppy,video,"
"plugdev,dip,netdev,sudo")