Revision eb3c549b snf-cyclades-app/synnefo/plankton/views.py

b/snf-cyclades-app/synnefo/plankton/views.py
62 62

  
63 63
DETAIL_FIELDS = ('name', 'disk_format', 'container_format', 'size', 'checksum',
64 64
                 'location', 'created_at', 'updated_at', 'deleted_at',
65
                 'status', 'is_public', 'owner', 'properties', 'id', "is_snapshot")
65
                 'status', 'is_public', 'owner', 'properties', 'id',
66
                 "is_snapshot")
66 67

  
67 68
ADD_FIELDS = ('name', 'id', 'store', 'disk_format', 'container_format', 'size',
68 69
              'checksum', 'is_public', 'owner', 'properties', 'location')
......
74 75
log = getLogger('synnefo.plankton')
75 76

  
76 77

  
78
API_STATUS_FROM_IMAGE_STATUS = {
79
    "CREATING": "SAVING",
80
    "AVAILABLE": "ACTIVE",
81
    "DELETED": "DELETED"}
82

  
83

  
77 84
def _create_image_response(image):
78 85
    response = HttpResponse()
86

  
79 87
    def normalize(s):
80 88
        return ''.join('_' if c in punctuation else c.lower() for c in s)\
81
                .replace("\n", "_")
89
                 .replace("\n", "_")
82 90

  
83 91
    for key in DETAIL_FIELDS:
84 92
        if key == 'properties':
......
86 94
                name = 'x-image-meta-property-' + k.replace('_', '-')
87 95
                response[name] = normalize(str(v))
88 96
        else:
89
            name = 'x-image-meta-' + key.replace('_', '-')
90
            response[name] = normalize(str(image.get(key, '')))
97
            if key == "status":
98
                img_status = image.get(key, "").upper()
99
                status = API_STATUS_FROM_IMAGE_STATUS.get(img_status,
100
                                                          "UNKNOWN")
101
                response["x-image-meta-status"] = status
102
            else:
103
                name = 'x-image-meta-' + key.replace('_', '-')
104
                response[name] = normalize(str(image.get(key, '')))
91 105

  
92 106
    return response
93 107

  

Also available in: Unified diff