File: router_interface.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (257 lines) | stat: -rw-r--r-- 7,973 bytes parent folder | download | duplicates (3)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package ecs

import (
	"time"

	"github.com/denverdino/aliyungo/common"
)

type EcsCommonResponse struct {
	common.Response
}
type RouterType string
type InterfaceStatus string
type Role string
type Spec string

const (
	VRouter = RouterType("VRouter")
	VBR     = RouterType("VBR")

	Idl      = InterfaceStatus("Idl")
	Active   = InterfaceStatus("Active")
	Inactive = InterfaceStatus("Inactive")
	// 'Idle' means the router interface is not connected. 'Idl' may be a incorrect status.
	Idle = InterfaceStatus("Idle")

	InitiatingSide = Role("InitiatingSide")
	AcceptingSide  = Role("AcceptingSide")

	Small1  = Spec("Small.1")
	Small2  = Spec("Small.2")
	Small5  = Spec("Small.5")
	Middle1 = Spec("Middle.1")
	Middle2 = Spec("Middle.2")
	Middle5 = Spec("Middle.5")
	Large1  = Spec("Large.1")
	Large2  = Spec("Large.2")
)

type CreateRouterInterfaceArgs struct {
	RegionId                 common.Region
	OppositeRegionId         common.Region
	RouterType               RouterType
	OppositeRouterType       RouterType
	RouterId                 string
	OppositeRouterId         string
	Role                     Role
	Spec                     Spec
	AccessPointId            string
	OppositeAccessPointId    string
	OppositeInterfaceId      string
	OppositeInterfaceOwnerId string
	Name                     string
	Description              string
	HealthCheckSourceIp      string
	HealthCheckTargetIp      string
}

type CreateRouterInterfaceResponse struct {
	common.Response
	RouterInterfaceId string
}

// CreateRouterInterface create Router interface
//
// You can read doc at https://help.aliyun.com/document_detail/36032.html?spm=5176.product27706.6.664.EbBsxC
func (client *Client) CreateRouterInterface(args *CreateRouterInterfaceArgs) (response *CreateRouterInterfaceResponse, err error) {
	response = &CreateRouterInterfaceResponse{}
	err = client.Invoke("CreateRouterInterface", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

type Filter struct {
	Key   string
	Value []string
}

type DescribeRouterInterfacesArgs struct {
	RegionId common.Region
	common.Pagination
	Filter []Filter
}

type RouterInterfaceItemType struct {
	ChargeType                      string
	RouterInterfaceId               string
	AccessPointId                   string
	OppositeRegionId                string
	OppositeAccessPointId           string
	Role                            Role
	Spec                            Spec
	Name                            string
	Description                     string
	RouterId                        string
	RouterType                      RouterType
	CreationTime                    string
	Status                          string
	BusinessStatus                  string
	ConnectedTime                   string
	OppositeInterfaceId             string
	OppositeInterfaceSpec           string
	OppositeInterfaceStatus         string
	OppositeInterfaceBusinessStatus string
	OppositeRouterId                string
	OppositeRouterType              RouterType
	OppositeInterfaceOwnerId        string
	HealthCheckSourceIp             string
	HealthCheckTargetIp             string
}

type DescribeRouterInterfacesResponse struct {
	RouterInterfaceSet struct {
		RouterInterfaceType []RouterInterfaceItemType
	}
	common.PaginationResult
}

// DescribeRouterInterfaces describe Router interfaces
//
// You can read doc at https://help.aliyun.com/document_detail/36032.html?spm=5176.product27706.6.664.EbBsxC
func (client *Client) DescribeRouterInterfaces(args *DescribeRouterInterfacesArgs) (response *DescribeRouterInterfacesResponse, err error) {
	response = &DescribeRouterInterfacesResponse{}
	err = client.Invoke("DescribeRouterInterfaces", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

type OperateRouterInterfaceArgs struct {
	RegionId          common.Region
	RouterInterfaceId string
}

// ConnectRouterInterface
//
// You can read doc at https://help.aliyun.com/document_detail/36031.html?spm=5176.doc36035.6.666.wkyljN
func (client *Client) ConnectRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
	response = &EcsCommonResponse{}
	err = client.Invoke("ConnectRouterInterface", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

// ActivateRouterInterface active Router Interface
//
// You can read doc at https://help.aliyun.com/document_detail/36030.html?spm=5176.doc36031.6.667.DAuZLD
func (client *Client) ActivateRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
	response = &EcsCommonResponse{}
	err = client.Invoke("ActivateRouterInterface", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

// DeactivateRouterInterface deactivate Router Interface
//
// You can read doc at https://help.aliyun.com/document_detail/36033.html?spm=5176.doc36030.6.668.JqCWUz
func (client *Client) DeactivateRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
	response = &EcsCommonResponse{}
	err = client.Invoke("DeactivateRouterInterface", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

type ModifyRouterInterfaceSpecArgs struct {
	RegionId          common.Region
	RouterInterfaceId string
	Spec              Spec
}

type ModifyRouterInterfaceSpecResponse struct {
	common.Response
	Spec Spec
}

// ModifyRouterInterfaceSpec
//
// You can read doc at https://help.aliyun.com/document_detail/36037.html?spm=5176.doc36036.6.669.McKiye
func (client *Client) ModifyRouterInterfaceSpec(args *ModifyRouterInterfaceSpecArgs) (response *ModifyRouterInterfaceSpecResponse, err error) {
	response = &ModifyRouterInterfaceSpecResponse{}
	err = client.Invoke("ModifyRouterInterfaceSpec", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

type ModifyRouterInterfaceAttributeArgs struct {
	RegionId                 common.Region
	RouterInterfaceId        string
	Name                     string
	Description              string
	OppositeInterfaceId      string
	OppositeRouterId         string
	OppositeInterfaceOwnerId string
	HealthCheckSourceIp      string
	HealthCheckTargetIp      string
}

// ModifyRouterInterfaceAttribute
//
// You can read doc at https://help.aliyun.com/document_detail/36036.html?spm=5176.doc36037.6.670.Dcz3xS
func (client *Client) ModifyRouterInterfaceAttribute(args *ModifyRouterInterfaceAttributeArgs) (response *EcsCommonResponse, err error) {
	response = &EcsCommonResponse{}
	err = client.Invoke("ModifyRouterInterfaceAttribute", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

// DeleteRouterInterface delete Router Interface
//
// You can read doc at https://help.aliyun.com/document_detail/36034.html?spm=5176.doc36036.6.671.y2xpNt
func (client *Client) DeleteRouterInterface(args *OperateRouterInterfaceArgs) (response *EcsCommonResponse, err error) {
	response = &EcsCommonResponse{}
	err = client.Invoke("DeleteRouterInterface", args, &response)
	if err != nil {
		return response, err
	}
	return response, nil
}

// WaitForRouterInterface waits for router interface to given status
func (client *Client) WaitForRouterInterfaceAsyn(regionId common.Region, interfaceId string, status InterfaceStatus, timeout int) error {
	if timeout <= 0 {
		timeout = InstanceDefaultTimeout
	}
	for {
		interfaces, err := client.DescribeRouterInterfaces(&DescribeRouterInterfacesArgs{
			RegionId: regionId,
			Filter:   []Filter{Filter{Key: "RouterInterfaceId", Value: []string{interfaceId}}},
		})
		if err != nil {
			return err
		} else if interfaces != nil && InterfaceStatus(interfaces.RouterInterfaceSet.RouterInterfaceType[0].Status) == status {
			//TODO
			break
		}
		timeout = timeout - DefaultWaitForInterval
		if timeout <= 0 {
			return common.GetClientErrorFromString("Timeout")
		}
		time.Sleep(DefaultWaitForInterval * time.Second)

	}
	return nil
}