gtm.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 aliyun
  15. import (
  16. "fmt"
  17. "yunion.io/x/pkg/errors"
  18. )
  19. type SDnsGtmInstance struct {
  20. InstanceId string
  21. Config struct {
  22. PublicZoneName string
  23. }
  24. }
  25. func (self *SAliyunClient) DescribeDnsGtmInstances() ([]SDnsGtmInstance, error) {
  26. params := map[string]string{
  27. "PageSize": "100",
  28. }
  29. ret := []SDnsGtmInstance{}
  30. pageNumber := 1
  31. for {
  32. params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
  33. resp, err := self.alidnsRequest("DescribeDnsGtmInstances", params)
  34. if err != nil {
  35. return nil, err
  36. }
  37. part := struct {
  38. GtmInstances []SDnsGtmInstance
  39. TotalItems int
  40. }{}
  41. err = resp.Unmarshal(&part)
  42. if err != nil {
  43. return nil, err
  44. }
  45. ret = append(ret, part.GtmInstances...)
  46. if len(ret) >= part.TotalItems || len(part.GtmInstances) == 0 {
  47. break
  48. }
  49. pageNumber++
  50. }
  51. return ret, nil
  52. }
  53. type SDnsGtmInstanceAddressPool struct {
  54. Name string
  55. AddrPoolId string
  56. AddrCount int
  57. Addrs struct {
  58. Addr []struct {
  59. Addr string
  60. }
  61. }
  62. }
  63. func (self *SAliyunClient) DescribeDnsGtmInstanceAddressPools(id string) ([]SDnsGtmInstanceAddressPool, error) {
  64. params := map[string]string{"InstanceId": id, "PageSize": "100"}
  65. ret := []SDnsGtmInstanceAddressPool{}
  66. pageNumber := 1
  67. for {
  68. params["PageNumber"] = fmt.Sprintf("%d", pageNumber)
  69. resp, err := self.alidnsRequest("DescribeDnsGtmInstanceAddressPools", params)
  70. if err != nil {
  71. return nil, err
  72. }
  73. part := struct {
  74. AddrPools struct {
  75. AddrPool []SDnsGtmInstanceAddressPool
  76. }
  77. TotalItems int
  78. }{}
  79. err = resp.Unmarshal(&part)
  80. if err != nil {
  81. return nil, err
  82. }
  83. ret = append(ret, part.AddrPools.AddrPool...)
  84. if len(ret) >= part.TotalItems || len(part.AddrPools.AddrPool) == 0 {
  85. break
  86. }
  87. pageNumber++
  88. }
  89. return ret, nil
  90. }
  91. func (self *SAliyunClient) DescribeDnsGtmInstanceAddressPool(id string) (*SDnsGtmInstanceAddressPool, error) {
  92. params := map[string]string{"AddrPoolId": id}
  93. resp, err := self.alidnsRequest("DescribeDnsGtmInstanceAddressPool", params)
  94. if err != nil {
  95. return nil, err
  96. }
  97. ret := &SDnsGtmInstanceAddressPool{}
  98. err = resp.Unmarshal(ret)
  99. if err != nil {
  100. return nil, errors.Wrapf(err, "Unmarshal")
  101. }
  102. return ret, nil
  103. }