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

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

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

    pretty_table = prettytable.PrettyTable(
        ("ID", "Last Accessed (UTC)", "Last Modified (UTC)", "Size", "Hits"))
    pretty_table.align['Size'] = "r"
    pretty_table.align['Hits'] = "r"

    for image in images:
        last_accessed = image['last_accessed']
        if last_accessed == 0:
            last_accessed = "N/A"
        else:
            last_accessed = datetime.datetime.utcfromtimestamp(
                last_accessed).isoformat()

        pretty_table.add_row((image['image_id'], last_accessed,
                              datetime.datetime.utcfromtimestamp(
                                  image['last_modified']).isoformat(),
                              image['size'], image['hits']))

    print(pretty_table.get_string())
    return SUCCESS
Beispiel #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"]))
Beispiel #3
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']))
Beispiel #4
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 = prettytable.PrettyTable(("ID",
                                            "Last Accessed (UTC)",
                                            "Last Modified (UTC)",
                                            "Size",
                                            "Hits"))
    pretty_table.align['Size'] = "r"
    pretty_table.align['Hits'] = "r"

    for image in images:
        last_accessed = image['last_accessed']
        if last_accessed == 0:
            last_accessed = "N/A"
        else:
            last_accessed = datetime.datetime.utcfromtimestamp(
                last_accessed).isoformat()

        pretty_table.add_row((
            image['image_id'],
            last_accessed,
            datetime.datetime.utcfromtimestamp(
                image['last_modified']).isoformat(),
            image['size'],
            image['hits']))

    print(pretty_table.get_string())