Class: Ec2ssh::Ec2Instances
- Inherits:
-
Object
- Object
- Ec2ssh::Ec2Instances
- Defined in:
- lib/ec2ssh/ec2_instances.rb
Defined Under Namespace
Classes: InstanceWrapper
Instance Attribute Summary collapse
-
#aws_keys ⇒ Object
readonly
Returns the value of attribute aws_keys.
-
#ec2s ⇒ Object
readonly
Returns the value of attribute ec2s.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(aws_keys, filters) ⇒ Ec2Instances
constructor
A new instance of Ec2Instances.
- #instances(key_name) ⇒ Object
- #make_ec2s ⇒ Object
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_keys ⇒ Object (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 |
#ec2s ⇒ Object (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.(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_ec2s ⇒ Object
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 |