~gundlach/nova/controllers-in-api

« back to all changes in this revision

Viewing changes to nova/endpoint/images.py

  • Committer: Michael Gundlach
  • Date: 2010-08-26 18:09:14 UTC
  • Revision ID: michael.gundlach@rackspace.com-20100826180914-htofziufwyg77lmw
work endpoint/images.py into an S3ImageService.  The translation isn't perfect, but it's a start.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import boto.s3.connection
28
28
 
 
29
from nova import image
29
30
from nova import flags
30
31
from nova import utils
31
32
from nova.auth import manager
35
36
 
36
37
 
37
38
def modify(context, image_id, operation):
38
 
    conn(context).make_request(
 
39
    image.S3ImageService(context)._conn().make_request(
39
40
        method='POST',
40
41
        bucket='_images',
41
42
        query_args=qs({'image_id': image_id, 'operation': operation}))
47
48
    """ rpc call to register a new image based from a manifest """
48
49
 
49
50
    image_id = utils.generate_uid('ami')
50
 
    conn(context).make_request(
 
51
    image.S3ImageService(context)._conn().make_request(
51
52
            method='PUT',
52
53
            bucket='_images',
53
54
            query_args=qs({'image_location': image_location,
61
62
 
62
63
    optionally filtered by a list of image_id """
63
64
 
64
 
    # FIXME: send along the list of only_images to check for
65
 
    response = conn(context).make_request(
66
 
            method='GET',
67
 
            bucket='_images')
68
 
 
69
 
    result = json.loads(response.read())
 
65
    result = image.S3ImageService(context).index().values()
70
66
    if not filter_list is None:
71
67
        return [i for i in result if i['imageId'] in filter_list]
72
68
    return result
74
70
 
75
71
def deregister(context, image_id):
76
72
    """ unregister an image """
77
 
    conn(context).make_request(
78
 
            method='DELETE',
79
 
            bucket='_images',
80
 
            query_args=qs({'image_id': image_id}))
81
 
 
82
 
 
83
 
def conn(context):
84
 
    access = manager.AuthManager().get_access_key(context.user,
85
 
                                                  context.project)
86
 
    secret = str(context.user.secret)
87
 
    calling = boto.s3.connection.OrdinaryCallingFormat()
88
 
    return boto.s3.connection.S3Connection(aws_access_key_id=access,
89
 
                                           aws_secret_access_key=secret,
90
 
                                           is_secure=False,
91
 
                                           calling_format=calling,
92
 
                                           port=FLAGS.s3_port,
93
 
                                           host=FLAGS.s3_host)
 
73
    image.S3ImageService(context).delete(image_id)
94
74
 
95
75
 
96
76
def qs(params):