/
memcached.go
314 lines (254 loc) · 8.64 KB
/
memcached.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// Copyright 2019 Yunion
//
// 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 qcloud
import (
"fmt"
"strconv"
"time"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
billing_api "yunion.io/x/cloudmux/pkg/apis/billing"
api "yunion.io/x/cloudmux/pkg/apis/compute"
"yunion.io/x/cloudmux/pkg/cloudprovider"
"yunion.io/x/cloudmux/pkg/multicloud"
"yunion.io/x/onecloud/pkg/util/billing"
)
type SMemcached struct {
multicloud.SElasticcacheBase
QcloudTags
region *SRegion
InstanceId string `json:"InstanceId"`
InstanceName string `json:"InstanceName"`
AppId int `json:"AppId"`
ProjectId int `json:"ProjectId"`
InstanceDesc string `json:"InstanceDesc"`
Vip string `json:"Vip"`
Vport int `json:"Vport"`
Status int `json:"Status"`
AutoRenewFlag int `json:"AutoRenewFlag"`
VpcId int `json:"VpcId"`
SubnetId int `json:"SubnetId"`
PayMode int `json:"PayMode"`
ZoneId int `json:"ZoneId"`
Expire int `json:"Expire"`
RegionId int `json:"RegionId"`
AddTimeStamp time.Time `json:"AddTimeStamp"`
ModtimeStamp time.Time `json:"ModTimeStamp"`
IsolateTimesSamp time.Time `json:"IsolateTimeStamp"`
UniqVpcId string `json:"UniqVpcId"`
UniqSubnetId string `json:"UniqSubnetId"`
DeadlineTimeStamp string `json:"DeadlineTimeStamp"`
SetId int `json:"SetId"`
CmemId int `json:"CmemId"`
}
func (self *SMemcached) GetId() string {
return self.InstanceId
}
func (self *SMemcached) GetName() string {
return self.InstanceName
}
func (self *SMemcached) GetGlobalId() string {
return self.GetId()
}
func (self *SMemcached) GetStatus() string {
switch self.Status {
case 0:
return api.ELASTIC_CACHE_STATUS_DEPLOYING
case 1:
return api.ELASTIC_CACHE_STATUS_RUNNING
case 2:
return api.ELASTIC_CACHE_STATUS_CREATE_FAILED
case 4, 5, 6, 7:
return api.ELASTIC_CACHE_STATUS_RELEASING
default:
return fmt.Sprintf("%d", self.Status)
}
}
func (self *SMemcached) GetProjectId() string {
return strconv.Itoa(self.ProjectId)
}
func (self *SMemcached) GetBillingType() string {
// 计费模式:0-按量计费,1-包年包月
if self.PayMode == 1 {
return billing_api.BILLING_TYPE_PREPAID
} else {
return billing_api.BILLING_TYPE_POSTPAID
}
}
func (self *SMemcached) GetCreatedAt() time.Time {
return self.AddTimeStamp
}
func (self *SMemcached) GetExpiredAt() time.Time {
return time.Time{}
}
func (self *SMemcached) SetAutoRenew(bc billing.SBillingCycle) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) IsAutoRenew() bool {
return self.AutoRenewFlag == 1
}
func (self *SMemcached) GetInstanceType() string {
return ""
}
func (self *SMemcached) GetCapacityMB() int {
return 0
}
func (self *SMemcached) GetArchType() string {
return api.ELASTIC_CACHE_NODE_TYPE_SINGLE
}
func (self *SMemcached) GetNodeType() string {
return api.ELASTIC_CACHE_ARCH_TYPE_SINGLE
}
func (self *SMemcached) GetEngine() string {
return api.ELASTIC_CACHE_ENGINE_MEMCACHED
}
func (self *SMemcached) GetEngineVersion() string {
return "latest"
}
func (self *SMemcached) GetVpcId() string {
return self.UniqVpcId
}
func (self *SMemcached) GetZoneId() string {
return fmt.Sprintf("%s/%s-%d", self.region.GetGlobalId(), self.region.Region, self.ZoneId%10)
}
func (self *SMemcached) GetNetworkType() string {
if len(self.UniqSubnetId) > 0 {
return api.LB_NETWORK_TYPE_VPC
}
return api.LB_NETWORK_TYPE_CLASSIC
}
func (self *SMemcached) GetNetworkId() string {
return self.UniqSubnetId
}
func (self *SMemcached) GetPrivateDNS() string {
return ""
}
func (self *SMemcached) GetPrivateIpAddr() string {
return self.Vip
}
func (self *SMemcached) GetPrivateConnectPort() int {
return self.Vport
}
func (self *SMemcached) GetPublicDNS() string {
return ""
}
func (self *SMemcached) GetPublicIpAddr() string {
return ""
}
func (self *SMemcached) GetPublicConnectPort() int {
return 0
}
func (self *SMemcached) GetMaintainStartTime() string {
return ""
}
func (self *SMemcached) GetMaintainEndTime() string {
return ""
}
func (self *SMemcached) GetAuthMode() string {
return "off"
}
func (self *SMemcached) GetSecurityGroupIds() ([]string, error) {
return []string{}, nil
}
func (self *SMemcached) GetICloudElasticcacheAccounts() ([]cloudprovider.ICloudElasticcacheAccount, error) {
return []cloudprovider.ICloudElasticcacheAccount{}, nil
}
func (self *SMemcached) GetICloudElasticcacheAcls() ([]cloudprovider.ICloudElasticcacheAcl, error) {
return []cloudprovider.ICloudElasticcacheAcl{}, nil
}
func (self *SMemcached) GetICloudElasticcacheBackups() ([]cloudprovider.ICloudElasticcacheBackup, error) {
return []cloudprovider.ICloudElasticcacheBackup{}, nil
}
func (self *SMemcached) GetICloudElasticcacheParameters() ([]cloudprovider.ICloudElasticcacheParameter, error) {
return []cloudprovider.ICloudElasticcacheParameter{}, nil
}
func (self *SMemcached) GetICloudElasticcacheAccount(accountId string) (cloudprovider.ICloudElasticcacheAccount, error) {
return nil, cloudprovider.ErrNotFound
}
func (self *SMemcached) GetICloudElasticcacheAcl(aclId string) (cloudprovider.ICloudElasticcacheAcl, error) {
return nil, cloudprovider.ErrNotFound
}
func (self *SMemcached) GetICloudElasticcacheBackup(backupId string) (cloudprovider.ICloudElasticcacheBackup, error) {
return nil, cloudprovider.ErrNotFound
}
func (self *SMemcached) Restart() error {
return errors.Wrap(cloudprovider.ErrNotSupported, "Restart")
}
func (self *SMemcached) Delete() error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) CleanupInstance() error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) ChangeInstanceSpec(spec string) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) SetMaintainTime(maintainStartTime, maintainEndTime string) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) AllocatePublicConnection(port int) (string, error) {
return "", cloudprovider.ErrNotSupported
}
func (self *SMemcached) ReleasePublicConnection() error {
return errors.Wrap(cloudprovider.ErrNotSupported, "ReleasePublicConnection")
}
func (self *SMemcached) CreateAccount(account cloudprovider.SCloudElasticCacheAccountInput) (cloudprovider.ICloudElasticcacheAccount, error) {
return nil, cloudprovider.ErrNotSupported
}
func (self *SMemcached) CreateAcl(aclName, securityIps string) (cloudprovider.ICloudElasticcacheAcl, error) {
return nil, errors.Wrap(cloudprovider.ErrNotSupported, "CreateAcl")
}
func (self *SMemcached) CreateBackup(desc string) (cloudprovider.ICloudElasticcacheBackup, error) {
return nil, cloudprovider.ErrNotSupported
}
func (self *SMemcached) FlushInstance(input cloudprovider.SCloudElasticCacheFlushInstanceInput) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) UpdateAuthMode(noPasswordAccess bool, password string) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) UpdateInstanceParameters(config jsonutils.JSONObject) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) UpdateBackupPolicy(config cloudprovider.SCloudElasticCacheBackupPolicyUpdateInput) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) UpdateSecurityGroups(secgroupIds []string) error {
return cloudprovider.ErrNotSupported
}
func (self *SMemcached) Renew(bc billing.SBillingCycle) error {
return cloudprovider.ErrNotSupported
}
func (self *SRegion) GetMemcaches(ids []string, limit, offset int) ([]SMemcached, int, error) {
params := map[string]string{}
if limit <= 0 {
limit = 100
}
params["Limit"] = fmt.Sprintf("%d", limit)
params["Offset"] = fmt.Sprintf("%d", offset)
for i, id := range ids {
params[fmt.Sprintf("InstanceIds.%d", i)] = id
}
resp, err := self.memcachedRequest("DescribeInstances", params)
if err != nil {
return nil, 0, errors.Wrapf(err, "DescribeInstances")
}
ret := []SMemcached{}
err = resp.Unmarshal(&ret, "InstanceList")
if err != nil {
return nil, 0, errors.Wrapf(err, "resp.Unmarshal InstanceList")
}
total, _ := resp.Float("TotalCount")
return ret, int(total), nil
}