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::EVENT_STATE_DIR, Constants::HUMAN_TIME_FORMAT, Constants::HUMAN_TIME_FORMAT_MS, Constants::SEARCH_SPLIT

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_response_blocks, #check_status, #cli_output_class, #conds_to_query, #dispatch, #display, #display_api_error, #display_class, #display_no_api_response, #do_delete, #do_describe, #do_dump, #do_import, #do_list, #do_search, #do_set, #do_undelete, #dump_json, #dump_yaml, #extract_values, #failed_validation_message, #format_var, #handle_error, #handle_response, #hcl_fields, #import_to_create, #initialize, #item_dump_call, #load_display_class, #matching_method, #method_word_list, #mk_creds, #mk_opts, #name_of_do_method, #no_api_response, #ok_exit, #one_or_all, #options_and_exit, #parseable_output, #range_hash, #require_sdk_class, #run, #search_key, #smart_delete, #smart_delete_message, #status_error_handler, #unsupported_format_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #warning_message

Constructor Details

This class inherits a constructor from WavefrontCli::Base

Instance Method Details

#build_bodyObject



37
38
39
40
41
42
43
44
# File 'lib/wavefront-cli/maintenancewindow.rb', line 37

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



91
92
93
# File 'lib/wavefront-cli/maintenancewindow.rb', line 91

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

#descriptive_nameObject



21
22
23
# File 'lib/wavefront-cli/maintenancewindow.rb', line 21

def descriptive_name
  'maintenance window'
end

#do_closeObject



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

def do_close
  cannot_noop!
  change_end_time(Time.now.to_i)
end

#do_createObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wavefront-cli/maintenancewindow.rb', line 25

def do_create
  body = build_body

  [%i[CustomerTags atag], %i[HostTags htag],
   %i[HostNames host]].each do |key, opt|
    k = :"relevant#{key}"
    body[k] = options[opt] unless options[opt].empty?
  end

  wf.create(body)
end

#do_extend_byObject



68
69
70
71
72
73
# File 'lib/wavefront-cli/maintenancewindow.rb', line 68

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

#do_extend_toObject



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

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

#do_ongoingObject



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

def do_ongoing
  ret = wf.ongoing

  exit if options[:noop]

  return ret unless ret.is_a?(Wavefront::Response) && ret.empty?

  ok_exit('No maintenance windows currently ongoing.')
end

#do_pendingObject



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/wavefront-cli/maintenancewindow.rb', line 105

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

  ret = wf.pending(range)

  exit if options[:noop]

  return ret unless ret.is_a?(Wavefront::Response) && ret.empty?

  ok_exit(format('No maintenance windows in the next %<range>s hours.',
                 range: range))
end

#parse_range_to_addObject



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

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

#validator_exceptionObject



17
18
19
# File 'lib/wavefront-cli/maintenancewindow.rb', line 17

def validator_exception
  Wavefront::Exception::InvalidMaintenanceWindowId
end

#validator_methodObject



13
14
15
# File 'lib/wavefront-cli/maintenancewindow.rb', line 13

def validator_method
  :wf_maintenance_window_id?
end

#window_endInteger

Returns end time of window, in seconds. If not given as an option, end it in an hour.

Returns:

  • (Integer)

    end time of window, in seconds. If not given as an option, end it in an hour



60
61
62
63
64
65
66
# File 'lib/wavefront-cli/maintenancewindow.rb', line 60

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

#window_startInteger

Returns start time of window, in seconds. If not given as an option, start it now.

Returns:

  • (Integer)

    start time of window, in seconds. If not given as an option, start it now



49
50
51
52
53
54
55
# File 'lib/wavefront-cli/maintenancewindow.rb', line 49

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