class Capistrano::Ec2Role::Servers

Attributes

cache_instances[RW]
ec2_instances[RW]

Public Class Methods

new(access_key_id, secret_access_key, region) click to toggle source
# File lib/capistrano/ec2_role/servers.rb, line 13
def initialize(access_key_id, secret_access_key, region)
 self.class.cache_instances ||= AWS::EC2.new(
   :access_key_id => access_key_id,
   :secret_access_key => secret_access_key,
   :region => region
 ).instances.to_a

 self.ec2_instances = self.class.cache_instances.clone
 self
end

Public Instance Methods

cache_instances() click to toggle source
# File lib/capistrano/ec2_role/servers.rb, line 24
def cache_instances
  self.class.cache_instances
end
running() click to toggle source
# File lib/capistrano/ec2_role/servers.rb, line 34
def running
  tap {
    ec2_instances.delete_if {|instance| instance.status != :running }
  }
end
tagged(tag) click to toggle source
# File lib/capistrano/ec2_role/servers.rb, line 28
def tagged(tag)
  tap { 
    ec2_instances.delete_if {|instance| untagged?(instance, tag) }
  }
end
to_instances_name() click to toggle source
# File lib/capistrano/ec2_role/servers.rb, line 40
def to_instances_name
  ec2_instances.map {|instance| instance.public_dns_name || instance.private_dns_name }
end

Private Instance Methods

untagged?(instance, tag) click to toggle source
# File lib/capistrano/ec2_role/servers.rb, line 46
def untagged?(instance, tag)
  return true if tag.empty?

  required = tag.map {|k, v|
    instance.tags[k.to_s].gsub(/[\s ]/, '').split(',').include?(v) rescue false
  } 
  
  required.uniq.any? {|r| r == false}
end