| 1 |
package ros |
| 2 |
|
| 3 |
import ( |
| 4 |
"net/http" |
| 5 |
|
| 6 |
"fmt" |
| 7 |
|
| 8 |
"github.com/denverdino/aliyungo/common" |
| 9 |
"github.com/denverdino/aliyungo/util" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
type CreateStackRequest struct { |
| 14 |
Name string |
| 15 |
Template string |
| 16 |
Parameters interface{} |
| 17 |
DisableRollback bool |
| 18 |
TimeoutMins int |
| 19 |
} |
| 20 |
|
| 21 |
type CreateStackResponse struct { |
| 22 |
Id string |
| 23 |
Name string |
| 24 |
} |
| 25 |
|
| 26 |
func (client *Client) CreateStack(regionId common.Region, args *CreateStackRequest) (*CreateStackResponse, error) { |
| 27 |
stack := &CreateStackResponse{} |
| 28 |
err := client.Invoke(regionId, http.MethodPost, "/stacks", nil, args, stack) |
| 29 |
if err != nil { |
| 30 |
return nil, err |
| 31 |
} |
| 32 |
|
| 33 |
return stack, nil |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
type DeleteStackRequest struct { |
| 38 |
RegionId common.Region |
| 39 |
} |
| 40 |
|
| 41 |
type DeleteStackResponse struct { |
| 42 |
common.Response |
| 43 |
} |
| 44 |
|
| 45 |
func (client *Client) DeleteStack(regionId common.Region, stackId string, stackName string) (*DeleteStackResponse, error) { |
| 46 |
args := &DeleteStackRequest{ |
| 47 |
RegionId: regionId, |
| 48 |
} |
| 49 |
|
| 50 |
response := &DeleteStackResponse{} |
| 51 |
query := util.ConvertToQueryValues(args) |
| 52 |
err := client.Invoke(regionId, http.MethodDelete, fmt.Sprintf("/stacks/%s/%s", stackName, stackId), query, nil, response) |
| 53 |
if err != nil { |
| 54 |
return nil, err |
| 55 |
} |
| 56 |
|
| 57 |
return response, nil |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
type AbandonStackRequest struct { |
| 62 |
RegionId common.Region |
| 63 |
} |
| 64 |
|
| 65 |
type AbandonStackResponse struct { |
| 66 |
common.Response |
| 67 |
Id string |
| 68 |
Name string |
| 69 |
Action string |
| 70 |
Status string |
| 71 |
Template interface{} |
| 72 |
Resources interface{} |
| 73 |
Environment interface{} |
| 74 |
} |
| 75 |
|
| 76 |
func (client *Client) AbandonStack(regionId common.Region, stackId string, stackName string) (*AbandonStackResponse, error) { |
| 77 |
args := &DeleteStackRequest{ |
| 78 |
RegionId: regionId, |
| 79 |
} |
| 80 |
|
| 81 |
response := &AbandonStackResponse{} |
| 82 |
query := util.ConvertToQueryValues(args) |
| 83 |
err := client.Invoke(regionId, http.MethodDelete, fmt.Sprintf("/stacks/%s/%s/abandon", stackName, stackId), query, nil, response) |
| 84 |
if err != nil { |
| 85 |
return nil, err |
| 86 |
} |
| 87 |
|
| 88 |
return response, nil |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
type DescribeStacksRequest struct { |
| 93 |
RegionId common.Region |
| 94 |
StackId string |
| 95 |
Name string |
| 96 |
Status string |
| 97 |
PageNumber string |
| 98 |
PageSize string |
| 99 |
} |
| 100 |
|
| 101 |
type DescribeStacksResponse struct { |
| 102 |
common.Response |
| 103 |
TotalCount int |
| 104 |
PageNumber int |
| 105 |
PageSize int |
| 106 |
Stacks []Stack |
| 107 |
} |
| 108 |
|
| 109 |
type Stack struct { |
| 110 |
Region common.Region |
| 111 |
Id string |
| 112 |
Name string |
| 113 |
Updated string |
| 114 |
Created string |
| 115 |
StatusReason string |
| 116 |
Status string |
| 117 |
Description string |
| 118 |
DisableRollback bool |
| 119 |
TimeoutMins int |
| 120 |
} |
| 121 |
|
| 122 |
func (client *Client) DescribeStacks(args *DescribeStacksRequest) (*DescribeStacksResponse, error) { |
| 123 |
query := util.ConvertToQueryValues(args) |
| 124 |
stacks := &DescribeStacksResponse{} |
| 125 |
err := client.Invoke(args.RegionId, http.MethodGet, "/stacks", query, nil, stacks) |
| 126 |
if err != nil { |
| 127 |
return nil, err |
| 128 |
} |
| 129 |
|
| 130 |
return stacks, nil |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
type DescribeStackRequest struct { |
| 135 |
RegionId common.Region |
| 136 |
} |
| 137 |
|
| 138 |
type DescribeStackResponse struct { |
| 139 |
Parameters interface{} |
| 140 |
common.Response |
| 141 |
Id string |
| 142 |
Region common.Region |
| 143 |
Name string |
| 144 |
Updated string |
| 145 |
Created string |
| 146 |
TemplateDescription string |
| 147 |
StatusReason string |
| 148 |
Status string |
| 149 |
Outputs interface{} |
| 150 |
DisableRollback bool |
| 151 |
TimeoutMins int |
| 152 |
} |
| 153 |
|
| 154 |
func (client *Client) DescribeStack(regionId common.Region, stackId string, stackName string) (*DescribeStackResponse, error) { |
| 155 |
args := &DescribeStackRequest{ |
| 156 |
RegionId: regionId, |
| 157 |
} |
| 158 |
|
| 159 |
response := &DescribeStackResponse{} |
| 160 |
query := util.ConvertToQueryValues(args) |
| 161 |
err := client.Invoke(regionId, http.MethodGet, fmt.Sprintf("/stacks/%s/%s", stackName, stackId), query, nil, response) |
| 162 |
if err != nil { |
| 163 |
return nil, err |
| 164 |
} |
| 165 |
|
| 166 |
return response, nil |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
type PreviewStackRequest struct { |
| 171 |
Name string |
| 172 |
Template string |
| 173 |
Parameters string |
| 174 |
DisableRollback bool |
| 175 |
TimeoutMins int |
| 176 |
} |
| 177 |
|
| 178 |
type PreviewStackResponse struct { |
| 179 |
common.Response |
| 180 |
Id string |
| 181 |
Resources interface{} |
| 182 |
Region common.Region |
| 183 |
Description string |
| 184 |
Updated string |
| 185 |
Created string |
| 186 |
Parameters interface{} |
| 187 |
TemplateDescription string |
| 188 |
Webhook string |
| 189 |
DisableRollback bool |
| 190 |
TimeoutMins int |
| 191 |
} |
| 192 |
|
| 193 |
func (client *Client) PreviewStack(regionId common.Region, args PreviewStackRequest) (*PreviewStackResponse, error) { |
| 194 |
query := util.ConvertToQueryValues(args) |
| 195 |
stack := &PreviewStackResponse{} |
| 196 |
err := client.Invoke(regionId, http.MethodPost, "/stacks/preview", query, args, stack) |
| 197 |
if err != nil { |
| 198 |
return nil, err |
| 199 |
} |
| 200 |
|
| 201 |
return stack, nil |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
type UpdateStackRequest struct { |
| 206 |
Template string |
| 207 |
Parameters interface{} |
| 208 |
DisableRollback bool |
| 209 |
TimeoutMins int |
| 210 |
} |
| 211 |
|
| 212 |
type UpdateStackResponse struct { |
| 213 |
common.Response |
| 214 |
Id string |
| 215 |
Name string |
| 216 |
} |
| 217 |
|
| 218 |
func (client *Client) UpdateStack(regionId common.Region, stackId string, stackName string, args *UpdateStackRequest) (*UpdateStackResponse, error) { |
| 219 |
stack := &UpdateStackResponse{} |
| 220 |
err := client.Invoke(regionId, http.MethodPut, fmt.Sprintf("/stacks/%s/%s", stackName, stackId), nil, args, stack) |
| 221 |
if err != nil { |
| 222 |
return nil, err |
| 223 |
} |
| 224 |
|
| 225 |
return stack, nil |
| 226 |
} |