Class: NodeSpec::CommunicationAdapters::AwsEc2

Inherits:
Object
  • Object
show all
Defined in:
lib/nodespec/communication_adapters/aws_ec2.rb

Constant Summary collapse

GEMLOAD_ERROR =
'In order to use any aws adapter you must install the Amazon Web Service gem'

Class Method Summary collapse

Class Method Details

.communicator_for(node_name, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nodespec/communication_adapters/aws_ec2.rb', line 9

def self.communicator_for(node_name, options = {})
  RuntimeGemLoader.require_or_fail('aws-sdk', GEMLOAD_ERROR) do
    instance_name = options['instance'] || node_name
    ec2_instance = AWS.ec2.instances[instance_name]

    raise "EC2 Instance #{instance_name} is not reachable" unless ec2_instance.exists? && ec2_instance.status == :running
    if options.has_key?('winrm')
      WinrmCommunicator.new(ec2_instance.public_ip_address, options['winrm'])
    else
      SshCommunicator.new(ec2_instance.public_ip_address, options['ssh'] || {})
    end
  end
end