Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 如何获取图像族中未使用图像的列表_Google Cloud Platform - Fatal编程技术网

Google cloud platform 如何获取图像族中未使用图像的列表

Google cloud platform 如何获取图像族中未使用图像的列表,google-cloud-platform,Google Cloud Platform,我在下面的文档中创建应用程序GCE图像。我正在设置要从中拾取最新图像的图像族。然而,我正在努力获得旧图像的排序列表以进行清理 gcloud compute images describe-from-family test-packerized-centos7-base 返回最新图像 { "archiveSizeBytes": "883668032", "creationTimestamp": "2018-04-25T23:25:36.137-07:00", "descr

我在下面的文档中创建应用程序GCE图像。我正在设置要从中拾取最新图像的图像族。然而,我正在努力获得旧图像的排序列表以进行清理

gcloud compute images describe-from-family test-packerized-centos7-base
返回最新图像

{
    "archiveSizeBytes": "883668032",
    "creationTimestamp": "2018-04-25T23:25:36.137-07:00",
    "description": "Created by Packer",
    "diskSizeGb": "20",
    "family": "test-packerized-centos7-base",
    "id": "6938962862287932976",
    "kind": "compute#image",
    "labelFingerprint": "42WmSpB8rSM=",
    "licenseCodes": [
    "1000207"
     ],
   "name": "wp-centos7-base-bbaelish-shenanigans-3-1524723518",
   "selfLink": "https://www.googleapis.com/compute/v1/projects/my_project/global/images/wp-centos7-base-bbaelish-shenanigans-3-1524723518",
   "sourceDisk": "https://www.googleapis.com/compute/v1/projects/my_project/zones/us-central1-a/disks/packer-5ae16f3e-13c6-0d93-da79-2f6e81f88fec",
  "sourceDiskId": "5923696438202388910",
  "sourceType": "RAW",
  "status": "READY"
}
但是,当我列出项目中的所有图像和带有姓氏的grep时,我可以看到所有旧图像仍然处于就绪状态

gcloud compute images list | grep test-packerized-centos7-base
wp-centos7-base-bbaelish-shenanigans-1-1523048775 test-packerized-centos7-base READY
wp-centos7-base-bbaelish-shenanigans-1-1523050176 test-packerized-centos7-base READY
wp-centos7-base-bbaelish-shenanigans-2-1524258996 test-packerized- centos7-base READY
wp-centos7-base-bbaelish-shenanigans-2-1524259307 test-packerized-centos7-base READY
我知道我必须反对旧图像,但是我正在努力获得旧图像的排序列表。我想被标记为不推荐的最后5个图像和最后3个图像后,这是过时的

我尝试使用过滤器来获得排序列表

gcloud compute images list --format json | jq '.[] | select(.family == "test-packerized-centos7-base") | sort_by(.creationTimestamp)'
但是,它返回以下错误

jq: error (at <stdin>:4622): Cannot index string with string "creationTimestamp"
jq:error(at:4622):无法为字符串“creationTimestamp”的字符串编制索引
任何人都知道在“图像族”中获取旧图像列表的简单方法。
我假设谷歌在某处维护着这个顺序,因为当我删除家族中最新的图像时,它会自动指向较旧的图像。

如果你想对图像列表进行排序,你必须运行
gcloud images list
命令,并应用该命令按日期对图像进行排序

您必须运行的命令是:

$ gcloud compute images list --format="value(NAME)" --filter="[sorting-filter]" 
其中,
[sorting filter]
将是一个按创建日期对图像进行排序的过滤器


有关如何编写过滤器以及如何使用过滤器的帮助,您可以参考本指南。基本上,你只需要找到合适的过滤器。因为它是一个特定的过滤器,并且这个问题对于您的用例来说是唯一的,所以您必须通读文档

我希望这能回答你的问题。当您试图根据“创建时间”获取图像列表时,您可以使用下面的命令

gcloud compute images list --format="table(name,creationTimestamp.date(tz=LOCAL))"
但如果您试图根据名称对其进行进一步排序,则可以使用grep