如何使用Resource Manager API在“无组织"下列出我的GCP项目? [英] How do I list my GCP projects under No Organization using the Resource Manager API?
本文介绍了如何使用Resource Manager API在“无组织"下列出我的GCP项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎找不到用于 Project List API方法,仅列出我有权访问但在无组织"下的项目.
I can't seem to find a proper filter for the Project List API method to list only the projects which I have access to but are under No Organization.
是否有针对此的过滤器?实现该目标的方法是什么?
Is there a filter for this? What would be the way to achieve this?.
推荐答案
根据文档,您应该可以使用过滤器来检查项目是否属于父级(组织).通过cli可以起作用:
According to the documentation you should be able to use filters to check whether a project belongs to a parent (organization). Through the cli this works:
gcloud projects list --filter="parent.id.yesno(yes='Yes', no='No')=No"
这也可以:
gcloud projects list --filter="parent.id:None"
那么python等效项将是:
The python equivalent would then be:
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('cloudresourcemanager', 'v1beta1', credentials=credentials)
filter = "parent.id:None"
projects = service.projects().list(filter=filter).execute()
这篇关于如何使用Resource Manager API在“无组织"下列出我的GCP项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文