Class: Ec2ssh::Ec2Instances

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2ssh/ec2_instances.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_keys, regions) ⇒ Ec2Instances

Returns a new instance of Ec2Instances.



7
8
9
10
# File 'lib/ec2ssh/ec2_instances.rb', line 7

def initialize(aws_keys, regions)
  @aws_keys = aws_keys
  @regions = regions
end

Instance Attribute Details

#aws_keysObject (readonly)

Returns the value of attribute aws_keys.



5
6
7
# File 'lib/ec2ssh/ec2_instances.rb', line 5

def aws_keys
  @aws_keys
end

#ec2sObject (readonly)

Returns the value of attribute ec2s.



5
6
7
# File 'lib/ec2ssh/ec2_instances.rb', line 5

def ec2s
  @ec2s
end

Class Method Details

.expand_profile_name_to_credential(profile_name) ⇒ Object



38
39
40
41
# File 'lib/ec2ssh/ec2_instances.rb', line 38

def self.expand_profile_name_to_credential(profile_name)
  provider = AWS::Core::CredentialProviders::SharedCredentialFileProvider.new(profile_name: profile_name)
  provider.credentials
end

Instance Method Details

#instances(key_name) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ec2ssh/ec2_instances.rb', line 29

def instances(key_name)
  @regions.map {|region|
    ec2s[key_name][region].instances.
      filter('instance-state-name', 'running').
      to_a.
      sort_by {|ins| ins.tags['Name'].to_s }
  }.flatten
end

#make_ec2sObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ec2ssh/ec2_instances.rb', line 12

def make_ec2s
  AWS.start_memoizing
  _ec2s = {}
  aws_keys.each do |name, key|
    _ec2s[name] = {}
    @regions.each do |region|
      options = key.merge ec2_region: region
      _ec2s[name][region] = AWS::EC2.new options
    end
  end
  _ec2s
end