Merge lp:~smoser/ubuntu/quantal/lxc/lp-1045955 into lp:ubuntu/quantal/lxc

Proposed by Scott Moser
Status: Merged
Merge reported by: Serge Hallyn
Merged at revision: not available
Proposed branch: lp:~smoser/ubuntu/quantal/lxc/lp-1045955
Merge into: lp:ubuntu/quantal/lxc
Diff against target: 362 lines (+226/-57)
5 files modified
.pc/applied-patches (+1/-0)
debian/changelog (+3/-0)
debian/patches/0207-ubuntu-cloud-fixes.patch (+159/-0)
debian/patches/series (+1/-0)
templates/lxc-ubuntu-cloud.in (+62/-57)
To merge this branch: bzr merge lp:~smoser/ubuntu/quantal/lxc/lp-1045955
Reviewer Review Type Date Requested Status
Serge Hallyn Approve
Ubuntu branches Pending
Review via email: mp+122749@code.launchpad.net

Commit message

do not depend on 'ubuntu' existing in image, rather let cloud-init create it.

Primary change here is to make cloud images in quantal work (LP: #1035955).
Other changes here are:
 * use meta-data for passing public keys in
 * use user-data for passing in password
 * support --auth-key being a non-absolute path
 * white space/indentation cleanups in templates/lxc-ubuntu-cloud.in

To post a comment you must log in.
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks, this has been merged upstream.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.pc/applied-patches'
2--- .pc/applied-patches 2012-08-30 16:32:45 +0000
3+++ .pc/applied-patches 2012-09-04 20:04:28 +0000
4@@ -78,3 +78,4 @@
5 0204-ubuntu-cloud-userdata-path
6 0205-lxc-ls-manpage-document-two-lines
7 0206-lxc-wait-initialize-timeout
8+0207-ubuntu-cloud-fixes.patch
9
10=== modified file 'debian/changelog'
11--- debian/changelog 2012-08-30 16:32:45 +0000
12+++ debian/changelog 2012-09-04 20:04:28 +0000
13@@ -2,6 +2,9 @@
14
15 * 0206-lxc-wait-initialize-timeout: initialize timeout to -1 so lxc-wait
16 will, by default, wait for the container to enter the requested state.
17+ * 0207-ubuntu-cloud-fixes.patch: cleanups to lxc-ubuntu-cloud.in
18+ fix for quantal images that do not have user 'ubuntu' present
19+ (LP: #1045955)
20
21 -- Serge Hallyn <serge.hallyn@ubuntu.com> Thu, 30 Aug 2012 11:32:06 -0500
22
23
24=== added file 'debian/patches/0207-ubuntu-cloud-fixes.patch'
25--- debian/patches/0207-ubuntu-cloud-fixes.patch 1970-01-01 00:00:00 +0000
26+++ debian/patches/0207-ubuntu-cloud-fixes.patch 2012-09-04 20:04:28 +0000
27@@ -0,0 +1,159 @@
28+--- a/templates/lxc-ubuntu-cloud.in
29++++ b/templates/lxc-ubuntu-cloud.in
30+@@ -230,6 +230,15 @@ if [ -n "$userdata" ]; then
31+ fi
32+ fi
33+
34++if [ -n "$auth_key" ]; then
35++ if [ ! -f "$auth_key" ]; then
36++ echo "--auth-key=${auth_key} must reference a file"
37++ exit 1
38++ fi
39++ auth_key=$(readlink -f "${auth_key}") ||
40++ { echo "failed to get full path for auth_key"; exit 1; }
41++fi
42++
43+ if [ -z "$path" ]; then
44+ echo "'path' parameter is required"
45+ exit 1
46+@@ -258,17 +267,17 @@ cache="/var/cache/lxc/cloud-$release"
47+ mkdir -p $cache
48+
49+ if [ -n "$tarball" ]; then
50+- url2="$tarball"
51++ url2="$tarball"
52+ else
53+- url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"`
54+- url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
55++ url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"`
56++ url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
57+ fi
58+
59+ filename=`basename $url2`
60+
61+ wgetcleanup()
62+ {
63+- rm -f $filename
64++ rm -f $filename
65+ }
66+
67+ buildcleanup()
68+@@ -321,7 +330,7 @@ mkdir -p /var/lock/subsys/
69+
70+ trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
71+ if [ ! -f $filename ]; then
72+- wget $url2 || build_root_tgz $url1 $filename
73++ wget $url2 || build_root_tgz $url1 $filename
74+ fi
75+ trap EXIT
76+ trap SIGHUP
77+@@ -335,67 +344,63 @@ mkdir -p /var/lock/subsys/
78+
79+
80+ if [ $cloud -eq 0 ]; then
81+- echo "Configuring for running outside of a cloud environment"
82+- echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container"
83++ echo "Configuring for running outside of a cloud environment"
84++ echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container"
85+
86+- seed_d=$rootfs/var/lib/cloud/seed/nocloud-net
87+- rhostid=$(uuidgen | cut -c -8)
88+- host_id=${hostid:-$rhostid}
89+- mkdir -p $seed_d
90++ seed_d=$rootfs/var/lib/cloud/seed/nocloud-net
91++ rhostid=$(uuidgen | cut -c -8)
92++ host_id=${hostid:-$rhostid}
93++ mkdir -p $seed_d
94+
95+- cat > "$seed_d/meta-data" <<EOF
96+-instance_id: lxc-$host_id
97++ cat > "$seed_d/meta-data" <<EOF
98++instance-id: lxc-$host_id
99+ EOF
100++ if [ -n "$auth_key" ]; then
101++ {
102++ echo "public-keys:" &&
103++ sed -e '/^$/d' -e 's,^,- ,' "$auth_key" "$auth_key"
104++ } >> "$seed_d/meta-data"
105++ [ $? -eq 0 ] ||
106++ { echo "failed to write public keys to metadata"; exit 1; }
107++ fi
108++
109++ rm $rootfs/etc/hostname
110++
111++ if [ $locales -eq 1 ]; then
112++ cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive
113++ fi
114++
115++ if [ -f "$userdata" ]; then
116++ echo "Using custom user-data"
117++ cp $userdata $seed_d/user-data
118++ else
119++
120++ if [ -z "$MIRROR" ]; then
121++ MIRROR="http://archive.ubuntu.com/ubuntu"
122++ fi
123+
124+- rm $rootfs/etc/hostname
125+-
126+- if [ $locales -eq 1 ]; then
127+- cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive
128+- fi
129+-
130+-
131+- if [ -n "$auth_key" -a -f "$auth_key" ]; then
132+- u_path="/home/ubuntu/.ssh"
133+- root_u_path="$rootfs/$u_path"
134+- mkdir -p $root_u_path
135+- cp $auth_key "$root_u_path/authorized_keys"
136+- chroot $rootfs chown -R ubuntu: "$u_path"
137+-
138+- echo "Inserted SSH public key from $auth_key into /home/ubuntu/.ssh/authorized_keys"
139+- fi
140+-
141+- if [ -f "$userdata" ]; then
142+- echo "Using custom user-data"
143+- cp $userdata $seed_d/user-data
144+- else
145+-
146+- if [ -z "$MIRROR" ]; then
147+- MIRROR="http://archive.ubuntu.com/ubuntu"
148+- fi
149+-
150+- cat > "$seed_d/user-data" <<EOF
151++ cat > "$seed_d/user-data" <<EOF
152+ #cloud-config
153+ output: {all: '| tee -a /var/log/cloud-init-output.log'}
154+-apt-mirror: $MIRROR
155++apt_mirror: $MIRROR
156+ manage_etc_hosts: localhost
157+ locale: $(/usr/bin/locale | awk -F= '/LANG=/ {print$NF}')
158++password: ubuntu
159++chpasswd: { expire: False }
160+ EOF
161+- fi
162+-
163+- chroot $rootfs /usr/sbin/usermod -U ubuntu
164+- echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
165+- echo "Please login as user ubuntu with password ubuntu."
166++ fi
167+
168+- else
169++ else
170+
171+- echo "Configured for running in a cloud environment."
172+- echo "If you do not have a meta-data service, this container will likely be useless."
173+-
174+- fi
175++ echo "Configured for running in a cloud environment."
176++ echo "If you do not have a meta-data service, this container will likely be useless."
177+
178++ fi
179+ ) 200>/var/lock/subsys/lxc-ubucloud
180+
181+ copy_configuration $path $rootfs $name $arch $release
182+
183+ echo "Container $name created."
184+ exit 0
185++
186++# vi: ts=4 expandtab
187
188=== modified file 'debian/patches/series'
189--- debian/patches/series 2012-08-30 16:32:45 +0000
190+++ debian/patches/series 2012-09-04 20:04:28 +0000
191@@ -80,3 +80,4 @@
192 0204-ubuntu-cloud-userdata-path
193 0205-lxc-ls-manpage-document-two-lines
194 0206-lxc-wait-initialize-timeout
195+0207-ubuntu-cloud-fixes.patch
196
197=== modified file 'templates/lxc-ubuntu-cloud.in'
198--- templates/lxc-ubuntu-cloud.in 2012-08-30 10:05:06 +0000
199+++ templates/lxc-ubuntu-cloud.in 2012-09-04 20:04:28 +0000
200@@ -230,6 +230,15 @@
201 fi
202 fi
203
204+if [ -n "$auth_key" ]; then
205+ if [ ! -f "$auth_key" ]; then
206+ echo "--auth-key=${auth_key} must reference a file"
207+ exit 1
208+ fi
209+ auth_key=$(readlink -f "${auth_key}") ||
210+ { echo "failed to get full path for auth_key"; exit 1; }
211+fi
212+
213 if [ -z "$path" ]; then
214 echo "'path' parameter is required"
215 exit 1
216@@ -258,17 +267,17 @@
217 mkdir -p $cache
218
219 if [ -n "$tarball" ]; then
220- url2="$tarball"
221+ url2="$tarball"
222 else
223- url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"`
224- url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
225+ url1=`ubuntu-cloudimg-query $release $stream $arch --format "%{url}\n"`
226+ url2=`echo $url1 | sed -e 's/.tar.gz/-root\0/'`
227 fi
228
229 filename=`basename $url2`
230
231 wgetcleanup()
232 {
233- rm -f $filename
234+ rm -f $filename
235 }
236
237 buildcleanup()
238@@ -321,7 +330,7 @@
239
240 trap wgetcleanup EXIT SIGHUP SIGINT SIGTERM
241 if [ ! -f $filename ]; then
242- wget $url2 || build_root_tgz $url1 $filename
243+ wget $url2 || build_root_tgz $url1 $filename
244 fi
245 trap EXIT
246 trap SIGHUP
247@@ -335,67 +344,63 @@
248
249
250 if [ $cloud -eq 0 ]; then
251- echo "Configuring for running outside of a cloud environment"
252- echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container"
253-
254- seed_d=$rootfs/var/lib/cloud/seed/nocloud-net
255- rhostid=$(uuidgen | cut -c -8)
256- host_id=${hostid:-$rhostid}
257- mkdir -p $seed_d
258-
259- cat > "$seed_d/meta-data" <<EOF
260-instance_id: lxc-$host_id
261+ echo "Configuring for running outside of a cloud environment"
262+ echo "If you want to configure for a cloud evironment, please use '-- -C' to create the container"
263+
264+ seed_d=$rootfs/var/lib/cloud/seed/nocloud-net
265+ rhostid=$(uuidgen | cut -c -8)
266+ host_id=${hostid:-$rhostid}
267+ mkdir -p $seed_d
268+
269+ cat > "$seed_d/meta-data" <<EOF
270+instance-id: lxc-$host_id
271 EOF
272-
273- rm $rootfs/etc/hostname
274-
275- if [ $locales -eq 1 ]; then
276- cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive
277- fi
278-
279-
280- if [ -n "$auth_key" -a -f "$auth_key" ]; then
281- u_path="/home/ubuntu/.ssh"
282- root_u_path="$rootfs/$u_path"
283- mkdir -p $root_u_path
284- cp $auth_key "$root_u_path/authorized_keys"
285- chroot $rootfs chown -R ubuntu: "$u_path"
286-
287- echo "Inserted SSH public key from $auth_key into /home/ubuntu/.ssh/authorized_keys"
288- fi
289-
290- if [ -f "$userdata" ]; then
291- echo "Using custom user-data"
292- cp $userdata $seed_d/user-data
293- else
294-
295- if [ -z "$MIRROR" ]; then
296- MIRROR="http://archive.ubuntu.com/ubuntu"
297- fi
298-
299- cat > "$seed_d/user-data" <<EOF
300+ if [ -n "$auth_key" ]; then
301+ {
302+ echo "public-keys:" &&
303+ sed -e '/^$/d' -e 's,^,- ,' "$auth_key" "$auth_key"
304+ } >> "$seed_d/meta-data"
305+ [ $? -eq 0 ] ||
306+ { echo "failed to write public keys to metadata"; exit 1; }
307+ fi
308+
309+ rm $rootfs/etc/hostname
310+
311+ if [ $locales -eq 1 ]; then
312+ cp /usr/lib/locale/locale-archive $rootfs/usr/lib/locale/locale-archive
313+ fi
314+
315+ if [ -f "$userdata" ]; then
316+ echo "Using custom user-data"
317+ cp $userdata $seed_d/user-data
318+ else
319+
320+ if [ -z "$MIRROR" ]; then
321+ MIRROR="http://archive.ubuntu.com/ubuntu"
322+ fi
323+
324+ cat > "$seed_d/user-data" <<EOF
325 #cloud-config
326 output: {all: '| tee -a /var/log/cloud-init-output.log'}
327-apt-mirror: $MIRROR
328+apt_mirror: $MIRROR
329 manage_etc_hosts: localhost
330 locale: $(/usr/bin/locale | awk -F= '/LANG=/ {print$NF}')
331+password: ubuntu
332+chpasswd: { expire: False }
333 EOF
334- fi
335-
336- chroot $rootfs /usr/sbin/usermod -U ubuntu
337- echo "ubuntu:ubuntu" | chroot $rootfs chpasswd
338- echo "Please login as user ubuntu with password ubuntu."
339-
340- else
341-
342- echo "Configured for running in a cloud environment."
343- echo "If you do not have a meta-data service, this container will likely be useless."
344-
345- fi
346-
347+ fi
348+
349+ else
350+
351+ echo "Configured for running in a cloud environment."
352+ echo "If you do not have a meta-data service, this container will likely be useless."
353+
354+ fi
355 ) 200>/var/lock/subsys/lxc-ubucloud
356
357 copy_configuration $path $rootfs $name $arch $release
358
359 echo "Container $name created."
360 exit 0
361+
362+# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches