class HammerCLICsv::CsvCommand::ReportsCommand

Constants

APPLIED
FAILED
FAILED_RESTARTS
METRICS
PENDING
RESTARTED
SKIPPED
TIME

Public Instance Methods

create_reports_from_csv(line) click to toggle source
# File lib/hammer_cli_csv/reports.rb, line 38
def create_reports_from_csv(line)
  count(line[COUNT]).times do |number|
    name = namify(line[NAME], number)

    if !@existing_reports[name]
      print "Creating report '#{name}'..." if option_verbose?
      reported_at = line[TIME] || Time.now
      report = @api.resource(:reports).call(:create, {
          'host' => name,
          'reported_at' => reported_at,
          'status' => {
              'applied' => line[APPLIED],
              'restarted' => line[RESTARTED],
              'failed' => line[FAILED],
              'failed_restarts' => line[FAILED_RESTARTS],
              'skipped' => line[SKIPPED],
              'pending' => line[PENDING]
          },
          'metrics' => JSON.parse(line[METRICS]),
          'logs' => []
      })
      @existing_reports[name] = report['id']
    else
      print "Updating report '#{name}'..." if option_verbose?
      @api.resource(:reports).call(:update, {
          'id' => @existing_reports[name]
      })
    end

    puts 'done' if option_verbose?
  end
end
export(csv) click to toggle source
# File lib/hammer_cli_csv/reports.rb, line 16
def export(csv)
  csv << [NAME]
  @api.resource(:reports).call(:index, {
      'per_page' => 999999
  })['results'].each do |report|
    csv << [report['host_name'], report['metrics'].to_json]
  end
end
import() click to toggle source
# File lib/hammer_cli_csv/reports.rb, line 25
def import
  @existing_reports = {}
  @api.resource(:reports).call(:index, {
      'per_page' => 999999
  })['results'].each do |report|
    @existing_reports[report['name']] = report['id']
  end

  thread_import do |line|
    create_reports_from_csv(line)
  end
end