github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/rds/v3/configurations/requests.go (about)

     1  package configurations
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
     8  	MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
     9  }
    10  
    11  // CreateOptsBuilder allows extensions to add additional parameters to the
    12  // Create request.
    13  type CreateOptsBuilder interface {
    14  	ToConfigCreateMap() (map[string]interface{}, error)
    15  }
    16  
    17  // CreateOpts contains all the values needed to create a new configuration.
    18  type CreateOpts struct {
    19  	//Configuration Name
    20  	Name string `json:"name" required:"true"`
    21  	//Configuration Description
    22  	Description string `json:"description,omitempty"`
    23  	//Configuration Values
    24  	Values map[string]string `json:"values,omitempty"`
    25  	//Database Object
    26  	DataStore DataStore `json:"datastore" required:"true"`
    27  }
    28  
    29  type DataStore struct {
    30  	//DB Engine
    31  	Type string `json:"type" required:"true"`
    32  	//DB version
    33  	Version string `json:"version" required:"true"`
    34  }
    35  
    36  // ToConfigCreateMap builds a create request body from CreateOpts.
    37  func (opts CreateOpts) ToConfigCreateMap() (map[string]interface{}, error) {
    38  	return golangsdk.BuildRequestBody(opts, "")
    39  }
    40  
    41  // Create will create a new Config based on the values in CreateOpts.
    42  func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    43  	b, err := opts.ToConfigCreateMap()
    44  	if err != nil {
    45  		r.Err = err
    46  		return
    47  	}
    48  	_, r.Err = c.Post(rootURL(c), b, &r.Body, &golangsdk.RequestOpts{
    49  		OkCodes:     []int{200},
    50  		MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
    51  	})
    52  	return
    53  }
    54  
    55  // UpdateOptsBuilder allows extensions to add additional parameters to the
    56  // Update request.
    57  type UpdateOptsBuilder interface {
    58  	ToConfigUpdateMap() (map[string]interface{}, error)
    59  }
    60  
    61  // UpdateOpts contains all the values needed to update a Configuration.
    62  type UpdateOpts struct {
    63  	//Configuration Name
    64  	Name string `json:"name,omitempty"`
    65  	//Configuration Description
    66  	Description string `json:"description,omitempty"`
    67  	//Configuration Values
    68  	Values map[string]string `json:"values,omitempty"`
    69  }
    70  
    71  // ToConfigUpdateMap builds a update request body from UpdateOpts.
    72  func (opts UpdateOpts) ToConfigUpdateMap() (map[string]interface{}, error) {
    73  	return golangsdk.BuildRequestBody(opts, "")
    74  }
    75  
    76  // Update accepts a UpdateOpts struct and uses the values to update a Configuration.The response code from api is 200
    77  func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
    78  	b, err := opts.ToConfigUpdateMap()
    79  	if err != nil {
    80  		r.Err = err
    81  		return
    82  	}
    83  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200},
    84  		MoreHeaders: RequestOpts.MoreHeaders}
    85  	_, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt)
    86  	return
    87  }
    88  
    89  // Get retrieves a particular Configuration based on its unique ID.
    90  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    91  	_, r.Err = c.Get(resourceURL(c, id), &r.Body, &golangsdk.RequestOpts{
    92  		MoreHeaders: RequestOpts.MoreHeaders,
    93  	})
    94  	return
    95  }
    96  
    97  // Delete will permanently delete a particular Configuration based on its unique ID.
    98  func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
    99  	reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200},
   100  		MoreHeaders: RequestOpts.MoreHeaders}
   101  	_, r.Err = c.Delete(resourceURL(c, id), reqOpt)
   102  	return
   103  }