class AWS::AutoScaling::ScheduledActionCollection

Public Class Methods

new(options = {}) click to toggle source

@api private

Calls superclass method
# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 24
def initialize options = {}
  @filters = options[:filters] || {}
  super
end

Public Instance Methods

[](name) click to toggle source

@param [String] name The name of the scheduled action. @return [ScheduledAction]

# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 79
def [] name
  if group_name = @filters[:auto_scaling_group_name]
    group = Group.new(group_name, :config => config)
    ScheduledAction.new(group, name)
  else
    msg = 'uou must filter this collection by a group to get a ' +
      'scheduled action by name'
    raise msg
  end
end
create(name, options = {}) click to toggle source

Creates a scheduled scaling action for an Auto Scaling group. If you leave a parameter unspecified, the corresponding attribute remains unchanged in the group.

You must specify an Auto Scaling group. This can be implicit or explicit:

# given explicitly
auto_scaling.scheduled_actions.create('action-name', :group => 'group-name')

# implied by the group
group = auto_scaling.groups.first
group.scheduled_actions.create('action-name')

@param [String] name

@param [Hash] options

@option options [Group,String] :group

@option options [Integer] :desired_capacity

@option options [Integer] :max_size

@option options [Integer] :min_size

@option options [String] :recurrence

@option options [Time] :start_time

@option options [Time] :end_time

@return [ScheduledAction]

# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 63
def create name, options = {}

  group = auto_scaling_group(options)

  scheduled_action = ScheduledAction.new(group, name,
    :auto_scaling_group_name => group.name,
    :config => config)

  scheduled_action.update(options)
  scheduled_action

end
Also aliased as: put
filter(filters = {}) click to toggle source

Returns a new {ScheduledActionCollection} filtered by the given options.

auto_scaling.scheduled_actions.filter(:end_time => Time.now).each do |a|
   # ...
end

You can chain filter calls:

actions = auto_scaling.scheduled_actions.
   filter(:group => 'auto-scaling-group-name').
   filter(:start_time => Time.now - 3600).
   filter(:end_time => Time.now)

actions.each {|scheduled_action| ... }

@param [Hash] filters

@option filters [Group,String] :group

@option filters [Array<String>] :scheduled_actions

A list of scheduled actions to be described. If this list is
omitted, all scheduled actions are described. The list of
requested scheduled actions cannot contain more than 50 items.
If an Auto Scaling group name is provided,
the results are limited to that group. If unknown scheduled
actions are requested, they are ignored with no error.

@option options [Time,String] :start_time The earliest scheduled

start time to return. If `:scheduled_actions` is provided,
this field will be ignored.  Should be a Time object or
an iso8601 string.

@option filters [Time,String] :end_time

@return [ScheduledActionCollection] Returns a scheduled action

collection that will filter the actions returned by the
given criteria.
# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 129
def filter filters = {}
  init_opts = {}
  init_opts[:config] = config
  init_opts[:filters] = @filters
  init_opts[:filters].merge!(filter_opts(filters))
  ScheduledActionCollection.new(init_opts)
end
put(name, options = {})
Alias for: create

Protected Instance Methods

_each_item(next_token, limit, options = {}) { |scheduled_action| ... } click to toggle source
# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 175
def _each_item next_token, limit, options = {}, &block

  options[:next_token] = next_token if next_token
  options[:max_records] = limit if limit

  resp = client.describe_scheduled_actions(options.merge(@filters))
  resp.scheduled_update_group_actions.each do |details|

    group = Group.new(details[:auto_scaling_group_name], :config => config)

    scheduled_action = ScheduledAction.new_from(
      :describe_scheduled_actions,
      details,
      group,
      details.scheduled_action_name,
      :config => config)

    yield(scheduled_action)

  end

  resp.data[:next_token]

end
auto_scaling_group(options) click to toggle source
# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 139
def auto_scaling_group(options)

  group = options.delete(:group)
  group ||= @filters[:auto_scaling_group_name]
  group = Group.new(group, :config => config) if group.is_a?(String)

  unless group
    raise ArgumentError, 'missing required option :group'
  end

  group

end
filter_opts(options) click to toggle source
# File lib/aws/auto_scaling/scheduled_action_collection.rb, line 153
def filter_opts options

  opts = {}

  if g = options[:group]
    opts[:auto_scaling_group_name] = g.is_a?(Group) ? g.name : g
  end

  if actions = options[:scheduled_actions]
    opts[:scheduled_action_names] = actions
  end

  [:end_time, :start_time].each do |opt|
    if options[opt].is_a?(Time)
      opts[opt] = options[opt].iso8601
    end
  end

  opts

end