diff --git a/openstack/gaussdbnosql/v3/ListDatastores.go b/openstack/gaussdbnosql/v3/ListDatastores.go new file mode 100644 index 000000000..d661b729a --- /dev/null +++ b/openstack/gaussdbnosql/v3/ListDatastores.go @@ -0,0 +1,18 @@ +package v3 + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ListDatastores(client *golangsdk.ServiceClient, datastoreName string) ([]string, error) { + // GET https://{Endpoint}/v3/{project_id}/datastores/{datastore_name}/versions + raw, err := client.Get(client.ServiceURL("datastores", datastoreName, "versions"), nil, nil) + if err != nil { + return nil, err + } + + var res []string + err = extract.IntoSlicePtr(raw.Body, &res, "versions") + return res, err +} diff --git a/openstack/gaussdbnosql/v3/ListFlavors.go b/openstack/gaussdbnosql/v3/ListFlavors.go new file mode 100644 index 000000000..6fd9884be --- /dev/null +++ b/openstack/gaussdbnosql/v3/ListFlavors.go @@ -0,0 +1,67 @@ +package v3 + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListFlavorsOpts struct { + // Region where the instance is deployed. + // Valid value: + // The value cannot be empty. For details about how to obtain this parameter value, see Regions and Endpoints. + Region string `q:"region"` + // engine_name No Database type + // If the value is cassandra, the GaussDB(for Cassandra) DB instance specifications are queried, + // If this parameter is not transferred, the default value is cassandra. + EngineName string `q:"engine_name,omitempty"` +} + +func ListFlavors(client *golangsdk.ServiceClient, opts ListFlavorsOpts) (*ListFlavorsResponse, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return nil, err + } + + // GET https://{Endpoint}/v3/{project_id}/flavors + raw, err := client.Get(client.ServiceURL("flavors")+q.String(), nil, nil) + if err != nil { + return nil, err + } + + var res ListFlavorsResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ListFlavorsResponse struct { + // Total number of records + TotalCount int32 `json:"total_count"` + // Instance specifications. + Flavors []ListFlavorsResult `json:"flavors"` +} + +type ListFlavorsResult struct { + // Engine name + EngineName string `json:"engine_name"` + // Engine version + EngineVersion string `json:"engine_version"` + // Number of vCPUs + Vcpus string `json:"vcpus"` + // Memory size in megabytes (MB) + Ram string `json:"ram"` + // Resource specification code + // Example: geminidb.cassandra.8xlarge.4 + // NOTE + // geminidb.cassandra indicates GaussDB(for Cassandra). + // 8xlarge.4 indicates the single-node specifications. + SpecCode string `json:"spec_code"` + // ID of the AZ that supports this specification + // NOTE + // This field is discarded and cannot be used. + AvailabilityZone []string `json:"availability_zone"` + // Status of specifications in an AZ. The value can be: + // normal: indicates that the specifications are on sale. + // unsupported: not supported. + // sellout: indicates that the instance specifications are sold out. + AzStatus string `json:"az_status"` +} diff --git a/openstack/gaussdbnosql/v3/ListSlowLogs.go b/openstack/gaussdbnosql/v3/ListSlowLogs.go new file mode 100644 index 000000000..31e8c20e5 --- /dev/null +++ b/openstack/gaussdbnosql/v3/ListSlowLogs.go @@ -0,0 +1,63 @@ +package v3 + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListSlowLogsOpts struct { + // Instance ID + InstanceId string `q:"instance_id"` + // Start time in the "yyyy-mm-ddThh:mm:ssZ" format. + StartDate string `q:"start_date"` + // End time in the "yyyy-mm-ddThh:mm:ssZ" format. + EndDate string `q:"end_date"` + // Node ID. If this parameter is left blank, all nodes of the instance are queried. + NodeId string `q:"node_id,omitempty"` + // Statement type. If this parameter is left empty, all statement types are queried. + // You can also specify the following log type: + // SELECT + Type string `q:"type,omitempty"` + // Index offset. Its value range is [0, 1999]. + // If offset is set to N, the resource query starts from the N+1 piece of data. The value is 0 by default, + // indicating that the query starts from the first piece of data. The value must be a positive number. + Offset int32 `q:"offset,omitempty"` + // Number of records to be queried. The value ranges from 1 (inclusive) to 100 (inclusive). + // The sum of values of limit and offset must be less than or equal to 2000. + Limit int32 `q:"limit,omitempty"` +} + +func ListSlowLogs(client *golangsdk.ServiceClient, opts ListSlowLogsOpts) (*ListSlowLogsResponse, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return nil, err + } + + // GET https://{Endpoint}/v3/{project_id}/instances/{instance_id}/slowlog + raw, err := client.Get(client.ServiceURL("instances", opts.InstanceId, "slowlog")+q.String(), nil, nil) + if err != nil { + return nil, err + } + + var res ListSlowLogsResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ListSlowLogsResponse struct { + SlowLogList []SlowlogResult `json:"slow_log_listq"` + TotalRecord int32 `json:"total_recordq"` +} + +type SlowlogResult struct { + // Execution time + Time string `json:"time"` + // Database which slow logs belong to + Database string `json:"database"` + // Execution syntax + QuerySample string `json:"query_sample"` + // Statement type + Type string `json:"type"` + // Time in the UTC format + StartTime string `json:"start_time"` +} diff --git a/openstack/gaussdbnosql/v3/backup/SetBackupPolicy.go b/openstack/gaussdbnosql/v3/backup/SetBackupPolicy.go new file mode 100644 index 000000000..6ac41e2f5 --- /dev/null +++ b/openstack/gaussdbnosql/v3/backup/SetBackupPolicy.go @@ -0,0 +1,46 @@ +package backup + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type SetBackupPolicyOpts struct { + InstanceId string + // Backup policy object, which includes the backup retention period (days) and start time. + BackupPolicy BackupPolicy `json:"backup_policy"` +} + +type BackupPolicy struct { + // Backup retention days. Value range: 0-35. The value 0 indicates that the automated backup policy is disabled. + KeepDays int32 `json:"keep_days"` + // Backup time window. Automated backups will be triggered during the backup time window. + // This parameter is mandatory if the automated backup policy is enabled. + // This parameter is not transferred if the automated backup policy is disabled. + // The value must be a valid value in the "hh:mm-HH:MM" format. The current time is in the UTC format. + // The HH value must be 1 greater than the hh value. + // The values of mm and MM must be the same and must be set to any of the following: 00, 15, 30, and 45. + // If this parameter is not transferred, the default backup time window is from 00:00 to 01:00. + // Example value: 23:00-00:00 + StartTime string `json:"start_time,omitempty"` + // Backup cycle configuration. Data will be automatically backed up on the selected days every week. + // Value range: The value is a number separated by DBS case commas (,). The number indicates the week. + // The restrictions on the backup retention period are as follows: + // This parameter is not transferred if its value is set to 0. + // If you set the retention period to 1 to 6 days, data is automatically backed up each day of the week. + // Set the parameter value to 1,2,3,4,5,6,7. + // If you set the retention period to 7 to 732 days, select at least one day of the week for the backup cycle. + // Example value: 1,2,3,4 + Period string `json:"period,omitempty"` +} + +func SetBackupPolicy(client *golangsdk.ServiceClient, opts SetBackupPolicyOpts) (err error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return + } + + // PUT https://{Endpoint}/v3/{project_id}/instances/{instance_id}/backups/policy + _, err = client.Put(client.ServiceURL("instances", opts.InstanceId, "backups", "policy"), b, nil, nil) + return +} diff --git a/openstack/gaussdbnosql/v3/backup/ShowBackupPolicy.go b/openstack/gaussdbnosql/v3/backup/ShowBackupPolicy.go new file mode 100644 index 000000000..d3fddb732 --- /dev/null +++ b/openstack/gaussdbnosql/v3/backup/ShowBackupPolicy.go @@ -0,0 +1,27 @@ +package backup + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowBackupPolicy(client *golangsdk.ServiceClient, instanceId string) (*ShowBackupPolicyResult, error) { + // GET https://{Endpoint}/v3/{project_id}/instances/{instance_id}/backups/policy + raw, err := client.Get(client.ServiceURL("instances", instanceId, "backups", "policy"), nil, nil) + if err != nil { + return nil, err + } + + var res ShowBackupPolicyResult + err = extract.IntoStructPtr(raw.Body, &res, "backup_policy") + return &res, err +} + +type ShowBackupPolicyResult struct { + // Backup retention days + KeepDays int32 `json:"keep_days"` + // Backup time window. Automated backups will be triggered during the backup time window. + StartTime string `json:"start_time"` + // Backup cycle configuration. Data will be automatically backed up on the selected days every week. + Period string `json:"period"` +} diff --git a/openstack/gaussdbnosql/v3/instance/CreateInstance.go b/openstack/gaussdbnosql/v3/instance/CreateInstance.go new file mode 100644 index 000000000..ce395740b --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/CreateInstance.go @@ -0,0 +1,143 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type CreateInstanceOpts struct { + // Instance name, which can be the same as an existing instance name. + // Value range: + // The value must be 4 to 64 characters in length and start with a letter (from A to Z or from a to z). + // It is case-sensitive and can contain only letters, digits (from 0 to 9), hyphens (-), and underscores (_). + Name string `json:"name"` + // Database information. + Datastore Datastore `json:"datastore"` + // Region ID + // The value cannot be empty. + Region string `json:"region"` + // AZ ID + // For details about the value, see az_status returned in 5.3 Querying All Instance Specifications. + // Separate multiple AZs by commas (,). + AvailabilityZone string `json:"availability_zone"` + // VPC ID. To obtain this parameter value, use either of the following methods: + // Method 1: Log in to VPC console and view the VPC ID on the VPC details page. + // Method 2: See the "Querying VPCs" section in the Virtual Private Cloud API Reference. + VpcId string `json:"vpc_id"` + // Network ID of the subnet. To obtain this parameter value, use either of the following methods: + // Method 1: Log in to VPC console and click the target subnet on the Subnets page. You can view the subnet ID on the displayed page. + // Method 2: See the "Querying Subnets" section in the Virtual Private Cloud API Reference. + SubnetId string `json:"subnet_id"` + // Security group ID. To obtain the security group ID, perform either of the following methods: + // Method 1: Log in to VPC console. Choose Access Control > Security Groups in the navigation pane on the left. + // On the displayed page, click the target security group. You can view the security group ID on the displayed page. + // Method 2: See the "Querying Security Groups" section in the Virtual Private Cloud API Reference. + SecurityGroupId string `json:"security_group_id"` + // Database password + // 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 ~!@#%^*-_=+? + // You are advised to enter a strong password to improve security, preventing security risks such as brute force cracking. + Password string `json:"password"` + // Instance type + // GaussDB(for Cassandra) supports the cluster type. The value is "Cluster". + Mode string `json:"mode"` + // Instance specifications + Flavor []InstanceFlavor `json:"flavor"` + // Parameter template ID + ConfigurationId string `json:"configuration_id,omitempty"` + // Advanced backup policy. + BackupStrategy BackupStrategy `json:"backup_strategy,omitempty"` + // Specifies whether to enable or disable SSL. + // Valid value: + // The value "0" indicates that SSL is disabled by default. + // The value "1" indicates that SSL is enabled by default. + // If this parameter is not transferred, SSL is disabled by default. + SslOption string `json:"ssl_option,omitempty"` +} + +func CreateInstance(client *golangsdk.ServiceClient, opts CreateInstanceOpts) (*CreateInstanceResponse, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return nil, err + } + + // POST https://{Endpoint}/v3/{project_id}/instances + raw, err := client.Post(client.ServiceURL("instances"), b, nil, nil) + if err != nil { + return nil, err + } + + var res CreateInstanceResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type CreateInstanceResponse struct { + // Instance ID + Id string `json:"id"` + // Database information, which is the same as the request parameter. + Datastore Datastore `json:"datastore"` + // Instance name, which is the same as the request parameter. + Name string `json:"name"` + // Creation time, which is in the yyyy-mm-dd hh:mm:ss format. + Created string `json:"created"` + // Instance status. The value is creating. + Status string `json:"status"` + // Region ID, which is the same as the request parameter. + Region string `json:"region"` + // AZ ID, which is the same as the request parameter. + AvailabilityZone string `json:"availability_zone"` + // VPC ID, which is the same as the request parameter. + VpcId string `json:"vpc_id"` + // Network ID of the subnet, which is the same as the request parameter. + SubnetId string `json:"subnet_id"` + // Security group ID, which is the same as the request parameter. + SecurityGroupId string `json:"security_group_id"` + // Instance type, which is the same as the request parameter. + Mode string `json:"mode"` + // Instance specification, which is the same as the request parameter. + Flavor []InstanceFlavor `json:"flavor"` + // Advanced backup policy, which is the same as the request parameter. + BackupStrategy BackupStrategy `json:"backup_strategy"` + // Indicates whether to enable SSL, which functions the same as the request parameter. + SslOption string `json:"ssl_option"` + // ID of the job for creating an instance. + JobId string `json:"job_id"` +} + +type Datastore struct { + // Database type + // GaussDB(for Cassandra) instances are supported. + // The value "cassandra" indicates that a GaussDB(for Cassandra) DB instance is created. + Type string `json:"type"` + // Database version + // The value "3.11" indicates that the GaussDB(for Cassandra) 3.11 is supported. + Version string `json:"version"` + // Storage engine + // The value "rocksDB" indicates that the GaussDB(for Cassandra) instance supports the RocksDB storage engine. + StorageEngine string `json:"storage_engine"` +} + +type InstanceFlavor struct { + // Node quantity + // The number of GaussDB(for Cassandra) instance nodes ranges from 3 to 200. + Num string `json:"num"` + // Disk type + // Valid value: ULTRAHIGH, which indicates the SSD disk. + Storage string `json:"storage"` + // Storage space. The value must be an integer, in GB. + Size string `json:"size"` + // Resource specification code + SpecCode string `json:"spec_code"` +} + +type BackupStrategy struct { + // Backup time window Automated backups will be triggered during the backup time window. + // 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. + StartTime string `json:"start_time"` + // Number of days to retain the generated backup files. + // Value range: 0-35. + KeepDays string `json:"keep_days,omitempty"` +} diff --git a/openstack/gaussdbnosql/v3/instance/DeleteInstance.go b/openstack/gaussdbnosql/v3/instance/DeleteInstance.go new file mode 100644 index 000000000..082626e82 --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/DeleteInstance.go @@ -0,0 +1,26 @@ +package instance + +import ( + "net/http" + + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func DeleteInstance(client *golangsdk.ServiceClient, instanceId string) (string, error) { + // DELETE https://{Endpoint}/v3/{project_id}/instances/{instance_id} + raw, err := client.Delete(client.ServiceURL("instances", instanceId), nil) + return extraJob(err, raw) +} + +func extraJob(err error, raw *http.Response) (string, error) { + if err != nil { + return "", err + } + + var res struct { + JobId string `json:"job_id"` + } + err = extract.Into(raw.Body, &res) + return res.JobId, err +} diff --git a/openstack/gaussdbnosql/v3/instance/ExpandInstanceNode.go b/openstack/gaussdbnosql/v3/instance/ExpandInstanceNode.go new file mode 100644 index 000000000..cf2307524 --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/ExpandInstanceNode.go @@ -0,0 +1,23 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type ExpandInstanceNodeOpts struct { + InstanceId string + // Number of new nodes + Num int32 `json:"num"` +} + +func ExpandInstanceNode(client *golangsdk.ServiceClient, opts ExpandInstanceNodeOpts) (string, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return "", err + } + + // POST https://{Endpoint}/v3/{project_id}/instances/{instance_id}/enlarge-node + raw, err := client.Post(client.ServiceURL("instances", opts.InstanceId, "enlarge-node"), b, nil, nil) + return extraJob(err, raw) +} diff --git a/openstack/gaussdbnosql/v3/instance/ListInstances.go b/openstack/gaussdbnosql/v3/instance/ListInstances.go new file mode 100644 index 000000000..25187be1b --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/ListInstances.go @@ -0,0 +1,168 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListInstancesOpts struct { + // Instance ID + // If you use asterisk (*) at the beginning of the id, fuzzy search results are returned. + // Otherwise, the exact results are returned. + Id string `q:"id,omitempty"` + // Instance name + // If you use asterisk (*) at the beginning of the name, fuzzy search results are returned. + // Otherwise, the exact results are returned. + Name string `q:"name,omitempty"` + // Instance type + // Cluster indicates the GaussDB(for Cassandra) cluster instance. + // If the datastore_type parameter is not transferred, this parameter is automatically ignored. + Mode string `q:"mode,omitempty"` + // Database type + // If the value is cassandra, GaussDB(for Cassandra) DB instances are queried. + // If this parameter is not transferred, all DB instances are queried. + DatastoreType string `q:"datastore_type,omitempty"` + // VPC ID. To obtain this parameter value, use either of the following methods: + // Method 1: Log in to VPC console and view the VPC ID on the VPC details page. + // Method 2: See the "Querying VPCs" section in the Virtual Private Cloud API Reference. + VpcId string `q:"vpc_id,omitempty"` + // Network ID of the subnet. To obtain this parameter value, use either of the following methods: + // Method 1: Log in to VPC console and click the target subnet on the Subnets page. You can view the subnet ID on the displayed page. + // Method 2: See the "Querying Subnets" section in the Virtual Private Cloud API Reference. + SubnetId string `q:"subnet_id,omitempty"` + // Index position. The query starts from the next instance creation time indexed by this parameter under a specified project. + // If offset is set to N, the resource query starts from the N+1 piece of data + // The value must be greater than or equal to 0. If this parameter is not transferred, + // offset is set to 0 by default, indicating that the query starts from the latest created instance. + Offset int32 `q:"offset,omitempty"` + // The maximum allowed number of instances. + // The value ranges from 1 to 100. If this parameter is not transferred, the first 100 instances are queried by default. + Limit int32 `q:"limit,omitempty"` +} + +func ListInstances(client *golangsdk.ServiceClient, opts ListInstancesOpts) (*ListInstancesResponse, error) { + q, err := golangsdk.BuildQueryString(opts) + if err != nil { + return nil, err + } + + // GET https://{Endpoint}/v3/{project_id}/instances + raw, err := client.Get(client.ServiceURL("instances")+q.String(), nil, nil) + if err != nil { + return nil, err + } + + var res ListInstancesResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ListInstancesResponse struct { + Instances []ListInstancesResult `json:"instances"` + TotalCount int32 `json:"total_count"` +} + +type ListInstancesResult struct { + // Instance ID + Id string `json:"id"` + // Instance name + Name string `json:"name"` + // Instance status + // Valid value: + // normal: indicates that the instance is running properly. + // abnormal: indicates that the instance is abnormal. + // creating: indicates that the instance is being created. + // data_disk_full: indicates that the instance disk is full. + // createfail: indicates that the instance failed to be created. + // enlargefail: indicates that nodes failed to be added to the instance. + Status string `json:"status"` + // Database port + Port string `json:"port"` + // Instance type, which is the same as the request parameter. + Mode string `json:"mode"` + // Region where the instance is deployed. + Region string `json:"region"` + // Database information. + Datastore InstancesDatastore `json:"datastore"` + // Storage engine + // The value is "rocksDB". + Engine string `json:"engine"` + // Instance creation time + Created string `json:"created"` + // The time when an instance is updated. + Updated string `json:"updated"` + // Default username. The value is rwuser. + DbUserName string `json:"db_user_name"` + // VPC ID + VpcId string `json:"vpc_id"` + // Subnet ID + SubnetId string `json:"subnet_id"` + // Security group ID + SecurityGroupId string `json:"security_group_id"` + // Backup policy. + BackupStrategy InstancesBackupStrategy `json:"backup_strategy"` + // The value is set to "0". + PayMode string `json:"pay_mode"` + // Maintenance time window + MaintenanceWindow string `json:"maintenance_window"` + // Group information. + Groups []InstancesGroup `json:"groups"` + // Time zone + TimeZone string `json:"time_zone"` + // The operation that is executed on the instance. + Actions []string `json:"actions"` +} + +type InstancesDatastore struct { + // Database type + Type string `json:"type"` + // Database version + Version string `json:"version"` +} + +type InstancesBackupStrategy struct { + // Backup time window. Automated backups will be triggered during the backup time window. The current time is the UTC time. + StartTime string `json:"start_time"` + // Backup retention days. Value range: 0-35. + KeepDays int32 `json:"keep_days"` +} + +type InstancesGroup struct { + // Group ID + Id string `json:"id"` + // Group status + Status string `json:"status"` + // Volume information. + Volume Volume `json:"volume"` + // Node information + Nodes []InstancesNode `json:"nodes"` +} + +type Volume struct { + // Storage space. Unit: GB + Size string `json:"size"` + // Storage space usage. Unit: GB + Used string `json:"used"` +} + +type InstancesNode struct { + // Node ID + Id string `json:"id"` + // Node name + Name string `json:"name"` + // Node status + Status string `json:"status"` + // Private IP address of a node. This parameter value exists after the ECS is created. Otherwise, the value is "". + PrivateIp string `json:"private_ip"` + // Bound EIP. This parameter is valid only for nodes bound with EIPs. + PublicIp string `json:"public_ip"` + // Resource specification code + // For details, see the value of the flavors.spec_code parameter in 5.3 Querying All Instance Specifications. + SpecCode string `json:"spec_code"` + // AvailabilityZone + AvailabilityZone string `json:"availability_zone"` + // Whether scaling in instances is supported. + // true: indicates that the node scale-in is supported. + // false: indicates that the node scale-in is not supported. + SupportReduce bool `json:"support_reduce"` +} diff --git a/openstack/gaussdbnosql/v3/instance/ResetPassword.go b/openstack/gaussdbnosql/v3/instance/ResetPassword.go new file mode 100644 index 000000000..b0ca6b0fc --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/ResetPassword.go @@ -0,0 +1,26 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type ResetPasswordOpts struct { + InstanceId string + // Database password + // 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 ~!@#%^*-_=+? + // You are advised to enter a strong password to improve security, preventing security risks such as brute force cracking. + Password string `json:"password"` +} + +func ResetPassword(client *golangsdk.ServiceClient, opts ResetPasswordOpts) (err error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return + } + + // PUT https://{Endpoint}/v3/{project_id}/instances/{instance_id}/password + _, err = client.Put(client.ServiceURL("instances", opts.InstanceId, "password"), b, nil, nil) + return +} diff --git a/openstack/gaussdbnosql/v3/instance/ResizeInstance.go b/openstack/gaussdbnosql/v3/instance/ResizeInstance.go new file mode 100644 index 000000000..bc0304fcd --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/ResizeInstance.go @@ -0,0 +1,27 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type ResizeInstanceOpts struct { + InstanceId string + Resize ResizeInstanceOption `json:"resize"` +} + +type ResizeInstanceOption struct { + // Resource specification code of the new specification + TargetSpecCode string `json:"target_spec_code"` +} + +func ResizeInstance(client *golangsdk.ServiceClient, opts ResizeInstanceOpts) (string, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return "", err + } + + // PUT https://{Endpoint}/v3/{project_id}/instances/{instance_id}/resize + raw, err := client.Put(client.ServiceURL("instances", opts.InstanceId, "resize"), b, nil, nil) + return extraJob(err, raw) +} diff --git a/openstack/gaussdbnosql/v3/instance/ResizeInstanceVolume.go b/openstack/gaussdbnosql/v3/instance/ResizeInstanceVolume.go new file mode 100644 index 000000000..7a777311b --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/ResizeInstanceVolume.go @@ -0,0 +1,24 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type ResizeInstanceVolumeOpts struct { + InstanceId string + // The requested disk capacity. The value must be an integer greater than the current disk capacity. + // The maximum disk capacity depends on the engine type and specifications. + Size int32 `json:"size"` +} + +func ResizeInstanceVolume(client *golangsdk.ServiceClient, opts ResizeInstanceVolumeOpts) (string, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return "", err + } + + // POST https://{Endpoint}/v3/{project_id}/instances/{instance_id}/extend-volume + raw, err := client.Post(client.ServiceURL("instances", opts.InstanceId, "extend-volume"), b, nil, nil) + return extraJob(err, raw) +} diff --git a/openstack/gaussdbnosql/v3/instance/ShrinkInstanceNode.go b/openstack/gaussdbnosql/v3/instance/ShrinkInstanceNode.go new file mode 100644 index 000000000..4dd4e71a3 --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/ShrinkInstanceNode.go @@ -0,0 +1,36 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type ShrinkInstanceNodeOpts struct { + InstanceId string + // The number of nodes that are reduced randomly. + // The value is 1. + // NOTE + // If the client is directly connected to a node, you are not advised to delete nodes randomly. + Num int32 `json:"num,omitempty"` + // The ID of the node to be deleted. The node must support scale-in. If this parameter is not transferred, the number of nodes to be deleted is specified based on the internal policy of the system. + // NOTE + // Either num or node_list must be set. + // If num is transferred, the value must be 1. + // If node_list is transferred, the value must be 1. + // If the values of num and node_list are transferred at the same time, the value of node_list is used. + // If the value of node_list is empty, scale-in is performed on random nodes. + // If the value of node_list is not empty, the scale-in is performed based on the specified node ID. + // Before scale-in, do not directly connect a node to prevent service interruption caused by scale-in. + NodeList []string `json:"node_list,omitempty"` +} + +func ShrinkInstanceNode(client *golangsdk.ServiceClient, opts ShrinkInstanceNodeOpts) (string, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return "", err + } + + // POST https://{Endpoint}/v3/{project_id}/instances/{instance_id}/reduce-node + raw, err := client.Post(client.ServiceURL("instances", opts.InstanceId, "reduce-node"), b, nil, nil) + return extraJob(err, raw) +} diff --git a/openstack/gaussdbnosql/v3/instance/UpdateInstanceName.go b/openstack/gaussdbnosql/v3/instance/UpdateInstanceName.go new file mode 100644 index 000000000..463b3bded --- /dev/null +++ b/openstack/gaussdbnosql/v3/instance/UpdateInstanceName.go @@ -0,0 +1,26 @@ +package instance + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type UpdateInstanceNameOpts struct { + InstanceId string + // New instance name + // Value range: + // The value must be 4 to 64 characters in length and start with a letter (from A to Z or from a to z). + // It is case-sensitive and can contain only letters, digits (from 0 to 9), hyphens (-), and underscores (_). + Name string `json:"name"` +} + +func UpdateInstanceName(client *golangsdk.ServiceClient, opts UpdateInstanceNameOpts) (err error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return + } + + // PUT https://{Endpoint}/v3/{project_id}/instances/{instance_id}/name + _, err = client.Put(client.ServiceURL("instances", opts.InstanceId, "name"), b, nil, nil) + return +} diff --git a/openstack/gaussdbnosql/v3/parameter/ApplyConfiguration.go b/openstack/gaussdbnosql/v3/parameter/ApplyConfiguration.go new file mode 100644 index 000000000..b3f4a01f3 --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/ApplyConfiguration.go @@ -0,0 +1,40 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ApplyConfigurationRequest struct { + // Parameter template ID + ConfigId string + // Instance IDs + InstanceIds []string `json:"instance_ids"` +} + +func ApplyConfiguration(client *golangsdk.ServiceClient, opts UpdateConfigurationOpts) (*ApplyConfigurationResponse, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return nil, err + } + + // PUT https://{Endpoint}/v3/{project_id}/configurations/{config_id}/apply + raw, err := client.Put(client.ServiceURL("configurations", opts.ConfigId, "apply"), b, nil, nil) + if err != nil { + return nil, err + } + + var res ApplyConfigurationResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ApplyConfigurationResponse struct { + // Asynchronous task ID of the application parameter template + JobId string `json:"job_id,omitempty"` + // Whether the parameter template application task is successfully submitted. + // If the value is true, the task is successfully submitted. + // If the value is false, the task fails to be submitted. + Success bool `json:"success,omitempty"` +} diff --git a/openstack/gaussdbnosql/v3/parameter/CreateConfiguration.go b/openstack/gaussdbnosql/v3/parameter/CreateConfiguration.go new file mode 100644 index 000000000..dd9b42b0c --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/CreateConfiguration.go @@ -0,0 +1,62 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type CreateConfigurationOpts struct { + // Parameter template name. It contains a maximum of 64 characters and can contain only uppercase letters, + // lowercase letters, digits, hyphens (-), underscores (_), and periods (.). + Name string `json:"name"` + // Parameter template description. It contains a maximum of 256 characters except the following special characters: + // >!<"&'= The value is left blank by default. + Description string `json:"description,omitempty"` + // Database object. + Datastore ConfigurationDatastore `json:"datastore"` + // The parameter values defined by users based on the default parameter template. + // By default, the parameter values cannot be changed. + Values map[string]string `json:"values,omitempty"` +} + +type ConfigurationDatastore struct { + // Database type. For GaussDB(for Cassandra), the value is "cassandra". + Type string `json:"type"` + // Database version The value 3.11 indicates that GaussDB(for Cassandra) 3.11 is supported. + Version string `json:"version"` +} + +func CreateInstance(client *golangsdk.ServiceClient, opts CreateConfigurationOpts) (*CreateConfigurationResult, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return nil, err + } + + // POST https://{Endpoint}/v3/{project_id}/configurations + raw, err := client.Post(client.ServiceURL("configurations"), b, nil, nil) + if err != nil { + return nil, err + } + + var res CreateConfigurationResult + err = extract.IntoStructPtr(raw.Body, &res, "configuration") + return &res, err +} + +type CreateConfigurationResult struct { + // Parameter template ID + Id string `json:"id"` + // Parameter template name + Name string `json:"name"` + // Parameter template description. + Description string `json:"description,omitempty"` + // DB version name + DatastoreVersionName string `json:"datastore_version_name"` + // Database name + DatastoreName string `json:"datastore_name"` + // Creation time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Created string `json:"created"` + // Update time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Updated string `json:"updated"` +} diff --git a/openstack/gaussdbnosql/v3/parameter/DeleteConfiguration.go b/openstack/gaussdbnosql/v3/parameter/DeleteConfiguration.go new file mode 100644 index 000000000..a12ad155e --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/DeleteConfiguration.go @@ -0,0 +1,9 @@ +package parameter + +import golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + +func DeleteConfiguration(client *golangsdk.ServiceClient, configId string) (err error) { + // DELETE https://{Endpoint}/v3/{project_id}/configurations/{config_id} + _, err = client.Delete(client.ServiceURL("configurations", configId), nil) + return +} diff --git a/openstack/gaussdbnosql/v3/parameter/ListConfigurations.go b/openstack/gaussdbnosql/v3/parameter/ListConfigurations.go new file mode 100644 index 000000000..bbf3e1049 --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/ListConfigurations.go @@ -0,0 +1,46 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ListConfigurations(client *golangsdk.ServiceClient) (*ListConfigurationsResponse, error) { + // GET https://{Endpoint}/v3/{project_id}/configurations + raw, err := client.Get(client.ServiceURL("configurations"), nil, nil) + if err != nil { + return nil, err + } + + var res ListConfigurationsResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ListConfigurationsResponse struct { + // Total number of queried records + Count int32 `json:"count,omitempty"` + // Parameter templates + Configurations []ListConfigurationsResult `json:"configurations,omitempty"` +} + +type ListConfigurationsResult struct { + // Parameter template ID + Id string `json:"id"` + // Parameter template name + Name string `json:"name"` + // Parameter template description + Description *string `json:"description,omitempty"` + // DB version name + DatastoreVersionName string `json:"datastore_version_name"` + // Database name + DatastoreName string `json:"datastore_name"` + // Creation time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Created string `json:"created"` + // Update time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Updated string `json:"updated"` + // Whether the parameter template is a custom template. + // false: The parameter template is a default parameter template. + // true: The parameter template is a custom template. + UserDefined bool `json:"user_defined"` +} diff --git a/openstack/gaussdbnosql/v3/parameter/ShowConfigurationDetail.go b/openstack/gaussdbnosql/v3/parameter/ShowConfigurationDetail.go new file mode 100644 index 000000000..204690e2d --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/ShowConfigurationDetail.go @@ -0,0 +1,37 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowConfigurationDetail(client *golangsdk.ServiceClient, configId string) (*ShowConfigurationDetailResponse, error) { + // GET https://{Endpoint}/v3/{project_id}/configurations/{config_id} + raw, err := client.Get(client.ServiceURL("configurations", configId), nil, nil) + if err != nil { + return nil, err + } + + var res ShowConfigurationDetailResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ShowConfigurationDetailResponse struct { + // Parameter template ID + Id string `json:"id,omitempty"` + // Parameter template name + Name string `json:"name,omitempty"` + // Parameter template description + Description string `json:"description,omitempty"` + // DB version name + DatastoreVersionName string `json:"datastore_version_name,omitempty"` + // Database name + DatastoreName string `json:"datastore_name,omitempty"` + // Creation time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Created string `json:"created,omitempty"` + // Update time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Updated string `json:"updated,omitempty"` + // The parameters defined by users based on the default parameter templates. + ConfigurationParameters []ConfigurationParameterResult `json:"configuration_parameters,omitempty"` +} diff --git a/openstack/gaussdbnosql/v3/parameter/ShowInstanceConfiguration.go b/openstack/gaussdbnosql/v3/parameter/ShowInstanceConfiguration.go new file mode 100644 index 000000000..466e76eb1 --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/ShowInstanceConfiguration.go @@ -0,0 +1,49 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ShowInstanceConfiguration(client *golangsdk.ServiceClient, instanceId string) (*ShowInstanceConfigurationResponse, error) { + // GET https://{Endpoint}/v3/{project_id}/instances/{instance_id}/configurations + raw, err := client.Get(client.ServiceURL("instances", instanceId, "configurations"), nil, nil) + if err != nil { + return nil, err + } + + var res ShowInstanceConfigurationResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ShowInstanceConfigurationResponse struct { + // DB version name + DatastoreVersionName string `json:"datastore_version_name,omitempty"` + // Database name + DatastoreName string `json:"datastore_name,omitempty"` + // Creation time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Created string `json:"created,omitempty"` + // Update time in the "yyyy-MM-ddTHH:mm:ssZ" format. + Updated string `json:"updated,omitempty"` + // The parameters defined by users based on the default parameter templates. + ConfigurationParameters []ConfigurationParameterResult `json:"configuration_parameters,omitempty"` +} + +type ConfigurationParameterResult struct { + // Parameter name + Name string `json:"name"` + // Parameter value + Value string `json:"value"` + // Whether the instance needs to be restarted. + RestartRequired bool `json:"restart_required"` + // Whether the parameter is read-only. + Readonly bool `json:"readonly"` + // Value range. For example, the value of the Integer type ranges from 0 to 1, + // and the value of the Boolean type is true or false. + ValueRange string `json:"value_range"` + // Parameter type. The value can be string, integer, boolean, list, or float. + Type string `json:"type"` + // Parameter description + Description string `json:"description"` +} diff --git a/openstack/gaussdbnosql/v3/parameter/UpdateConfiguration.go b/openstack/gaussdbnosql/v3/parameter/UpdateConfiguration.go new file mode 100644 index 000000000..6c841df5f --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/UpdateConfiguration.go @@ -0,0 +1,31 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type UpdateConfigurationOpts struct { + // Parameter template ID + ConfigId string `json:"config_id"` + // Parameter template name. It contains a maximum of 64 characters and can contain only uppercase letters, + // lowercase letters, digits, hyphens (-), underscores (_), and periods (.). + Name string `json:"name,omitempty"` + // Parameter template description. It contains a maximum of 256 characters except the following special characters: + // >!<"&'= The value is left blank by default. + Description string `json:"description,omitempty"` + // The parameter values defined by users based on the default parameter template. + // If the value is empty, the parameter value is not changed. + Values map[string]string `json:"values,omitempty"` +} + +func UpdateConfiguration(client *golangsdk.ServiceClient, opts UpdateConfigurationOpts) (err error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return + } + + // PUT https://{Endpoint}/v3/{project_id}/configurations/{config_id} + _, err = client.Put(client.ServiceURL("configurations", opts.ConfigId), b, nil, nil) + return +} diff --git a/openstack/gaussdbnosql/v3/parameter/UpdateInstanceConfiguration.go b/openstack/gaussdbnosql/v3/parameter/UpdateInstanceConfiguration.go new file mode 100644 index 000000000..159caa646 --- /dev/null +++ b/openstack/gaussdbnosql/v3/parameter/UpdateInstanceConfiguration.go @@ -0,0 +1,37 @@ +package parameter + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type UpdateInstanceConfigurationOpts struct { + InstanceId string + // The parameter values defined by users based on the default parameter template + Values map[string]string `json:"values"` +} + +func UpdateInstanceConfiguration(client *golangsdk.ServiceClient, opts UpdateInstanceConfigurationOpts) (*UpdateInstanceConfigurationResponse, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return nil, err + } + + // PUT https://{Endpoint}/v3/{project_id}/instances/{instance_id}/configurations + raw, err := client.Put(client.ServiceURL("instances", opts.InstanceId, "configurations"), b, nil, nil) + if err != nil { + return nil, err + } + + var res UpdateInstanceConfigurationResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type UpdateInstanceConfigurationResponse struct { + // ID of the asynchronous task for modifying instance parameters + JobId string `json:"job_id,omitempty"` + // Whether the instance needs to be restarted. + RestartRequired bool `json:"restart_required,omitempty"` +} diff --git a/openstack/gaussdbnosql/v3/tag/BatchTagAction.go b/openstack/gaussdbnosql/v3/tag/BatchTagAction.go new file mode 100644 index 000000000..b7c878341 --- /dev/null +++ b/openstack/gaussdbnosql/v3/tag/BatchTagAction.go @@ -0,0 +1,41 @@ +package tag + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" +) + +type BatchTagActionOpts struct { + InstanceId string + // Operation identifier. Valid value: + // create: indicates to add tags. + // delete: indicates to delete tags. + Action string `json:"action"` + // Tag list. + Tags []BatchTagActionTagOption `json:"tags"` +} + +type BatchTagActionTagOption struct { + // Tag key. It contains a maximum of 36 Unicode characters. It cannot be null or an empty string or contain spaces. + // Before verifying and using key, spaces are automatically filtered out. Character set: 0-9, A-Z, a-z, "_", and "-". + Key string `json:"key"` + // Tag value. It contains a maximum of 43 Unicode characters, can be an empty string, and cannot contain spaces. + // Before verifying or using value, spaces are automatically filtered out. + // Character set: 0-9, A-Z, a-z, "_", and "-". + // If action is set to create, this parameter is mandatory. + // If action is set to delete, this parameter is optional. + // NOTE If value is specified, tags are deleted by key and value. + // If value is not specified, tags are deleted by key. + Value string `json:"value,omitempty"` +} + +func BatchTagAction(client *golangsdk.ServiceClient, opts BatchTagActionOpts) (err error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return + } + + // POST https://{Endpoint}/v3/{project_id}/instances/{instance_id}/tags/action + _, err = client.Post(client.ServiceURL("instances", opts.InstanceId, "tags", "action"), b, nil, nil) + return +} diff --git a/openstack/gaussdbnosql/v3/tag/ListInstanceTags.go b/openstack/gaussdbnosql/v3/tag/ListInstanceTags.go new file mode 100644 index 000000000..d2ecf10d4 --- /dev/null +++ b/openstack/gaussdbnosql/v3/tag/ListInstanceTags.go @@ -0,0 +1,18 @@ +package tag + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +func ListInstanceTags(client *golangsdk.ServiceClient, instanceId string) ([]InstanceTagResult, error) { + // GET https://{Endpoint}/v3/{project_id}/instances/{instance_id}/tags + raw, err := client.Get(client.ServiceURL("instances", instanceId, "tags"), nil, nil) + if err != nil { + return nil, err + } + + var res []InstanceTagResult + err = extract.IntoSlicePtr(raw.Body, &res, "tags") + return res, err +} diff --git a/openstack/gaussdbnosql/v3/tag/ListInstancesByResourceTags.go b/openstack/gaussdbnosql/v3/tag/ListInstancesByResourceTags.go new file mode 100644 index 000000000..defd08dab --- /dev/null +++ b/openstack/gaussdbnosql/v3/tag/ListInstancesByResourceTags.go @@ -0,0 +1,87 @@ +package tag + +import ( + golangsdk "github.com/opentelekomcloud/gophertelekomcloud" + "github.com/opentelekomcloud/gophertelekomcloud/internal/build" + "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" +) + +type ListInstancesByTagsOpts struct { + // Index position. The query starts from the next piece of data indexed by this parameter. + // If action is set to count, this parameter is not transferred. + // If action is set to filter, this parameter must be a positive integer. The default value is 0, + // indicating that the query starts from the first piece of data. + Offset string `json:"offset,omitempty"` + // Number of records to be queried. l If action is set to count, this parameter is not transferred. + // If action is set to filter, the value range is from 1 to 100. If this parameter is not transferred, + // the first 100 instances are queried by default. + Limit string `json:"limit,omitempty"` + // Specifies the operation identifier. + // If action is set to filter, instances are queried by tag filtering criteria. + // If action is set to count, only the total number of records is returned. + Action string `json:"action"` + // Field to be matched. + // If the value is left blank, the query is not based on the instance name or instance ID. + // If the value is not empty + Matches []MatchOption `json:"matches,omitempty"` + // Specifies the included tags. Each tag contains up to 20 keys. + Tags []TagOption `json:"tags,omitempty"` +} + +type TagOption struct { + // Tag key. It contains a maximum of 36 Unicode characters. key cannot be empty, an empty string, or spaces. + // Before using key, delete spaces of single-byte character (SBC) before and after the value. + // NOTE The character set of this parameter is not verified in the search process. + Key string `json:"key"` + // Lists the tag values. Each value contains a maximum of 43 Unicode characters and cannot contain spaces. + // Before using values, delete SBC spaces before and after the value. + // If the values are null, it indicates querying any value. The values are in OR relationship. + Values []string `json:"values"` +} + +type MatchOption struct { + // Query criteria. The value can be instance_name or instance_id, + // indicating that the query is based on the instance name or instance ID. + Key string `json:"key"` + // The name or ID of the instance to be matched. + Value string `json:"value"` +} + +func ListInstancesByResourceTags(client *golangsdk.ServiceClient, opts ListInstancesByTagsOpts) (*ListInstancesByResourceTagsResponse, error) { + b, err := build.RequestBody(opts, "") + if err != nil { + return nil, err + } + + // POST https://{Endpoint}/v3/{project_id}/instances/resource_instances/action + raw, err := client.Post(client.ServiceURL("instances", "resource_instances", "action"), b, nil, nil) + if err != nil { + return nil, err + } + + var res ListInstancesByResourceTagsResponse + err = extract.Into(raw.Body, &res) + return &res, err +} + +type ListInstancesByResourceTagsResponse struct { + Instances []InstanceResult `json:"instances,omitempty"` + TotalCount int32 `json:"total_count,omitempty"` +} + +type InstanceResult struct { + // Instance ID + InstanceId string `json:"instance_id"` + // Instance name + InstanceName string `json:"instance_name"` + // Tag list. If there is no tag in the list, tags is taken as an empty array + Tags []InstanceTagResult `json:"tags"` +} + +type InstanceTagResult struct { + // Tag key. The value contains 36 Unicode characters and cannot be blank. Character set: 0-9, A-Z, a-z, "_", and "-". + Key string `json:"key,omitempty"` + // Tag value. The value contains a maximum of 43 Unicode characters and can also be an empty string. + // Character set: 0-9, A-Z, a-z, "_", and "-". + Value string `json:"value,omitempty"` +}