module Momentum::OpsWorks

Public Class Methods

client(aws_id, aws_secret) click to toggle source
# File lib/momentum/opsworks.rb, line 3
def self.client(aws_id, aws_secret)
  raise "You must specify aws_id and aws_secret!" if aws_id.nil? || aws_secret.nil?
  require 'aws-sdk'
  AWS::OpsWorks::Client.new(access_key_id: aws_id, secret_access_key: aws_secret)
end
get_app(client, stack, app_name) click to toggle source
# File lib/momentum/opsworks.rb, line 15
def self.get_app(client, stack, app_name)
  client.describe_apps(stack_id: stack[:stack_id])[:apps].detect { |a| a[:name] == app_name }
end
get_instance_endpoint(instance) click to toggle source

apparently, public_dns is not always set, fallback to elastic_ip (if available!) else private_dns

# File lib/momentum/opsworks.rb, line 20
def self.get_instance_endpoint(instance)
  instance[:public_dns] || instance[:elastic_ip] || instance[:private_dns]
end
get_layers(client, stack, layer_names) click to toggle source
# File lib/momentum/opsworks.rb, line 24
def self.get_layers(client, stack, layer_names)
  client.describe_layers(stack_id: stack[:stack_id])[:layers].select { |l| layer_names.include?(l[:shortname]) }
end
get_online_instance_ids(client, query = {}) click to toggle source
# File lib/momentum/opsworks.rb, line 28
def self.get_online_instance_ids(client, query = {})
  get_online_instances(client, query).map { |i| i[:instance_id] }
end
get_online_instances(client, query = {}) click to toggle source
# File lib/momentum/opsworks.rb, line 32
def self.get_online_instances(client, query = {})
  client.describe_instances(query)[:instances].select { |i| i[:status] == 'online' }
end
get_stack(client, stack_name) click to toggle source
# File lib/momentum/opsworks.rb, line 9
def self.get_stack(client, stack_name)
  client.describe_stacks[:stacks].detect { |k, v| k[:name] == stack_name }.tap do |stack|
    raise "No #{stack_name} stack found!" unless stack
  end
end
ssh_command_to(endpoint, command = nil) click to toggle source
# File lib/momentum/opsworks.rb, line 36
def self.ssh_command_to(endpoint, command = nil)
    [ 'ssh -t -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no',
      (['-i', ENV['AWS_PUBLICKEY']] if ENV['AWS_PUBLICKEY']),
      (['-l', ENV['AWS_USER']] if ENV['AWS_USER']),
      endpoint,
      command ].compact.flatten.join(' ')
end