Class: WavefrontCli::MaintenanceWindow
- Inherits:
-
Base
- Object
- Base
- WavefrontCli::MaintenanceWindow
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_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_message, #import_object, #import_to_create, #import_update, #initialize, #item_dump_call, #load_display_class, #load_file, #load_from_stdin, #load_json, #load_yaml, #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, #run, #search_key, #smart_delete, #smart_delete_message, #status_error_handler, #unsupported_format_message, #validate_id, #validate_input, #validate_opts, #validate_tags, #warning_message
Instance Method Details
#build_body ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 33
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
87
88
89
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 87
def change_end_time(timestamp)
wf.update(options[:'<id>'], endTimeInSeconds: timestamp)
end
|
#do_close ⇒ Object
82
83
84
85
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 82
def do_close
cannot_noop!
change_end_time(Time.now.to_i)
end
|
#do_create ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 21
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_by ⇒ Object
64
65
66
67
68
69
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 64
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_to ⇒ Object
77
78
79
80
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 77
def do_extend_to
cannot_noop!
change_end_time(parse_time(options[:'<time>']))
end
|
#do_ongoing ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 91
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_pending ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 101
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_add ⇒ Object
71
72
73
74
75
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 71
def parse_range_to_add
options[:'<time>'].to_seconds
rescue ArgumentError
abort "Could not parse time range '#{options[:'<time>']}'."
end
|
#validator_exception ⇒ Object
17
18
19
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 17
def validator_exception
Wavefront::Exception::InvalidMaintenanceWindowId
end
|
#validator_method ⇒ Object
13
14
15
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 13
def validator_method
:wf_maintenance_window_id?
end
|
#window_end ⇒ Integer
Returns end time of window, in seconds. If not given as an option, end it in an hour.
56
57
58
59
60
61
62
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 56
def window_end
if options[:end]
parse_time(options[:end])
else
window_start + 3600
end
end
|
#window_start ⇒ Integer
Returns start time of window, in seconds. If not given as an option, start it now.
45
46
47
48
49
50
51
|
# File 'lib/wavefront-cli/maintenancewindow.rb', line 45
def window_start
if options[:start]
parse_time(options[:start])
else
Time.now.to_i
end
end
|