Class: AwsRsync::Host
- Inherits:
-
Object
- Object
- AwsRsync::Host
- Includes:
- AwsServices
- Defined in:
- lib/aws_rsync/host.rb
Instance Method Summary collapse
- #find_instance ⇒ Object
-
#initialize(options = {}) ⇒ Host
constructor
A new instance of Host.
- #instance ⇒ Object
- #ip ⇒ Object
- #region ⇒ Object
Methods included from AwsServices
Constructor Details
#initialize(options = {}) ⇒ Host
Returns a new instance of Host.
5 6 7 8 |
# File 'lib/aws_rsync/host.rb', line 5 def initialize(={}) @options = @instance_id = [:instance_id] end |
Instance Method Details
#find_instance ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/aws_rsync/host.rb', line 19 def find_instance instances = ec2.describe_instances(instance_ids: [@instance_id]). reservations.first["instances"] || [] instance = instances.first rescue Aws::EC2::Errors::ServiceError => e puts "ERROR: Could not find the instance #{@instance_id}".colorize(:red) puts e. puts "For the full internal backtrace re-run the command with DEBUG=1" unless ENV['DEBUG'] puts e.backtrace if ENV['DEBUG'] exit 1 end |
#instance ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/aws_rsync/host.rb', line 10 def instance instance = find_instance unless instance puts "ERROR: unable to find instance '#{@instance_id}' in this aws account and region: #{region}" exit 1 end instance end |
#ip ⇒ Object
35 36 37 38 39 |
# File 'lib/aws_rsync/host.rb', line 35 def ip @options[:private_ip] ? instance.private_ip_address : instance.public_ip_address end |
#region ⇒ Object
31 32 33 |
# File 'lib/aws_rsync/host.rb', line 31 def region `aws configure get region`.strip rescue 'us-east-1' end |