嗨我正在嘗試列表計算實例在特定的網絡和子網絡中,似乎無法獲得過濾權限。例如,我有一個名爲「prod-net」的網絡,其子網名爲「app-central」。當我運行搜索,我只是「列出0項」。子網中的列表實例
~ gcloud compute instances list --filter='network:prod-net'
Listed 0 items.
有什麼建議嗎?
嗨我正在嘗試列表計算實例在特定的網絡和子網絡中,似乎無法獲得過濾權限。例如,我有一個名爲「prod-net」的網絡,其子網名爲「app-central」。當我運行搜索,我只是「列出0項」。子網中的列表實例
~ gcloud compute instances list --filter='network:prod-net'
Listed 0 items.
有什麼建議嗎?
--filter
標誌不對錶數據進行操作,而是對底層的豐富資源對象進行操作。要查看此對象,請運行gcloud compute instances list --format=json
。
你在找什麼在這種情況下是:
$ gcloud compute instances list --filter='networkInterfaces.network=prod-net'
(我切換到:
因爲=
前者意味着「包含」,後者指的是精確匹配見gcloud topic filters
更多)。
我需要做'gcloud計算實例列表--filter ='networkInterfaces [0] .network = prod-net 「讓它工作。 –
有趣的是,我剛剛證實我的原始答案仍然有效。你在最新版本的gcloud(138.0.0)? –
啊,你說得對。在我的Ubuntu VM上,'apt'告訴我「google-cloud-sdk已經是最新版本(111.0.0-0ubuntu1〜16.04.0)」。在GCE Web控制檯上使用Google Cloud Shell時,我在版本138上,您的命令正常工作。謝謝! –
你確實可以通過子網使用gcloud
過濾GCE實例。
您需要篩選networkInterfaces.subnetwork
以及與之比較的文字值是完整的子網資源url,而不僅僅是子網名。
gcloud compute networks subnets list <YOUR_SUBNET_NAME> --format=flattened
舉例::
「資源URL」 爲您的子網獲得人
$ gcloud compute networks subnets list sg-zk-1 --project my-gcp-project --format=flattened
---
creationTimestamp: 2017-04-20T02:22:17.853-07:00
gatewayAddress: 10.9.19.33
id: 6783412628763296550
ipCidrRange: 10.9.19.32/28
kind: compute#subnetwork
name: sg-zk-1
network: valkyrie
privateIpGoogleAccess: True
region: asia-southeast1
selfLink: https://www.googleapis.com/compute/v1/projects/my-gcp-project/regions/asia-southeast1/subnetworks/sg-zk-1
在上述例子中,子網-name是sg-zk-1
。
該子網的相應資源URL是selfLink
的值,即https://www.googleapis.com/compute/v1/projects/my-gcp-project/regions/asia-southeast1/subnetworks/sg-zk-1
。
現在,我有我subnet_url
可以過濾屬於它的實例:
$ subnet_url="https://www.googleapis.com/compute/v1/projects/my-gcp-project/regions/asia-southeast1/subnetworks/sg-zk-1"
$ gcloud compute instances list --filter="networkInterfaces.subnetwork=${subnet_url}"
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
sg-zookeeper-4 asia-southeast1-b n1-standard-2 10.9.19.37 RUNNING
sg-zookeeper-5 asia-southeast1-b n1-standard-2 10.9.19.38 RUNNING
sg-zookeeper-1 asia-southeast1-a n1-standard-2 10.9.19.34 RUNNING
sg-zookeeper-2 asia-southeast1-a n1-standard-2 10.9.19.35 RUNNING
sg-zookeeper-3 asia-southeast1-a n1-standard-2 10.9.19.36 RUNNING
似乎無法通過網絡進行過濾,因爲當你不應用過濾器沒有網絡列。例如,您可以使用--filter = ZONE〜us來過濾美國區域中的實例。作爲@Dagang提到的 – Dagang
, - 過濾器標誌考慮列出的列。但是,我建議在此公共問題跟蹤器[1]中提交功能請求,以便在將來的版本中提供此功能。 [1]:https://code.google.com/p/google-compute-engine/issues/list – George