2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright 2010 United States Government as represented by the
5
# Administrator of the National Aeronautics and Space Administration.
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9
# not use this file except in compliance with the License. You may obtain
10
# a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
# License for the specific language governing permissions and limitations
21
Download images from Canonical Image Store
33
# If ../nova/__init__.py exists, add ../ to Python search path, so that
34
# it will override what happens to be installed in /usr/(local/)lib/python...
35
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
38
if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
39
sys.path.insert(0, possible_topdir)
41
gettext.install('nova', unicode=1)
43
from nova import flags
44
from nova import log as logging
45
from nova import utils
46
from nova.objectstore import image
50
API_URL = 'https://imagestore.canonical.com/api/dashboard'
54
"""Get a list of the images from the imagestore URL."""
55
images = json.load(urllib2.urlopen(API_URL))['images']
56
images = [img for img in images if img['title'].find('amd64') > -1]
61
"""Download an image to the local filesystem."""
62
# FIXME(ja): add checksum/signature checks
63
tempdir = tempfile.mkdtemp(prefix='cis-')
68
for f in img['files']:
69
if f['kind'] == 'kernel':
70
dest = os.path.join(tempdir, 'kernel')
71
subprocess.call(['curl', '--fail', f['url'], '-o', dest])
72
kernel_id = image.Image.add(dest,
73
description='kernel/' + img['title'], kernel=True)
75
for f in img['files']:
76
if f['kind'] == 'ramdisk':
77
dest = os.path.join(tempdir, 'ramdisk')
78
subprocess.call(['curl', '--fail', f['url'], '-o', dest])
79
ramdisk_id = image.Image.add(dest,
80
description='ramdisk/' + img['title'], ramdisk=True)
82
for f in img['files']:
83
if f['kind'] == 'image':
84
dest = os.path.join(tempdir, 'image')
85
subprocess.call(['curl', '--fail', f['url'], '-o', dest])
86
ramdisk_id = image.Image.add(dest,
87
description=img['title'], kernel=kernel_id, ramdisk=ramdisk_id)
89
shutil.rmtree(tempdir)
93
"""Main entry point."""
94
utils.default_flagfile()
95
argv = FLAGS(sys.argv)
101
if argv[1] == 'all' or argv[1] == img['title']:
104
print 'usage: %s (title|all)'
105
print 'available images:'
109
if __name__ == '__main__':