diff --git a/cmd/climc/shell/cloudaccounts.go b/cmd/climc/shell/cloudaccounts.go index 38ef4d53f0..fb378a1902 100644 --- a/cmd/climc/shell/cloudaccounts.go +++ b/cmd/climc/shell/cloudaccounts.go @@ -88,6 +88,16 @@ func init() { R(&options.SAliyunCloudAccountCreateOptions{}, "cloud-account-create-aliyun", "Create an Aliyun cloud account", func(s *mcclient.ClientSession, args *options.SAliyunCloudAccountCreateOptions) error { params := jsonutils.Marshal(args) params.(*jsonutils.JSONDict).Add(jsonutils.NewString("Aliyun"), "provider") + options := jsonutils.NewDict() + if len(args.OptionsBillingReportBucket) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingReportBucket), "billing_report_bucket") + } + if len(args.OptionsBillingBucketAccount) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingBucketAccount), "billing_bucket_account") + } + if options.Size() > 0 { + params.(*jsonutils.JSONDict).Add(options, "options") + } result, err := modules.Cloudaccounts.Create(s, params) if err != nil { return err @@ -147,6 +157,12 @@ func init() { if len(args.OptionsBillingReportBucket) > 0 { options.Add(jsonutils.NewString(args.OptionsBillingReportBucket), "billing_report_bucket") } + if len(args.OptionsBillingBucketAccount) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingBucketAccount), "billing_bucket_account") + } + if len(args.OptionsBillingFileAccount) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingFileAccount), "billing_file_account") + } if options.Size() > 0 { params.Add(options, "options") } @@ -280,6 +296,28 @@ func init() { if params.Size() == 0 { return InvalidUpdateError() } + + options := jsonutils.NewDict() + if len(args.OptionsBillingReportBucket) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingReportBucket), "billing_report_bucket") + } + if len(args.OptionsBillingBucketAccount) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingBucketAccount), "billing_bucket_account") + } + if options.Size() > 0 { + params.Add(options, "options") + } + removeOptions := make([]string, 0) + if args.RemoveOptionsBillingReportBucket { + removeOptions = append(removeOptions, "billing_report_bucket") + } + if args.RemoveOptionsBillingBucketAccount { + removeOptions = append(removeOptions, "billing_bucket_account") + } + if len(removeOptions) > 0 { + params.Add(jsonutils.NewStringArray(removeOptions), "remove_options") + } + result, err := modules.Cloudaccounts.Update(s, args.ID, params) if err != nil { return err @@ -337,6 +375,12 @@ func init() { if len(args.OptionsBillingReportBucket) > 0 { options.Add(jsonutils.NewString(args.OptionsBillingReportBucket), "billing_report_bucket") } + if len(args.OptionsBillingBucketAccount) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingBucketAccount), "billing_bucket_account") + } + if len(args.OptionsBillingFileAccount) > 0 { + options.Add(jsonutils.NewString(args.OptionsBillingFileAccount), "billing_file_account") + } if options.Size() > 0 { params.Add(options, "options") } @@ -344,6 +388,12 @@ func init() { if args.RemoveOptionsBillingReportBucket { removeOptions = append(removeOptions, "billing_report_bucket") } + if args.RemoveOptionsBillingBucketAccount { + removeOptions = append(removeOptions, "billing_bucket_account") + } + if args.RemoveOptionsBillingFileAccount { + removeOptions = append(removeOptions, "billing_file_account") + } if len(removeOptions) > 0 { params.Add(jsonutils.NewStringArray(removeOptions), "remove_options") } diff --git a/pkg/mcclient/options/cloudaccounts.go b/pkg/mcclient/options/cloudaccounts.go index e7a028758b..bb7af5a9cc 100644 --- a/pkg/mcclient/options/cloudaccounts.go +++ b/pkg/mcclient/options/cloudaccounts.go @@ -93,6 +93,9 @@ type SVMwareCloudAccountCreateOptions struct { type SAliyunCloudAccountCreateOptions struct { SCloudAccountCreateBaseOptions SAccessKeyCredential + + OptionsBillingReportBucket string `help:"bucket that stores billing report" json:"-"` + OptionsBillingBucketAccount string `help:"id of account that can access bucket, blank if this account can access" json:"-"` } type SAzureCloudAccountCreateOptions struct { @@ -114,7 +117,9 @@ type SAWSCloudAccountCreateOptions struct { SCloudAccountCreateBaseOptions SAccessKeyCredentialWithEnvironment - OptionsBillingReportBucket string `help:"bucket that stores billing report" json:"-"` + OptionsBillingReportBucket string `help:"bucket that stores billing report" json:"-"` + OptionsBillingBucketAccount string `help:"id of account that can access bucket, blank if this account can access" json:"-"` + OptionsBillingFileAccount string `help:"account number, prefix of billing file name, blank if this account number is prefix" json:"-"` } type SOpenStackCloudAccountCreateOptions struct { @@ -228,6 +233,11 @@ type SVMwareCloudAccountUpdateOptions struct { type SAliyunCloudAccountUpdateOptions struct { SCloudAccountUpdateBaseOptions + + OptionsBillingReportBucket string `help:"update Aliyun S3 bucket that stores account billing report" json:"-"` + RemoveOptionsBillingReportBucket bool `help:"remove Aliyun S3 bucket that stores account billing report" json:"-"` + OptionsBillingBucketAccount string `help:"update id of account that can access bucket, blank if this account can access" json:"-"` + RemoveOptionsBillingBucketAccount bool `help:"remove id of account that can access bucket, blank if this account can access" json:"-"` } type SAzureCloudAccountUpdateOptions struct { @@ -244,8 +254,12 @@ type SQcloudCloudAccountUpdateOptions struct { type SAWSCloudAccountUpdateOptions struct { SCloudAccountUpdateBaseOptions - OptionsBillingReportBucket string `help:"update AWS S3 bucket that stores account billing report" json:"-"` - RemoveOptionsBillingReportBucket bool `help:"remote AWS S3 bucket that stores account billing report" json:"-"` + OptionsBillingReportBucket string `help:"update AWS S3 bucket that stores account billing report" json:"-"` + RemoveOptionsBillingReportBucket bool `help:"remove AWS S3 bucket that stores account billing report" json:"-"` + OptionsBillingBucketAccount string `help:"update id of account that can access bucket, blank if this account can access" json:"-"` + RemoveOptionsBillingBucketAccount bool `help:"remove id of account that can access bucket, blank if this account can access" json:"-"` + OptionsBillingFileAccount string `help:"update account number, prefix of billing file name, blank if this account number is prefix" json:"-"` + RemoveOptionsBillingFileAccount bool `help:"remove account number, prefix of billing file name, blank if this account number is prefix" json:"-"` } type SOpenStackCloudAccountUpdateOptions struct {