~smoser/simplestreams/trunk

« back to all changes in this revision

Viewing changes to simplestreams/mirrors/glance.py

  • Committer: Scott Moser
  • Date: 2016-02-01 09:18:28 UTC
  • mfrom: (415.2.10 simplestreams)
  • Revision ID: smoser@ubuntu.com-20160201091828-ln5r30e4yfn8geg2
Enable better support for multi-hypervisor regions in OpenStack

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    return newarch
62
62
 
63
63
 
 
64
LXC_FTYPES = [
 
65
    'root.tar.gz',
 
66
    'root.tar.xz',
 
67
]
 
68
 
 
69
QEMU_FTYPES = [
 
70
    'disk.img',
 
71
    'disk1.img',
 
72
]
 
73
 
 
74
 
 
75
def disk_format(ftype):
 
76
    '''Canonicalize disk formats for use in OpenStack'''
 
77
    newftype = ftype.lower()
 
78
    if newftype in LXC_FTYPES:
 
79
        return 'root-tar'
 
80
    if newftype in QEMU_FTYPES:
 
81
        return 'qcow2'
 
82
    return None
 
83
 
 
84
 
 
85
def hypervisor_type(ftype):
 
86
    '''Determine hypervisor type based on image format'''
 
87
    newftype = ftype.lower()
 
88
    if newftype in LXC_FTYPES:
 
89
        return 'lxc'
 
90
    if newftype in QEMU_FTYPES:
 
91
        return 'qemu'
 
92
    return None
 
93
 
 
94
 
64
95
# glance mirror 'image-downloads' content into glance
65
96
# if provided an object store, it will produce a 'image-ids' mirror
66
97
class GlanceMirror(mirrors.BasicMirrorWriter):
198
229
            t_item['arch'] = arch
199
230
            props['architecture'] = canonicalize_arch(arch)
200
231
 
 
232
        if self.config['hypervisor_mapping'] and 'ftype' in flat:
 
233
            _hypervisor_type = hypervisor_type(flat['ftype'])
 
234
            if _hypervisor_type:
 
235
                props['hypervisor_type'] = _hypervisor_type
 
236
                t_item['hypervisor_type'] = _hypervisor_type
 
237
 
201
238
        if 'os' in flat:
202
239
            props['os_distro'] = flat['os']
203
240
 
208
245
        create_kwargs = {
209
246
            'name': fullname,
210
247
            'properties': props,
211
 
            'disk_format': 'qcow2',
212
248
            'container_format': 'bare',
213
249
            'is_public': True,
214
250
        }
218
254
        if 'md5' in data:
219
255
            create_kwargs['checksum'] = data.get('md5')
220
256
 
 
257
        if 'ftype' in flat:
 
258
            create_kwargs['disk_format'] = (
 
259
                disk_format(flat['ftype']) or 'qcow2'
 
260
            )
 
261
        else:
 
262
            create_kwargs['disk_format'] = 'qcow2'
 
263
 
221
264
        if self.progress_callback:
222
265
            def progress_wrapper(written):
223
266
                self.progress_callback(dict(status="Downloading",