-
Notifications
You must be signed in to change notification settings - Fork 36
/
requests.go
129 lines (109 loc) · 4.26 KB
/
requests.go
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
// Copyright © 2019 Banzai Cloud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package alibaba
import (
"strconv"
"time"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
"github.com/banzaicloud/cloudinfo/internal/cloudinfo"
)
// CommonDescriber interface for all Alibaba API calls
type CommonDescriber interface {
ProcessCommonRequest(request *requests.CommonRequest) (*responses.CommonResponse, error)
}
func (a *AlibabaInfoer) describeSpotPriceHistoryRequest(region, instanceType string) *requests.CommonRequest {
domain, _ := endpoints[region]
if domain == "" { // Best effort: fallback to the global endpoint
domain = "ecs.aliyuncs.com" // nolint: ineffassign
}
request := requests.NewCommonRequest()
request.Method = "POST"
request.ApiName = "DescribeSpotPriceHistory"
// request.Domain = domain
request.Product = "ecs"
request.Version = "2014-05-26"
request.QueryParams["RegionId"] = region
request.QueryParams["NetworkType"] = "vpc"
request.QueryParams["OSType"] = "linux"
request.QueryParams["StartTime"] = time.Now().Round(1 * time.Hour).UTC().Format(time.RFC3339)
request.QueryParams["InstanceType"] = instanceType
return request
}
func (a *AlibabaInfoer) describeInstanceTypesRequest() *requests.CommonRequest {
request := requests.NewCommonRequest()
request.Method = "POST"
request.ApiName = "DescribeInstanceTypes"
request.Domain = "ecs.aliyuncs.com"
request.Product = "ecs"
request.Version = "2014-05-26"
return request
}
func (a *AlibabaInfoer) describeZonesRequest(region string) *requests.CommonRequest {
domain, _ := endpoints[region]
if domain == "" { // Best effort: fallback to the global endpoint
domain = "ecs.aliyuncs.com" // nolint: ineffassign
}
request := requests.NewCommonRequest()
request.Method = "POST"
request.ApiName = "DescribeZones"
// request.Domain = domain
request.Product = "ecs"
request.Version = "2014-05-26"
request.QueryParams["RegionId"] = region
return request
}
func (a *AlibabaInfoer) getPayAsYouGoPriceRequest(region string, instanceTypes []string) *requests.CommonRequest {
request := requests.NewCommonRequest()
request.Method = "POST"
request.ApiName = "GetPayAsYouGoPrice"
request.Scheme = "https"
request.Domain = "business.ap-southeast-1.aliyuncs.com"
request.Version = "2017-12-14"
request.QueryParams["RegionId"] = region
request.QueryParams["ProductCode"] = "ecs"
request.QueryParams["SubscriptionType"] = "PayAsYouGo"
for i, instanceType := range instanceTypes {
request.QueryParams[cloudinfo.CreateString("ModuleList.", strconv.Itoa(i+1), ".ModuleCode")] = "InstanceType"
request.QueryParams[cloudinfo.CreateString("ModuleList.", strconv.Itoa(i+1), ".Config")] =
cloudinfo.CreateString("InstanceType:", instanceType, ",IoOptimized:IoOptimized,ImageOs:linux")
request.QueryParams[cloudinfo.CreateString("ModuleList.", strconv.Itoa(i+1), ".PriceType")] = "Hour"
}
return request
}
func (a *AlibabaInfoer) describeRegionsRequest() *requests.CommonRequest {
request := requests.NewCommonRequest()
request.Method = "POST"
request.ApiName = "DescribeRegions"
// request.Domain = "ecs.aliyuncs.com"
request.Product = "ecs"
request.Version = "2014-05-26"
request.QueryParams["AcceptLanguage"] = "en-US"
return request
}
func (a *AlibabaInfoer) describeImagesRequest(region string) *requests.CommonRequest {
domain, _ := endpoints[region]
if domain == "" { // Best effort: fallback to the global endpoint
domain = "ecs.aliyuncs.com" // nolint: ineffassign
}
request := requests.NewCommonRequest()
request.Method = "POST"
request.ApiName = "DescribeImages"
// request.Domain = domain
request.Product = "ecs"
request.Version = "2014-05-26"
request.QueryParams["OSType"] = "linux"
request.QueryParams["RegionId"] = region
return request
}