File: stack.go

package info (click to toggle)
golang-github-denverdino-aliyungo 0.0~git20180921.13fa8aa-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,824 kB
  • sloc: xml: 1,359; makefile: 3
file content (226 lines) | stat: -rwxr-xr-x 5,731 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
package ros

import (
	"net/http"

	"fmt"

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

//https://help.aliyun.com/document_detail/28910.html?spm=5176.doc50083.6.580.b5wkQr
type CreateStackRequest struct {
	Name            string
	Template        string
	Parameters      interface{}
	DisableRollback bool
	TimeoutMins     int
}

type CreateStackResponse struct {
	Id   string
	Name string
}

func (client *Client) CreateStack(regionId common.Region, args *CreateStackRequest) (*CreateStackResponse, error) {
	stack := &CreateStackResponse{}
	err := client.Invoke(regionId, http.MethodPost, "/stacks", nil, args, stack)
	if err != nil {
		return nil, err
	}

	return stack, nil
}

//https://help.aliyun.com/document_detail/28911.html?spm=5176.doc28910.6.581.etoi2Z
type DeleteStackRequest struct {
	RegionId common.Region
}

type DeleteStackResponse struct {
	common.Response
}

func (client *Client) DeleteStack(regionId common.Region, stackId string, stackName string) (*DeleteStackResponse, error) {
	args := &DeleteStackRequest{
		RegionId: regionId,
	}

	response := &DeleteStackResponse{}
	query := util.ConvertToQueryValues(args)
	err := client.Invoke(regionId, http.MethodDelete, fmt.Sprintf("/stacks/%s/%s", stackName, stackId), query, nil, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

//https://help.aliyun.com/document_detail/28912.html?spm=5176.doc28911.6.582.X0FKwG
type AbandonStackRequest struct {
	RegionId common.Region
}

type AbandonStackResponse struct {
	common.Response
	Id          string
	Name        string
	Action      string
	Status      string
	Template    interface{}
	Resources   interface{}
	Environment interface{}
}

func (client *Client) AbandonStack(regionId common.Region, stackId string, stackName string) (*AbandonStackResponse, error) {
	args := &DeleteStackRequest{
		RegionId: regionId,
	}

	response := &AbandonStackResponse{}
	query := util.ConvertToQueryValues(args)
	err := client.Invoke(regionId, http.MethodDelete, fmt.Sprintf("/stacks/%s/%s/abandon", stackName, stackId), query, nil, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

//https://help.aliyun.com/document_detail/28913.html?spm=5176.doc28912.6.583.vrfk38
type DescribeStacksRequest struct {
	RegionId   common.Region
	StackId    string
	Name       string
	Status     string
	PageNumber string
	PageSize   string
}

type DescribeStacksResponse struct {
	common.Response
	TotalCount int
	PageNumber int
	PageSize   int
	Stacks     []Stack
}

type Stack struct {
	Region          common.Region
	Id              string
	Name            string
	Updated         string
	Created         string
	StatusReason    string
	Status          string
	Description     string
	DisableRollback bool
	TimeoutMins     int
}

func (client *Client) DescribeStacks(args *DescribeStacksRequest) (*DescribeStacksResponse, error) {
	query := util.ConvertToQueryValues(args)
	stacks := &DescribeStacksResponse{}
	err := client.Invoke(args.RegionId, http.MethodGet, "/stacks", query, nil, stacks)
	if err != nil {
		return nil, err
	}

	return stacks, nil
}

//https://help.aliyun.com/document_detail/28914.html?spm=5176.doc28913.6.584.9JAYPI
type DescribeStackRequest struct {
	RegionId common.Region
}

type DescribeStackResponse struct {
	Parameters interface{}
	common.Response
	Id                  string
	Region              common.Region
	Name                string
	Updated             string
	Created             string
	TemplateDescription string
	StatusReason        string
	Status              string
	Outputs             interface{}
	DisableRollback     bool
	TimeoutMins         int
}

func (client *Client) DescribeStack(regionId common.Region, stackId string, stackName string) (*DescribeStackResponse, error) {
	args := &DescribeStackRequest{
		RegionId: regionId,
	}

	response := &DescribeStackResponse{}
	query := util.ConvertToQueryValues(args)
	err := client.Invoke(regionId, http.MethodGet, fmt.Sprintf("/stacks/%s/%s", stackName, stackId), query, nil, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}

//https://help.aliyun.com/document_detail/50083.html?spm=5176.doc28914.6.585.QnbbaF
type PreviewStackRequest struct {
	Name            string
	Template        string
	Parameters      string
	DisableRollback bool
	TimeoutMins     int
}

type PreviewStackResponse struct {
	common.Response
	Id                  string
	Resources           interface{}
	Region              common.Region
	Description         string
	Updated             string
	Created             string
	Parameters          interface{}
	TemplateDescription string
	Webhook             string
	DisableRollback     bool
	TimeoutMins         int
}

func (client *Client) PreviewStack(regionId common.Region, args PreviewStackRequest) (*PreviewStackResponse, error) {
	query := util.ConvertToQueryValues(args)
	stack := &PreviewStackResponse{}
	err := client.Invoke(regionId, http.MethodPost, "/stacks/preview", query, args, stack)
	if err != nil {
		return nil, err
	}

	return stack, nil
}

//https://help.aliyun.com/document_detail/49066.html?spm=5176.doc28910.6.586.MJjWQh
type UpdateStackRequest struct {
	Template        string
	Parameters      interface{}
	DisableRollback bool
	TimeoutMins     int
}

type UpdateStackResponse struct {
	common.Response
	Id   string
	Name string
}

func (client *Client) UpdateStack(regionId common.Region, stackId string, stackName string, args *UpdateStackRequest) (*UpdateStackResponse, error) {
	stack := &UpdateStackResponse{}
	err := client.Invoke(regionId, http.MethodPut, fmt.Sprintf("/stacks/%s/%s", stackName, stackId), nil, args, stack)
	if err != nil {
		return nil, err
	}

	return stack, nil
}