Debian Codegraph @

ecs/router_interface.go

raw symbols SCIP
1 package ecs
2
3 import (
4 "time"
5
6 "github.com/denverdino/aliyungo/common"
7 )
8
9 type EcsCommonResponse struct {
10 common.Response
11 }
12 type RouterType string
13 type InterfaceStatus string
14 type Role string
15 type Spec string
16
17 const (
18 VRouter = RouterType("VRouter")
19 VBR = RouterType("VBR")
20
21 Idl = InterfaceStatus("Idl")
22 Active = InterfaceStatus("Active")
23 Inactive = InterfaceStatus("Inactive")
24 // 'Idle' means the router interface is not connected. 'Idl' may be a incorrect status.
25 Idle = InterfaceStatus("Idle")
26
27 InitiatingSide = Role("InitiatingSide")
28 AcceptingSide = Role("AcceptingSide")
29
30 Small1 = Spec("Small.1")
31 Small2 = Spec("Small.2")
32 Small5 = Spec("Small.5")
33 Middle1 = Spec("Middle.1")
34 Middle2 = Spec("Middle.2")
35 Middle5 = Spec("Middle.5")
36 Large1 = Spec("Large.1")
37 Large2 = Spec("Large.2")
38 )
39
40 type CreateRouterInterfaceArgs struct {
41 RegionId common.Region
42 OppositeRegionId common.Region
43 RouterType RouterType
44 OppositeRouterType RouterType
45 RouterId string
46 OppositeRouterId string
47 Role Role
48 Spec Spec
49 AccessPointId string
50 OppositeAccessPointId string
51 OppositeInterfaceId string
52 OppositeInterfaceOwnerId string
53 Name string
54 Description string
55 HealthCheckSourceIp string
56 HealthCheckTargetIp string
57 }
58
59 type CreateRouterInterfaceResponse struct {
60 common.Response
61 RouterInterfaceId string
62 }
63
64 // CreateRouterInterface create Router interface
65 //
66 // You can read doc at https://help.aliyun.com/document_detail/36032.html?spm=5176.product27706.6.664.EbBsxC
67 func (client *Client) CreateRouterInterface(args *CreateRouterInterfaceArgs) (response *CreateRouterInterfaceResponse, err error) {
68 response = &CreateRouterInterfaceResponse{}
69 err = client.Invoke("CreateRouterInterface", args, &response)
70 if err != nil {
71 return response, err
72 }
73 return response, nil
74 }
75
76 type Filter struct {
77 Key string
78 Value []string
79 }
80
81 type DescribeRouterInterfacesArgs struct {
82 RegionId common.Region
83 common.Pagination
84 Filter []Filter
85 }
86
87 type RouterInterfaceItemType struct {
88 ChargeType string
89 RouterInterfaceId string
90 AccessPointId string
91 OppositeRegionId string
92 OppositeAccessPointId string
93 Role Role
94 Spec Spec
95 Name string
96 Description string
97 RouterId string
98 RouterType RouterType
99 CreationTime string
100 Status string
101 BusinessStatus string
102 ConnectedTime string
103 OppositeInterfaceId string
104 OppositeInterfaceSpec string
105 OppositeInterfaceStatus string
106 OppositeInterfaceBusinessStatus string
107 OppositeRouterId string
108 OppositeRouterType RouterType
109 OppositeInterfaceOwnerId string
110 HealthCheckSourceIp string
111 HealthCheckTargetIp string
112 }
113
114 type DescribeRouterInterfacesResponse struct {
115 RouterInterfaceSet struct {
116 RouterInterfaceType []RouterInterfaceItemType
117 }
118 common.PaginationResult
119 }
120
121 // DescribeRouterInterfaces describe Router interfaces
122 //
123 // You can read doc at https://help.aliyun.com/document_detail/36032.html?spm=5176.product27706.6.664.EbBsxC
124 func (client *Client) DescribeRouterInterfaces(args *DescribeRouterInterfacesArgs) (response *DescribeRouterInterfacesResponse, err error) {
125 response = &DescribeRouterInterfacesResponse{}
126 err = client.Invoke("DescribeRouterInterfaces", args, &response)
127 if err != nil {
128 return response, err
129 }
130 return response, nil
131 }
132
133 type OperateRouterInterfaceArgs struct {
134 RegionId common.Region
135 RouterInterfaceId string
136 }
137
138 // ConnectRouterInterface
139 //
140 // You can read doc at https://help.aliyun.com/document_detail/36031.html?spm=5176.doc36035.6.666.wkyljN
141 func (client *Client) ConnectRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
142 response = &EcsCommonResponse{}
143 err = client.Invoke("ConnectRouterInterface", args, &response)
144 if err != nil {
145 return response, err
146 }
147 return response, nil
148 }
149
150 // ActivateRouterInterface active Router Interface
151 //
152 // You can read doc at https://help.aliyun.com/document_detail/36030.html?spm=5176.doc36031.6.667.DAuZLD
153 func (client *Client) ActivateRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
154 response = &EcsCommonResponse{}
155 err = client.Invoke("ActivateRouterInterface", args, &response)
156 if err != nil {
157 return response, err
158 }
159 return response, nil
160 }
161
162 // DeactivateRouterInterface deactivate Router Interface
163 //
164 // You can read doc at https://help.aliyun.com/document_detail/36033.html?spm=5176.doc36030.6.668.JqCWUz
165 func (client *Client) DeactivateRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
166 response = &EcsCommonResponse{}
167 err = client.Invoke("DeactivateRouterInterface", args, &response)
168 if err != nil {
169 return response, err
170 }
171 return response, nil
172 }
173
174 type ModifyRouterInterfaceSpecArgs struct {
175 RegionId common.Region
176 RouterInterfaceId string
177 Spec Spec
178 }
179
180 type ModifyRouterInterfaceSpecResponse struct {
181 common.Response
182 Spec Spec
183 }
184
185 // ModifyRouterInterfaceSpec
186 //
187 // You can read doc at https://help.aliyun.com/document_detail/36037.html?spm=5176.doc36036.6.669.McKiye
188 func (client *Client) ModifyRouterInterfaceSpec(args *ModifyRouterInterfaceSpecArgs) (response *ModifyRouterInterfaceSpecResponse, err error) {
189 response = &ModifyRouterInterfaceSpecResponse{}
190 err = client.Invoke("ModifyRouterInterfaceSpec", args, &response)
191 if err != nil {
192 return response, err
193 }
194 return response, nil
195 }
196
197 type ModifyRouterInterfaceAttributeArgs struct {
198 RegionId common.Region
199 RouterInterfaceId string
200 Name string
201 Description string
202 OppositeInterfaceId string
203 OppositeRouterId string
204 OppositeInterfaceOwnerId string
205 HealthCheckSourceIp string
206 HealthCheckTargetIp string
207 }
208
209 // ModifyRouterInterfaceAttribute
210 //
211 // You can read doc at https://help.aliyun.com/document_detail/36036.html?spm=5176.doc36037.6.670.Dcz3xS
212 func (client *Client) ModifyRouterInterfaceAttribute(args *ModifyRouterInterfaceAttributeArgs) (response *EcsCommonResponse, err error) {
213 response = &EcsCommonResponse{}
214 err = client.Invoke("ModifyRouterInterfaceAttribute", args, &response)
215 if err != nil {
216 return response, err
217 }
218 return response, nil
219 }
220
221 // DeleteRouterInterface delete Router Interface
222 //
223 // You can read doc at https://help.aliyun.com/document_detail/36034.html?spm=5176.doc36036.6.671.y2xpNt
224 func (client *Client) DeleteRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
225 response = &EcsCommonResponse{}
226 err = client.Invoke("DeleteRouterInterface", args, &response)
227 if err != nil {
228 return response, err
229 }
230 return response, nil
231 }
232
233 // WaitForRouterInterface waits for router interface to given status
234 func (client *Client) WaitForRouterInterfaceAsyn(regionId common.Region, interfaceId string, status InterfaceStatus, timeout int) error {
235 if timeout <= 0 {
236 timeout = InstanceDefaultTimeout
237 }
238 for {
239 interfaces, err := client.DescribeRouterInterfaces(&DescribeRouterInterfacesArgs{
240 RegionId: regionId,
241 Filter: []Filter{Filter{Key: "RouterInterfaceId", Value: []string{interfaceId}}},
242 })
243 if err != nil {
244 return err
245 } else if interfaces != nil && InterfaceStatus(interfaces.RouterInterfaceSet.RouterInterfaceType[0].Status) == status {
246 //TODO
247 break
248 }
249 timeout = timeout - DefaultWaitForInterval
250 if timeout <= 0 {
251 return common.GetClientErrorFromString("Timeout")
252 }
253 time.Sleep(DefaultWaitForInterval * time.Second)
254
255 }
256 return nil
257 }