我正在使用
Package Version
------------------------ ---------
google-api-core 2.0.1
google-auth 2.0.2
google-cloud-compute 0.5.0
google-compute-engine 2.8.13检索google云实例数据。我指的是docs来获取实例的聚合列表。我无法根据计算VM实例的标签来过滤实例。有没有一种使用python的特殊方法,因为documentation中没有特别提到它。?
发布于 2021-09-02 16:16:26
请包括您的代码。
您应该能够将Filter应用于AggregatedListInstancesRequest,并且应该能够指定标签,请参见Filtering searches using labels。我很有信心(!?)API是一致的。
发布于 2022-02-18 06:32:19
查询引用filter查询参数。我没能让它和tags一起工作。但您仍然可以列出所有实例并直接对其进行过滤。
在下面的示例中,我正在寻找gke-nginx-1-cluster-846d7440-node标记。
from googleapiclient import discovery
from google.oauth2 import service_account
scopes = ['https://www.googleapis.com/auth/compute']
sa_file = 'alon-lavian-0474ca3b9309.json'
credentials = service_account.Credentials.from_service_account_file(sa_file, scopes=scopes)
service = discovery.build('compute', 'v1', credentials=credentials)
project = 'alon-lavian'
zone = 'us-central1-a'
request = service.instances().list(project=project, zone=zone)
while request is not None:
response = request.execute()
for instance in response['items']:
if 'gke-nginx-1-cluster-846d7440-node' in instance['tags']['items']:
print(instance)
request = service.instances().list_next(previous_request=request, previous_response=response)https://stackoverflow.com/questions/69032707
复制相似问题