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

     1  package instance
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  )
     7  
     8  type ListInstancesOpts struct {
     9  	// Instance ID The asterisk (*) is reserved for the system. If the instance ID starts with *,
    10  	// it indicates that fuzzy match is performed based on the value following *.
    11  	// Otherwise, the exact match is performed based on the instance ID. The value cannot contain only asterisks (*).
    12  	Id string `json:"id,omitempty"`
    13  	// Instance name The asterisk (*) is reserved for the system. If the instance name starts with *,
    14  	// it indicates that fuzzy match is performed based on the value following *.
    15  	// Otherwise, the exact match is performed based on the instance name. The value cannot contain only asterisks (*).
    16  	Name string `json:"name,omitempty"`
    17  	// Instance type to be queried. Currently, its value can only be Cluster.
    18  	Type string `json:"type,omitempty"`
    19  	// DB type. Currently, only gaussdb-mysql is supported.
    20  	DatastoreType string `json:"datastore_type,omitempty"`
    21  	// VPC ID
    22  	// Method 1: Log in to the VPC console and view the VPC ID on the VPC details page.
    23  	// Method 2: See section "Querying VPCs" in the Virtual Private Cloud API Reference.
    24  	VpcId string `json:"vpc_id,omitempty"`
    25  	// Network ID of the subnet
    26  	// 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.
    27  	// Method 2: See section "Querying Subnets" under "APIs" or section "Querying Networks" under "OpenStack Neutron APIs" in the Virtual Private Cloud API Reference.
    28  	SubnetId string `json:"subnet_id,omitempty"`
    29  	// Private IP address
    30  	PrivateIp string `json:"private_ip,omitempty"`
    31  	// Index offset. If offset is set to N, the resource query starts from the N+1 piece of data.
    32  	// The default value is 0, indicating that the query starts from the first piece of data. The value must be a positive integer.
    33  	Offset int `json:"offset,omitempty"`
    34  	// Number of records to be queried. The default value is 100. The value must be a positive integer.
    35  	// The minimum value is 1 and the maximum value is 100.
    36  	Limit int `json:"limit,omitempty"`
    37  	// Query based on the instance tag key and value. {key} indicates the tag key, and {value} indicates the tag value.
    38  	// To query instances with multiple tag keys and values, separate key-value pairs with commas (,).
    39  	// The key must be unique. Multiple keys are in AND relationship.
    40  	Tags string `json:"tags,omitempty"`
    41  }
    42  
    43  func ListInstances(client *golangsdk.ServiceClient, opts ListInstancesOpts) (*ListInstancesResponse, error) {
    44  	url, err := golangsdk.NewURLBuilder().WithEndpoints("instances").WithQueryParams(&opts).Build()
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	// GET https://{Endpoint}/mysql/v3/{project_id}/instances
    50  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
    51  	if err != nil {
    52  		return nil, err
    53  	}
    54  
    55  	var res ListInstancesResponse
    56  	err = extract.Into(raw.Body, &res)
    57  	return &res, err
    58  }
    59  
    60  type ListInstancesResponse struct {
    61  	// Instance list information.
    62  	Instances []InstancesListInfo `json:"instances"`
    63  	// Total number of records.
    64  	TotalCount int `json:"total_count"`
    65  }
    66  
    67  type InstancesListInfo struct {
    68  	// Instance ID
    69  	Id string `json:"id"`
    70  	// Project ID of a tenant in a region
    71  	ProjectId string `json:"project_id"`
    72  	// The number of nodes.
    73  	NodeCount int `json:"node_count"`
    74  	// Instance name
    75  	Name string `json:"name"`
    76  	// Instance status
    77  	Status string `json:"status"`
    78  	// Private IP address for write It is a blank string until an ECS is created.
    79  	PrivateIps []string `json:"private_ips"`
    80  	// Public IP address list
    81  	PublicIps []string `json:"public_ips"`
    82  	// Database port
    83  	Port string `json:"port"`
    84  	// Instance type. The value is Cluster.
    85  	Type string `json:"type"`
    86  	// Region where the instance is deployed
    87  	Region string `json:"region"`
    88  	// Database information
    89  	Datastore Datastore `json:"datastore"`
    90  	// Used backup space in GB
    91  	BackupUsedSpace float64 `json:"backup_used_space"`
    92  	// Creation time in the "yyyy-mm-ddThh:mm:ssZ" format.
    93  	// T is the separator between the calendar and the hourly notation of time.
    94  	// Z indicates the time zone offset. For example, for French Winter Time (FWT), the time offset is shown as +0200.
    95  	// The value is empty unless the instance creation is complete.
    96  	Created string `json:"created"`
    97  	// Update time. The format is the same as that of the created field.
    98  	// The value is empty unless the instance creation is complete.
    99  	Updated string `json:"updated"`
   100  	// Private IP address for write
   101  	PrivateWriteIps []string `json:"private_write_ips"`
   102  	// Default username
   103  	DbUserName string `json:"db_user_name"`
   104  	// VPC ID
   105  	VpcId string `json:"vpc_id"`
   106  	// Network ID of the subnet
   107  	SubnetId string `json:"subnet_id"`
   108  	// Security group ID
   109  	SecurityGroupId string `json:"security_group_id"`
   110  	// ID of the parameter template used for creating an instance or ID of the latest parameter template that is applied to an instance.
   111  	ConfigurationId string `json:"configuration_id"`
   112  	// Specification code
   113  	FlavorRef string `json:"flavor_ref"`
   114  	// Specification description
   115  	FlavorInfo FlavorInfo `json:"flavor_info"`
   116  	// AZ type. It can be single or multi.
   117  	AzMode string `json:"az_mode"`
   118  	// Primary AZ
   119  	MasterAzCode string `json:"master_az_code"`
   120  	// Maintenance window in the UTC format
   121  	MaintenanceWindow string `json:"maintenance_window"`
   122  	// Storage disk information
   123  	Volume VolumeInfo `json:"volume"`
   124  	// Backup policy
   125  	BackupStrategy BackupStrategy `json:"backup_strategy"`
   126  	// Time zone
   127  	TimeZone string `json:"time_zone"`
   128  	// Billing mode, which is yearly/monthly or pay-per-use (default setting).
   129  	ChargeInfo ChargeInfo `json:"charge_info"`
   130  	// Dedicated resource pool ID. This parameter is returned only when the instance belongs to a dedicated resource pool.
   131  	DedicatedResourceId string `json:"dedicated_resource_id"`
   132  	// Tag list
   133  	Tags []TagItem `json:"tags"`
   134  }
   135  
   136  type FlavorInfo struct {
   137  	// Number of vCPUs
   138  	Vcpus string `json:"vcpus"`
   139  	// Memory size in GB
   140  	Ram string `json:"ram"`
   141  }
   142  
   143  type VolumeInfo struct {
   144  	// Disk type
   145  	Type string `json:"type"`
   146  	// Used disk size in GB
   147  	Size string `json:"size"`
   148  }
   149  
   150  type TagItem struct {
   151  	Key   string `json:"key"`
   152  	Value string `json:"value"`
   153  }