Class: WavefrontCli::MaintenanceWindow

Inherits:
Base
  • Object
show all
Includes:
Wavefront::Mixins
Defined in:
lib/wavefront-cli/maintenancewindow.rb

Overview

CLI coverage for the v2 ‘maintenancewindow’ API.

Constant Summary

Constants included from Constants

Constants::ALL_PAGE_SIZE, Constants::DEFAULT_CONFIG, Constants::DEFAULT_OPTS, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS

Instance Attribute Summary

Attributes inherited from Base

#klass, #klass_word, #options, #wf

Instance Method Summary collapse

Methods inherited from Base

#_sdk_class, #cannot_noop!, #check_status, #conds_to_query, #dispatch, #display, #display_api_error, #display_no_api_response, #do_delete, #do_describe, #do_import, #do_list, #do_search, #do_undelete, #do_update, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #import_to_create, #initialize, #load_display_class, #load_file, #load_from_stdin, #mk_creds, #mk_opts, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #run, #search_key, #smart_delete, #smart_delete_message, #validate_id, #validate_input, #validate_opts, #validate_tags

Constructor Details

This class inherits a constructor from WavefrontCli::Base

Instance Method Details

#build_bodyObject



31
32
33
34
35
36
37
38
# File 'lib/wavefront-cli/maintenancewindow.rb', line 31

def build_body
  ret = { title:              options[:'<title>'],
          startTimeInSeconds: window_start,
          endTimeInSeconds:   window_end }

  ret[:reason] = options[:desc] if options[:desc]
  ret
end

#change_end_time(timestamp) ⇒ Object



81
82
83
# File 'lib/wavefront-cli/maintenancewindow.rb', line 81

def change_end_time(timestamp)
  wf.update(options[:'<id>'], endTimeInSeconds: timestamp)
end

#do_closeObject



77
78
79
# File 'lib/wavefront-cli/maintenancewindow.rb', line 77

def do_close
  change_end_time(Time.now.to_i)
end

#do_createObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wavefront-cli/maintenancewindow.rb', line 19

def do_create
  body = build_body

  [%i[CustomerTags atag], %i[HostTags htag],
   %i[HostNames host]].each do |key, opt|
    k = ('relevant' + key.to_s).to_sym
    body[k] = options[opt] unless options[opt].empty?
  end

  wf.create(body)
end

#do_extend_byObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/wavefront-cli/maintenancewindow.rb', line 62

def do_extend_by
  begin
    to_add = options[:'<time>'].to_seconds
  rescue ArgumentError
    abort "Could not parse time range '#{options[:'<time>']}'."
  end

  old_end = wf.describe(options[:'<id>']).response.endTimeInSeconds
  change_end_time(old_end + to_add)
end

#do_extend_toObject



73
74
75
# File 'lib/wavefront-cli/maintenancewindow.rb', line 73

def do_extend_to
  change_end_time(parse_time(options[:'<time>']))
end

#do_ongoingObject



85
86
87
88
89
# File 'lib/wavefront-cli/maintenancewindow.rb', line 85

def do_ongoing
  w = wf.ongoing
  ok_exit('No maintenance windows currently ongoing.') if w.empty?
  w
end

#do_pendingObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/wavefront-cli/maintenancewindow.rb', line 91

def do_pending
  range = options[:'<hours>'].to_f
  range = 24 unless range.positive?

  w = wf.pending(range)

  if w.empty?
    ok_exit(format('No maintenance windows in the next %s hours.',
                   range))
  end
  w
end

#validator_exceptionObject



15
16
17
# File 'lib/wavefront-cli/maintenancewindow.rb', line 15

def validator_exception
  Wavefront::Exception::InvalidMaintenanceWindowId
end

#validator_methodObject



11
12
13
# File 'lib/wavefront-cli/maintenancewindow.rb', line 11

def validator_method
  :wf_maintenance_window_id?
end

#window_endInteger



54
55
56
57
58
59
60
# File 'lib/wavefront-cli/maintenancewindow.rb', line 54

def window_end
  if options[:end]
    parse_time(options[:end])
  else
    window_start + 3600
  end
end

#window_startInteger



43
44
45
46
47
48
49
# File 'lib/wavefront-cli/maintenancewindow.rb', line 43

def window_start
  if options[:start]
    parse_time(options[:start])
  else
    Time.now.to_i
  end
end