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.
This commit is contained in:
parent
634164137b
commit
02fe019367
@ -34,12 +34,6 @@ from cloudinit import log as logging
|
|||||||
from cloudinit import ssh_util
|
from cloudinit import ssh_util
|
||||||
from cloudinit import util
|
from cloudinit import util
|
||||||
|
|
||||||
# TODO(harlowja): Make this via config??
|
|
||||||
IFACE_ACTIONS = {
|
|
||||||
'up': ['ifup', '--all'],
|
|
||||||
'down': ['ifdown', '--all'],
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -134,10 +128,10 @@ class Distro(object):
|
|||||||
|
|
||||||
def apply_network(self, settings, bring_up=True):
|
def apply_network(self, settings, bring_up=True):
|
||||||
# Write it out
|
# Write it out
|
||||||
self._write_network(settings)
|
dev_names = self._write_network(settings)
|
||||||
# Now try to bring them up
|
# Now try to bring them up
|
||||||
if bring_up:
|
if bring_up:
|
||||||
return self._interface_action('up')
|
return self._bring_up_interfaces(dev_names)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
@ -189,13 +183,11 @@ class Distro(object):
|
|||||||
util.write_file(self._paths.join(False, "/etc/hosts"),
|
util.write_file(self._paths.join(False, "/etc/hosts"),
|
||||||
contents, mode=0644)
|
contents, mode=0644)
|
||||||
|
|
||||||
def _interface_action(self, action):
|
def _bring_up_interface(self, device_name):
|
||||||
if action not in IFACE_ACTIONS:
|
cmd = ['ifup', device_name]
|
||||||
raise NotImplementedError("Unknown interface action %s" % (action))
|
LOG.debug("Attempting to run bring up interface %s using command %s",
|
||||||
cmd = IFACE_ACTIONS[action]
|
device_name, cmd)
|
||||||
try:
|
try:
|
||||||
LOG.debug("Attempting to run %s interface action using command %s",
|
|
||||||
action, cmd)
|
|
||||||
(_out, err) = util.subp(cmd)
|
(_out, err) = util.subp(cmd)
|
||||||
if len(err):
|
if len(err):
|
||||||
LOG.warn("Running %s resulted in stderr output: %s", cmd, 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)
|
util.logexc(LOG, "Running interface command %s failed", cmd)
|
||||||
return False
|
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):
|
def isuser(self, name):
|
||||||
try:
|
try:
|
||||||
if pwd.getpwnam(name):
|
if pwd.getpwnam(name):
|
||||||
|
@ -56,6 +56,12 @@ class Distro(distros.Distro):
|
|||||||
def _write_network(self, settings):
|
def _write_network(self, settings):
|
||||||
net_fn = self._paths.join(False, "/etc/network/interfaces")
|
net_fn = self._paths.join(False, "/etc/network/interfaces")
|
||||||
util.write_file(net_fn, settings)
|
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):
|
def set_hostname(self, hostname):
|
||||||
out_fn = self._paths.join(False, "/etc/hostname")
|
out_fn = self._paths.join(False, "/etc/hostname")
|
||||||
|
@ -28,5 +28,4 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class Distro(rhel.Distro):
|
class Distro(rhel.Distro):
|
||||||
distro_name = 'fedora'
|
|
||||||
default_user = 'ec2-user'
|
default_user = 'ec2-user'
|
||||||
|
@ -88,6 +88,7 @@ class Distro(distros.Distro):
|
|||||||
# Make the intermediate format as the rhel format...
|
# Make the intermediate format as the rhel format...
|
||||||
nameservers = []
|
nameservers = []
|
||||||
searchservers = []
|
searchservers = []
|
||||||
|
dev_names = entries.keys()
|
||||||
for (dev, info) in entries.iteritems():
|
for (dev, info) in entries.iteritems():
|
||||||
net_fn = NETWORK_FN_TPL % (dev)
|
net_fn = NETWORK_FN_TPL % (dev)
|
||||||
net_ro_fn = self._paths.join(True, net_fn)
|
net_ro_fn = self._paths.join(True, net_fn)
|
||||||
@ -127,6 +128,7 @@ class Distro(distros.Distro):
|
|||||||
util.write_file(net_rw_fn, w_contents, 0644)
|
util.write_file(net_rw_fn, w_contents, 0644)
|
||||||
if nameservers or searchservers:
|
if nameservers or searchservers:
|
||||||
self._write_resolve(nameservers, searchservers)
|
self._write_resolve(nameservers, searchservers)
|
||||||
|
return dev_names
|
||||||
|
|
||||||
def set_hostname(self, hostname):
|
def set_hostname(self, hostname):
|
||||||
out_fn = self._paths.join(False, '/etc/sysconfig/network')
|
out_fn = self._paths.join(False, '/etc/sysconfig/network')
|
||||||
|
@ -29,7 +29,6 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class Distro(debian.Distro):
|
class Distro(debian.Distro):
|
||||||
|
|
||||||
distro_name = 'ubuntu'
|
|
||||||
default_user = 'ubuntu'
|
default_user = 'ubuntu'
|
||||||
default_user_groups = ("adm,audio,cdrom,dialout,floppy,video,"
|
default_user_groups = ("adm,audio,cdrom,dialout,floppy,video,"
|
||||||
"plugdev,dip,netdev,sudo")
|
"plugdev,dip,netdev,sudo")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user