Merge lp:~harlowja/cloud-init/patch-ifup-names into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Joshua Harlow
Status: Merged
Merged at revision: 667
Proposed branch: lp:~harlowja/cloud-init/patch-ifup-names
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 127 lines (+28/-16)
5 files modified
cloudinit/distros/__init__.py (+15/-14)
cloudinit/distros/debian.py (+11/-0)
cloudinit/distros/fedora.py (+0/-1)
cloudinit/distros/rhel.py (+2/-0)
cloudinit/distros/ubuntu.py (+0/-1)
To merge this branch: bzr merge lp:~harlowja/cloud-init/patch-ifup-names
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+125386@code.launchpad.net
To post a comment you must log in.
660. By Joshua Harlow

Instead of special casing the empty list
we are going to check for the 'all' entry
and if that exists then only fire off one
call (since debian supports this).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/distros/__init__.py'
2--- cloudinit/distros/__init__.py 2012-09-18 17:27:41 +0000
3+++ cloudinit/distros/__init__.py 2012-09-20 22:58:20 +0000
4@@ -34,12 +34,6 @@
5 from cloudinit import ssh_util
6 from cloudinit import util
7
8-# TODO(harlowja): Make this via config??
9-IFACE_ACTIONS = {
10- 'up': ['ifup', '--all'],
11- 'down': ['ifdown', '--all'],
12-}
13-
14 LOG = logging.getLogger(__name__)
15
16
17@@ -134,10 +128,10 @@
18
19 def apply_network(self, settings, bring_up=True):
20 # Write it out
21- self._write_network(settings)
22+ dev_names = self._write_network(settings)
23 # Now try to bring them up
24 if bring_up:
25- return self._interface_action('up')
26+ return self._bring_up_interfaces(dev_names)
27 return False
28
29 @abc.abstractmethod
30@@ -189,13 +183,11 @@
31 util.write_file(self._paths.join(False, "/etc/hosts"),
32 contents, mode=0644)
33
34- def _interface_action(self, action):
35- if action not in IFACE_ACTIONS:
36- raise NotImplementedError("Unknown interface action %s" % (action))
37- cmd = IFACE_ACTIONS[action]
38+ def _bring_up_interface(self, device_name):
39+ cmd = ['ifup', device_name]
40+ LOG.debug("Attempting to run bring up interface %s using command %s",
41+ device_name, cmd)
42 try:
43- LOG.debug("Attempting to run %s interface action using command %s",
44- action, cmd)
45 (_out, err) = util.subp(cmd)
46 if len(err):
47 LOG.warn("Running %s resulted in stderr output: %s", cmd, err)
48@@ -204,6 +196,15 @@
49 util.logexc(LOG, "Running interface command %s failed", cmd)
50 return False
51
52+ def _bring_up_interfaces(self, device_names):
53+ am_failed = 0
54+ for d in device_names:
55+ if not self._bring_up_interface(d):
56+ am_failed += 1
57+ if am_failed == 0:
58+ return True
59+ return False
60+
61 def isuser(self, name):
62 try:
63 if pwd.getpwnam(name):
64
65=== modified file 'cloudinit/distros/debian.py'
66--- cloudinit/distros/debian.py 2012-09-19 19:07:03 +0000
67+++ cloudinit/distros/debian.py 2012-09-20 22:58:20 +0000
68@@ -56,6 +56,17 @@
69 def _write_network(self, settings):
70 net_fn = self._paths.join(False, "/etc/network/interfaces")
71 util.write_file(net_fn, settings)
72+ return ['all']
73+
74+ def _bring_up_interfaces(self, device_names):
75+ use_all = False
76+ for d in device_names:
77+ if d == 'all':
78+ use_all = True
79+ if use_all:
80+ return distros.Distro._bring_up_interface(self, '--all')
81+ else:
82+ return distros.Distro._bring_up_interfaces(self, device_names)
83
84 def set_hostname(self, hostname):
85 out_fn = self._paths.join(False, "/etc/hostname")
86
87=== modified file 'cloudinit/distros/fedora.py'
88--- cloudinit/distros/fedora.py 2012-09-17 18:23:51 +0000
89+++ cloudinit/distros/fedora.py 2012-09-20 22:58:20 +0000
90@@ -28,5 +28,4 @@
91
92
93 class Distro(rhel.Distro):
94- distro_name = 'fedora'
95 default_user = 'ec2-user'
96
97=== modified file 'cloudinit/distros/rhel.py'
98--- cloudinit/distros/rhel.py 2012-09-19 20:06:58 +0000
99+++ cloudinit/distros/rhel.py 2012-09-20 22:58:20 +0000
100@@ -88,6 +88,7 @@
101 # Make the intermediate format as the rhel format...
102 nameservers = []
103 searchservers = []
104+ dev_names = entries.keys()
105 for (dev, info) in entries.iteritems():
106 net_fn = NETWORK_FN_TPL % (dev)
107 net_ro_fn = self._paths.join(True, net_fn)
108@@ -127,6 +128,7 @@
109 util.write_file(net_rw_fn, w_contents, 0644)
110 if nameservers or searchservers:
111 self._write_resolve(nameservers, searchservers)
112+ return dev_names
113
114 def set_hostname(self, hostname):
115 out_fn = self._paths.join(False, '/etc/sysconfig/network')
116
117=== modified file 'cloudinit/distros/ubuntu.py'
118--- cloudinit/distros/ubuntu.py 2012-08-31 21:45:15 +0000
119+++ cloudinit/distros/ubuntu.py 2012-09-20 22:58:20 +0000
120@@ -29,7 +29,6 @@
121
122 class Distro(debian.Distro):
123
124- distro_name = 'ubuntu'
125 default_user = 'ubuntu'
126 default_user_groups = ("adm,audio,cdrom,dialout,floppy,video,"
127 "plugdev,dip,netdev,sudo")