Debian Codegraph @

glanceclient/v2/cache.py

raw symbols SCIP
1 # Copyright 2021 OpenStack Foundation
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
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