+def ptimestamp(t):
+ s = t.split(".")
+ if len(s) == 2:
+ t = s[0] + s[1][-1:]
+ return datetime.datetime.strptime(t, "%Y-%m-%dT%H:%M:%SZ")
+
+def list_images_in_arv():
+ existing_links = arvados.api('v1').links().list(filters=[['link_class', 'in', ['docker_image_hash', 'docker_image_repo+tag']]]).execute()['items']
+ images = {}
+ for link in existing_links:
+ collection_uuid = link["head_uuid"]
+ if collection_uuid not in images:
+ images[collection_uuid]= {"dockerhash": "<none>",
+ "repo":"<none>",
+ "tag":"<none>",
+ "timestamp": ptimestamp("1970-01-01T00:00:01Z")}
+
+ if link["link_class"] == "docker_image_hash":
+ images[collection_uuid]["dockerhash"] = link["name"]
+
+ if link["link_class"] == "docker_image_repo+tag":
+ r = link["name"].split(":")
+ images[collection_uuid]["repo"] = r[0]
+ if len(r) > 1:
+ images[collection_uuid]["tag"] = r[1]
+
+ if "image_timestamp" in link["properties"]:
+ images[collection_uuid]["timestamp"] = ptimestamp(link["properties"]["image_timestamp"])
+ else:
+ images[collection_uuid]["timestamp"] = ptimestamp(link["created_at"])
+
+ st = sorted(images.items(), lambda a, b: cmp(b[1]["timestamp"], a[1]["timestamp"]))
+
+ fmt = "{:30} {:10} {:12} {:38} {:20}"
+ print fmt.format("REPOSITORY", "TAG", "IMAGE ID", "KEEP LOCATOR", "CREATED")
+ for i, j in st:
+ print(fmt.format(j["repo"], j["tag"], j["dockerhash"][0:11], i, j["timestamp"].strftime("%c")))
+