class Bonobo

this is our main bonobo class

Constants

VERSION

Attributes

filter[RW]
params[RW]

Public Class Methods

new() click to toggle source
# File lib/bonobo.rb, line 17
def initialize
  # set up some nice defaults
  @params = {}
  @params[:tags] = []
  @params[:arrays] = []
  @params[:deployments] = []
  @params[:inputs] = []
  @params[:script] = ''

  @filter = :none
end

Public Instance Methods

find_objects(filter) click to toggle source
# File lib/bonobo.rb, line 85
def find_objects(filter)
  case filter
  when :tag
    results = @client.by_tag(@params[:tags])
  when :array
    results = @client.by_array(@params[:arrays])
  when :deployment
    raise 'Not done yet'
  end

  results
end
parse_command_line() click to toggle source
# File lib/bonobo.rb, line 29
def parse_command_line
  opts = GetoptLong.new(
    ['--tag', '-t', GetoptLong::REQUIRED_ARGUMENT],
    ['--array', '-a', GetoptLong::REQUIRED_ARGUMENT],
    ['--deployment', '-d', GetoptLong::REQUIRED_ARGUMENT],
    ['--script', '-s', GetoptLong::REQUIRED_ARGUMENT],
    ['--input', '-i', GetoptLong::REQUIRED_ARGUMENT],
    ['--help', '-h', GetoptLong::NO_ARGUMENT],
    ['--version', '-v', GetoptLong::NO_ARGUMENT],
    ['--verbose', GetoptLong::NO_ARGUMENT]
  )

  opts.each do |opt, arg|
    case opt
    when '--tag', '-t'
      @params[:tags] << arg
      @filter = :tag
    when '--array', '-a'
      @params[:arrays] << arg
      @filter = :array
    when '--deployment', '-d'
      @params[:deployments] << arg
      @filter = :deployment
    when '--script', '-s'
      @params[:script] = arg
    when '--input', '-i'
      @params[:inputs] << arg
    when '--help', '-h'
      help
      exit 0
    when '--version', '-v'
      Log.info VERSION
      exit 0
    when '--verbose'
      Log.threshold = Logger::DEBUG
    end
  end

rescue GetoptLong::InvalidOption => ex
  help
  p ex
  exit 1
end
run() click to toggle source
# File lib/bonobo.rb, line 73
def run
  parse_command_line
  # Connect to the api
  @client = Bonobo::Connection.new

  servers = find_objects(@filter)

  servers.each do |s|
    Log.info s['name']
  end
end