Module: Awsome

Defined in:
lib/awsome.rb,
lib/awsome/ec2.rb,
lib/awsome/elb.rb,
lib/awsome/r53.rb,
lib/awsome/ssh.rb,
lib/awsome/debian.rb,
lib/awsome/executor.rb,
lib/awsome/matchmaker.rb,
lib/awsome/ec2/instance.rb,
lib/awsome/requirements.rb,
lib/awsome/elb/load_balancer.rb,
lib/awsome/instance_requirement.rb,
lib/awsome/requirements_options.rb

Defined Under Namespace

Modules: Debian, Ec2, Elb, R53, Ssh Classes: Config, Executor, InstanceRequirement, Matchmaker, Requirements, RequirementsOptions

Class Method Summary collapse

Class Method Details

.configObject



4
5
6
# File 'lib/awsome.rb', line 4

def self.config
  @@config ||= Config.new
end

.execute(command, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/awsome.rb', line 8

def self.execute(command, options={})
  command = command.join(' ') if command.is_a?(Array)
  verbose = config.verbose && options[:verbose] != false
  if verbose
    puts
    puts
    if options[:task]
      puts options[:task].upcase
      puts '-' * options[:task].length
    end
    puts "> #{command}"
  end
  if options[:system]
    result = system(command)
  else
    result = `#{command}`
    result = options[:preprocess].call(result) if options[:preprocess]
    result = map_table(result, options)
  end
ensure
  if verbose && options[:output] != false
    if result.is_a?(Array)
      if result.any?
        headings = result.first.collect(&:first)
        rows = result.collect{|r| headings.collect{|h| r[h]}}
        puts Terminal::Table.new headings: headings, rows: rows
      else
        puts Terminal::Table.new title: 'No Results'
      end
    else
      puts result
    end
  end
  if config.stacks
    ap Kernel.caller
  end
end

.map_table(table, options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/awsome.rb', line 46

def self.map_table(table, options)
  return table unless options[:columns]
  rows = table.split("\n")
  rows.select! { |row| row =~ options[:filter] } if options[:filter]
  rows.collect do |row|
    properties = {}
    values = options[:delimiter] ? row.split(options[:delimiter]) : row.split
    values.each_with_index { |value, index| 
      field = options[:columns][index]
      properties[field] = value
    }
    properties
  end
end

.wait_until(opts = {}, &block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/awsome.rb', line 61

def self.wait_until(opts={}, &block)
  retries = opts[:retries] || 5
  interval = opts[:interval] || 5
  while !yield && retries > 0
    if config.verbose
      task = opts[:task] || 'block returned false'
      puts "[#{retries} more retries] #{task}"
    end
    sleep interval
    retries -= 1
  end
end