获取资源SKU以查找GCP (go)中的资源价格



我正试图找出一种方法,当给定一个资源来确定它的SKU,所以我可以查找它的定价信息。

package main
import (
"context"
billingpb "google.golang.org/genproto/googleapis/cloud/billing/v1"
billing "cloud.google.com/go/billing/apiv1"
)
func main() {

ctx := context.Background()
client, err := billing.NewCloudCatalogClient(ctx)
if err != nil {
return nil, err
}
req := billingpb.ListSkusRequest{
Parent: "services/<SKU>",
}
result := client.ListSkus(ctx, &req)
// ... handle result

}

例如,如果我们检查一个compute.Disk,没有任何关于它的SKU的信息,只有它的类型(pd-ssd,pd-standard)。

computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"

computepb.Disk{
CreationTimestamp:           nil,
Description:                 nil,
DiskEncryptionKey:           nil,
GuestOsFeatures:             nil,
Id:                          nil,
Kind:                        nil,
LabelFingerprint:            nil,
Labels:                      nil,
LastAttachTimestamp:         nil,
LastDetachTimestamp:         nil,
LicenseCodes:                nil,
Licenses:                    nil,
LocationHint:                nil,
Name:                        nil,
Options:                     nil,
PhysicalBlockSizeBytes:      nil,
ProvisionedIops:             nil,
Region:                      nil,
ReplicaZones:                nil,
ResourcePolicies:            nil,
SatisfiesPzs:                nil,
SelfLink:                    nil,
SizeGb:                      nil,
SourceDisk:                  nil,
SourceDiskId:                nil,
SourceImage:                 nil,
SourceImageEncryptionKey:    nil,
SourceImageId:               nil,
SourceSnapshot:              nil,
SourceSnapshotEncryptionKey: nil,
SourceSnapshotId:            nil,
SourceStorageObject:         nil,
Status:                      nil,
Type:                        nil,
Users:                       nil,
Zone:                        nil,
}

result := client.ListSkus(ctx, &req)

result将是*SkuInterator

type SkuIterator struct {
items    []*billingpb.Sku
pageInfo *iterator.PageInfo
nextFunc func() error
Response interface{}
InternalFetch func(pageSize int, pageToken string) (results []*billingpb.Sku, nextPageToken string, err error)
}

,SkuIterator。响应的类型为ListSkusResponse

type ListSkusResponse struct {
state         protoimpl.MessageState
sizeCache     protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Skus []*Sku `protobuf:"bytes,1,rep,name=skus,proto3" json:"skus,omitempty"`

NextPageToken string `protobuf:"bytes,2,opt,name=next_page_token,json=nextPageToken,proto3" json:"next_page_token,omitempty"`
}

包含字段Skus,这是Sku

的数组
type Sku struct {
state         protoimpl.MessageState
sizeCache     protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
SkuId string `protobuf:"bytes,2,opt,name=sku_id,json=skuId,proto3" json:"sku_id,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
Category *Category `protobuf:"bytes,4,opt,name=category,proto3" json:"category,omitempty"`
https://cloud.google.com/about/locations/

ServiceRegions []string `protobuf:"bytes,5,rep,name=service_regions,json=serviceRegions,proto3" json:"service_regions,omitempty"`
PricingInfo []*PricingInfo `protobuf:"bytes,6,rep,name=pricing_info,json=pricingInfo,proto3" json:"pricing_info,omitempty"`
ServiceProviderName string `protobuf:"bytes,7,opt,name=service_provider_name,json=serviceProviderName,proto3" json:"service_provider_name,omitempty"`
}

Sku。PricingInfo是PricingInfo

的数组。
type PricingInfo struct {
state         protoimpl.MessageState
sizeCache     protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
EffectiveTime *timestamppb.Timestamp `protobuf:"bytes,1,opt,name=effective_time,json=effectiveTime,proto3" json:"effective_time,omitempty"`
Summary string `protobuf:"bytes,2,opt,name=summary,proto3" json:"summary,omitempty"`
PricingExpression *PricingExpression `protobuf:"bytes,3,opt,name=pricing_expression,json=pricingExpression,proto3" json:"pricing_expression,omitempty"`
AggregationInfo *AggregationInfo `protobuf:"bytes,4,opt,name=aggregation_info,json=aggregationInfo,proto3" json:"aggregation_info,omitempty"`
CurrencyConversionRate float64 `protobuf:"fixed64,5,opt,name=currency_conversion_rate,json=currencyConversionRate,proto3" json:"currency_conversion_rate,omitempty"`
}

可以提供你想要的信息。

相关内容

  • 没有找到相关文章

最新更新