Sha256: 74b90ca00e0d0ffd49830c24ab26130f239c4c5dcba86d362248cbd4cfbc01ca

Contents?: true

Size: 1.42 KB

Versions: 11

Compression:

Stored size: 1.42 KB

Contents

#
# Report
#
# :fields is a comma seperated list of fields to report on,
# and are taken from the RestConnection Server objects directly.
#
# Example: ip-address,name,href,private-ip-address,aws-id,ec2-instance-type,dns-name,locked
#
module Chimp
  class ExecReport < Executor
    attr_reader :server, :fields
    attr_writer :server, :fields
    
    def info
      return "report on server #{fields.inspect}"
    end

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
right_chimp-1.1.3 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.1.2 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.1.1 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.1.0 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0.9 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0.8 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0.7 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0.3 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0.2 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0.1 lib/right_chimp/exec/ExecReport.rb
right_chimp-1.0 lib/right_chimp/exec/ExecReport.rb