vmware-labs / marketplace-cli

A CLI for interacting with the VMware Marketplace
Other
11 stars 2 forks source link

When printing VM sizes, see if we can use the `ProductDeploymentFile.size` field #70

Closed petewall closed 2 years ago

petewall commented 2 years ago

When printing VMs (i.e. via mkpcli vm list), we print the size of the file. This is done in cmd/output/human_output.go:RenderFiles()

This is useful information, because it helps the user understand how long it would take to download, or if attaching the file was successful, etc...

Currently, we parse the ItemJson field, iterate over each file that's inside and sum the size fields. However, this was before I noticed that there is a size parameter parallel to the ItemJson field. If these values are the same, we should just use the size field and stop the complex parsing and summation.

Also, worth looking to see if there are size fields for container images and/or helm charts, too.

petewall commented 2 years ago

It's not always present. For example, this one has it:

$ ./build/mkpcli vm list --product veeam-backup-and-replication-version-111 --product-version 11 --output json | jq .
[
  {
    "id": "90e86c08-41a1-4376-8276-665023b63267",
    "name": "veeambackup&replication_11-1625253242382.iso",
    "url": "https://s3.us-west-2.amazonaws.com/cspmarketplacemainbuck/2d2fff99-3066-44e6-9c36-19296e79349b/veeambackup&replication_11-1625253242382.iso",
    "status": "ACTIVE",
    "uploadedon": 1625253631,
    "uploadedby": "dustin.albertson@veeam.com",
    "updatedon": 1625253879,
    "updatedby": "dustin.albertson@veeam.com",
    "itemjson": "{\n\t\"created\": \"2021-07-02T19:24Z\",\n\t\"description\": \"\",\n\t\"version\": \"2\",\n\t\"files\": [\n\t\t{\n\t\t\t\"name\": \"veeambackup%26replication_11-1625253242382.iso\",\n\t\t\t\"size\": 7215939584,\n\t\t\t\"etag\": \"37a2e8668fc3de40f1bf8f0cf0c4c079-108\",\n\t\t\t\"generationNum\": 1625253818,\n\t\t\t\"hrefs\": [\n\t\t\t\t\"veeambackup%26replication_11-1625253242382/veeambackup%26replication_11-1625253242382.iso\"\n\t\t\t]\n\t\t}\n\t],\n\t\"id\": \"urn:uuid:ba4bb3d2-984a-461d-bb6b-e45deefc44fb\",\n\t\"name\": \"veeambackup%26replication_11-1625253242382\",\n\t\"properties\": {},\n\t\"selfHref\": \"veeambackup%26replication_11-1625253242382/item.json\",\n\t\"type\": \"vcsp.iso\",\n\t\"contentVersion\": \"2\"\n}",
    "itemkey": "marketplace-product-files/veeambackup%26replication_11-1625253242382",
    "fileid": "fd939ab1-cce2-45aa-9040-b81bcedbfbab",
    "issubscribed": true,
    "appversion": "11",
    "hashdigest": "1b2fa3bff775049670a5f02d927b0f77262deb90",
    "hashalgo": "SHA1",
    "downloadcount": 59,
    "versionList": null,
    "size": 7215939584
  }
]

But this one does not:

$ ./build/mkpcli vm list --product nginxstack --product-version 1.21.3_1 -o json | jq .
[
  {
    "id": "5c3b578f-42be-4845-8b33-62ad4996dbdf",
    "name": "nginxstack",
    "url": "https://cspmarketplacemainbuck.s3.us-west-2.amazonaws.com/8b8499c6-703d-4b32-a49e-36d6fd47eb00/bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami.ova",
    "status": "ACTIVE",
    "uploadedon": 1631287208,
    "uploadedby": "bitnami-publishing",
    "updatedon": 1631287282,
    "updatedby": "bitnami-publishing",
    "itemjson": "{\n\t\"created\": \"2021-09-10T15:21Z\",\n\t\"description\": \"\",\n\t\"version\": \"2\",\n\t\"files\": [\n\t\t{\n\t\t\t\"name\": \"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami-disk1.vmdk\",\n\t\t\t\"size\": 1436431360,\n\t\t\t\"etag\": \"af0b4d7c5dd17d67cf3344266ed7acee-22\",\n\t\t\t\"generationNum\": 1631287273,\n\t\t\t\"hrefs\": [\n\t\t\t\t\"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami/bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami-disk1.vmdk\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"name\": \"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami.mf\",\n\t\t\t\"size\": 211,\n\t\t\t\"etag\": \"569c8f3a0f96d157bedfea61afb77d5d\",\n\t\t\t\"generationNum\": 1631287277,\n\t\t\t\"hrefs\": [\n\t\t\t\t\"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami/bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami.mf\"\n\t\t\t]\n\t\t},\n\t\t{\n\t\t\t\"name\": \"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami.ovf\",\n\t\t\t\"size\": 6706,\n\t\t\t\"etag\": \"7963df99bcd977417286dca14f4efe48\",\n\t\t\t\"generationNum\": 1631287277,\n\t\t\t\"hrefs\": [\n\t\t\t\t\"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami/bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami.ovf\"\n\t\t\t]\n\t\t}\n\t],\n\t\"id\": \"urn:uuid:dfb92e2b-c9ff-40e4-a65e-94142af5537a\",\n\t\"name\": \"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami\",\n\t\"properties\": {},\n\t\"selfHref\": \"bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami/item.json\",\n\t\"type\": \"vcsp.ovf\",\n\t\"contentVersion\": \"2\"\n}",
    "itemkey": "marketplace-product-files/bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami",
    "fileid": "c939dee7-83a8-4078-867b-49657139ab09",
    "issubscribed": true,
    "appversion": "1.21.3_1",
    "hashdigest": "0846d8db1fe8f8e5210eb2648d0cfbcbd3c0d455",
    "isthirdpartyurl": true,
    "thirdpartyurl": "https://downloads.bitnami.com/files/stacks/nginx/1.21.3-1/bitnami-nginx-1.21.3-1-linux-centos-7-x86_64-nami.ova",
    "hashalgo": "SHA1",
    "versionList": null
  }
]
petewall commented 2 years ago

This is working now.