yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/elasticcache_backup.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package huawei 16 17 import ( 18 "time" 19 20 "yunion.io/x/jsonutils" 21 "yunion.io/x/pkg/errors" 22 23 api "yunion.io/x/cloudmux/pkg/apis/compute" 24 "yunion.io/x/cloudmux/pkg/cloudprovider" 25 "yunion.io/x/cloudmux/pkg/multicloud" 26 ) 27 28 // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423035.html 29 type SElasticcacheBackup struct { 30 multicloud.SElasticcacheBackupBase 31 HuaweiTags 32 33 cacheDB *SElasticcache 34 35 Status string `json:"status"` 36 Remark string `json:"remark"` 37 Period string `json:"period"` 38 Progress string `json:"progress"` 39 SizeByte int64 `json:"size"` 40 InstanceID string `json:"instance_id"` 41 BackupID string `json:"backup_id"` 42 CreatedAt time.Time `json:"created_at"` 43 UpdatedAt time.Time `json:"updated_at"` 44 ExecutionAt time.Time `json:"execution_at"` 45 BackupType string `json:"backup_type"` 46 BackupName string `json:"backup_name"` 47 ErrorCode string `json:"error_code"` 48 IsSupportRestore string `json:"is_support_restore"` 49 } 50 51 func (self *SElasticcacheBackup) GetId() string { 52 return self.BackupID 53 } 54 55 func (self *SElasticcacheBackup) GetName() string { 56 return self.BackupName 57 } 58 59 func (self *SElasticcacheBackup) GetGlobalId() string { 60 return self.GetId() 61 } 62 63 func (self *SElasticcacheBackup) Refresh() error { 64 cache, err := self.cacheDB.GetICloudElasticcacheBackup(self.GetId()) 65 if err != nil { 66 return errors.Wrap(err, "ElasticcacheBackup.Refresh.GetICloudElasticcacheBackup") 67 } 68 69 err = jsonutils.Update(self, cache) 70 if err != nil { 71 return errors.Wrap(err, "ElasticcacheBackup.Refresh.Update") 72 } 73 74 return nil 75 } 76 77 func (self *SElasticcacheBackup) GetStatus() string { 78 switch self.Status { 79 case "waiting", "backuping": 80 return api.ELASTIC_CACHE_BACKUP_STATUS_CREATING 81 case "succeed": 82 return api.ELASTIC_CACHE_BACKUP_STATUS_SUCCESS 83 case "failed": 84 return api.ELASTIC_CACHE_BACKUP_STATUS_FAILED 85 case "expired": 86 return api.ELASTIC_CACHE_BACKUP_STATUS_CREATE_EXPIRED 87 case "deleted": 88 return api.ELASTIC_CACHE_BACKUP_STATUS_CREATE_DELETED 89 default: 90 return self.Status 91 } 92 } 93 94 func (self *SElasticcacheBackup) GetBackupSizeMb() int { 95 return int(self.SizeByte / 1024 / 1024) 96 } 97 98 func (self *SElasticcacheBackup) GetBackupType() string { 99 switch self.BackupType { 100 case "manual": 101 return api.ELASTIC_CACHE_BACKUP_MODE_MANUAL 102 case "auto": 103 return api.ELASTIC_CACHE_BACKUP_MODE_AUTOMATED 104 default: 105 return self.BackupType 106 } 107 108 } 109 110 func (self *SElasticcacheBackup) GetBackupMode() string { 111 return "" 112 } 113 114 func (self *SElasticcacheBackup) GetDownloadURL() string { 115 return "" 116 } 117 118 func (self *SElasticcacheBackup) GetStartTime() time.Time { 119 return self.CreatedAt 120 } 121 122 func (self *SElasticcacheBackup) GetEndTime() time.Time { 123 return self.UpdatedAt 124 } 125 126 func (self *SElasticcacheBackup) Delete() error { 127 return cloudprovider.ErrNotSupported 128 } 129 130 // https://support.huaweicloud.com/api-dcs/dcs-zh-api-180423034.html 131 func (self *SElasticcacheBackup) RestoreInstance(instanceId string) error { 132 _, err := self.cacheDB.region.ecsClient.Elasticcache.RestoreInstance(instanceId, self.GetId()) 133 if err != nil { 134 return nil 135 } 136 137 return nil 138 }