Class: Ec2::Tracer::Writer
- Inherits:
-
Object
- Object
- Ec2::Tracer::Writer
- Defined in:
- lib/ec2/tracer.rb
Constant Summary collapse
- WRITE_MODE =
'a'.freeze
- TEMP_IP =
'0.0.0.0'
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#host_prefix ⇒ Object
readonly
Returns the value of attribute host_prefix.
-
#identity_file ⇒ Object
readonly
Returns the value of attribute identity_file.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(file_name = 'ec2.d', host_prefix = 'welligence_ml', range = (2..10), user = 'ubuntu', identity_file = '~/.ssh/welligence.pem') ⇒ Writer
constructor
A new instance of Writer.
- #write_config ⇒ Object
Constructor Details
#initialize(file_name = 'ec2.d', host_prefix = 'welligence_ml', range = (2..10), user = 'ubuntu', identity_file = '~/.ssh/welligence.pem') ⇒ Writer
Returns a new instance of Writer.
12 13 14 15 16 17 18 |
# File 'lib/ec2/tracer.rb', line 12 def initialize(file_name = 'ec2.d', host_prefix = 'welligence_ml', range = (2..10), user = 'ubuntu', identity_file = '~/.ssh/welligence.pem' ) @file_name = file_name @host_prefix = host_prefix @range = range @user = user @identity_file = identity_file end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/ec2/tracer.rb', line 10 def file_name @file_name end |
#host_prefix ⇒ Object (readonly)
Returns the value of attribute host_prefix.
10 11 12 |
# File 'lib/ec2/tracer.rb', line 10 def host_prefix @host_prefix end |
#identity_file ⇒ Object (readonly)
Returns the value of attribute identity_file.
10 11 12 |
# File 'lib/ec2/tracer.rb', line 10 def identity_file @identity_file end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
10 11 12 |
# File 'lib/ec2/tracer.rb', line 10 def range @range end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
10 11 12 |
# File 'lib/ec2/tracer.rb', line 10 def user @user end |
Instance Method Details
#write_config ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ec2/tracer.rb', line 20 def write_config ec2 = Aws::EC2::Resource.new(region: 'us-west-2') filepath = "#{Dir.pwd}/#{file_name}" FileUtils.rm_rf filepath FileUtils.touch filepath ec2.instances({filters: [{name: 'tag:Name', values: range.map{|i| "#{host_prefix}_#{i}"} }]}).each do |i| instance_tag_name = i..map(&:value).join() public_ip_address = i.public_ip_address puts "#{instance_tag_name} - #{public_ip_address}" File.open(filepath, WRITE_MODE) { |f| f << ssh_host(host: instance_tag_name, host_name: public_ip_address) } end end |