/
ipv6_gateway.go
132 lines (116 loc) · 3.33 KB
/
ipv6_gateway.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2019 Yunion
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package apsara
import (
"fmt"
"time"
"yunion.io/x/pkg/errors"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
)
type SIPv6Gateway struct {
multicloud.SResourceBase
ApsaraTags
region *SRegion
Status string `json:"Status"`
Description string `json:"Description"`
InstanceChargeType string `json:"InstanceChargeType"`
Ipv6GatewayId string `json:"Ipv6GatewayId"`
BusinessStatus string `json:"BusinessStatus"`
Name string `json:"Name"`
VpcID string `json:"VpcId"`
ExpiredTime string `json:"ExpiredTime"`
CreationTime time.Time `json:"CreationTime"`
RegionId string `json:"RegionId"`
Spec string `json:"Spec"`
DepartmentInfo
}
func (self *SIPv6Gateway) GetGlobalId() string {
return self.Ipv6GatewayId
}
func (self *SIPv6Gateway) GetId() string {
return self.Ipv6GatewayId
}
func (self *SIPv6Gateway) GetName() string {
if len(self.Name) > 0 {
return self.Name
}
return self.Ipv6GatewayId
}
func (self *SIPv6Gateway) GetStatus() string {
return self.Status
}
func (self *SIPv6Gateway) GetInstanceType() string {
return self.Spec
}
func (self *SIPv6Gateway) GetCreatedAt() time.Time {
return self.CreationTime
}
func (self *SRegion) GetIPv6Gateways(vpcId string, pageNumber, pageSize int) ([]SIPv6Gateway, int, error) {
if pageSize < 1 {
pageSize = 50
}
if pageNumber < 1 {
pageNumber = 1
}
params := map[string]string{
"PageSize": fmt.Sprintf("%d", pageSize),
"PageNumber": fmt.Sprintf("%d", 1),
}
if len(vpcId) > 0 {
params["VpcId"] = vpcId
}
resp, err := self.vpcRequest("DescribeIpv6Gateways", params)
if err != nil {
return nil, 0, errors.Wrapf(err, "DescribeIpv6Gateways")
}
ret := []SIPv6Gateway{}
err = resp.Unmarshal(&ret, "Ipv6Gateways", "Ipv6Gateway")
if err != nil {
return nil, 0, errors.Wrapf(err, "resp.Unmarshal")
}
totalCount, _ := resp.Int("TotalCount")
return ret, int(totalCount), nil
}
func (self *SRegion) GetIPv6Gateway(id string) (*SIPv6Gateway, error) {
params := map[string]string{
"Ipv6GatewayId": id,
}
resp, err := self.vpcRequest("DescribeIpv6GatewayAttribute", params)
if err != nil {
return nil, err
}
ret := &SIPv6Gateway{region: self}
return ret, resp.Unmarshal(ret)
}
func (self *SVpc) GetICloudIPv6Gateways() ([]cloudprovider.ICloudIPv6Gateway, error) {
res, pageNumber := []SIPv6Gateway{}, 1
for {
part, total, err := self.region.GetIPv6Gateways(self.VpcId, pageNumber, 50)
if err != nil {
return nil, err
}
res = append(res, part...)
if len(res) >= total {
break
}
pageNumber++
}
ret := []cloudprovider.ICloudIPv6Gateway{}
for i := range res {
res[i].region = self.region
ret = append(ret, &res[i])
}
return ret, nil
}