Revision eb3c549b
b/snf-cyclades-app/synnefo/api/images.py | ||
---|---|---|
103 | 103 |
'DELETE']) |
104 | 104 |
|
105 | 105 |
|
106 |
API_STATUS_FROM_IMAGE_STATUS = { |
|
107 |
"CREATING": "SAVING", |
|
108 |
"AVAILABLE": "ACTIVE", |
|
109 |
"ERROR": "ERROR", |
|
110 |
"DELETED": "DELETED"} |
|
111 |
|
|
112 |
|
|
106 | 113 |
def image_to_dict(image, detail=True): |
107 | 114 |
d = dict(id=image['id'], name=image['name']) |
108 | 115 |
if detail: |
109 | 116 |
d['updated'] = utils.isoformat(date_parse(image['updated_at'])) |
110 | 117 |
d['created'] = utils.isoformat(date_parse(image['created_at'])) |
111 |
d['status'] = 'DELETED' if image['deleted_at'] else 'ACTIVE' |
|
112 |
d['progress'] = 100 if image['status'] == 'available' else 0 |
|
118 |
img_status = image.get("status", "").upper() |
|
119 |
status = API_STATUS_FROM_IMAGE_STATUS.get(img_status, "UNKNOWN") |
|
120 |
d['status'] = status |
|
121 |
d['progress'] = 100 if status == 'ACTIVE' else 0 |
|
113 | 122 |
d['user_id'] = image['owner'] |
114 | 123 |
d['tenant_id'] = image['owner'] |
115 | 124 |
d['links'] = util.image_to_links(image["id"]) |
b/snf-cyclades-app/synnefo/plankton/backend.py | ||
---|---|---|
375 | 375 |
image_url = self._get_image_url(image_uuid) |
376 | 376 |
self._get_image(image_url) # Assert that it is an image |
377 | 377 |
|
378 |
self._update_meta(image_url, {"status": status}) |
|
378 |
self._update_meta(image_url, {"status": status.upper()})
|
|
379 | 379 |
image_url = self._get_image_url(image_uuid) |
380 | 380 |
return self._get_image(image_url) |
381 | 381 |
|
... | ... | |
428 | 428 |
# queries when retrieving the list of images. |
429 | 429 |
meta['created_at'] = time() |
430 | 430 |
# Update rest metadata |
431 |
meta.update(name=name, status='available', **metadata)
|
|
431 |
meta.update(name=name, status='AVAILABLE', **metadata)
|
|
432 | 432 |
|
433 | 433 |
# Do the actualy update in the Pithos backend |
434 | 434 |
self._update_meta(image_url, meta) |
... | ... | |
558 | 558 |
key = key.replace(PLANKTON_PREFIX, "") |
559 | 559 |
# Keep only those in plankton meta |
560 | 560 |
if key in PLANKTON_META: |
561 |
if key == "status": |
|
562 |
image["status"] = val.upper() |
|
561 | 563 |
if key != "created_at": |
562 | 564 |
# created timestamp is return in 'created_at' field |
563 | 565 |
image[key] = val |
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