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

     1  package instances
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags"
     7  )
     8  
     9  type ListOpts struct {
    10  	// Specifies the DB instance ID.
    11  	// The asterisk (*) is reserved for the system. If the instance ID starts with *, it indicates that fuzzy match is performed based on the value following * Otherwise, the exact match is performed based on the instance ID. The value cannot contain only asterisks (*).
    12  	Id string `q:"id"`
    13  	// Specifies the DB instance name.
    14  	// The asterisk (*) is reserved for the system. If the instance name starts with *, it indicates that fuzzy match is performed based on the value following * Otherwise, the exact match is performed based on the instance name. The value cannot contain only asterisks (*).
    15  	Name string `q:"name"`
    16  	// Specifies the instance type based query. The value is Single, Ha, or Replica, which correspond to single instance, primary/standby instances, and read replica, respectively.
    17  	Type string `q:"type"`
    18  	// Specifies the database type. Its value can be any of the following and is case-sensitive:
    19  	// MySQL
    20  	// PostgreSQL
    21  	// SQLServer
    22  	DataStoreType string `q:"datastore_type"`
    23  	// Specifies the VPC ID.
    24  	// Method 1: Log in to VPC console and view the VPC ID in the VPC details.
    25  	// Method 2: See the "Querying VPCs" section in the Virtual Private Cloud API Reference.
    26  	VpcId string `q:"vpc_id"`
    27  	// Specifies the network ID of the subnet.
    28  	// Method 1: Log in to VPC console and click the target subnet on the Subnets page. You can view the network ID on the displayed page.
    29  	// Method 2: See the "Querying Subnets" section under "APIs" or the "Querying Networks" section under "OpenStack Neutron APIs" in Virtual Private Cloud API Reference.
    30  	SubnetId string `q:"subnet_id"`
    31  	// Specifies the index position. 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.
    32  	Offset int `q:"offset"`
    33  	// Specifies the number of records to be queried. The default value is 100. The value cannot be a negative number. The minimum value is 1 and the maximum value is 100.
    34  	Limit int `q:"limit"`
    35  }
    36  
    37  func List(client *golangsdk.ServiceClient, opts ListOpts) (*ListResponse, error) {
    38  	url, err := golangsdk.NewURLBuilder().WithEndpoints("instances").WithQueryParams(&opts).Build()
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	// GET https://{Endpoint}/v3/{project_id}/instances
    44  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	var res ListResponse
    50  	err = extract.Into(raw.Body, &res)
    51  	return &res, err
    52  }
    53  
    54  type ListResponse struct {
    55  	Instances  []InstanceResponse `json:"instances"`
    56  	TotalCount int                `json:"total_count"`
    57  }
    58  
    59  type InstanceResponse struct {
    60  	// Indicates the DB instance ID.
    61  	Id string `json:"id"`
    62  	// Indicates the created DB instance name.
    63  	Name string `json:"name"`
    64  	// Indicates the DB instance status.
    65  	// Value:
    66  	// If the value is BUILD, the instance is being created.
    67  	// If the value is ACTIVE, the instance is normal.
    68  	// If the value is FAILED, the instance is abnormal.
    69  	// If the value is MODIFYING, the instance is being scaled up.
    70  	// If the value is REBOOTING, the instance is being rebooted.
    71  	// If the value is RESTORING, the instance is being restored.
    72  	// If the value is MODIFYING INSTANCE TYPE, the instance is changing from primary to standby.
    73  	// If the value is SWITCHOVER, the primary/standby switchover is being performed.
    74  	// If the value is MIGRATING, the instance is being migrated.
    75  	// If the value is BACKING UP, the instance is being backed up.
    76  	// If the value is MODIFYING DATABASE PORT, the database port is being changed.
    77  	// If the value is SHUTDOWN, the DB instance is stopped.
    78  	Status string `json:"status"`
    79  	// Indicates the DB instance alias.
    80  	Alias string `json:"alias"`
    81  	// Indicates the private IP address list. It is a blank string until an ECS is created.
    82  	PrivateIps []string `json:"private_ips"`
    83  	// Indicates the public IP address list.
    84  	PublicIps []string `json:"public_ips"`
    85  	// Indicates the database port number.
    86  	// The MySQL database port ranges from 1024 to 65535 (excluding 12017 and 33071, which are occupied by the RDS system and cannot be used).
    87  	// The PostgreSQL database port ranges from 2100 to 9500.
    88  	// The Microsoft SQL Server database port is 1433 or ranges from 2100 to 9500 (excluding 5355 and 5985).
    89  	// If this parameter is not set, the default value is as follows:
    90  	// For MySQL, the default value is 3306.
    91  	// For PostgreSQL, the default value is 5432.
    92  	// For Microsoft SQL Server, the default value is 1433.
    93  	Port int `json:"port"`
    94  	// The value is Single, Ha, or Replica, which correspond to single instance, primary/standby instances, and read replica, respectively.
    95  	Type string `json:"type"`
    96  	// Indicates the primary/standby DB instance information. Returned only when you obtain a primary/standby DB instance list.
    97  	Ha Ha `json:"ha"`
    98  	// Indicates the region where the DB instance is deployed.
    99  	Region string `json:"region"`
   100  	// Indicates the database information.
   101  	DataStore Datastore `json:"datastore"`
   102  	// Indicates the creation time in the "yyyy-mm-ddThh:mm:ssZ" format.
   103  	// T is the separator between the calendar and the hourly notation of time. Z indicates the time zone offset.
   104  	// The value is empty when the DB instance is being created. After the DB instance is created, the value is not empty.
   105  	Created string `json:"created"`
   106  	// Indicates the update time. The format is the same as that of the created field.
   107  	// The value is empty when the DB instance is being created. After the DB instance is created, the value is not empty.
   108  	Updated string `json:"updated"`
   109  	// Indicates the default username.
   110  	DbUserName string `json:"db_user_name"`
   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 number of CPUs. For example, the value 1 indicates 1 vCPU.
   118  	Cpu string `json:"cpu"`
   119  	// Indicates the memory size in GB.
   120  	Mem string `json:"mem"`
   121  	// Indicates the specification code.
   122  	FlavorRef string `json:"flavor_ref"`
   123  	// Indicates the volume information.
   124  	Volume Volume `json:"volume"`
   125  	// Indicates the database switchover policy. The value can be reliability or availability, indicating the reliability first and availability first, respectively.
   126  	SwitchStrategy string `json:"switch_strategy"`
   127  	// Indicates the backup policy.
   128  	BackupStrategy BackupStrategy `json:"backup_strategy"`
   129  	// Indicates the start time of the maintenance time window in the UTC format.
   130  	MaintenanceWindow string `json:"maintenance_window"`
   131  	// Indicates the primary/standby DB instance information.
   132  	Nodes []Nodes `json:"nodes"`
   133  	// Indicates the list of associated DB instances
   134  	RelatedInstance []RelatedInstance `json:"related_instance"`
   135  	// Indicates the disk encryption key ID.
   136  	DiskEncryptionId string `json:"disk_encryption_id"`
   137  	// Indicates the time zone.
   138  	TimeZone string `json:"time_zone"`
   139  	// Indicates the billing information, which is pay-per-use.
   140  	ChargeInfo ChargeInfo `json:"charge_info"`
   141  	// Indicates the tag list. If there is no tag in the list, an empty array is returned.
   142  	Tags []tags.ResourceTag `json:"tags"`
   143  	// Indicates whether a DDM instance has been associated.
   144  	AssociatedWithDdm bool `json:"associated_with_ddm"`
   145  	// Indicates whether SSL is enabled for an instance
   146  	EnableSSL *bool `json:"enable_ssl,omitempty"`
   147  }
   148  
   149  type Nodes struct {
   150  	// Indicates the node ID.
   151  	Id string `json:"id"`
   152  	// Indicates the node name.
   153  	Name string `json:"name"`
   154  	// Indicates the node type. The value can be master, slave, or readreplica, indicating the primary node, standby node, and read replica node, respectively.
   155  	Role string `json:"role"`
   156  	// Indicates the node status.
   157  	Status string `json:"status"`
   158  	// Indicates the AZ.
   159  	AvailabilityZone string `json:"availability_zone"`
   160  }
   161  
   162  type RelatedInstance struct {
   163  	// Indicates the associated DB instance ID.
   164  	Id string `json:"id"`
   165  	// Indicates the associated DB instance type.
   166  	// replica_of: indicates the primary DB instance.
   167  	// replica: indicates read replicas.
   168  	Type string `json:"type"`
   169  }