github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/rds/v3/configurations/Create.go (about)

     1  package configurations
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/openstack"
     8  )
     9  
    10  // CreateOpts contains all the values needed to create a new configuration.
    11  type CreateOpts struct {
    12  	// Specifies the parameter template name. It contains a maximum of 64 characters and can contain only uppercase letters, lowercase letters, digits, hyphens (-), underscores (_), and periods (.).
    13  	Name string `json:"name" required:"true"`
    14  	// Specifies the parameter template description. It contains a maximum of 256 characters and cannot contain the following special characters: >!<"&'= Its value is left blank by default.
    15  	Description string `json:"description,omitempty"`
    16  	// Specifies the parameter values defined by users based on the default parameter template. By default, the parameter values cannot be changed.
    17  	Values map[string]string `json:"values,omitempty"`
    18  	// Specifies the database object.
    19  	DataStore DataStore `json:"datastore" required:"true"`
    20  }
    21  
    22  type DataStore struct {
    23  	// Specifies the DB engine. Its value can be any of the following and is case-insensitive:
    24  	// MySQL
    25  	// PostgreSQL
    26  	// SQLServer
    27  	Type string `json:"type" required:"true"`
    28  	// Specifies the database version.
    29  	// Example values:
    30  	// MySQL: 8.0
    31  	// PostgreSQL: 13
    32  	// SQLServer: 2017_SE
    33  	Version string `json:"version" required:"true"`
    34  }
    35  
    36  // Create will create a new Config based on the values in CreateOpts.
    37  func Create(c *golangsdk.ServiceClient, opts CreateOpts) (*Configuration, error) {
    38  	b, err := build.RequestBody(opts, "")
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	// POST https://{Endpoint}/v3/{project_id}/configurations
    44  	raw, err := c.Post(c.ServiceURL("configurations"), b, nil, &golangsdk.RequestOpts{
    45  		OkCodes:     []int{200},
    46  		MoreHeaders: openstack.StdRequestOpts().MoreHeaders,
    47  	})
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  
    52  	var res Configuration
    53  	err = extract.IntoStructPtr(raw.Body, &res, "configuration")
    54  	return &res, err
    55  }