yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/dbinstance_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 aliyun
    16  
    17  import (
    18  	"yunion.io/x/pkg/errors"
    19  	"yunion.io/x/pkg/utils"
    20  )
    21  
    22  type SDBInstanceParameter struct {
    23  	instance *SDBInstance
    24  
    25  	ParameterDescription string
    26  	ParameterValue       string
    27  	ParameterName        string
    28  }
    29  
    30  func (param *SDBInstanceParameter) GetGlobalId() string {
    31  	return param.ParameterName
    32  }
    33  
    34  func (param *SDBInstanceParameter) GetKey() string {
    35  	return param.ParameterName
    36  }
    37  
    38  func (param *SDBInstanceParameter) GetValue() string {
    39  	return param.ParameterValue
    40  }
    41  
    42  func (param *SDBInstanceParameter) GetDescription() string {
    43  	return param.ParameterDescription
    44  }
    45  
    46  func (region *SRegion) GetDBInstanceParameters(instanceId string) ([]SDBInstanceParameter, error) {
    47  	params := map[string]string{
    48  		"RegionId":     region.RegionId,
    49  		"DBInstanceId": instanceId,
    50  		"ClientToken":  utils.GenRequestId(20),
    51  	}
    52  
    53  	body, err := region.rdsRequest("DescribeParameters", params)
    54  	if err != nil {
    55  		return nil, errors.Wrapf(err, "DescribeParameters")
    56  	}
    57  	parameters1 := []SDBInstanceParameter{}
    58  	err = body.Unmarshal(&parameters1, "ConfigParameters", "DBInstanceParameter")
    59  	if err != nil {
    60  		return nil, errors.Wrap(err, "Unmarshal.ConfigParameters")
    61  	}
    62  	parameters2 := []SDBInstanceParameter{}
    63  	err = body.Unmarshal(&parameters1, "RunningParameters", "DBInstanceParameter")
    64  	if err != nil {
    65  		return nil, errors.Wrap(err, "Unmarshal.RunningParameters")
    66  	}
    67  	return append(parameters1, parameters2...), nil
    68  }