Debian Codegraph @

ecs/route_tables.go

raw symbols SCIP
1 package ecs
2
3 import (
4 "time"
5
6 "github.com/denverdino/aliyungo/common"
7 "github.com/denverdino/aliyungo/util"
8 )
9
10 type DescribeRouteTablesArgs struct {
11 VRouterId string
12 RouteTableId string
13 common.Pagination
14 }
15
16 type RouteTableType string
17
18 const (
19 RouteTableSystem = RouteTableType("System")
20 RouteTableCustom = RouteTableType("Custom")
21 )
22
23 type RouteEntryStatus string
24
25 const (
26 RouteEntryStatusPending = RouteEntryStatus("Pending")
27 RouteEntryStatusAvailable = RouteEntryStatus("Available")
28 RouteEntryStatusModifying = RouteEntryStatus("Modifying")
29 )
30
31 type NextHopListType struct {
32 NextHopList struct {
33 NextHopItem []NextHopItemType
34 }
35 }
36
37 type NextHopItemType struct {
38 NextHopType string
39 NextHopId string
40 }
41
42 //
43 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&routeentrysettype
44 type RouteEntrySetType struct {
45 RouteTableId string
46 DestinationCidrBlock string
47 Type RouteTableType
48 NextHopType string
49 NextHopId string
50 NextHopList NextHopListType
51 InstanceId string
52 Status RouteEntryStatus // enum Pending | Available | Modifying
53 }
54
55 //
56 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&routetablesettype
57 type RouteTableSetType struct {
58 VRouterId string
59 RouteTableId string
60 RouteEntrys struct {
61 RouteEntry []RouteEntrySetType
62 }
63 RouteTableType RouteTableType
64 CreationTime util.ISO6801Time
65 }
66
67 type DescribeRouteTablesResponse struct {
68 common.Response
69 common.PaginationResult
70 RouteTables struct {
71 RouteTable []RouteTableSetType
72 }
73 }
74
75 // DescribeRouteTables describes Virtual Routers
76 //
77 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/routertable&describeroutetables
78 func (client *Client) DescribeRouteTables(args *DescribeRouteTablesArgs) (routeTables []RouteTableSetType, pagination *common.PaginationResult, err error) {
79 response, err := client.DescribeRouteTablesWithRaw(args)
80 if err == nil {
81 return response.RouteTables.RouteTable, &response.PaginationResult, nil
82 }
83
84 return nil, nil, err
85 }
86
87 func (client *Client) DescribeRouteTablesWithRaw(args *DescribeRouteTablesArgs) (response *DescribeRouteTablesResponse, err error) {
88 args.Validate()
89 response = &DescribeRouteTablesResponse{}
90
91 err = client.Invoke("DescribeRouteTables", args, &response)
92
93 if err == nil {
94 return response, nil
95 }
96
97 return nil, err
98 }
99
100 type NextHopType string
101
102 const (
103 NextHopIntance = NextHopType("Instance") //Default
104 NextHopTunnel = NextHopType("Tunnel")
105 NextHopTunnelRouterInterface = NextHopType("RouterInterface")
106 )
107
108 type CreateRouteEntryArgs struct {
109 RouteTableId string
110 DestinationCidrBlock string
111 NextHopType NextHopType
112 NextHopId string
113 ClientToken string
114 }
115
116 type CreateRouteEntryResponse struct {
117 common.Response
118 }
119
120 // CreateRouteEntry creates route entry
121 //
122 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/routertable&createrouteentry
123 func (client *Client) CreateRouteEntry(args *CreateRouteEntryArgs) error {
124 response := CreateRouteEntryResponse{}
125 return client.Invoke("CreateRouteEntry", args, &response)
126 }
127
128 type DeleteRouteEntryArgs struct {
129 RouteTableId string
130 DestinationCidrBlock string
131 NextHopId string
132 }
133
134 type DeleteRouteEntryResponse struct {
135 common.Response
136 }
137
138 // DeleteRouteEntry deletes route entry
139 //
140 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/routertable&deleterouteentry
141 func (client *Client) DeleteRouteEntry(args *DeleteRouteEntryArgs) error {
142 response := DeleteRouteEntryResponse{}
143 return client.Invoke("DeleteRouteEntry", args, &response)
144 }
145
146 // WaitForAllRouteEntriesAvailable waits for all route entries to Available status
147 func (client *Client) WaitForAllRouteEntriesAvailable(vrouterId string, routeTableId string, timeout int) error {
148 if timeout <= 0 {
149 timeout = DefaultTimeout
150 }
151 args := DescribeRouteTablesArgs{
152 VRouterId: vrouterId,
153 RouteTableId: routeTableId,
154 }
155 for {
156
157 routeTables, _, err := client.DescribeRouteTables(&args)
158
159 if err != nil {
160 return err
161 }
162 if len(routeTables) == 0 {
163 return common.GetClientErrorFromString("Not found")
164 }
165 success := true
166
167 loop:
168 for _, routeTable := range routeTables {
169 for _, routeEntry := range routeTable.RouteEntrys.RouteEntry {
170 if routeEntry.Status != RouteEntryStatusAvailable {
171 success = false
172 break loop
173 }
174 }
175 }
176 if success {
177 break
178 }
179 timeout = timeout - DefaultWaitForInterval
180 if timeout <= 0 {
181 return common.GetClientErrorFromString("Timeout")
182 }
183 time.Sleep(DefaultWaitForInterval * time.Second)
184 }
185 return nil
186 }