【发布时间】:2020-09-10 09:30:48
【问题描述】:
我是谷歌云应用程序的新手,所以我想在 python 中使用 GCP SDK 时使用各种方法列出所有不同的服务列表。
我编写了以下代码来为计算服务创建一个客户端实例,以列出 Python3 项目中存在的所有防火墙。
from google.oauth2 import service_account
import googleapiclient.discovery
credentials = service_account.Credentials.from_service_account_file(filename='/path/to/cred/file.json')
client = googleapiclient.discovery.build(
'compute', 'v1', credentials=credentials)
def __test_firewall():
result = client.firewalls().list(project='project-id').execute()
return result['items'] if 'items' in result else None
此代码按我的意愿成功返回了项目中存在的所有防火墙。
我想要类似的东西,我可以用它来通过 SDK 列出 GCP 中的所有 Cloud Functions,我不想使用 CLI。我想不出办法,所以在这里发帖。
非常感谢任何帮助。 提前致谢。 ????
【问题讨论】:
标签: google-cloud-platform google-cloud-functions python-3.7