Merge lp:~pwlars/core-image-publisher/build-cloud-image into lp:core-image-publisher

Proposed by Paul Larson
Status: Superseded
Proposed branch: lp:~pwlars/core-image-publisher/build-cloud-image
Merge into: lp:core-image-publisher
Prerequisite: lp:~pwlars/core-image-publisher/fix-logger
Diff against target: 69 lines (+36/-6)
1 file modified
core_image_publisher/worker.py (+36/-6)
To merge this branch: bzr merge lp:~pwlars/core-image-publisher/build-cloud-image
Reviewer Review Type Date Requested Status
Canonical CI Engineering Pending
Review via email: mp+254340@code.launchpad.net

This proposal has been superseded by a proposal from 2015-03-27.

Commit message

add support for building and converting the cloud image

Description of the change

Work in progress to add support for building and converting the cloud image

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Happy to land once you fix the one note I made in the diff.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core_image_publisher/worker.py'
2--- core_image_publisher/worker.py 2015-03-27 03:29:44 +0000
3+++ core_image_publisher/worker.py 2015-03-27 03:29:44 +0000
4@@ -18,6 +18,9 @@
5 """Business logic or the service lives here."""
6
7 import logging
8+import os
9+import subprocess
10+import tempfile
11 from core_image_publisher.queue import enqueue_message
12
13 logger = logging.getLogger(__name__)
14@@ -39,22 +42,49 @@
15 message.reject()
16 return
17
18- image_path = download_image(image_name, channel, device)
19- nova_image_path = convert_nova_image(image_path)
20- glance_image_name = upload_image_to_glance(nova_image_path)
21+ with tempfile.TemporaryDirectory as tmpdir:
22+ image_path = download_image(image_name, channel, device, tmpdir)
23+ nova_image_path = convert_nova_image(image_path)
24+ glance_image_name = upload_image_to_glance(nova_image_path)
25
26 payload['nova_image'] = glance_image_name
27 enqueue_message(payload)
28 message.ack()
29
30
31-def download_image(name, channel, device):
32+def download_image(name, channel, device, tmpdir):
33 """Download the ubuntu code image, return a path to it on disk."""
34+ image_path = os.path.join(tmpdir, 'core-{}.img'.format(name))
35+ cmd = ['sudo',
36+ 'ubuntu-device-flash',
37+ '--revision', name,
38+ 'core',
39+ ' --device=generic_amd64',
40+ '--channel', channel,
41+ '--size', '3',
42+ '-o', image_path,
43+ '--developer-mode',
44+ '--cloud']
45+ subprocess.check_call(cmd)
46+ return image_path
47
48
49 def convert_nova_image(image_path):
50- """Convert a core image to a nova image, return path to the converted image."""
51+ """
52+ Convert a core image to a nova image, return path to the converted image.
53+ """
54+ converted_image_path = '{}-cloud.img'.format(image_path.strip('.img'))
55+ cmd = ['qemu-img',
56+ 'convert',
57+ '-f', 'raw',
58+ '-O', 'qcow2',
59+ image_path,
60+ converted_image_path]
61+ subprocess.check_call(cmd)
62+ return converted_image_path
63
64
65 def upload_image_to_glance(nova_image_path):
66- """Upload the nova image to glance, returning the name of the image in glance."""
67+ """
68+ Upload the nova image to glance, returning the name of the image in glance.
69+ """

Subscribers

People subscribed via source and target branches