@@ -31,16 +31,6 @@ type CreateOptsBuilder interface {
31
31
ToPolicyCreateMap () ([]map [string ]interface {}, error )
32
32
}
33
33
34
- // Adjustment represents the change in capacity associated with a policy.
35
- type Adjustment struct {
36
- // The type for this adjustment.
37
- Type AdjustmentType
38
-
39
- // The value of the adjustment. For adjustments of type Change or
40
- // DesiredCapacity, this will be converted to an integer.
41
- Value float64
42
- }
43
-
44
34
// AdjustmentType represents the way in which a policy will change a group.
45
35
type AdjustmentType string
46
36
@@ -66,8 +56,14 @@ type CreateOpt struct {
66
56
// Cooldown [required] period in seconds.
67
57
Cooldown int
68
58
69
- // Adjustment [requried] type and value for the policy.
70
- Adjustment Adjustment
59
+ // AdjustmentType [requried] is the method used to change the capacity of
60
+ // the group, i.e. one of: Change, ChangePercent, or DesiredCapacity.
61
+ AdjustmentType AdjustmentType
62
+
63
+ // AdjustmentValue [required] is the numeric value of the adjustment. For
64
+ // adjustments of type Change or DesiredCapacity, this will be converted to
65
+ // an integer.
66
+ AdjustmentValue float64
71
67
72
68
// Additional configuration options for some types of policy.
73
69
Args map [string ]interface {}
@@ -93,7 +89,9 @@ func (opts CreateOpts) ToPolicyCreateMap() ([]map[string]interface{}, error) {
93
89
policy ["type" ] = o .Type
94
90
policy ["cooldown" ] = o .Cooldown
95
91
96
- if err := setAdjustment (o .Adjustment , policy ); err != nil {
92
+ err := setAdjustment (o .AdjustmentType , o .AdjustmentValue , policy )
93
+
94
+ if err != nil {
97
95
return nil , err
98
96
}
99
97
@@ -154,8 +152,14 @@ type UpdateOpts struct {
154
152
// it will default to zero, and the policy will be configured as such.
155
153
Cooldown int
156
154
157
- // Adjustment [requried] type and value for the policy.
158
- Adjustment Adjustment
155
+ // AdjustmentType [requried] is the method used to change the capacity of
156
+ // the group, i.e. one of: Change, ChangePercent, or DesiredCapacity.
157
+ AdjustmentType AdjustmentType
158
+
159
+ // AdjustmentValue [required] is the numeric value of the adjustment. For
160
+ // adjustments of type Change or DesiredCapacity, this will be converted to
161
+ // an integer.
162
+ AdjustmentValue float64
159
163
160
164
// Additional configuration options for some types of policy.
161
165
Args map [string ]interface {}
@@ -178,7 +182,9 @@ func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) {
178
182
policy ["type" ] = opts .Type
179
183
policy ["cooldown" ] = opts .Cooldown
180
184
181
- if err := setAdjustment (opts .Adjustment , policy ); err != nil {
185
+ err := setAdjustment (opts .AdjustmentType , opts .AdjustmentValue , policy )
186
+
187
+ if err != nil {
182
188
return nil , err
183
189
}
184
190
@@ -233,15 +239,15 @@ func Execute(client *gophercloud.ServiceClient, groupID, policyID string) Execut
233
239
}
234
240
235
241
// Validate and set an adjustment on the given request body.
236
- func setAdjustment (adjustment Adjustment , reqBody map [string ]interface {}) error {
237
- key := string (adjustment . Type )
242
+ func setAdjustment (t AdjustmentType , v float64 , body map [string ]interface {}) error {
243
+ key := string (t )
238
244
239
- switch adjustment . Type {
245
+ switch t {
240
246
case ChangePercent :
241
- reqBody [key ] = adjustment . Value
247
+ body [key ] = v
242
248
243
249
case Change , DesiredCapacity :
244
- reqBody [key ] = int (adjustment . Value )
250
+ body [key ] = int (v )
245
251
246
252
default :
247
253
return ErrInvalidAdjustment
0 commit comments