2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright 2011 OpenStack LLC.
7
# Licensed under the Apache License, Version 2.0 (the "License"); you may
8
# not use this file except in compliance with the License. You may obtain
9
# a copy of the License at
11
# http://www.apache.org/licenses/LICENSE-2.0
13
# Unless required by applicable law or agreed to in writing, software
14
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16
# License for the specific language governing permissions and limitations
20
Upload an image into Glance
25
Machine - Kernel outside of the image
26
-------------------------------------
28
glance-upload --type=kernel <filename> <name>
29
glance-upload --type=ramdisk <filename> <name>
30
glance-upload --type=machine --kernel=KERNEL_ID --ramdisk=RAMDISK_ID \
33
Raw - Kernel inside, raw image data
34
-----------------------------------
36
glance-upload --type=raw --kernel=nokernel --ramdisk=noramdisk \
40
VHD - Kernel inside, data encoded with VHD format
41
-------------------------------------------------
43
glance-upload --type=vhd --kernel=nokernel --ramdisk=noramdisk \
47
# FIXME(sirp): This can be merged into glance-admin when that becomes
54
# If ../glance/__init__.py exists, add ../ to Python search path, so that
55
# it will override what happens to be installed in /usr/(local/)lib/python...
56
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
59
if os.path.exists(os.path.join(possible_topdir, 'glance', '__init__.py')):
60
sys.path.insert(0, possible_topdir)
62
from glance.client import Client
63
from glance.registry.db.api import DISK_FORMATS, CONTAINER_FORMATS
67
print >> sys.stderr, msg
72
parser = argparse.ArgumentParser(description='Upload an image into Glance')
73
parser.add_argument('filename', help='file to upload into Glance')
74
parser.add_argument('name', help='name of image')
75
parser.add_argument('--host', metavar='HOST', default='127.0.0.1',
76
help='Location of Glance Server (default: %default)')
77
parser.add_argument('--port', metavar='PORT', type=int, default=9292,
78
help='Port of Glance Server (default: %default)')
79
parser.add_argument('--type', metavar='TYPE', default='raw',
80
help='Type of Image [kernel, ramdisk, machine, raw] '
81
'(default: %default)')
82
parser.add_argument('--disk-format', metavar='DISK_FORMAT', default=None,
84
help='Disk format of Image [%s] '
85
'(default: %%default)' % ','.join(DISK_FORMATS))
86
parser.add_argument('--container-format', metavar='CONTAINER_FORMAT',
87
default=None, choices=CONTAINER_FORMATS,
88
help='Disk format of Image [%s] '
89
'(default: %%default)' % ','.join(CONTAINER_FORMATS))
90
parser.add_argument('--kernel', metavar='KERNEL',
91
help='ID of kernel associated with this machine image')
92
parser.add_argument('--ramdisk', metavar='RAMDISK',
93
help='ID of ramdisk associated with this machine '
95
args = parser.parse_args()
101
meta = {'name': args.name,
106
meta['properties']['kernel_id'] = args.kernel
109
meta['properties']['ramdisk_id'] = args.ramdisk
112
meta['properties']['type'] = args.type
115
meta['disk_format'] = args.disk_format
117
if args.container_format:
118
meta['container_format'] = args.container_format
120
client = Client(args.host, args.port)
121
with open(args.filename) as f:
123
new_meta = client.add_image(meta, f)
125
print "Failed to add new image. Got error: ", str(e)
128
print 'Stored image. Got identifier: %s' % pprint.pformat(new_meta)
131
if __name__ == "__main__":