github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dcs/v1/instances/requests.go (about) 1 package instances 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // CreateOpsBuilder is used for creating instance parameters. 9 // any struct providing the parameters should implement this interface 10 type CreateOpsBuilder interface { 11 ToInstanceCreateMap() (map[string]interface{}, error) 12 } 13 14 // CreateOps is a struct that contains all the parameters. 15 type CreateOps struct { 16 // DCS instance name. 17 // An instance name is a string of 4–64 characters 18 // that contain letters, digits, underscores (_), and hyphens (-). 19 // An instance name must start with letters. 20 Name string `json:"name" required:"true"` 21 22 // Brief description of the DCS instance. 23 // A brief description supports up to 1024 characters. 24 Description string `json:"description,omitempty"` 25 26 // Cache engine, which is Redis or Memcached. 27 Engine string `json:"engine" required:"true"` 28 29 // Cache engine version, When the cache engine is Redis, the value is 3.0, 4.0 or 5.0. 30 EngineVersion string `json:"engine_version"` 31 32 // Cache capacity. Unit: GB. 33 // Indicates the message storage space. 34 // 35 // Redis 3.0: Stand-alone and active/standby type instance values: 2, 4, 8, 16, 32, 64. 36 // Proxy cluster instance specifications support 64, 128, 256, 512, and 1024. 37 // Redis4.0 and 5.0: Stand-alone and active/standby type instance values: 0.125, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64. 38 // Cluster instance specifications support 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024. 39 // Memcached: Stand-alone and active/standby type instance values: 2, 4, 8, 16, 32, 64. 40 Capacity float64 `json:"capacity" required:"true"` 41 42 // Indicate if no password visit cache instance is allowed. 43 NoPasswordAccess string `json:"no_password_access,omitempty"` 44 45 // Indicates the password of an instance. 46 // An instance password must meet the following complexity requirements: 47 48 // Password of a DCS instance. 49 // The password of a DCS Redis instance must meet 50 // the following complexity requirements: 51 // A string of 6–32 characters. 52 // Contains at least two of the following character types: 53 // Uppercase letters 54 // Lowercase letters 55 // Digits 56 // Special characters, such as `~!@#$%^&*()-_=+\|[{}]:'",<.>/? 57 Password string `json:"password,omitempty"` 58 59 // When NoPasswordAccess is flase, the AccessUser is enabled. 60 AccessUser string `json:"access_user,omitempty"` 61 62 // Tenant's VPC ID. 63 VPCID string `json:"vpc_id" required:"true"` 64 65 // Tenant's security group ID. 66 SecurityGroupID string `json:"security_group_id,omitempty"` 67 68 // Subnet ID. 69 SubnetID string `json:"subnet_id" required:"true"` 70 71 // IDs of the AZs where cache nodes reside. 72 // In the current version, only one AZ ID can be set in the request. 73 AvailableZones []string `json:"available_zones" required:"true"` 74 75 // Product ID used to differentiate DCS instance types. 76 ProductID string `json:"product_id" required:"true"` 77 78 // Backup policy. 79 // This parameter is available for master/standby DCS instances. 80 InstanceBackupPolicy *InstanceBackupPolicy `json:"instance_backup_policy,omitempty"` 81 82 // Indicates the time at which a maintenance time window starts. 83 // Format: HH:mm:ss 84 MaintainBegin string `json:"maintain_begin,omitempty"` 85 86 // Indicates the time at which a maintenance time window ends. 87 // Format: HH:mm:ss 88 MaintainEnd string `json:"maintain_end,omitempty"` 89 90 // Enterprise project id. 91 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 92 93 // Enterprise project name. 94 EnterpriseProjectName string `json:"enterprise_project_name,omitempty"` 95 } 96 97 // InstanceBackupPolicy for dcs 98 type InstanceBackupPolicy struct { 99 // Retention time. 100 // Unit: day. 101 // Range: 1–7. 102 SaveDays int `json:"save_days" required:"true"` 103 104 // Backup type. Options: 105 // auto: automatic backup. 106 // manual: manual backup. 107 BackupType string `json:"backup_type" required:"true"` 108 109 // Backup plan. 110 PeriodicalBackupPlan PeriodicalBackupPlan `json:"periodical_backup_plan" required:"true"` 111 } 112 113 // PeriodicalBackupPlan for dcs 114 type PeriodicalBackupPlan struct { 115 // Time at which backup starts. 116 // "00:00-01:00" indicates that backup starts at 00:00:00. 117 BeginAt string `json:"begin_at" required:"true"` 118 119 // Interval at which backup is performed. 120 // Currently, only weekly backup is supported. 121 PeriodType string `json:"period_type" required:"true"` 122 123 // Day in a week on which backup starts. 124 // Range: 1–7. Where: 1 indicates Monday; 7 indicates Sunday. 125 BackupAt []int `json:"backup_at" required:"true"` 126 } 127 128 type ListDcsInstanceOpts struct { 129 Id string `q:"id"` 130 Name string `q:"name"` 131 Type string `q:"type"` 132 DataStoreType string `q:"datastore_type"` 133 VpcId string `q:"vpc_id"` 134 SubnetId string `q:"subnet_id"` 135 Offset int `q:"offset"` 136 Limit int `q:"limit"` 137 } 138 139 type ListDcsBuilder interface { 140 ToDcsListDetailQuery() (string, error) 141 } 142 143 func (opts ListDcsInstanceOpts) ToDcsListDetailQuery() (string, error) { 144 q, err := golangsdk.BuildQueryString(opts) 145 if err != nil { 146 return "", err 147 } 148 return q.String(), err 149 } 150 151 // ToInstanceCreateMap is used for type convert 152 func (ops CreateOps) ToInstanceCreateMap() (map[string]interface{}, error) { 153 return golangsdk.BuildRequestBody(ops, "") 154 } 155 156 // Create an instance with given parameters. 157 func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResult) { 158 b, err := ops.ToInstanceCreateMap() 159 if err != nil { 160 r.Err = err 161 return 162 } 163 164 _, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{ 165 OkCodes: []int{200}, 166 }) 167 return 168 } 169 170 // Delete an instance by id 171 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 172 _, r.Err = client.Delete(deleteURL(client, id), nil) 173 return 174 } 175 176 //UpdateOptsBuilder is an interface which can build the map paramter of update function 177 type UpdateOptsBuilder interface { 178 ToInstanceUpdateMap() (map[string]interface{}, error) 179 } 180 181 //UpdateOpts is a struct which represents the parameters of update function 182 type UpdateOpts struct { 183 // DCS instance name. 184 // An instance name is a string of 4–64 characters 185 // that contain letters, digits, underscores (_), and hyphens (-). 186 // An instance name must start with letters. 187 Name string `json:"name,omitempty"` 188 189 // Brief description of the DCS instance. 190 // A brief description supports up to 1024 characters. 191 Description *string `json:"description,omitempty"` 192 193 // Backup policy. 194 // This parameter is available for master/standby DCS instances. 195 InstanceBackupPolicy *InstanceBackupPolicy `json:"instance_backup_policy,omitempty"` 196 197 // Time at which the maintenance time window starts. 198 // Format: HH:mm:ss 199 MaintainBegin string `json:"maintain_begin,omitempty"` 200 201 // Time at which the maintenance time window ends. 202 // Format: HH:mm:ss 203 MaintainEnd string `json:"maintain_end,omitempty"` 204 205 // Security group ID. 206 SecurityGroupID string `json:"security_group_id,omitempty"` 207 } 208 209 // ToInstanceUpdateMap is used for type convert 210 func (opts UpdateOpts) ToInstanceUpdateMap() (map[string]interface{}, error) { 211 return golangsdk.BuildRequestBody(opts, "") 212 } 213 214 // Update is a method which can be able to update the instance 215 // via accessing to the service with Put method and parameters 216 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 217 body, err := opts.ToInstanceUpdateMap() 218 if err != nil { 219 r.Err = err 220 return 221 } 222 223 _, r.Err = client.Put(updateURL(client, id), body, nil, &golangsdk.RequestOpts{ 224 OkCodes: []int{204}, 225 }) 226 return 227 } 228 229 // Get a instance with detailed information by id 230 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 231 _, r.Err = client.Get(getURL(client, id), &r.Body, nil) 232 return 233 } 234 235 //UpdatePasswordOptsBuilder is an interface which can build the map paramter of update password function 236 type UpdatePasswordOptsBuilder interface { 237 ToPasswordUpdateMap() (map[string]interface{}, error) 238 } 239 240 //UpdatePasswordOpts is a struct which represents the parameters of update function 241 type UpdatePasswordOpts struct { 242 // Old password. It may be empty. 243 OldPassword string `json:"old_password" required:"true"` 244 245 // New password. 246 // Password complexity requirements: 247 // A string of 6–32 characters. 248 // Must be different from the old password. 249 // Contains at least two types of the following characters: 250 // Uppercase letters 251 // Lowercase letters 252 // Digits 253 // Special characters `~!@#$%^&*()-_=+\|[{}]:'",<.>/? 254 NewPassword string `json:"new_password" required:"true"` 255 } 256 257 // ToPasswordUpdateMap is used for type convert 258 func (opts UpdatePasswordOpts) ToPasswordUpdateMap() (map[string]interface{}, error) { 259 return golangsdk.BuildRequestBody(opts, "") 260 } 261 262 // UpdatePassword is updating password for a dcs instance 263 func UpdatePassword(client *golangsdk.ServiceClient, id string, opts UpdatePasswordOptsBuilder) (r UpdatePasswordResult) { 264 265 body, err := opts.ToPasswordUpdateMap() 266 if err != nil { 267 r.Err = err 268 return 269 } 270 271 _, r.Err = client.Put(passwordURL(client, id), body, &r.Body, &golangsdk.RequestOpts{ 272 OkCodes: []int{200}, 273 }) 274 return 275 } 276 277 //ExtendOptsBuilder is an interface which can build the map paramter of extend function 278 type ExtendOptsBuilder interface { 279 ToExtendMap() (map[string]interface{}, error) 280 } 281 282 //ExtendOpts is a struct which represents the parameters of extend function 283 type ExtendOpts struct { 284 // New specifications (memory space) of the DCS instance. 285 // The new specification value to which the DCS instance 286 // will be scaled up must be greater than the current specification value. 287 // Unit: GB. 288 NewCapacity int `json:"new_capacity" required:"true"` 289 290 // New order ID. 291 OrderID string `json:"order_id,omitempty"` 292 } 293 294 // ToExtendMap is used for type convert 295 func (opts ExtendOpts) ToExtendMap() (map[string]interface{}, error) { 296 return golangsdk.BuildRequestBody(opts, "") 297 } 298 299 // Extend is extending for a dcs instance 300 func Extend(client *golangsdk.ServiceClient, id string, opts ExtendOptsBuilder) (r ExtendResult) { 301 302 body, err := opts.ToExtendMap() 303 if err != nil { 304 r.Err = err 305 return 306 } 307 308 _, r.Err = client.Post(extendURL(client, id), body, nil, &golangsdk.RequestOpts{ 309 OkCodes: []int{204}, 310 }) 311 return 312 } 313 314 func List(client *golangsdk.ServiceClient, opts ListDcsBuilder) pagination.Pager { 315 url := listURL(client) 316 if opts != nil { 317 query, err := opts.ToDcsListDetailQuery() 318 319 if err != nil { 320 return pagination.Pager{Err: err} 321 } 322 url += query 323 } 324 325 pageDcsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 326 return DcsPage{pagination.SinglePageBase(r)} 327 }) 328 329 dcsheader := map[string]string{"Content-Type": "application/json"} 330 pageDcsList.Headers = dcsheader 331 return pageDcsList 332 }