Revision 17b255c7 kamaki/clients/image/__init__.py

b/kamaki/clients/image/__init__.py
35 35
from kamaki.clients.utils import path4url, filter_in
36 36

  
37 37

  
38
def _format_image_headers(headers):
39
    reply = dict(properties=dict())
40
    meta_prefix = 'x-image-meta-'
41
    property_prefix = 'x-image-meta-property-'
42

  
43
    for key, val in headers.items():
44
        key = key.lower()
45
        if key.startswith(property_prefix):
46
            key = key[len(property_prefix):].upper().replace('-', '_')
47
            reply['properties'][key] = val
48
        elif key.startswith(meta_prefix):
49
            key = key[len(meta_prefix):]
50
            reply[key] = val
51
    return reply
52

  
53

  
38 54
class ImageClient(Client):
39 55
    """Synnefo Plankton API client"""
40 56

  
......
80 96
        path = path4url('images', image_id)
81 97
        r = self.head(path, success=200)
82 98

  
83
        reply = {}
84
        properties = {}
85
        meta_prefix = 'x-image-meta-'
86
        property_prefix = 'x-image-meta-property-'
87

  
88
        for key, val in r.headers.items():
89
            key = key.lower()
90
            if key.startswith(property_prefix):
91
                key = key[len(property_prefix):]
92
                properties[key] = val
93
            elif key.startswith(meta_prefix):
94
                key = key[len(meta_prefix):]
95
                reply[key] = val
96

  
97
        if properties:
98
            reply['properties'] = properties
99
        return reply
99
        return _format_image_headers(r.headers)
100 100

  
101 101
    def register(self, name, location, params={}, properties={}):
102 102
        """Register an image that is uploaded at location
......
110 110

  
111 111
        :param properties: (dict) image properties (X-Image-Meta-Property)
112 112

  
113
        :returns: (dict) details of the created image
113
        :returns: (dict) metadata of the created image
114 114
        """
115 115
        path = path4url('images') + '/'
116 116
        self.set_header('X-Image-Meta-Name', name)
......
127 127
            async_headers['x-image-meta-property-%s' % key] = val
128 128

  
129 129
        r = self.post(path, success=200, async_headers=async_headers)
130
        return filter_in(r.headers, 'X-Image-')
130

  
131
        return _format_image_headers(r.headers)
131 132

  
132 133
    def unregister(self, image_id):
133 134
        """Unregister an image

Also available in: Unified diff