Merge lp:~james-page/simplestreams/multihypervisor into lp:~smoser/simplestreams/trunk

Proposed by James Page on 2015-11-20
Status: Merged
Merged at revision: 423
Proposed branch: lp:~james-page/simplestreams/multihypervisor
Merge into: lp:~smoser/simplestreams/trunk
Diff against target: 102 lines (+51/-2)
2 files modified
simplestreams/mirrors/glance.py (+44/-1)
tools/sstream-mirror-glance (+7/-1)
To merge this branch: bzr merge lp:~james-page/simplestreams/multihypervisor
Reviewer Review Type Date Requested Status
James Page (community) Resubmit on 2015-12-14
Scott Moser 2015-11-20 Pending
Review via email: mp+278127@code.launchpad.net

Description of the Change

Enable better support for multi-hypervisor regions in OpenStack

1) Determine correct disk format.
2) Set hypervisor_type on images based on ftype field.

To post a comment you must log in.
417. By James Page on 2015-11-20

Fixup syntax

418. By James Page on 2015-11-20

Fixup lint

419. By James Page on 2015-11-20

Fixup disk_format handling

420. By James Page on 2015-11-20

Set sane default

421. By James Page on 2015-11-20

Tidy

422. By James Page on 2015-11-20

Use constants for disk format mappings

Scott Moser (smoser) wrote :

<smoser> jamespage, is 'hypervisor_type' a openstack documented thing ?
<jamespage> smoser, it is
<smoser> can it be a list ?
<smoser> http://docs.openstack.org/cli-reference/content/chapter_cli-glance-property.html
<jamespage> smoser, http://docs.openstack.org/cli-reference/content/chapter_cli-glance-property.html
<smoser> right.
<smoser> it woudlseem limiting for us to say 'qemu' when in all likelyhood that image shoudl run in xen at least
<jamespage> smoser, I don't think so but I'll check
<jamespage> smoser, yeah that was actually my concern about turning this on by default

423. By James Page on 2015-12-14

Add configuration option to enable hypervisor mapping in glance mirror

424. By James Page on 2015-12-14

Fixup hypervisor_mapping key use

425. By James Page on 2015-12-14

Also set hypervisor_type on stream data so that tools can index by hypervisor_type if need be

James Page (james-page) wrote :

I've added an option to enable this feature (it would be off by default) and also updated the Glance mirror to set the hypervisor_type in the stream data as well so that tools using the stream data can query by virt type as well.

review: Resubmit

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'simplestreams/mirrors/glance.py'
2--- simplestreams/mirrors/glance.py 2015-09-22 18:42:12 +0000
3+++ simplestreams/mirrors/glance.py 2015-12-14 09:42:45 +0000
4@@ -61,6 +61,37 @@
5 return newarch
6
7
8+LXC_FTYPES = [
9+ 'root.tar.gz',
10+ 'root.tar.xz',
11+]
12+
13+QEMU_FTYPES = [
14+ 'disk.img',
15+ 'disk1.img',
16+]
17+
18+
19+def disk_format(ftype):
20+ '''Canonicalize disk formats for use in OpenStack'''
21+ newftype = ftype.lower()
22+ if newftype in LXC_FTYPES:
23+ return 'root-tar'
24+ if newftype in QEMU_FTYPES:
25+ return 'qcow2'
26+ return None
27+
28+
29+def hypervisor_type(ftype):
30+ '''Determine hypervisor type based on image format'''
31+ newftype = ftype.lower()
32+ if newftype in LXC_FTYPES:
33+ return 'lxc'
34+ if newftype in QEMU_FTYPES:
35+ return 'qemu'
36+ return None
37+
38+
39 # glance mirror 'image-downloads' content into glance
40 # if provided an object store, it will produce a 'image-ids' mirror
41 class GlanceMirror(mirrors.BasicMirrorWriter):
42@@ -198,6 +229,12 @@
43 t_item['arch'] = arch
44 props['architecture'] = canonicalize_arch(arch)
45
46+ if self.config['hypervisor_mapping'] and 'ftype' in flat:
47+ _hypervisor_type = hypervisor_type(flat['ftype'])
48+ if _hypervisor_type:
49+ props['hypervisor_type'] = _hypervisor_type
50+ t_item['hypervisor_type'] = _hypervisor_type
51+
52 if 'os' in flat:
53 props['os_distro'] = flat['os']
54
55@@ -208,7 +245,6 @@
56 create_kwargs = {
57 'name': fullname,
58 'properties': props,
59- 'disk_format': 'qcow2',
60 'container_format': 'bare',
61 'is_public': True,
62 }
63@@ -218,6 +254,13 @@
64 if 'md5' in data:
65 create_kwargs['checksum'] = data.get('md5')
66
67+ if 'ftype' in flat:
68+ create_kwargs['disk_format'] = (
69+ disk_format(flat['ftype']) or 'qcow2'
70+ )
71+ else:
72+ create_kwargs['disk_format'] = 'qcow2'
73+
74 if self.progress_callback:
75 def progress_wrapper(written):
76 self.progress_callback(dict(status="Downloading",
77
78=== modified file 'tools/sstream-mirror-glance'
79--- tools/sstream-mirror-glance 2015-04-10 21:00:00 +0000
80+++ tools/sstream-mirror-glance 2015-12-14 09:42:45 +0000
81@@ -104,6 +104,11 @@
82 "Expressions are key[!]=literal_string "
83 "or key[!]~regexp.")
84
85+ parser.add_argument('--hypervisor-mapping', action='store_true', default=False,
86+ help="Set hypervisor_type attribute on stored images. "
87+ "This is useful in OpenStack Clouds which use multiple "
88+ "hypervisor types with in a single region.")
89+
90 args = parser.parse_args()
91
92 modify_hook = None
93@@ -113,7 +118,8 @@
94 mirror_config = {'max_items': args.max, 'keep_items': args.keep,
95 'cloud_name': args.cloud_name,
96 'modify_hook': modify_hook,
97- 'item_filters': args.item_filters}
98+ 'item_filters': args.item_filters,
99+ 'hypervisor_mapping': args.hypervisor_mapping}
100
101 (mirror_url, args.path) = util.path_from_mirror_url(args.source_mirror,
102 args.path)

Subscribers

People subscribed via source and target branches

to all changes: