Module: AwsOpsworksDataHelper

Defined in:
lib/easy_aws_ssh/aws_opsworks_data_helper.rb

Instance Method Summary collapse

Instance Method Details

#all_stack_instance_namesObject



19
20
21
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 19

def all_stack_instance_names
  stack_instance_data.map{|data| data['Hostname']}
end

#all_stack_namesObject



23
24
25
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 23

def all_stack_names
  stack_data.map{|s| s['Name']}.sort
end

#instance_dataObject



7
8
9
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 7

def instance_data
  stack_instance_data.find{|data| data['Hostname'] == @instance_name}
end

#instance_ipObject



11
12
13
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 11

def instance_ip
  instance_data['PublicIp']
end

#ssh_key_nameObject



15
16
17
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 15

def ssh_key_name
  instance_data['SshKeyName']
end

#stack_dataObject



27
28
29
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 27

def stack_data
  @stack_data = JSON.parse(`aws opsworks describe-stacks`)['Stacks']
end

#stack_idObject



31
32
33
34
35
36
37
38
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 31

def stack_id
  stack = stack_data.select{|s| s['Name'].downcase == @stack_name.downcase}.first
  if stack
    stack['StackId']
  else
    raise "Stack not found.  Available opsworks stacks: #{all_stack_names}"
  end
end

#stack_instance_dataObject



3
4
5
# File 'lib/easy_aws_ssh/aws_opsworks_data_helper.rb', line 3

def stack_instance_data
  @stack_instance_data ||= JSON.parse(`aws opsworks describe-instances --stack-id=#{stack_id}`)['Instances']
end