Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,12 @@ func NewWAFV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*gol
return sc, err
}

// NewRDSV3 creates a ServiceClient that may be used to access the RDS service.
func NewRDSV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "rdsv3")
return sc, err
}

func NewSDKClient(c *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, serviceType string) (*golangsdk.ServiceClient, error) {
switch serviceType {
case "mls":
Expand Down
101 changes: 101 additions & 0 deletions openstack/rds/v3/configurations/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package configurations

import (
"github.com/huaweicloud/golangsdk"
)

var RequestOpts golangsdk.RequestOpts = golangsdk.RequestOpts{
MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"},
}

// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToConfigCreateMap() (map[string]interface{}, error)
}

// CreateOpts contains all the values needed to create a new configuration.
type CreateOpts struct {
//Configuration Name
Name string `json:"name" required:"true"`
//Configuration Description
Description string `json:"description,omitempty"`
//Configuration Values
Values map[string]string `json:"values,omitempty"`
//Database Object
DataStore DataStore `json:"datastore" required:"true"`
}

type DataStore struct {
//DB Engine
Type string `json:"type" required:"true"`
//DB version
Version string `json:"version" required:"true"`
}

// ToConfigCreateMap builds a create request body from CreateOpts.
func (opts CreateOpts) ToConfigCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

// Create will create a new Config based on the values in CreateOpts.
func Create(c *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToConfigCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = c.Post(rootURL(c), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders, JSONBody: nil,
})
return
}

// UpdateOptsBuilder allows extensions to add additional parameters to the
// Update request.
type UpdateOptsBuilder interface {
ToConfigUpdateMap() (map[string]interface{}, error)
}

// UpdateOpts contains all the values needed to update a Configuration.
type UpdateOpts struct {
//Configuration Name
Name string `json:"name,omitempty"`
//Configuration Description
Description string `json:"description,omitempty"`
//Configuration Values
Values map[string]string `json:"values,omitempty"`
}

// ToConfigUpdateMap builds a update request body from UpdateOpts.
func (opts UpdateOpts) ToConfigUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "")
}

// Update accepts a UpdateOpts struct and uses the values to update a Configuration.The response code from api is 200
func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToConfigUpdateMap()
if err != nil {
r.Err = err
return
}
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders}
_, r.Err = c.Put(resourceURL(c, id), b, nil, reqOpt)
return
}

// Get retrieves a particular Configuration based on its unique ID.
func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = c.Get(resourceURL(c, id), &r.Body, &RequestOpts)
return
}

// Delete will permanently delete a particular Configuration based on its unique ID.
func Delete(c *golangsdk.ServiceClient, id string) (r DeleteResult) {
reqOpt := &golangsdk.RequestOpts{OkCodes: []int{200},
MoreHeaders: RequestOpts.MoreHeaders}
_, r.Err = c.Delete(resourceURL(c, id), reqOpt)
return
}
91 changes: 91 additions & 0 deletions openstack/rds/v3/configurations/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package configurations

import (
"github.com/huaweicloud/golangsdk"
)

type ConfigurationCreate struct {
//Configuration ID
Id string `json:"id"`
//Configuration Name
Name string `json:"name"`
//Database version Name
DatastoreVersionName string `json:"datastore_version_name"`
//Database Name
DatastoreName string `json:"datastore_name"`
//Configuration Description
Description string `json:"description"`
}

type Configuration struct {
//Configuration ID
Id string `json:"id"`
//Configuration Name
Name string `json:"name"`
//Database version Name
DatastoreVersionName string `json:"datastore_version_name"`
//Database Name
DatastoreName string `json:"datastore_name"`
//Configuration Description
Description string `json:"description"`
//Configuration Parameters
Parameters []Parameter `json:"configuration_parameters"`
}

type Parameter struct {
//Parameter Name
Name string `json:"name"`
//Parameter value
Value string `json:"value"`
//Whether a restart is required
RestartRequired bool `json:"restart_required"`
//Whether the parameter is read-only
ReadOnly bool `json:"readonly"`
//Parameter value range
ValueRange string `json:"value_range"`
//Parameter type
Type string `json:"type"`
//Parameter description
Description string `json:"description"`
}

// Extract is a function that accepts a result and extracts a configuration.
func (r CreateResult) Extract() (*ConfigurationCreate, error) {
var response ConfigurationCreate
err := r.ExtractInto(&response)
return &response, err
}

func (r CreateResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "configuration")
}

// CreateResult represents the result of a create operation. Call its Extract
// method to interpret it as a Configuration.
type CreateResult struct {
golangsdk.Result
}

// UpdateResult represents the result of a update operation.
type UpdateResult struct {
golangsdk.ErrResult
}

// Extract is a function that accepts a result and extracts a configuration.
func (r GetResult) Extract() (*Configuration, error) {
var response Configuration
err := r.ExtractInto(&response)
return &response, err
}

// GetResult represents the result of a get operation. Call its Extract
// method to interpret it as a Configuration.
type GetResult struct {
golangsdk.Result
}

// DeleteResult represents the result of a delete operation. Call its ExtractErr
// method to determine if the request succeeded or failed.
type DeleteResult struct {
golangsdk.ErrResult
}
11 changes: 11 additions & 0 deletions openstack/rds/v3/configurations/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package configurations

import "github.com/huaweicloud/golangsdk"

func rootURL(c *golangsdk.ServiceClient) string {
return c.ServiceURL("configurations")
}

func resourceURL(c *golangsdk.ServiceClient, id string) string {
return c.ServiceURL("configurations", id)
}