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

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

Instance Attribute Summary collapse

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Attribute Details

#argsString (readonly)

Returns Arguments used for the policy.

Returns:

  • (String)

    Arguments used for the policy



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

#changeFixnum (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



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

#changePercentFixnum (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



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

attribute :change_percent, :aliases => 'changePercent'

#cooldownFixnum (readonly)

Returns The policy’s cooldown.

Returns:

  • (Fixnum)

    The policy’s cooldown



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

#desiredCapacityFixnum (readonly)

Returns The desired capacity of the group.

Returns:

  • (Fixnum)

    The desired capacity of the group



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

attribute :desired_capacity, :aliases => 'desiredCapacity'

#group_idString (readonly)

Returns The autoscale group’s id.

Returns:

  • (String)

    The autoscale group’s id



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

attribute :group_id

#idString (readonly)

Returns The policy id.

Returns:



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

identity :id

Returns Policy links.

Returns:

  • (Array)

    Policy links



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

#nameString (readonly)

Returns The policy’s name.

Returns:

  • (String)

    The policy’s name



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

attribute :name

#typeString (readonly)

Note:

Can only be “webhook”, “schedule” or “cloud_monitoring”

Returns The policy’s type.

Returns:

  • (String)

    The policy’s type



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

Instance Method Details

#check_attributesBoolean

Returns true if the check passes

Returns:

  • (Boolean)

    Returns true if the check passes

Raises:

  • (ArgumentError)


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

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

#destroyBoolean

Returns true if policy has started deleting

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:



163
164
165
166
167
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 163

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

#executeBoolean

Returns true if policy has been executed

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:



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

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

#saveBoolean

  • 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:



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

def save
  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

#updateBoolean

Returns true if policy has started updating

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:



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

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

#webhooksFog::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)


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

def webhooks
  data = service.list_webhooks(group_id, self.id)

  Fog::Rackspace::AutoScale::Webhooks.new({
    :service   => service,
    :policy_id => self.id,
    :group_id  => group_id
  }).merge_attributes(data.body)
end