Class: Fog::Rackspace::AutoScale::Policy
- Defined in:
- lib/fog/rackspace/models/auto_scale/policy.rb
Instance Attribute Summary collapse
-
#args ⇒ String
readonly
-
“cron”: “23 * * * *” - “at”: “2013-06-05T03:12Z” - “check”: { “label”: “Website check 1”, “type”: “remote.http”, “details”: { “url”: “www.example.com”, “method”: “GET” }, “monitoring_zones_poll”: [ “mzA” ], “timeout”: 30, “period”: 100, “target_alias”: “default” }, “alarm_criteria”: { “criteria”: “if (metric >= 2) { return new AlarmStatus(OK); } return new AlarmStatus(CRITICAL);” }.
-
-
#change ⇒ Fixnum
readonly
The fixed change to the autoscale group’s number of units.
-
#changePercent ⇒ Fixnum
readonly
The percentage change to the autoscale group’s number of units.
-
#cooldown ⇒ Fixnum
readonly
The policy’s cooldown.
-
#desiredCapacity ⇒ Fixnum
readonly
The desired capacity of the group.
-
#group ⇒ Group
The autoscale group.
-
#id ⇒ String
readonly
The policy id.
-
#links ⇒ Array
readonly
Policy links.
-
#name ⇒ String
readonly
The policy’s name.
-
#type ⇒ String
readonly
The policy’s type.
Attributes inherited from Model
Instance Method Summary collapse
-
#check_attributes ⇒ Boolean
Returns true if the check passes.
-
#create ⇒ Boolean
Creates policy * requires attributes: :name, :type, :cooldown.
-
#destroy ⇒ Boolean
Destroy the policy.
-
#execute ⇒ Boolean
Executes the scaling policy.
-
#save ⇒ Boolean
Saves the policy Creates policy if it is new, otherwise it will update it.
-
#update ⇒ Boolean
Updates the policy.
-
#webhooks ⇒ Fog::Rackspace::AutoScale::Webhooks
Gets the associated webhooks for this policy.
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
#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);" }
65 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 65 attribute :args |
#change ⇒ Fixnum (readonly)
Returns The fixed change to the autoscale group’s number of units.
27 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 27 attribute :change |
#changePercent ⇒ Fixnum (readonly)
Returns 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' |
#cooldown ⇒ Fixnum (readonly)
Returns The policy’s cooldown.
35 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 35 attribute :cooldown |
#desiredCapacity ⇒ Fixnum (readonly)
Returns The desired capacity of the group.
69 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 69 attribute :desired_capacity, :aliases => 'desiredCapacity' |
#group ⇒ Group
Returns The autoscale group.
15 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 15 attribute :group |
#id ⇒ String (readonly)
Returns The policy id.
11 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 11 identity :id |
#links ⇒ Array (readonly)
Returns Policy links.
19 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 19 attribute :links |
#name ⇒ String (readonly)
Returns The policy’s name.
23 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 23 attribute :name |
#type ⇒ String (readonly)
Can only be “webhook”, “schedule” or “cloud_monitoring”
Returns The policy’s type.
40 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 40 attribute :type |
Instance Method Details
#check_attributes ⇒ Boolean
Returns true if the check passes
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 |
#create ⇒ Boolean
Creates policy
-
requires attributes: :name, :type, :cooldown
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 103 def create requires :name, :type, :cooldown check_attributes = {} ['name'] = name unless name.nil? ['change'] = change unless change.nil? ['changePercent'] = change_percent unless change_percent.nil? ['cooldown'] = cooldown unless cooldown.nil? ['type'] = type unless type.nil? ['desiredCapacity'] = desired_capacity unless desired_capacity.nil? if type == 'schedule' ['args'] = args end data = service.create_policy(group.id, ) merge_attributes(data.body['policies'][0]) true end |
#destroy ⇒ Boolean
Destroy the policy
179 180 181 182 183 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 179 def destroy requires :identity service.delete_policy(group.id, identity) true end |
#execute ⇒ Boolean
Executes the scaling policy
195 196 197 198 199 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 195 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
160 161 162 163 164 165 166 167 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 160 def save if persisted? update else create end true end |
#update ⇒ Boolean
Updates the policy
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 135 def update requires :identity check_attributes = {} ['name'] = name unless name.nil? ['change'] = change unless change.nil? ['changePercent'] = change_percent unless change_percent.nil? ['cooldown'] = cooldown unless cooldown.nil? ['type'] = type unless type.nil? ['desiredCapacity'] = desired_capacity unless desired_capacity.nil? if type == 'schedule' ['args'] = args end data = service.update_policy(group.id, identity, ) merge_attributes(data.body) true end |
#webhooks ⇒ Fog::Rackspace::AutoScale::Webhooks
Gets the associated webhooks for this policy
209 210 211 212 213 214 215 216 217 |
# File 'lib/fog/rackspace/models/auto_scale/policy.rb', line 209 def webhooks requires :identity @webhooks ||= Fog::Rackspace::AutoScale::Webhooks.new({ :service => service, :policy => self, :group => group }) end |