Class: Bonobo

Inherits:
Object
  • Object
show all
Defined in:
lib/bonobo.rb,
lib/bonobo/log.rb,
lib/bonobo/connection.rb

Overview

this is our main bonobo class

Defined Under Namespace

Classes: Connection, Log

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBonobo

Returns a new instance of Bonobo.



17
18
19
20
21
22
23
24
25
26
27
# 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

Instance Attribute Details

#filterObject

Returns the value of attribute filter.



15
16
17
# File 'lib/bonobo.rb', line 15

def filter
  @filter
end

#paramsObject

Returns the value of attribute params.



15
16
17
# File 'lib/bonobo.rb', line 15

def params
  @params
end

Instance Method Details

#find_objects(filter) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# 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_lineObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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

#runObject



73
74
75
76
77
78
79
80
81
82
83
# 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