summaryrefslogtreecommitdiff
path: root/glanceclient/common
diff options
context:
space:
mode:
authorErno Kuvaja <jokke@usr.fi>2021-07-09 10:41:22 +0100
committerAbhishek Kekane <akekane@redhat.com>2022-02-22 16:39:33 +0000
commit62f4f67d1d3f1ad74418d1e8cd5bb946cc8425d9 (patch)
tree64a005802f6e5b7f85fe3bbe1679069e2da592b5 /glanceclient/common
parent63bb03a145a7003a7e9ba40dd325995986fa953a (diff)
downloadpython-glanceclient-62f4f67d1d3f1ad74418d1e8cd5bb946cc8425d9.tar.gz
Add support for Cache API
This change provides support for the Cache API changes and deprecation path for glance-cache-manage command. Change-Id: I6fca9bbe6bc0bd9b14d8dba685405838131160af
Diffstat (limited to 'glanceclient/common')
-rw-r--r--glanceclient/common/utils.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index 1691264..fd0243c 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import datetime
import errno
import functools
import hashlib
@@ -175,13 +176,54 @@ def pretty_choice_list(l):
def has_version(client, version):
versions = client.get('/versions')[1].get('versions')
- supported = ['SUPPORTED', 'CURRENT']
+ supported = ['SUPPORTED', 'CURRENT', 'EXPERIMENTAL']
for version_struct in versions:
if version_struct['id'] == version:
return version_struct['status'] in supported
return False
+def print_cached_images(cached_images):
+ cache_pt = prettytable.PrettyTable(("ID",
+ "State",
+ "Last Accessed (UTC)",
+ "Last Modified (UTC)",
+ "Size",
+ "Hits"))
+ for item in cached_images:
+ state = "queued"
+ last_accessed = "N/A"
+ last_modified = "N/A"
+ size = "N/A"
+ hits = "N/A"
+ if item == 'cached_images':
+ state = "cached"
+ for image in cached_images[item]:
+ last_accessed = image['last_accessed']
+ if last_accessed == 0:
+ last_accessed = "N/A"
+ else:
+ last_accessed = datetime.datetime.utcfromtimestamp(
+ last_accessed).isoformat()
+
+ cache_pt.add_row((image['image_id'], state,
+ last_accessed,
+ datetime.datetime.utcfromtimestamp(
+ image['last_modified']).isoformat(),
+ image['size'],
+ image['hits']))
+ else:
+ for image in cached_images[item]:
+ cache_pt.add_row((image,
+ state,
+ last_accessed,
+ last_modified,
+ size,
+ hits))
+
+ print(cache_pt.get_string())
+
+
def print_dict_list(objects, fields):
pt = prettytable.PrettyTable([f for f in fields], caching=False)
pt.align = 'l'