github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/gaussdb/v3/instance/CreateInstance.go (about)

     1  package instance
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateInstanceOpts struct {
    10  	// Billing mode
    11  	ChargeInfo *ChargeInfo `json:"charge_info,omitempty"`
    12  	// Region ID The value cannot be empty. To obtain this value, see Regions and Endpoints.
    13  	Region string `json:"region" required:"true"`
    14  	// Instance name Instances of the same type can have same names under the same tenant.
    15  	// The name consists of 4 to 64 characters and starts with a letter.
    16  	// It is case-sensitive and can contain only letters, digits, hyphens (-), and underscores (_).
    17  	Name string `json:"name" required:"true"`
    18  	// Database information
    19  	Datastore Datastore `json:"datastore" required:"true"`
    20  	// Instance type, which is case-insensitive. Currently, its value can only be Cluster.
    21  	Mode string `json:"mode" required:"true"`
    22  	// Specification code. For details, see Querying Database Specifications.
    23  	FlavorRef string `json:"flavor_ref" required:"true"`
    24  	// VPC ID. To obtain this value, use either of the following methods:
    25  	// Method 1: Log in to the VPC console and view the VPC ID on the VPC details page.
    26  	// Method 2: See section "Querying VPCs" in the Virtual Private Cloud API Reference.
    27  	VpcId string `json:"vpc_id" required:"true"`
    28  	// Network ID of the subnet. To obtain this value, use either of the following methods:
    29  	// Method 1: Log in to the VPC console and click the target subnet on the Subnets page to view the network ID on the displayed page.
    30  	// Method 2: See section "Querying Subnets" in the Virtual Private Cloud API Reference.
    31  	SubnetId string `json:"subnet_id" required:"true"`
    32  	// Security group ID If the network ACL is enabled for the subnet used by the created instance, this parameter is optional.
    33  	// If the network ACL is not enabled, this parameter is mandatory.
    34  	// Method 1: Log in to VPC console. Choose Access Control > Security Groups in the navigation pane on the left.
    35  	// On the displayed page, click the target security group. You can view the security group ID on the displayed page.
    36  	// Method 2: See section "Querying Security Groups" in the Virtual Private Cloud API Reference.
    37  	SecurityGroupId string `json:"security_group_id,omitempty"`
    38  	// Parameter template ID
    39  	ConfigurationId string `json:"configuration_id,omitempty"`
    40  	// Database password. Value range: The password consists of 8 to 32 characters and contains at least three types of the following:
    41  	// uppercase letters, lowercase letters, digits, and special characters (~!@#%^*-_=+?).
    42  	// Enter a strong password to improve security, preventing security risks such as brute force cracking.
    43  	// If you enter a weak password, the system automatically determines that the password is invalid.
    44  	Password string `json:"password" required:"true"`
    45  	// Automated backup policy
    46  	BackupStrategy *BackupStrategy `json:"backup_strategy,omitempty"`
    47  	// UTC time zone. l If this parameter is not specified, UTC is used by default.
    48  	// If this parameter is specified, the value ranges from UTC-12:00 to UTC+12:00 at the full hour.
    49  	// For example, the parameter can be UTC+08:00 rather than UTC+08:30.
    50  	TimeZone string `json:"time_zone,omitempty"`
    51  	// AZ type. The value can be Single or multi.
    52  	AvailabilityZoneMode string `json:"availability_zone_mode"`
    53  	// Primary AZ
    54  	MasterAvailabilityZone string `json:"master_availability_zone,omitempty"`
    55  	// Number of created read replicas. The value ranges from 1 to 9. An instance contains up to 15 read replicas.
    56  	SlaveCount *int `json:"slave_count"`
    57  	// Volume information.
    58  	// Missing in documentation
    59  	Volume *MysqlVolume `json:"volume,omitempty"`
    60  	// Tag list. Instances are created based on tag keys and values.
    61  	// {key} indicates the tag key. It must be unique and cannot be empty.
    62  	// {value} indicates the tag value, which can be empty. To create instances with multiple tag keys and values,
    63  	// separate key-value pairs with commas (,). Up to 10 key-value pairs can be added.
    64  	Tags []MysqlTags `json:"tags,omitempty"`
    65  	// Dedicated resource pool ID. This parameter can be displayed only after the dedicated resource pool is enabled.
    66  	DedicatedResourceId string `json:"dedicated_resource_id,omitempty"`
    67  }
    68  
    69  type MysqlVolume struct {
    70  	// Storage space. The default value is 40 in GB.
    71  	// The value ranges from 40 GB to 128,000 GB and must be a multiple of 10.
    72  	Size string `json:"size"`
    73  }
    74  
    75  type MysqlTags struct {
    76  	// Tag key. The value can contain up to 36 unicode characters. The value cannot be an empty string, a space, or left blank.
    77  	// Only uppercase letters, lowercase letters, digits, hyphens (-), and underscores (_) are allowed.
    78  	Key string `json:"key"`
    79  	// Tag value. It contains up to 43 Unicode characters. The value can be an empty string.
    80  	// Only uppercase letters, lowercase letters, digits, periods (.), hyphens (-), and underscores (_) are allowed.
    81  	Value string `json:"value"`
    82  }
    83  
    84  func CreateInstance(client *golangsdk.ServiceClient, opts CreateInstanceOpts) (*CreateInstanceResponse, error) {
    85  	b, err := build.RequestBody(opts, "")
    86  	if err != nil {
    87  		return nil, err
    88  	}
    89  
    90  	// POST https://{Endpoint}/mysql/v3/{project_id}/instances
    91  	raw, err := client.Post(client.ServiceURL("instances"), b, nil, nil)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  
    96  	var res CreateInstanceResponse
    97  	err = extract.Into(raw.Body, &res)
    98  	return &res, err
    99  }
   100  
   101  type CreateInstanceResponse struct {
   102  	// Instance information
   103  	Instance InstResponse `json:"instance"`
   104  	// Instance creation task ID This parameter is returned only for the creation of pay-per-use instances.
   105  	JobId string `json:"job_id"`
   106  }
   107  
   108  type InstResponse struct {
   109  	// Instance ID
   110  	Id string `json:"id"`
   111  	// Instance name. Instances of the same type can have same names under the same tenant.
   112  	// The name consists of 4 to 64 characters and starts with a letter.
   113  	// It is case-insensitive and contains only letters, digits, hyphens (-), and underscores (_).
   114  	Name string `json:"name"`
   115  	// Instance status Value: creating.
   116  	Status string `json:"status"`
   117  	// Database information
   118  	Datastore Datastore `json:"datastore"`
   119  	// Instance type. Currently, only the cluster type is supported.
   120  	Mode string `json:"mode"`
   121  	// Parameter template ID.
   122  	ConfigurationId string `json:"configuration_id"`
   123  	// Database port, which is the same as the request parameter.
   124  	Port string `json:"port"`
   125  	// Automated backup policy
   126  	BackupStrategy BackupStrategy `json:"backup_strategy"`
   127  	// Region ID, which is the same as the request parameter.
   128  	Region string `json:"region"`
   129  	// AZ mode, which is the same as the request parameter.
   130  	AvailabilityZoneMode string `json:"availability_zone_mode"`
   131  	// Primary AZ ID.
   132  	MasterAvailabilityZone string `json:"master_availability_zone"`
   133  	// VPC ID, which is the same as the request parameter.
   134  	VpcId string `json:"vpc_id"`
   135  	// Security group ID, which is the same as the request parameter.
   136  	SecurityGroupId string `json:"security_group_id"`
   137  	// Subnet ID, which is the same as the request parameter.
   138  	SubnetId string `json:"subnet_id"`
   139  	// Specification code, which is the same as the request parameter.
   140  	FlavorRef string `json:"flavor_ref"`
   141  	// Billing mode, which is yearly/monthly or pay-per-use (default setting).
   142  	ChargeInfo ChargeInfo `json:"charge_info"`
   143  }
   144  
   145  type Datastore struct {
   146  	// DB engine. Currently, only gaussdb-mysql is supported.
   147  	Type string `json:"type" required:"true"`
   148  	// DB engine version For details about supported database versions, see Querying Version Information About a DB Engine.
   149  	Version string `json:"version" required:"true"`
   150  }
   151  
   152  type BackupStrategy struct {
   153  	// Automated backup start time. The automated backup will be triggered within one hour after the time specified by this parameter.
   154  	// The value cannot be empty. It must be a valid value in the "hh:mm-HH:MM" format. The current time is in the UTC format.
   155  	// The HH value must be 1 greater than the hh value.
   156  	// The values of mm and MM must be the same and must be set to 00.
   157  	// Example value: 21:00-22:00
   158  	StartTime string `json:"start_time"`
   159  	// Automated backup retention days. The value ranges from 1 to 732.
   160  	KeepDays string `json:"keep_days,omitempty"`
   161  }
   162  
   163  type ChargeInfo struct {
   164  	// Billing mode. Value: postPaid
   165  	ChargeMode string `json:"charge_mode"`
   166  	// Order ID
   167  	OrderId string `json:"order_id"`
   168  }