Class: Opsicle::FailureLog
- Inherits:
-
Object
- Object
- Opsicle::FailureLog
- Defined in:
- lib/opsicle/commands/failure_log.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #execute ⇒ Object
- #fetch ⇒ Object
- #fetch_failed_deployments ⇒ Object
- #fetch_instance_id(failed_deployments_instances) ⇒ Object
- #fetch_target_command(involved_instance_id, failed_deployment_id) ⇒ Object
-
#initialize(environment) ⇒ FailureLog
constructor
A new instance of FailureLog.
- #select_instance(instance_list) ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/opsicle/commands/failure_log.rb', line 3 def client @client end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
3 4 5 |
# File 'lib/opsicle/commands/failure_log.rb', line 3 def stack @stack end |
Instance Method Details
#execute ⇒ Object
11 12 13 14 15 |
# File 'lib/opsicle/commands/failure_log.rb', line 11 def execute puts "Getting most recent failure log..." fetch end |
#fetch ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/opsicle/commands/failure_log.rb', line 17 def fetch failed_deployments = fetch_failed_deployments unless failed_deployments.empty? failed_deployment_id = failed_deployments.first.deployment_id failed_deployments_instances = failed_deployments.first.instance_ids unless failed_deployments_instances.empty? involved_instance_id = fetch_instance_id(failed_deployments_instances) target_failed_command = fetch_target_command(involved_instance_id, failed_deployment_id) log_url = target_failed_command.first.log_url system("open", log_url) if log_url puts "Unable to find a url to open." unless log_url else puts "There is at least one failed deployment, but there is no log available for that failure." end else puts "No failed deployments in available history." end end |
#fetch_failed_deployments ⇒ Object
40 41 42 43 |
# File 'lib/opsicle/commands/failure_log.rb', line 40 def fetch_failed_deployments deployments = @client.opsworks.describe_deployments(stack_id: @stack.stack_id).deployments deployments.select{ |deploy| deploy.status.eql? "failed" } end |
#fetch_instance_id(failed_deployments_instances) ⇒ Object
45 46 47 48 49 |
# File 'lib/opsicle/commands/failure_log.rb', line 45 def fetch_instance_id(failed_deployments_instances) involved_instances = @client.opsworks.describe_instances(instance_ids: failed_deployments_instances).instances choice = select_instance(involved_instances) involved_instances[choice-1].instance_id end |
#fetch_target_command(involved_instance_id, failed_deployment_id) ⇒ Object
51 52 53 54 |
# File 'lib/opsicle/commands/failure_log.rb', line 51 def fetch_target_command(involved_instance_id, failed_deployment_id) command_list = @client.opsworks.describe_commands(instance_id: involved_instance_id)[:commands] command_list.select{ |command| command.deployment_id == failed_deployment_id } end |
#select_instance(instance_list) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/opsicle/commands/failure_log.rb', line 56 def select_instance(instance_list) if instance_list.length == 1 choice = 1 else Output.say "Choose an Opsworks instance:" instance_list.each_with_index do |instance, index| Output.say "#{index+1}) #{instance[:hostname]}" end choice = Output.ask("? ", Integer) { |q| q.in = 1..instance_list.length } end return choice end |