github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/autoscaling/v1/instances/list.go (about)

     1  package instances
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     6  )
     7  
     8  type ListOpts struct {
     9  	// Specifies the AS group ID.
    10  	ScalingGroupId string
    11  	// Specifies the instance lifecycle status in the AS group.
    12  	// INSERVICE: The instance is enabled.
    13  	// PENDING: The instance is being added to the AS group.
    14  	// REMOVING: The instance is being removed from the AS group.
    15  	LifeCycleState string `q:"life_cycle_state,omitempty"`
    16  	// Specifies the instance health status.
    17  	// INITIALIZING: The instance is initializing.
    18  	// NORMAL: The instance is normal.
    19  	// ERROR: The instance is abnormal.
    20  	HealthStatus string `q:"health_status,omitempty"`
    21  	// Specifies the instance protection status.
    22  	// true: Instance protection is enabled.
    23  	// false: Instance protection is disabled.
    24  	ProtectFromScalingDown string `q:"protect_from_scaling_down,omitempty"`
    25  	// Specifies the start line number. The default value is 0. The minimum parameter value is 0.
    26  	StartNumber int32 `q:"start_number,omitempty"`
    27  	// Specifies the number of query records. The default value is 20. The value range is 0 to 100.
    28  	Limit int32 `q:"limit,omitempty"`
    29  }
    30  
    31  func List(client *golangsdk.ServiceClient, opts ListOpts) (*ListScalingInstancesResponse, error) {
    32  	url, err := golangsdk.NewURLBuilder().WithEndpoints("scaling_group_instance", opts.ScalingGroupId, "list").WithQueryParams(&opts).Build()
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	// GET /autoscaling-api/v1/{project_id}/scaling_group_instance/{scaling_group_id}/list
    38  	raw, err := client.Get(client.ServiceURL(url.String()), nil, nil)
    39  	if err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	var res ListScalingInstancesResponse
    44  	err = extract.Into(raw.Body, &res)
    45  	return &res, err
    46  }
    47  
    48  type ListScalingInstancesResponse struct {
    49  	TotalNumber           int32      `json:"total_number,omitempty"`
    50  	StartNumber           int32      `json:"start_number,omitempty"`
    51  	Limit                 int32      `json:"limit,omitempty"`
    52  	ScalingGroupInstances []Instance `json:"scaling_group_instances,omitempty"`
    53  }
    54  
    55  type Instance struct {
    56  	// Specifies the instance ID.
    57  	ID string `json:"instance_id"`
    58  	// Specifies the instance name.
    59  	Name string `json:"instance_name"`
    60  	// Specifies the ID of the AS group to which the instance belongs.
    61  	GroupID string `json:"scaling_group_id"`
    62  	// Specifies the name of the AS group to which the instance belongs.
    63  	// Supports fuzzy search.
    64  	GroupName string `json:"scaling_group_name"`
    65  	// Specifies the instance lifecycle status in the AS group.
    66  	// INSERVICE: The instance is enabled.
    67  	// PENDING: The instance is being added to the AS group.
    68  	// REMOVING: The instance is being removed from the AS group.
    69  	LifeCycleStatus string `json:"life_cycle_state"`
    70  	// Specifies the instance health status.
    71  	// INITIALIZING: The instance is being initialized.
    72  	// NORMAL: The instance is functional.
    73  	// ERROR: The instance is faulty.
    74  	HealthStatus string `json:"health_status"`
    75  	// Specifies the AS configuration name.
    76  	ConfigurationName string `json:"scaling_configuration_name"`
    77  	// Specifies the AS configuration ID.
    78  	// If the returned value is not empty, the instance is an ECS automatically created in a scaling action.
    79  	// If the returned value is empty, the instance is an ECS manually added to the AS group.
    80  	ConfigurationID string `json:"scaling_configuration_id"`
    81  	// Specifies the time when the instance is added to the AS group. The time format complies with UTC.
    82  	CreateTime string `json:"create_time"`
    83  	// Specifies the instance protection status.
    84  	ProtectFromScalingDown bool `json:"protect_from_scaling_down"`
    85  }