Module: AwsDataHelper
- Defined in:
- lib/opsworks_ship/aws_data_helper.rb
Instance Method Summary collapse
- #all_stack_names ⇒ Object
- #app_id(stack_id) ⇒ Object
- #describe_deployments(deployment_id) ⇒ Object
- #instance_name(instance_id) ⇒ Object
- #layer_instance_ids(layer_ids) ⇒ Object
- #opsworks_app_types ⇒ Object
- #per_server_status_descriptions(deployment_id) ⇒ Object
- #relevant_app_layer_ids(stack_id) ⇒ Object
- #relevant_instance_ids(stack_id) ⇒ Object
- #stack_data ⇒ Object
- #stack_id ⇒ Object
- #stack_layers(stack_id) ⇒ Object
Instance Method Details
#all_stack_names ⇒ Object
33 34 35 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 33 def all_stack_names @all_stack_names ||= stack_data.map{|s| s['Name']}.sort end |
#app_id(stack_id) ⇒ Object
52 53 54 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 52 def app_id(stack_id) JSON.parse(`aws opsworks describe-apps --stack-id=#{stack_id}`)['Apps'].select{|a| a['Type'] == @app_type}.first['AppId'] end |
#describe_deployments(deployment_id) ⇒ Object
56 57 58 59 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 56 def describe_deployments(deployment_id) cmd = "aws opsworks describe-deployments --deployment-ids #{deployment_id}" JSON.parse(`#{cmd}`) end |
#instance_name(instance_id) ⇒ Object
65 66 67 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 65 def instance_name(instance_id) JSON.parse(`aws opsworks describe-instances --instance-id #{instance_id}`)['Instances'].first['Hostname'] end |
#layer_instance_ids(layer_ids) ⇒ Object
3 4 5 6 7 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 3 def layer_instance_ids(layer_ids) layer_ids.map do |layer_id| JSON.parse(`aws opsworks describe-instances --layer-id=#{layer_id}`)['Instances'].map{|i| i['InstanceId']} end.flatten end |
#opsworks_app_types ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 21 def opsworks_app_types [ 'aws-flow-ruby', 'java', 'rails', 'php', 'nodejs', 'static', 'other', ] end |
#per_server_status_descriptions(deployment_id) ⇒ Object
61 62 63 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 61 def per_server_status_descriptions(deployment_id) JSON.parse(`aws opsworks describe-commands --deployment-id #{deployment_id}`)['Commands'].map{|deploy| "#{instance_name(deploy['InstanceId'])} - Status: #{deploy['Status']} - Log: #{deploy['LogUrl']}"} end |
#relevant_app_layer_ids(stack_id) ⇒ Object
13 14 15 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 13 def relevant_app_layer_ids(stack_id) stack_layers(stack_id).select{|l| l['Name'] =~ /#{@app_layer_name_regex}/i}.map{|layer_data| layer_data['LayerId']} end |
#relevant_instance_ids(stack_id) ⇒ Object
9 10 11 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 9 def relevant_instance_ids(stack_id) layer_instance_ids(relevant_app_layer_ids(stack_id)) end |
#stack_data ⇒ Object
37 38 39 40 41 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 37 def stack_data @stack_data ||= begin JSON.parse(`aws opsworks describe-stacks`)['Stacks'] end end |
#stack_id ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/opsworks_ship/aws_data_helper.rb', line 43 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 |