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

     1  package instances
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
     7  )
     8  
     9  type ListInstanceOpts struct {
    10  	// Specifies the instance ID, which can be obtained by calling the API for querying instances and details.
    11  	Id string `q:"id"`
    12  	// Specifies the DB instance name.
    13  	//
    14  	// If you use asterisk (*) at the beginning of the name, fuzzy search results are returned. Otherwise, the exact results are returned.
    15  	//
    16  	// NOTE:
    17  	// The asterisk (*) is a reserved character in the system and cannot be used alone.
    18  	Name string `q:"name"`
    19  	// Specifies the instance type.
    20  	//
    21  	// Sharding indicates the cluster instance.
    22  	// ReplicaSet indicate the replica set instance.
    23  	// Single indicates the single node instance.
    24  	Mode string `q:"mode"`
    25  	// Specifies the database type. The value is DDS-Community.
    26  	DataStoreType string `q:"datastore_type"`
    27  	// Specifies the VPC ID.
    28  	VpcId string `q:"vpc_id"`
    29  	// Specifies the network ID of the subnet.
    30  	SubnetId string `q:"subnet_id"`
    31  	//
    32  	// Specifies the 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.
    33  	//
    34  	// 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 DB instance.
    35  	Offset int `q:"offset"`
    36  	// Specifies the maximum allowed number of DB instances.
    37  	//
    38  	// The value ranges from 1 to 100. If this parameter is not transferred, the first 100 DB instances are queried by default.
    39  	Limit int `q:"limit"`
    40  	// Query based on the instance tag key and value.
    41  	//
    42  	// {key} indicates the tag key, and {value} indicates the tag value. A maximum of 20 key-value pairs are supported. The key cannot be empty or duplicate, but the value can be empty.
    43  	//
    44  	// To query instances with multiple tag keys and values, separate key-value pairs with commas (,).
    45  	Tags string `q:"tags"`
    46  }
    47  
    48  func List(client *golangsdk.ServiceClient, opts ListInstanceOpts) (*ListResponse, error) {
    49  	url, err := golangsdk.NewURLBuilder().WithEndpoints("instances").WithQueryParams(&opts).Build()
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	// GET https://{Endpoint}/v3/{project_id}/instances
    55  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	var res ListResponse
    61  	err = extract.Into(raw.Body, &res)
    62  	return &res, err
    63  }
    64  
    65  type ListResponse struct {
    66  	Instances  []InstanceResponse `json:"instances"`
    67  	TotalCount int                `json:"total_count"`
    68  }
    69  
    70  type InstanceResponse struct {
    71  	// Indicates the DB instance ID.
    72  	Id string `json:"id"`
    73  	// Indicates the DB instance name.
    74  	Name string `json:"name"`
    75  	// Instance remarks
    76  	Remark string `json:"remark"`
    77  	// Indicates the DB instance status.
    78  	//
    79  	// Valid value:
    80  	//
    81  	// normal: indicates that the instance is running properly.
    82  	// abnormal: indicates that the instance is abnormal.
    83  	// creating: indicates that the instance is being created.
    84  	// data_disk_full: The storage space is full.
    85  	// createfail: indicates that the instance failed to be created.
    86  	// enlargefail: indicates that nodes failed to be added to the instance.
    87  	// NOTE:
    88  	// Actions that are being executed on an instance, for example, rebooting, which are essentially different from the instance status. For details, see the actions field in this table.
    89  	Status string `json:"status"`
    90  	// Indicates the database port number. The port range is 2100 to 9500.
    91  	Port int `json:"port,string"`
    92  	// Indicates the instance type, which is the same as the request parameter.
    93  	Mode string `json:"mode"`
    94  	// Indicates the region where the DB instance is deployed.
    95  	Region string `json:"region"`
    96  	// Indicates the database information.
    97  	DataStore DataStore `json:"datastore"`
    98  	// Indicates the storage engine. The value is wiredTiger.
    99  	Engine string `json:"engine"`
   100  	// Indicates the DB instance creation time.
   101  	Created string `json:"created"`
   102  	// Indicates the time when a DB instance is updated.
   103  	Updated string `json:"updated"`
   104  	// Indicates the default username. The value is rwuser.
   105  	DbUserName string `json:"db_user_name"`
   106  	// Indicates that SSL is enabled or not.
   107  	//
   108  	// 1: indicate that SSL is enabled.
   109  	// 0: indicate that SSL is disabled.
   110  	Ssl int `json:"ssl"`
   111  	// Indicates the VPC ID.
   112  	VpcId string `json:"vpc_id"`
   113  	// Indicates the network ID of the subnet.
   114  	SubnetId string `json:"subnet_id"`
   115  	// Indicates the security group ID.
   116  	SecurityGroupId string `json:"security_group_id"`
   117  	// Indicates the backup policy.
   118  	BackupStrategy BackupStrategy `json:"backup_strategy"`
   119  	// Indicates the maintenance time window.
   120  	MaintenanceWindow string `json:"maintenance_window"`
   121  	// Indicates group information.
   122  	Groups []Group `json:"groups"`
   123  	// Indicates the disk encryption key ID. This parameter is returned only when the instance disk is encrypted.
   124  	DiskEncryptionId string `json:"disk_encryption_id"`
   125  	// Indicates the time zone.
   126  	TimeZone string `json:"time_zone"`
   127  	// Action that is being executed on an instance.
   128  	//
   129  	// Valid value:
   130  	//
   131  	// RESTARTING: The instance is being restarted.
   132  	// RESTORE: restoring.
   133  	// RESIZE_FLAVOR: The specifications are being changed.
   134  	// RESTORE_TO_NEW_INSTANCE: The instance is being restored.
   135  	// MODIFY_VPC_PEER: Cross-subnet access is being configured.
   136  	// CREATE: creating
   137  	// FROZEN: The account is frozen.
   138  	// RESIZE_VOLUME: The storage is being scaled up.
   139  	// RESTORE_CHECK: The restoration is being checked.
   140  	// RESTORE_FAILED_HANGUP: The restoration failed.
   141  	// CLOSE_AUDIT_LOG: Disabling audit log.
   142  	// OPEN_AUDIT_LOG: Enabling audit log.
   143  	// CREATE_IP_SHARD: The shard IP address is being enabled.
   144  	// CREATE_IP_CONFIG: The config IP address is being enabled.
   145  	// GROWING: The node is being scaled up.
   146  	// SET_CONFIGURATION: Parameters are being modified.
   147  	// RESTORE_TABLE: The database is being backed up.
   148  	// MODIFY_SECURITYGROUP: A security group is being changed.
   149  	// BIND_EIP: The EIP is being changed.
   150  	// UNBIND_EIP: The EIP is being unbound.
   151  	// SWITCH_SSL: The SSL is being switched.
   152  	// SWITCH_PRIMARY: A primary/standby switchover is being performed.
   153  	// CHANGE_DBUSER_PASSWORD: The password is being changed.
   154  	// MODIFY_PORT: The port is being changed.
   155  	// MODIFY_IP: The private IP address is being changed.
   156  	// DELETE_INSTANCE: The instance is being deleted.
   157  	// REBOOT: The system is restarting.
   158  	// BACKUP: The backup is in progress.
   159  	// MIGRATE_AZ: The AZ is being changed.
   160  	// RESTORING: The backup is in progress.
   161  	// PWD_RESETING: The password is being reset.
   162  	// UPGRADE_DATABASE: The patch is being upgraded.
   163  	// DATA_MIGRATION: Data is being migrated.
   164  	// SHARD_GROWING: The shard is being scaled out.
   165  	// APPLY_CONFIGURATION: A parameter group is being changed.
   166  	// RESET_PASSWORD: The password is being reset.
   167  	// GROWING_REVERT: Nodes are being deleted.
   168  	// SHARD_GROWING_REVERT: Shards are being deleted.
   169  	// LOG_PLAINTEXT_SWITCH: The slow query log configuration is being modified.
   170  	// CREATE_DATABASE_USER: The database user is being created.
   171  	// CREATE_DATABASE_ROLE: The database role is being created.
   172  	// MODIFY_NAME: The name is being changed.
   173  	// MODIFY_PRIVATE_DNS: The private zone is being modified.
   174  	// MODIFY_OP_LOG_SIZE: The oplog size is being changed.
   175  	// ADD_READONLY_NODES: Read replicas are being scaled up.
   176  	Actions []string `json:"actions"`
   177  	// The value is set to "0".
   178  	PayMode string `json:"pay_mode"`
   179  	// Tag list
   180  	Tags []tags.ResourceTag `json:"tags"`
   181  }
   182  
   183  type Group struct {
   184  	// Indicates the node type.
   185  	//
   186  	// Valid value:
   187  	//
   188  	// shard
   189  	// config
   190  	// mongos
   191  	// replica
   192  	// single
   193  	Type string `json:"type"`
   194  	//
   195  	Id string `json:"id"`
   196  	//
   197  	Name string `json:"name"`
   198  	//
   199  	Status string `json:"status"`
   200  	// Indicates the volume information.
   201  	Volume Volume `json:"volume"`
   202  	// Indicates node information.
   203  	Nodes []Nodes `json:"nodes"`
   204  }
   205  
   206  type Volume struct {
   207  	// Indicates the disk size. Unit: GB
   208  	Size string `json:"size"`
   209  	// Indicates the disk usage. Unit: GB
   210  	Used string `json:"used"`
   211  }
   212  
   213  type Nodes struct {
   214  	// Indicates the node ID.
   215  	Id string `json:"id"`
   216  	// Indicates the node name.
   217  	Name string `json:"name"`
   218  	// Indicates the node status.
   219  	//
   220  	// Valid value:
   221  	//
   222  	// normal: The instance is running properly.
   223  	// abnormal: The instance is abnormal.
   224  	// backup: The instance is being backed up.
   225  	// frozen: The instance has been frozen.
   226  	// unfrozen: The instance is being unfrozen.
   227  	// restore_table: Database- and table-level backup and restoration are being performed for the DB instance.
   228  	// reboot: The instance is being restarted.
   229  	// upgrade_database: The instance version is being upgraded.
   230  	// resize_flavor: The instance class is being changed.
   231  	// resize_volume: The instance storage is being scaled up.
   232  	// restore: The instance is being restored.
   233  	// bind_eip: An EIP is being bound to the instance.
   234  	Status string `json:"status"`
   235  	// Indicates the node role.
   236  	//
   237  	// Valid value:
   238  	// master: This value is returned for the mongos node.
   239  	// Primary: This value is returned for the primary shard and config nodes, the primary node of a replica set, and a single node.
   240  	// Secondary: This value is returned for the secondary shard and config nodes, and the secondary node of a replica set.
   241  	// Hidden: This value is returned for the hidden shard and config nodes, and the hidden node of a replica set.
   242  	// unknown. This value is returned when the node is abnormal.
   243  	Role string `json:"role"`
   244  	// Indicates the private IP address of a node. By default, this parameter is valid only for mongos nodes, replica set instances, and single node instances. The value exists only after ECSs are created successfully. Otherwise, the value is "".
   245  	//
   246  	// CAUTION:
   247  	// After the shard or config IP address is enabled, private IP addresses are assigned to the primary and secondary shard or config nodes of the cluster instance.
   248  	PrivateIP string `json:"private_ip"`
   249  	// Indicates the EIP that has been bound. This parameter is valid only for mongos nodes of cluster instances, primary nodes and secondary nodes of replica set instances, and single node instances.
   250  	PublicIP string `json:"public_ip"`
   251  	// Indicates the resource specification code.
   252  	SpecCode string `json:"spec_code"`
   253  	// Indicates the AZ.
   254  	AvailabilityZone string `json:"availability_zone"`
   255  }