Merge pull request #1064 from swordqiu/feature/qj-aliyun-billing-report-support

feature: api support aliyun billing report export to OSS
This commit is contained in:
yunion-ci-robot
2019-06-05 11:28:49 +08:00
committed by GitHub
2 changed files with 27 additions and 0 deletions
+15
View File
@@ -19,6 +19,7 @@ import (
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
)
func (self *SAliyunClient) businessRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
@@ -110,3 +111,17 @@ func (self *SAliyunClient) QueryPrepaidCards() ([]SPrepaidCard, error) {
}
return cards, nil
}
func (self *SAliyunClient) SubscribeBillToOSS(bucket string) error {
params := make(map[string]string)
params["SubscribeBucket"] = bucket
params["SubscribeType.0"] = "BillingItemDetailForBillingPeriod"
params["SubscribeType.1"] = "InstanceDetailForBillingPeriod"
body, err := self.businessRequest("SubscribeBillToOSS", params)
if err != nil {
log.Errorf("SubscribeBillToOSS fail %s", err)
return errors.Wrap(err, "SubscribeBillToOSS")
}
log.Debugf("%s", body)
return nil
}
+12
View File
@@ -42,4 +42,16 @@ func init() {
printList(result3, len(result3), 0, 0, nil)
return nil
})
type AliyunSubscribeBillOptions struct {
BUCKET string `help:"bucket name to store billing records"`
}
shellutils.R(&AliyunSubscribeBillOptions{}, "subscribe-bill", "Subscribe bill to OSS storage", func(cli *aliyun.SRegion, args *AliyunSubscribeBillOptions) error {
err := cli.GetClient().SubscribeBillToOSS(args.BUCKET)
if err != nil {
return err
}
return nil
})
}