Class: Fog::Rackspace::AutoScale::Policy

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/rackspace/models/auto_scale/policy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#args ⇒ String (readonly)

  • "cron": "23 * * * *"
  • "at": "2013-06-05T03:12Z"
  • "check": { "label": "Website check 1", "type": "remote.http", "details": { "url": "http://www.example.com", "method": "GET" }, "monitoring_zones_poll": [ "mzA" ], "timeout": 30, "period": 100, "target_alias": "default" }, "alarm_criteria": { "criteria": "if (metric["duration"] >= 2) { return new AlarmStatus(OK); } return new AlarmStatus(CRITICAL);" }

Examples:

See below:

Returns:

  • (String) —

    Arguments used for the policy



64
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 64

attribute :args

#change ⇒ Fixnum (readonly)

Returns The fixed change to the autoscale group's number of units.

Returns:

  • (Fixnum) —

    The fixed change to the autoscale group's number of units



26
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 26

attribute :change

#changePercent ⇒ Fixnum (readonly)

Returns The percentage change to the autoscale group's number of units.

Returns:

  • (Fixnum) —

    The percentage change to the autoscale group's number of units



30
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 30

attribute :change_percent, :aliases => 'changePercent'

#cooldown ⇒ Fixnum (readonly)

Returns The policy's cooldown.

Returns:

  • (Fixnum) —

    The policy's cooldown



34
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 34

attribute :cooldown

#desiredCapacity ⇒ Fixnum (readonly)

Returns The desired capacity of the group.

Returns:

  • (Fixnum) —

    The desired capacity of the group



68
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 68

attribute :desired_capacity, :aliases => 'desiredCapacity'

#group ⇒ Group

Returns The autoscale group.

Returns:

  • (Group) —

    The autoscale group



14
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 14

attribute :group

#id ⇒ String (readonly)

Returns The policy id.

Returns:

  • (String) —

    The policy id



10
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 10

identity :id

Returns Policy links.

Returns:

  • (Array) —

    Policy links



18
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 18

attribute :links

#name ⇒ String (readonly)

Returns The policy's name.

Returns:

  • (String) —

    The policy's name



22
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 22

attribute :name

#type ⇒ String (readonly)

Note:

Can only be "webhook", "schedule" or "cloud_monitoring"

Returns The policy's type.

Returns:

  • (String) —

    The policy's type



39
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 39

attribute :type

Instance Method Details

#check_attributes ⇒ Boolean

Returns true if the check passes

Returns:

  • (Boolean) —

    Returns true if the check passes

Raises:

  • (ArgumentError)


76
77
78
79
80
81
82
83
84
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 76

def check_attributes
  raise ArgumentError, "This #{self.name} resource requires the #{type} argument" if type.nil?

  if type == 'schedule'
    raise ArgumentError, "This #{self.name} resource requires the args[cron] OR args[at] argument" if args['cron'].nil? && args['at'].nil?
  end

  true
end

#create ⇒ Boolean

Creates policy

  • requires attributes: :name, :type, :cooldown

Returns:

  • (Boolean) —

    returns true if policy is being created

Raises:

  • (Fog::Rackspace::AutoScale:::NotFound) —
    • HTTP 404
  • (Fog::Rackspace::AutoScale:::BadRequest) —
    • HTTP 400
  • (Fog::Rackspace::AutoScale:::InternalServerError) —
    • HTTP 500
  • (Fog::Rackspace::AutoScale:::ServiceError)

See Also:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 102

def create
  requires :name, :type, :cooldown

  check_attributes

  options = {}
  options['name'] = name unless name.nil?
  options['change'] = change unless change.nil?
  options['changePercent'] = change_percent unless change_percent.nil?
  options['cooldown'] = cooldown unless cooldown.nil?
  options['type'] = type unless type.nil?
  options['desiredCapacity'] = desired_capacity unless desired_capacity.nil?

  if type == 'schedule'
    options['args'] = args
  end

  data = service.create_policy(group.id, options)
  merge_attributes(data.body['policies'][0])
  true
end

#destroy ⇒ Boolean

Destroy the policy

Returns:

  • (Boolean) —

    returns true if policy has started deleting

Raises:

  • (Fog::Rackspace::AutoScale:::NotFound) —
    • HTTP 404
  • (Fog::Rackspace::AutoScale:::BadRequest) —
    • HTTP 400
  • (Fog::Rackspace::AutoScale:::InternalServerError) —
    • HTTP 500
  • (Fog::Rackspace::AutoScale:::ServiceError)

See Also:



178
179
180
181
182
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 178

def destroy
  requires :identity
  service.delete_policy(group.id, identity)
  true
end

#execute ⇒ Boolean

Executes the scaling policy

Returns:

  • (Boolean) —

    returns true if policy has been executed

Raises:

  • (Fog::Rackspace::AutoScale:::NotFound) —
    • HTTP 404
  • (Fog::Rackspace::AutoScale:::BadRequest) —
    • HTTP 400
  • (Fog::Rackspace::AutoScale:::InternalServerError) —
    • HTTP 500
  • (Fog::Rackspace::AutoScale:::ServiceError)

See Also:



194
195
196
197
198
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 194

def execute
  requires :identity
  service.execute_policy(group.id, identity)
  true
end

#save ⇒ Boolean

Saves the policy Creates policy if it is new, otherwise it will update it

Returns:

  • (Boolean) —

    true if policy has saved



159
160
161
162
163
164
165
166
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 159

def save
  if persisted?
    update
  else
    create
  end
  true
end

#update ⇒ Boolean

Updates the policy

Returns:

  • (Boolean) —

    returns true if policy has started updating

Raises:

  • (Fog::Rackspace::AutoScale:::NotFound) —
    • HTTP 404
  • (Fog::Rackspace::AutoScale:::BadRequest) —
    • HTTP 400
  • (Fog::Rackspace::AutoScale:::InternalServerError) —
    • HTTP 500
  • (Fog::Rackspace::AutoScale:::ServiceError)

See Also:



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 134

def update
  requires :identity

  check_attributes

  options = {}
  options['name'] = name unless name.nil?
  options['change'] = change unless change.nil?
  options['changePercent'] = change_percent unless change_percent.nil?
  options['cooldown'] = cooldown unless cooldown.nil?
  options['type'] = type unless type.nil?
  options['desiredCapacity'] = desired_capacity unless desired_capacity.nil?

  if type == 'schedule'
    options['args'] = args
  end

  data = service.update_policy(group.id, identity, options)
  merge_attributes(data.body)
  true
end

#webhooks ⇒ Fog::Rackspace::AutoScale::Webhooks

Gets the associated webhooks for this policy

Returns:

Raises:

  • (Fog::Rackspace::AutoScale:::NotFound) —
    • HTTP 404
  • (Fog::Rackspace::AutoScale:::BadRequest) —
    • HTTP 400
  • (Fog::Rackspace::AutoScale:::InternalServerError) —
    • HTTP 500
  • (Fog::Rackspace::AutoScale:::ServiceError)


208
209
210
211
212
213
214
215
216
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 208

def webhooks
  requires :identity

  @webhooks ||= Fog::Rackspace::AutoScale::Webhooks.new({
    :service   => service,
    :policy => self,
    :group  => group
  })
end