Class: Chimp::ExecReport

Inherits:
Executor show all
Defined in:
lib/right_chimp/exec/ExecReport.rb

Constant Summary

Constants inherited from Executor

Chimp::Executor::STATUS_DONE, Chimp::Executor::STATUS_ERROR, Chimp::Executor::STATUS_HOLDING, Chimp::Executor::STATUS_NONE, Chimp::Executor::STATUS_RETRYING, Chimp::Executor::STATUS_RUNNING

Instance Attribute Summary collapse

Attributes inherited from Executor

#array, #dry_run, #error, #exec, #group, #inputs, #job_id, #owner, #quiet, #results, #retry_count, #retry_sleep, #status, #template, #time_end, #time_start, #timeout, #verbose

Instance Method Summary collapse

Methods inherited from Executor

#cancel, #get_total_exec_time, #initialize, #queue, #requeue, #target

Constructor Details

This class inherits a constructor from Chimp::Executor

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



11
12
13
# File 'lib/right_chimp/exec/ExecReport.rb', line 11

def fields
  @fields
end

#serverObject

Returns the value of attribute server.



11
12
13
# File 'lib/right_chimp/exec/ExecReport.rb', line 11

def server
  @server
end

Instance Method Details

#infoObject



14
15
16
# File 'lib/right_chimp/exec/ExecReport.rb', line 14

def info
  return "report on server #{fields.inspect}"
end

#runObject



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
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/right_chimp/exec/ExecReport.rb', line 18

def run
  run_with_retry do
    output = []
    
    #
    # The API and rest_connection return very different data
    # depending on the API call made (here, tag query vs. array)
    # so the logic to load the server information and tags is
    # messy.
    #
    begin
      s = Server.find(@server.href)
      s.settings
      response = ::Tag.search_by_href(s.current_instance_href)
    rescue Exception => ex
      s = @server
      response = ::Tag.search_by_href(s.href)
    end

    s.tags = [] unless s.tags
    response.each do |t|
      s.tags += [ t['name'] ]
    end
    
    @fields.split(",").each do |f|
      if f =~ /^tag=([^,]+)/
        tag_search_string = $1
        s.tags.each do |tag|
          output << tag if tag =~ /^#{tag_search_string}/
        end
      else
        output << s.params[f]
      end
    end
    
    puts output.join(",")
  end
end