github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dds/v3/instances/Create.go (about) 1 package instances 2 3 import ( 4 "net/http" 5 6 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/internal/build" 8 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 9 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 10 ) 11 12 type CreateOpts struct { 13 // Specifies the DB instance name. Instance name, which can be the same as an existing name. 14 // 15 // The instance name must contain 4 to 64 characters and must start with a letter. It is case sensitive and can contain letters, digits, hyphens (-), and underscores (_). It cannot contain other special characters. 16 Name string `json:"name" required:"true"` 17 // Specifies the database information. 18 DataStore DataStore `json:"datastore" required:"true"` 19 // Specifies the region ID. 20 // The value cannot be empty. 21 Region string `json:"region" required:"true"` 22 // Specifies the AZ ID. You can select multiple AZs to create a cross-AZ cluster based on az_status returned by the API described in Querying Database Specifications. 23 AvailabilityZone string `json:"availability_zone" required:"true"` 24 // Specifies the VPC ID. 25 VpcId string `json:"vpc_id" required:"true"` 26 // Specifies the network ID of the subnet. 27 SubnetId string `json:"subnet_id" required:"true"` 28 // Specifies the security group ID. 29 SecurityGroupId string `json:"security_group_id" required:"true"` 30 // Database access port 31 // Value range: 2100-9500, 27017, 27018, and 27019. 32 // If this parameter is not transferred, the port of the created DB instance is 8635 by default. 33 Port string `json:"port,omitempty"` 34 // Specifies the database password. 35 // The value must be 8 to 32 characters in length and contain uppercase letters (A to Z), lowercase letters (a to z), digits (0 to 9), and special characters, such as ~!@#%^*-_=+? 36 // Enter a strong password to improve security, preventing security risks such as brute force cracking. 37 Password string `json:"password" required:"true"` 38 // Specifies the key ID used for disk encryption. The string must comply with UUID regular expression rules. 39 // If this parameter is not transferred, disk encryption is not performed. 40 DiskEncryptionId string `json:"disk_encryption_id,omitempty"` 41 // Specifies the instance type. Cluster, replica set, and single node instances are supported. 42 // 43 // Valid value: 44 // 45 // Sharding 46 // ReplicaSet 47 // Single 48 Mode string `json:"mode" required:"true"` 49 // Specifies the instance specifications. 50 Flavor []Flavor `json:"flavor" required:"true"` 51 // Specifies the advanced backup policy. 52 BackupStrategy BackupStrategy `json:"backup_strategy" required:"true"` 53 // Specifies whether to enable or disable SSL. 54 // 55 // Valid value: 56 // 57 // The value 0 indicates that SSL is disabled by default. 58 // The value 1 indicates that SSL is enabled by default. 59 // If this parameter is not transferred, SSL is enabled by default. 60 Ssl string `json:"ssl_option,omitempty"` 61 // Tag list 62 // A maximum of 20 tags can be added for each instance. 63 Tags []tags.ResourceTag `json:"tags,omitempty"` 64 } 65 66 type DataStore struct { 67 // Specifies the database type. The value is DDS-Community. 68 Type string `json:"type" required:"true"` 69 // Specifies the database version. Versions 4.2, 4.0, and 3.4 are supported. The value can be 4.2, 4.0, or 3.4. 70 Version string `json:"version" required:"true"` 71 // Specifies the storage engine. DDS supports the WiredTiger and RocksDB storage engines. 72 // 73 // If the database version is 4.2 and the storage engine is RocksDB, the value is rocksDB. 74 // If the database version is 4.0 or 3.4 and the storage engine is WiredTiger, the value is wiredTiger. 75 StorageEngine string `json:"storage_engine" required:"true"` 76 } 77 78 type Flavor struct { 79 // Specifies the node type. 80 // 81 // Valid value: 82 // 83 // For a cluster instance, the value can be mongos, shard, or config. 84 // For a replica set instance, the value is replica. 85 // For a single node instance, the value is single. 86 Type string `json:"type" required:"true"` 87 // Specifies node quantity. 88 // 89 // Valid value: 90 // 91 // mongos: The value ranges from 2 to 32. 92 // mongos: The value ranges from 2 to 32. 93 // config: The value is 1. 94 // replica: The number of nodes can be 3, 5, or 7. 95 // single: The value is 1. 96 Num int `json:"num" required:"true"` 97 // Specifies the disk type. 98 // 99 // Valid value: ULTRAHIGH, which indicates the type SSD. 100 // 101 // This parameter is valid for the shard and config nodes of a cluster instance, replica set instances, and single node instances. This parameter is invalid for mongos nodes. Therefore, you do not need to specify the storage space for mongos nodes. 102 Storage string `json:"storage,omitempty"` 103 // Specifies the disk size. 104 // 105 // This parameter is mandatory for all nodes except mongos. This parameter is invalid for the mongos nodes. 106 // 107 // The value must be a multiple of 10. The unit is GB. 108 // 109 // For a cluster instance, the storage space of a shard node can be 10 to 2000 GB, and the config storage space is 20 GB. This parameter is invalid for mongos nodes. Therefore, you do not need to specify the storage space for mongos nodes. 110 // For a replica set instance, the value ranges from 10 to 2000. 111 // For a single node instance, the value ranges from 10 to 1000. 112 Size int `json:"size,omitempty"` 113 // Specifies the resource specification code. For details about how to obtain the value, see the response values of spec_code in Querying Database Specifications. 114 // 115 // In a cluster instance, multiple specifications need to be specified. All specifications must be of the same series, that is, general-purpose (s6), enhanced (c3), or enhanced II (c6). 116 SpecCode string `json:"spec_code" required:"true"` 117 } 118 119 type BackupStrategy struct { 120 // Specifies the backup time window. Automated backups will be triggered during the backup time window. 121 // 122 // 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. 123 // 124 // The HH value must be 1 greater than the hh value. 125 // The values of mm and MM must be the same and must be set to 00. 126 // If this parameter is not transferred, the default backup time window is set to 00:00-01:00. 127 // Example value: 128 // 129 //23:00-00:00 130 StartTime string `json:"start_time" required:"true"` 131 // 132 // Specifies the number of days to retain the generated backup files. 133 // 134 // The value range is from 0 to 732. 135 // 136 // If this parameter is set to 0, the automated backup policy is not set. 137 // If this parameter is not transferred, the automated backup policy is enabled by default. Backup files are stored for seven days by default. 138 KeepDays int `json:"keep_days,omitempty"` 139 } 140 141 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*Instance, error) { 142 b, err := build.RequestBody(opts, "") 143 if err != nil { 144 return nil, err 145 } 146 147 // POST https://{Endpoint}/v3/{project_id}/instances 148 raw, err := client.Post(client.ServiceURL("instances"), b, nil, nil) 149 if err != nil { 150 return nil, err 151 } 152 153 return extra(err, raw) 154 } 155 156 func extra(err error, raw *http.Response) (*Instance, error) { 157 if err != nil { 158 return nil, err 159 } 160 161 var res Instance 162 err = extract.Into(raw.Body, &res) 163 return &res, err 164 } 165 166 type Instance struct { 167 // Indicates the DB instance ID. 168 Id string `json:"id"` 169 // Same as the request parameter. 170 Name string `json:"name"` 171 // Indicates the database information, which is the same as the request parameter. 172 DataStore DataStore `json:"datastore"` 173 // Indicates the creation time in the following format: yyyy-mm-dd hh:mm:ss. 174 CreatedAt string `json:"created"` 175 // Indicates the DB instance status. The value is creating. 176 Status string `json:"status"` 177 // Indicates the region ID, which is the same as the request parameter. 178 Region string `json:"region"` 179 // Indicates the AZ ID, which is the same as the request parameter. 180 AvailabilityZone string `json:"availability_zone"` 181 // Indicates the VPC ID, which is the same as the request parameter. 182 VpcId string `json:"vpc_id"` 183 // Indicates the network ID of the subnet, which is the same as the request parameter. 184 SubnetId string `json:"subnet_id"` 185 // Indicates the security group ID, which is the same as the request parameter. 186 SecurityGroupId string `json:"security_group_id"` 187 // Indicates the database port. 188 Port int `json:"port"` 189 // Indicates the ID of the disk encryption key, which is the same as the request parameter. 190 DiskEncryptionId string `json:"disk_encryption_id"` 191 // Indicates the instance type, which is the same as the request parameter. 192 Mode string `json:"mode"` 193 // Indicates the instance specification, which is the same as the request parameter. 194 Flavor []FlavorOpt `json:"flavor"` 195 // Indicates the advanced backup policy, which is the same as the request parameter. 196 BackupStrategy BackupStrategyOpt `json:"backup_strategy"` 197 // Indicates whether to enable SSL, which functions the same as the request parameter. 198 Ssl string `json:"ssl_option"` 199 // Indicates the ID of the workflow for creating a DB instance. 200 JobId string `json:"job_id"` 201 // Tag list, which is the same as the request parameter. 202 Tags []tags.ResourceTag `json:"tags"` 203 } 204 205 type FlavorOpt struct { 206 // Specifies the node type. 207 // 208 // Valid value: 209 // 210 // For a cluster instance, the value can be mongos, shard, or config. 211 // For a replica set instance, the value is replica. 212 // For a single node instance, the value is single. 213 Type string `json:"type" required:"true"` 214 // Specifies node quantity. 215 // 216 // Valid value: 217 // 218 // mongos: The value ranges from 2 to 32. 219 // mongos: The value ranges from 2 to 32. 220 // config: The value is 1. 221 // replica: The number of nodes can be 3, 5, or 7. 222 // single: The value is 1. 223 Num string `json:"num" required:"true"` 224 // 225 // Specifies the disk type. 226 // 227 // Valid value: ULTRAHIGH, which indicates the type SSD. 228 // 229 // This parameter is valid for the shard and config nodes of a cluster instance, replica set instances, and single node instances. This parameter is invalid for mongos nodes. Therefore, you do not need to specify the storage space for mongos nodes. 230 Storage string `json:"storage,omitempty"` 231 // Specifies the disk size. 232 // 233 // This parameter is mandatory for all nodes except mongos. This parameter is invalid for the mongos nodes. 234 // 235 // The value must be a multiple of 10. The unit is GB. 236 // 237 // For a cluster instance, the storage space of a shard node can be 10 to 2000 GB, and the config storage space is 20 GB. This parameter is invalid for mongos nodes. Therefore, you do not need to specify the storage space for mongos nodes. 238 // For a replica set instance, the value ranges from 10 to 2000. 239 // For a single node instance, the value ranges from 10 to 1000. 240 Size string `json:"size,omitempty"` 241 // Specifies the resource specification code. For details about how to obtain the value, see the response values of spec_code in Querying Database Specifications. 242 // 243 // In a cluster instance, multiple specifications need to be specified. All specifications must be of the same series, that is, general-purpose (s6), enhanced (c3), or enhanced II (c6). 244 SpecCode string `json:"spec_code" required:"true"` 245 } 246 247 type BackupStrategyOpt struct { 248 // Specifies the backup time window. Automated backups will be triggered during the backup time window. 249 // 250 // 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. 251 // 252 // The HH value must be 1 greater than the hh value. 253 // The values of mm and MM must be the same and must be set to 00. 254 // If this parameter is not transferred, the default backup time window is set to 00:00-01:00. 255 // Example value: 256 // 257 //23:00-00:00 258 StartTime string `json:"start_time" required:"true"` 259 // Specifies the number of days to retain the generated backup files. 260 // 261 // The value range is from 0 to 732. 262 // 263 // If this parameter is set to 0, the automated backup policy is not set. 264 // If this parameter is not transferred, the automated backup policy is enabled by default. Backup files are stored for seven days by default. 265 KeepDays string `json:"keep_days,omitempty"` 266 }