bandwidthpackage.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package qcloud
  15. import (
  16. "fmt"
  17. "time"
  18. "yunion.io/x/pkg/errors"
  19. )
  20. type SBandwidthPackageSet struct {
  21. AddressIp string
  22. ResourceId string
  23. ResourceType string
  24. }
  25. type SBandwidthPackage struct {
  26. BandwidthPackageId string
  27. BandwidthPackageName string
  28. ChargeType string
  29. CreatedTime time.Time
  30. NetworkType string
  31. Protocol string
  32. ResourceSet []SBandwidthPackageSet
  33. }
  34. func (region *SRegion) GetBandwidthPackages(ids []string, offset int, limit int) ([]SBandwidthPackage, int, error) {
  35. if limit < 1 || limit > 50 {
  36. limit = 50
  37. }
  38. params := map[string]string{
  39. "Region": region.Region,
  40. "Limit": fmt.Sprintf("%d", limit),
  41. "Offset": fmt.Sprintf("%d", offset),
  42. }
  43. for idx, id := range ids {
  44. params[fmt.Sprintf("BandwidthPackageIds.%d", idx)] = id
  45. }
  46. packages := []SBandwidthPackage{}
  47. resp, err := region.vpcRequest("DescribeBandwidthPackages", params)
  48. if err != nil {
  49. return nil, 0, errors.Wrap(err, "DescribeBandwidthPackages")
  50. }
  51. err = resp.Unmarshal(&packages, "BandwidthPackageSet")
  52. if err != nil {
  53. return nil, 0, errors.Wrap(err, "resp.Unmarshal")
  54. }
  55. total, _ := resp.Float("TotalCount")
  56. return packages, int(total), nil
  57. }