I have a large number of projects in my organization that I want to shift the billing account for. The Ruby API has Google::Apis::CloudbillingV1::ProjectBillingInfo which contains an update! method that should let me do this.
我的组织中有大量项目要转移结算帐户。 Ruby API包含Google :: Apis :: CloudbillingV1 :: ProjectBillingInfo,其中包含更新!应该让我这样做的方法。
I'm missing a step though. My code looks like this:
我错过了一步。我的代码如下所示:
require 'googleauth'
require 'google/apis/cloudbilling_v1'
service = Google::Apis::CloudbillingV1::CloudbillingService.new
service.authorization = Google::Auth.get_application_default(['https://www.googleapis.com/auth/cloud-platform'])
FROM_BA = 'billingAccounts/123456'
TO_BA = 'billingAccounts/789012'
puts "Changing billing account on projects:"
service.list_billing_account_projects(FROM_BA).project_billing_info.each do |p|
puts "\t#{p.name} (#{p.project_id}): #{p.billing_account_name} --> #{TO_BA}"
p.update!(billing_account_name: TO_BA)
end
The loop does find and list all the projects in the FROM_BA
billing account. And I know update!
is being called. But the changes aren't persisted to the projects in the account. I suspect I'm missing a step here. A commit call? I can't seem to find any examples and the docs aren't helpful here.
循环确实找到并列出FROM_BA结算帐户中的所有项目。而且我知道更新!正在被召集。但是这些更改并未持久保存到帐户中的项目中。我怀疑我在这里错过了一步。提交电话?我似乎无法找到任何示例,文档在这里没有帮助。
Anyone know how to persist the update!
changes upstream to the actual projects in the account?
任何人都知道如何坚持更新!上游更改为帐户中的实际项目?
1 个解决方案
#1
0
You use the update_project_billing_info method on the CloudBillingService
instance to commit the changes to the ProjectBillingInfo
object.
您可以使用CloudBillingService实例上的update_project_billing_info方法将更改提交到ProjectBillingInfo对象。
The full snippet, that works, now looks like this:
完整的代码片段现在看起来像这样:
require 'googleauth'
require 'google/apis/cloudbilling_v1'
service = Google::Apis::CloudbillingV1::CloudbillingService.new
service.authorization = Google::Auth.get_application_default(['https://www.googleapis.com/auth/cloud-platform'])
FROM_BA = 'billingAccounts/123456'
TO_BA = 'billingAccounts/789012'
puts "Changing billing account on projects:"
service.list_billing_account_projects(FROM_BA).project_billing_info.each do |p|
project = p.name.split('/')[0..1].join('/')
puts "\t#{project} (#{p.project_id}): #{p.billing_account_name} --> #{TO_BA}"
p.update!(billing_account_name: TO_BA)
service.update_project_billing_info(project, p)
end
I see the billing info changes propagated to the web UI now.
我现在看到结算信息更改传播到Web UI。