yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/elasticache_parameter.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 aws 16 17 import ( 18 "fmt" 19 20 "github.com/aws/aws-sdk-go/service/elasticache" 21 22 "yunion.io/x/pkg/errors" 23 24 api "yunion.io/x/cloudmux/pkg/apis/compute" 25 "yunion.io/x/cloudmux/pkg/multicloud" 26 ) 27 28 func (region *SRegion) DescribeCacheParameters(parameterGroupId string) ([]*elasticache.Parameter, error) { 29 ecClient, err := region.getAwsElasticacheClient() 30 if err != nil { 31 return nil, errors.Wrap(err, "client.getAwsElasticacheClient") 32 } 33 34 input := elasticache.DescribeCacheParametersInput{} 35 if len(parameterGroupId) > 0 { 36 input.CacheParameterGroupName = ¶meterGroupId 37 } 38 39 marker := "" 40 maxrecords := (int64)(50) 41 input.MaxRecords = &maxrecords 42 43 parameters := []*elasticache.Parameter{} 44 for { 45 if len(marker) >= 0 { 46 input.Marker = &marker 47 } 48 out, err := ecClient.DescribeCacheParameters(&input) 49 if err != nil { 50 return nil, errors.Wrap(err, "ecClient.DescribeCacheParameters") 51 } 52 parameters = append(parameters, out.Parameters...) 53 54 if out.Marker != nil && len(*out.Marker) > 0 { 55 marker = *out.Marker 56 } else { 57 break 58 } 59 } 60 61 return parameters, nil 62 } 63 64 type SElasticacheParameter struct { 65 multicloud.SElasticcacheParameterBase 66 AwsTags 67 parameterGroup string 68 parameter *elasticache.Parameter 69 } 70 71 func (self *SElasticacheParameter) GetId() string { 72 return fmt.Sprintf("%s/%s", self.parameterGroup, *self.parameter.ParameterName) 73 } 74 75 func (self *SElasticacheParameter) GetName() string { 76 return *self.parameter.ParameterName 77 } 78 79 func (self *SElasticacheParameter) GetGlobalId() string { 80 return self.GetId() 81 } 82 83 func (self *SElasticacheParameter) GetStatus() string { 84 return api.ELASTIC_CACHE_PARAMETER_STATUS_AVAILABLE 85 } 86 87 func (self *SElasticacheParameter) GetParameterKey() string { 88 if self.parameter == nil || self.parameter.ParameterName == nil { 89 return "" 90 } 91 return *self.parameter.ParameterName 92 } 93 94 func (self *SElasticacheParameter) GetParameterValue() string { 95 if self.parameter == nil || self.parameter.ParameterValue == nil { 96 return "" 97 } 98 return *self.parameter.ParameterValue 99 } 100 101 func (self *SElasticacheParameter) GetParameterValueRange() string { 102 if self.parameter == nil || self.parameter.AllowedValues == nil { 103 return "" 104 } 105 return *self.parameter.AllowedValues 106 } 107 108 func (self *SElasticacheParameter) GetDescription() string { 109 if self.parameter == nil || self.parameter.Description == nil { 110 return "" 111 } 112 return *self.parameter.Description 113 } 114 115 func (self *SElasticacheParameter) GetModifiable() bool { 116 if self.parameter == nil || self.parameter.IsModifiable == nil { 117 return *self.parameter.IsModifiable 118 } 119 return false 120 } 121 122 func (self *SElasticacheParameter) GetForceRestart() bool { 123 if self.parameter == nil || self.parameter.ChangeType == nil { 124 return false 125 } 126 if *self.parameter.ChangeType == "requires-reboot" { 127 return true 128 } 129 return false 130 }