Revove useless test_data.py file, add image uploader

This commit is contained in:
Rick Harris 2011-01-22 19:17:07 +00:00
parent ba947efb78
commit d0ba568360
2 changed files with 67 additions and 47 deletions

View File

@ -1,47 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2010 OpenStack, LLC
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from glance.registry import db
def make_swift_image():
"""Create a real image record """
# TODO(sirp): Create a testing account, and define gflags for
# test_swift_username and test_swift_api_key
USERNAME = "your user name here" # fill these out for testing
API_KEY = "your api key here"
#IMAGE_CHUNKS = [("filename", 123)] # filename, size in bytes
IMAGE_CHUNKS = [("your test chunk here", 12345)]
image = db.image_create(
None,
dict(name="testsnap",
state="available",
public=True,
image_type="raw"))
for obj, size in IMAGE_CHUNKS:
location = (
"swift://%s:%s@auth.api.rackspacecloud.com/v1.0/cloudservers/%s"
) % (USERNAME, API_KEY, obj)
db.image_file_create(None,
dict(image_id=image.id, location=location, size=size))
if __name__ == "__main__":
make_swift_image() # NOTE: uncomment if you have a username and api_key

67
tools/glance_upload.py Executable file
View File

@ -0,0 +1,67 @@
#!/usr/bin/python
"""
Upload an image into Glance
Usage:
Raw:
glance_upload.py <filename> <name>
Kernel-outside:
glance_upload.py --type=kernel <filename> <name>
glance_upload.py --type=ramdisk <filename> <name>
glance_upload.py --type=machine --kernel=KERNEL_ID --ramdisk=RAMDISK_ID \
<filename> <name>
"""
import argparse
import pprint
import sys
from glance.client import Client
def die(msg):
print >>sys.stderr, msg
sys.exit(1)
def parse_args():
parser = argparse.ArgumentParser(description='Upload an image into Glance')
parser.add_argument('filename', help='file to upload into Glance')
parser.add_argument('name', help='name of image')
parser.add_argument('--host', metavar='HOST', default='127.0.0.1',
help='Location of Glance Server (default: 127.0.0.1)')
parser.add_argument('--type', metavar='TYPE', default='raw',
help='Type of Image [kernel, ramdisk, machine, raw] '
'(default: raw)')
parser.add_argument('--kernel', metavar='KERNEL',
help='ID of kernel associated with this machine image')
parser.add_argument('--ramdisk', metavar='RAMDISK',
help='ID of ramdisk associated with this machine image')
args = parser.parse_args()
return args
def main():
args = parse_args()
meta = {'name': args.name, 'type': args.type, 'is_public': True}
if args.type == 'machine':
if args.kernel and args.ramdisk:
meta['properties'] = {'kernel_id': args.kernel,
'ramdisk_id': args.ramdisk}
else:
die("kernel and ramdisk required for machine image")
client = Client(args.host, 9292)
with open(args.filename) as f:
new_meta = client.add_image(meta, f)
print 'Stored image. Got identifier: %s' % pprint.pformat(new_meta)
if __name__ == "__main__":
main()