Class: CollinsShell::Cli
- Inherits:
-
Thor
- Object
- Thor
- CollinsShell::Cli
show all
- Includes:
- ThorHelper, Util
- Defined in:
- lib/collins_shell/cli.rb
Constant Summary
Constants included
from Util
Util::SIZABLE_ATTRIBUTES
Constants included
from ThorHelper
ThorHelper::COLLINS_OPTIONS, ThorHelper::PAGE_OPTIONS
Instance Method Summary
collapse
Methods included from Util
#asset_exec, #asset_get, #call_collins, #finalize_exec, #format_asset_tags, #format_asset_value, #get_selector, #is_array?, #print_find_results, #run_command_in_thread, #say_status, #thread_mgr
Methods included from ThorHelper
#appropriate_answer?, #batch_selector_operation, #collins_config_from_file, #ensure_password, #get_collins_client, #get_collins_config, #get_password, included, #require_valid_collins_config, #require_yes, #say_error, #say_success, #selector_or_tag, #try_config_merge, #use_collins_options, #use_nuke_option, #use_page_options, #use_selector_option, #use_tag_option
Instance Method Details
#console ⇒ Object
144
145
146
147
|
# File 'lib/collins_shell/cli.rb', line 144
def console
ensure_password
CollinsShell::Console.launch(options)
end
|
#latest ⇒ Object
35
36
37
|
# File 'lib/collins_shell/cli.rb', line 35
def latest
puts(get_latest_version)
end
|
#log(message) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/collins_shell/cli.rb', line 89
def log message
batch_selector_operation Hash[
:remote => options.remote,
:operation => "log",
:success_message => proc {|asset| "Logged to #{asset.tag}"},
:error_message => proc{|asset| "Log to #{asset.tag}"},
:confirmation_message => proc do |assets|
"You are about to log '#{message}' on #{assets.length} hosts. ARE YOU SURE?"
end
] do |client,asset|
client.log!(asset, message, options.severity)
end
end
|
#logs(tag) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/collins_shell/cli.rb', line 107
def logs tag
call_collins get_collins_client, "logs" do |client|
severity = []
if options.severity? then
severity = options.severity
end
params = Hash[
:filter => severity.join(';'),
:size => options[:size].to_i,
:sort => options[:sort]
]
logs = client.logs tag, params.merge(:all_tag => 'all')
logs.reverse! if options[:sort].to_s.downcase == 'desc'
printer = CollinsShell::LogPrinter.new(tag, logs)
puts printer.render
end
end
|
#power(action) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/collins_shell/cli.rb', line 72
def power action
action = Collins::Power.normalize_action(action)
call_collins get_collins_client, "power" do |client|
client.log! options.tag, options.reason, 'ALERT'
if client.power!(options.tag, action) then
say_success "power #{action} on #{options.tag}"
else
say_error "power #{action} on #{options.tag}", :exit => true
end
end
end
|
#power_status ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/collins_shell/cli.rb', line 48
def power_status
batch_selector_operation Hash[
:remote => options.remote,
:operation => "power_status",
:success_message => proc {|asset| "Got power status for #{asset.tag}"},
:error_message => proc{|asset| "Error getting power status for #{asset.tag}"},
:confirmation_message => proc do |assets|
"You are about to check the power status of #{assets.length} hosts. ARE YOU SURE?"
end
] do |client,asset|
puts('*'*80)
begin
status = client.power_status(asset)
say_success "Power status of #{asset.tag}: #{status}"
rescue Exception => e
print_error e, "Unable to check power status of #{asset.tag}", false
end
end
end
|
#search_logs(query) ⇒ Object
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/collins_shell/cli.rb', line 128
def search_logs query
call_collins get_collins_client, "logs" do |client|
params = Hash[
:query => query,
:size => options[:size].to_i,
:sort => options[:sort],
:sortField => 'date'
]
logs = client.search_logs params
printer = CollinsShell::LogPrinter.new("all assets", logs)
puts printer.render
end
end
|
#version ⇒ Object
40
41
42
|
# File 'lib/collins_shell/cli.rb', line 40
def version
puts("collins-shell #{get_version}")
end
|