This repository has been archived by the owner on May 8, 2024. It is now read-only.
forked from huaweicloud/huaweicloud-sdk-go
/
results.go
101 lines (80 loc) · 3.02 KB
/
results.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package instances
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
"strconv"
)
type ScalingGroupInstance struct {
// Specifies the instance ID.
InstanceId string `json:"instance_id"`
// Specifies the instance name.
InstanceName string `json:"instance_name"`
// Specifies the ID of the AS group to which the instance
// belongs.
ScalingGroupId string `json:"scaling_group_id"`
// Specifies the name of the AS group to which the instance
// belongs.
ScalingGroupName string `json:"scaling_group_name"`
// Specifies the instance lifecycle status in the AS
// group.INSERVICE: The instance in the AS group is in use.PENDING: The instance is
// being added to the AS group.PENDING_WAIT: The instance is waiting to be added to the
// AS group.REMOVING: The instance is being removed from the AS group.REMOVING_WAIT: The
// instance is waiting to be removed from the AS group.
LifeCycleState string `json:"life_cycle_state"`
// Specifies the instance health status.The status can be NORMAL
// or ERROR.
HealthStatus string `json:"health_status"`
// Specifies the AS configuration name.If the AS configuration has
// been deleted, no information is displayed.If the instance is manually added to the AS
// group, MANNUAL_ADD is returned.
ScalingConfigurationName string `json:"scaling_configuration_name"`
// Specifies the AS configuration ID.
ScalingConfigurationId string `json:"scaling_configuration_id"`
// Specifies the time when the instance is added to the AS group.
// The time format complies with UTC.
CreateTime string `json:"create_time"`
// Specifies the instance protection status.
ProtectFromScalingDown bool `json:"protect_from_scaling_down"`
}
type ActionResult struct {
gophercloud.ErrResult
}
type DeleteResult struct {
gophercloud.ErrResult
}
type ListResponse struct {
// Specifies the total number of query records.
TotalNumber int `json:"total_number"`
// Specifies the start line number.
StartNumber int `json:"start_number"`
// Specifies the number of query records.
Limit int `json:"limit"`
// Specifies details about the instances in the AS group.
ScalingGroupInstances []ScalingGroupInstance `json:"scaling_group_instances"`
}
type InstancePage struct {
pagination.NumberPageBase
}
// IsEmpty returns true if a ListResult contains no services.
func (r InstancePage) IsEmpty() (bool, error) {
data, err := ExtractInstances(r)
return data.StartNumber > data.TotalNumber, err
}
// LastStartNumber returns the last service in a ListResult.
func (r InstancePage) LastStartNumber() (string, error) {
data, err := ExtractInstances(r)
if err != nil {
return "", err
}
nextStartNumber := data.Limit + data.StartNumber
if nextStartNumber >= data.TotalNumber {
return "", nil
}
return strconv.Itoa(nextStartNumber), nil
}
// ExtractInstances is a function that takes a ListResult and returns the services' information.
func ExtractInstances(r pagination.Page) (ListResponse, error) {
var s ListResponse
err := (r.(InstancePage)).ExtractInto(&s)
return s, err
}