Debian Codegraph @

ecs/vswitches.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 CreateVSwitchArgs struct {
11 ZoneId string
12 CidrBlock string
13 VpcId string
14 VSwitchName string
15 Description string
16 ClientToken string
17 }
18
19 type CreateVSwitchResponse struct {
20 common.Response
21 VSwitchId string
22 }
23
24 // CreateVSwitch creates Virtual Switch
25 //
26 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/vswitch&createvswitch
27 func (client *Client) CreateVSwitch(args *CreateVSwitchArgs) (vswitchId string, err error) {
28 response := CreateVSwitchResponse{}
29 err = client.Invoke("CreateVSwitch", args, &response)
30 if err != nil {
31 return "", err
32 }
33 return response.VSwitchId, err
34 }
35
36 type DeleteVSwitchArgs struct {
37 VSwitchId string
38 }
39
40 type DeleteVSwitchResponse struct {
41 common.Response
42 }
43
44 // DeleteVSwitch deletes Virtual Switch
45 //
46 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/vswitch&deletevswitch
47 func (client *Client) DeleteVSwitch(VSwitchId string) error {
48 args := DeleteVSwitchArgs{
49 VSwitchId: VSwitchId,
50 }
51 response := DeleteVSwitchResponse{}
52 return client.Invoke("DeleteVSwitch", &args, &response)
53 }
54
55 type DescribeVSwitchesArgs struct {
56 RegionId common.Region
57 VpcId string
58 VSwitchId string
59 ZoneId string
60 common.Pagination
61 }
62
63 type VSwitchStatus string
64
65 const (
66 VSwitchStatusPending = VSwitchStatus("Pending")
67 VSwitchStatusAvailable = VSwitchStatus("Available")
68 )
69
70 //
71 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/datatype&vswitchsettype
72 type VSwitchSetType struct {
73 VSwitchId string
74 VpcId string
75 Status VSwitchStatus // enum Pending | Available
76 CidrBlock string
77 ZoneId string
78 AvailableIpAddressCount int
79 Description string
80 VSwitchName string
81 IsDefault bool
82 CreationTime util.ISO6801Time
83 }
84
85 type DescribeVSwitchesResponse struct {
86 common.Response
87 common.PaginationResult
88 VSwitches struct {
89 VSwitch []VSwitchSetType
90 }
91 }
92
93 // DescribeVSwitches describes Virtual Switches
94 //
95 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/vswitch&describevswitches
96 func (client *Client) DescribeVSwitches(args *DescribeVSwitchesArgs) (vswitches []VSwitchSetType, pagination *common.PaginationResult, err error) {
97 args.Validate()
98 response, err := client.DescribeVSwitchesWithRaw(args)
99 if err == nil {
100 return response.VSwitches.VSwitch, &response.PaginationResult, nil
101 }
102
103 return nil, nil, err
104 }
105
106 func (client *Client) DescribeVSwitchesWithRaw(args *DescribeVSwitchesArgs) (response *DescribeVSwitchesResponse, err error) {
107 args.Validate()
108 response = &DescribeVSwitchesResponse{}
109
110 err = client.Invoke("DescribeVSwitches", args, &response)
111
112 if err == nil {
113 return response, nil
114 }
115
116 return nil, err
117 }
118
119 type ModifyVSwitchAttributeArgs struct {
120 VSwitchId string
121 VSwitchName string
122 Description string
123 }
124
125 type ModifyVSwitchAttributeResponse struct {
126 common.Response
127 }
128
129 // ModifyVSwitchAttribute modifies attribute of Virtual Private Cloud
130 //
131 // You can read doc at http://docs.aliyun.com/#/pub/ecs/open-api/vswitch&modifyvswitchattribute
132 func (client *Client) ModifyVSwitchAttribute(args *ModifyVSwitchAttributeArgs) error {
133 response := ModifyVSwitchAttributeResponse{}
134 return client.Invoke("ModifyVSwitchAttribute", args, &response)
135 }
136
137 // WaitForVSwitchAvailable waits for VSwitch to given status
138 func (client *Client) WaitForVSwitchAvailable(vpcId string, vswitchId string, timeout int) error {
139 if timeout <= 0 {
140 timeout = DefaultTimeout
141 }
142 args := DescribeVSwitchesArgs{
143 VpcId: vpcId,
144 VSwitchId: vswitchId,
145 }
146 for {
147 vswitches, _, err := client.DescribeVSwitches(&args)
148 if err != nil {
149 return err
150 }
151 if len(vswitches) == 0 {
152 return common.GetClientErrorFromString("Not found")
153 }
154 if vswitches[0].Status == VSwitchStatusAvailable {
155 break
156 }
157 timeout = timeout - DefaultWaitForInterval
158 if timeout <= 0 {
159 return common.GetClientErrorFromString("Timeout")
160 }
161 time.Sleep(DefaultWaitForInterval * time.Second)
162 }
163 return nil
164 }