列出给定项目和区域中所有已计划的快照的程序化方法(使用golang)。

huangapple go评论80阅读模式
英文:

List all the scheduled snapshots in a given project and region programmatically (golang)

问题

我正在尝试使用Golang客户端以编程方式列出给定项目和区域中的所有计划快照策略,并对它们进行描述。

我可以使用gcloud命令获取它们,但想知道如何以编程方式实现相同的功能(最好使用Compute Golang客户端)。

gcloud compute resource-policies list --project myproject
gcloud compute resource-policies describe my-snapshot-policy --project myproject --region myregion

提前感谢。

英文:

I am trying to use a golang client to programmatically list all the scheduled snapshot policies in a given project and region and describe them.

I am able to fetch them using gcloud commands, but wondering how I can do the same programmatically (preferably compute golang client)?

gcloud  compute resource-policies list  --project myproject
gcloud  compute resource-policies describe my-snapshot-policy  --project myproject --region myregion

thanks in advance.

答案1

得分: 1

根据 @john-hanley 的建议,鼓励你在问题中展示自己解决问题的尝试。

Google为其所有服务提供SDK。有两种类型,可能会让人感到困惑。你可以在任何Google服务中找到的原始样式称为API客户端库。对于Google Cloud Platform,许多服务也有云客户端库。请参阅Google 客户端库解释

对于Golang的Compute,有一个新的云客户端库

你可以在这里看到它的使用示例。我鼓励你遵循Google的风格,包括使用应用程序默认凭据。

你将需要使用ResourcePoliciesClient和客户端的GetList方法。

英文:

Per @john-hanley, you are encouraged to demonstrate your own attempt to solve the problem in your question.

Google provides SDKs for all of its services. There are 2 flavors and this can be confusing. The original style which you can find for any Google service are called API Client Libraries. For Google Cloud Platform many (!) of the services also (!) have Cloud Client Libraries. See Google Client Libraries Explained.

For Compute for Golang, there's a new Cloud Client Library.

You can see examples of its use here. I encourage you to follow Google's style including by using Application Default Credentials.

You will want to use a ResourcePoliciesClient and the client's Get and List methods.

huangapple
  • 本文由 发表于 2022年3月14日 09:32:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/71462203.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定