| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
from glanceclient.common import utils |
| 17 |
from glanceclient import exc |
| 18 |
|
| 19 |
TARGET_VALUES = ('both', 'cache', 'queue') |
| 20 |
|
| 21 |
|
| 22 |
class Controller(object): |
| 23 |
def __init__(self, http_client): |
| 24 |
self.http_client = http_client |
| 25 |
|
| 26 |
def is_supported(self, version): |
| 27 |
if utils.has_version(self.http_client, version): |
| 28 |
return True |
| 29 |
else: |
| 30 |
raise exc.HTTPNotImplemented( |
| 31 |
'Glance does not support image caching API (v2.14)') |
| 32 |
|
| 33 |
@utils.add_req_id_to_object() |
| 34 |
def list(self): |
| 35 |
if self.is_supported('v2.14'): |
| 36 |
url = '/v2/cache' |
| 37 |
resp, body = self.http_client.get(url) |
| 38 |
return body, resp |
| 39 |
|
| 40 |
@utils.add_req_id_to_object() |
| 41 |
def delete(self, image_id): |
| 42 |
if self.is_supported('v2.14'): |
| 43 |
resp, body = self.http_client.delete('/v2/cache/%s' % |
| 44 |
image_id) |
| 45 |
return body, resp |
| 46 |
|
| 47 |
@utils.add_req_id_to_object() |
| 48 |
def clear(self, target): |
| 49 |
if self.is_supported('v2.14'): |
| 50 |
url = '/v2/cache' |
| 51 |
headers = {} |
| 52 |
if target != "both": |
| 53 |
headers = {'x-image-cache-clear-target': target} |
| 54 |
resp, body = self.http_client.delete(url, headers=headers) |
| 55 |
return body, resp |
| 56 |
|
| 57 |
@utils.add_req_id_to_object() |
| 58 |
def queue(self, image_id): |
| 59 |
if self.is_supported('v2.14'): |
| 60 |
url = '/v2/cache/%s' % image_id |
| 61 |
resp, body = self.http_client.put(url) |
| 62 |
return body, resp |