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.



61
62
63
64
# File 'lib/ec2ssh/ec2_instances.rb', line 61

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.



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

def aws_keys
  @aws_keys
end

#ec2sObject (readonly)

Returns the value of attribute ec2s.



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

def ec2s
  @ec2s
end

Class Method Details

.expand_profile_name_to_credential(profile_name, region) ⇒ Object



92
93
94
95
# File 'lib/ec2ssh/ec2_instances.rb', line 92

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



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

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



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

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