Class: Ec2ssh::Ec2Instances

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

Defined Under Namespace

Classes: InstanceWrapper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aws_keys, filters) ⇒ Ec2Instances

Returns a new instance of Ec2Instances.



59
60
61
62
# File 'lib/ec2ssh/ec2_instances.rb', line 59

def initialize(aws_keys, filters)
  @aws_keys = aws_keys
  @filters = filters
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, region) ⇒ Object



90
91
92
93
# File 'lib/ec2ssh/ec2_instances.rb', line 90

def self.expand_profile_name_to_credential(profile_name, region)
  client = Aws::STS::Client.new(profile: profile_name, region: region)
  client.config.credentials
end

Instance Method Details

#instances(key_name) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/ec2ssh/ec2_instances.rb', line 80

def instances(key_name)
  aws_keys[key_name].each_key.map {|region|
    ec2s[key_name][region].instances(
      filters: @filters
    ).
    map {|ins| InstanceWrapper.new(ins) }.
    sort_by {|ins| ins.tag('Name').to_s }
  }.flatten
end

#make_ec2sObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ec2ssh/ec2_instances.rb', line 64

def make_ec2s
  _ec2s = {}
  aws_keys.each_pair do |name, keys|
    _ec2s[name] = {}
    keys.each_pair do |region, key|
      client = Aws::EC2::Client.new region: region, credentials: key
      _ec2s[name][region] = Aws::EC2::Resource.new client: client
    end
  end
  _ec2s
end