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

     1  package instances
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/opentelekomcloud/gophertelekomcloud"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     9  )
    10  
    11  type CreateReplicaOpts struct {
    12  	// Specifies the DB instance name.
    13  	// DB instances of the same type can have same names under the same tenant.
    14  	// The value must be 4 to 64 characters in length and start with a letter. It is case-sensitive and can contain only letters, digits, hyphens (-), and underscores (_).
    15  	Name string `json:"name"  required:"true"`
    16  	// Specifies the DB instance ID, which is used to create a read replica.
    17  	ReplicaOfId string `json:"replica_of_id" required:"true"`
    18  	// Specifies the key ID for disk encryption. The default value is empty.
    19  	EnterpriseProjectId string `json:"enterprise_project_id,omitempty"`
    20  	// Specifies the key ID for disk encryption. The default value is empty.
    21  	DiskEncryptionId string `json:"disk_encryption_id,omitempty"`
    22  	// Specifies the specification code. The value cannot be empty.
    23  	FlavorRef string `json:"flavor_ref" required:"true"`
    24  	// Specifies the volume information.
    25  	Volume *Volume `json:"volume" required:"true"`
    26  	// Specifies the region ID. Currently, read replicas can be created only in the same region as that of the primary DB instance.
    27  	// The value cannot be empty.
    28  	Region string `json:"region"`
    29  	// Specifies the AZ ID.
    30  	AvailabilityZone string `json:"availability_zone" required:"true"`
    31  	// Specifies the billing information, which is pay-per-use. By default, pay-per-use is used.
    32  	ChargeInfo *ChargeInfo `json:"charge_info,omitempty"`
    33  }
    34  
    35  type Volume struct {
    36  	// Indicates the volume type.
    37  	// Its value can be any of the following and is case-sensitive:
    38  	// COMMON: indicates the SATA type.
    39  	// ULTRAHIGH: indicates the SSD type.
    40  	Type string `json:"type" required:"true"`
    41  	// Indicates the volume size.
    42  	// Its value range is from 40 GB to 4000 GB. The value must be a multiple of 10.
    43  	Size int `json:"size,omitempty"`
    44  }
    45  
    46  type ChargeInfo struct {
    47  	// Indicates the billing information, which is pay-per-use.
    48  	ChargeMode string `json:"charge_mode" required:"true"`
    49  
    50  	PeriodType  string `json:"period_type,omitempty"`
    51  	PeriodNum   int    `json:"period_num,omitempty"`
    52  	IsAutoRenew string `json:"is_auto_renew,omitempty"`
    53  	IsAutoPay   string `json:"is_auto_pay,omitempty"`
    54  }
    55  
    56  // CreateReplica (Only Microsoft SQL Server 2017 EE supports read replicas and does not support single DB instances.)
    57  func CreateReplica(client *golangsdk.ServiceClient, opts CreateReplicaOpts) (*CreateRds, error) {
    58  	b, err := build.RequestBody(opts, "")
    59  	if err != nil {
    60  		return nil, err
    61  	}
    62  
    63  	raw, err := client.Post(client.ServiceURL("instances"), b, nil, &golangsdk.RequestOpts{
    64  		OkCodes: []int{202},
    65  	})
    66  	return extra(err, raw)
    67  }
    68  
    69  func extra(err error, raw *http.Response) (*CreateRds, error) {
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  
    74  	var res CreateRds
    75  	err = extract.Into(raw.Body, &res)
    76  	return &res, err
    77  }