Exemple #1
0
def list_cached(options, args):
    """%(prog)s list-cached [options]

List all images currently cached.
    """
    client = get_client(options)
    images = client.get_cached_images()
    if not images:
        print("No cached images.")
        return SUCCESS

    print("Found %d cached images..." % len(images))

    pretty_table = utils.PrettyTable()
    pretty_table.add_column(36, label="ID")
    pretty_table.add_column(19, label="Last Accessed (UTC)")
    pretty_table.add_column(19, label="Last Modified (UTC)")
    # 1 TB takes 13 characters to display: len(str(2**40)) == 13
    pretty_table.add_column(14, label="Size", just="r")
    pretty_table.add_column(10, label="Hits", just="r")

    print(pretty_table.make_header())

    for image in images:
        last_modified = image["last_modified"]
        last_modified = timeutils.iso8601_from_timestamp(last_modified)

        last_accessed = image["last_accessed"]
        if last_accessed == 0:
            last_accessed = "N/A"
        else:
            last_accessed = timeutils.iso8601_from_timestamp(last_accessed)

        print(pretty_table.make_row(image["image_id"], last_accessed, last_modified, image["size"], image["hits"]))
Exemple #2
0
def list_cached(options, args):
    """%(prog)s list-cached [options]

List all images currently cached.
    """
    client = get_client(options)
    images = client.get_cached_images()
    if not images:
        print("No cached images.")
        return SUCCESS

    print("Found %d cached images..." % len(images))

    pretty_table = utils.PrettyTable()
    pretty_table.add_column(36, label="ID")
    pretty_table.add_column(19, label="Last Accessed (UTC)")
    pretty_table.add_column(19, label="Last Modified (UTC)")
    # 1 TB takes 13 characters to display: len(str(2**40)) == 13
    pretty_table.add_column(14, label="Size", just="r")
    pretty_table.add_column(10, label="Hits", just="r")

    print(pretty_table.make_header())

    for image in images:
        last_modified = image['last_modified']
        last_modified = timeutils.iso8601_from_timestamp(last_modified)

        last_accessed = image['last_accessed']
        if last_accessed == 0:
            last_accessed = "N/A"
        else:
            last_accessed = timeutils.iso8601_from_timestamp(last_accessed)

        print(pretty_table.make_row(
            image['image_id'],
            last_accessed,
            last_modified,
            image['size'],
            image['hits']))
 def test_iso8601_from_timestamp(self):
     utcnow = timeutils.utcnow()
     iso = timeutils.isotime(utcnow)
     ts = calendar.timegm(utcnow.timetuple())
     self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))
 def test_iso8601_from_timestamp(self):
     utcnow = timeutils.utcnow()
     iso = timeutils.isotime(utcnow)
     ts = calendar.timegm(utcnow.timetuple())
     self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))