@@ -31,16 +31,6 @@ type CreateOptsBuilder interface {
3131 ToPolicyCreateMap () ([]map [string ]interface {}, error )
3232}
3333
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-
4434// AdjustmentType represents the way in which a policy will change a group.
4535type AdjustmentType string
4636
@@ -66,8 +56,14 @@ type CreateOpt struct {
6656 // Cooldown [required] period in seconds.
6757 Cooldown int
6858
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
7167
7268 // Additional configuration options for some types of policy.
7369 Args map [string ]interface {}
@@ -93,7 +89,9 @@ func (opts CreateOpts) ToPolicyCreateMap() ([]map[string]interface{}, error) {
9389 policy ["type" ] = o .Type
9490 policy ["cooldown" ] = o .Cooldown
9591
96- if err := setAdjustment (o .Adjustment , policy ); err != nil {
92+ err := setAdjustment (o .AdjustmentType , o .AdjustmentValue , policy )
93+
94+ if err != nil {
9795 return nil , err
9896 }
9997
@@ -154,8 +152,14 @@ type UpdateOpts struct {
154152 // it will default to zero, and the policy will be configured as such.
155153 Cooldown int
156154
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
159163
160164 // Additional configuration options for some types of policy.
161165 Args map [string ]interface {}
@@ -178,7 +182,9 @@ func (opts UpdateOpts) ToPolicyUpdateMap() (map[string]interface{}, error) {
178182 policy ["type" ] = opts .Type
179183 policy ["cooldown" ] = opts .Cooldown
180184
181- if err := setAdjustment (opts .Adjustment , policy ); err != nil {
185+ err := setAdjustment (opts .AdjustmentType , opts .AdjustmentValue , policy )
186+
187+ if err != nil {
182188 return nil , err
183189 }
184190
@@ -233,15 +239,15 @@ func Execute(client *gophercloud.ServiceClient, groupID, policyID string) Execut
233239}
234240
235241// 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 )
238244
239- switch adjustment . Type {
245+ switch t {
240246 case ChangePercent :
241- reqBody [key ] = adjustment . Value
247+ body [key ] = v
242248
243249 case Change , DesiredCapacity :
244- reqBody [key ] = int (adjustment . Value )
250+ body [key ] = int (v )
245251
246252 default :
247253 return ErrInvalidAdjustment
0 commit comments