Class: Morpheus::Cli::GuidanceSettings
- Inherits:
-
Object
- Object
- Morpheus::Cli::GuidanceSettings
show all
- Includes:
- AccountsHelper, CliCommand
- Defined in:
- lib/morpheus/cli/commands/guidance_settings.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#account_column_definitions, #account_users_interface, #accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_all_user_ids, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #find_user_group_by_id, #find_user_group_by_name, #find_user_group_by_name_or_id, #format_access_string, #format_role_type, #format_user_role_names, #format_user_status, #get_access_color, #get_access_string, included, #list_account_column_definitions, #list_user_column_definitions, #list_user_group_column_definitions, #role_column_definitions, #roles_interface, #subtenant_role_column_definitions, #user_column_definitions, #user_group_column_definitions, #user_groups_interface
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Instance Method Details
#connect(opts) ⇒ Object
11
12
13
14
15
|
# File 'lib/morpheus/cli/commands/guidance_settings.rb', line 11
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@guidance_settings_interface = @api_client.guidance_settings
@options_interface = @api_client.options
end
|
#get(args) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/morpheus/cli/commands/guidance_settings.rb', line 21
def get(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage()
build_standard_get_options(opts, options)
opts. = "Get guidance settings."
end
optparse.parse!(args)
connect(options)
verify_args!(args:args, optparse:optparse, count:0)
params.merge!(parse_query_options(options))
@guidance_settings_interface.setopts(options)
if options[:dry_run]
print_dry_run @guidance_settings_interface.dry.get(options)
return
end
json_response = @guidance_settings_interface.get(options)
render_response(json_response, options, object_key) do
guidance_settings = json_response[object_key]
print_h1 "Guidance Settings", options
print_h2 "Power Settings", options.merge(:border_style => :thin)
print_description_list({
"Average CPU (%)" => lambda {|it| it['cpuAvgCutoffPower'] }, "Maximum CPU (%)" => lambda {|it| it['cpuMaxCutoffPower'] }, "Network threshold (bytes)" => lambda {|it| it['networkCutoffPower'] }, }, guidance_settings, options)
print_h2 "CPU Up-size Settings", options.merge(:border_style => :thin)
print_description_list({
"Average CPU (%)" => lambda {|it| it['cpuUpAvgStandardCutoffRightSize'] }, "Maximum CPU (%)" => lambda {|it| it['cpuUpMaxStandardCutoffRightSize'] }, }, guidance_settings, options)
print_h2 "Memory Up-size Settings", options.merge(:border_style => :thin)
print_description_list({
"Minimum Free Memory (%)" => lambda {|it| it['memoryUpAvgStandardCutoffRightSize'] }, }, guidance_settings, options)
print_h2 "Memory Down-size Settings", options.merge(:border_style => :thin)
print_description_list({
"Average Free Memory (%)" => lambda {|it| it['memoryDownAvgStandardCutoffRightSize'] },
"Maximum Free Memory (%)" => lambda {|it| it['memoryDownMaxStandardCutoffRightSize'] },
}, guidance_settings, options)
print reset, "\n"
end
return 0, nil
end
|
#handle(args) ⇒ Object
17
18
19
|
# File 'lib/morpheus/cli/commands/guidance_settings.rb', line 17
def handle(args)
handle_subcommand(args)
end
|
#update(args) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/morpheus/cli/commands/guidance_settings.rb', line 79
def update(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = opts.banner = subcommand_usage()
opts.on('--power-cpu-avg PERCENT', String, "Power Shutdown Average CPU (%). Lower limit for average CPU usage") do |val|
params['cpuAvgCutoffPower'] = val.to_i
end
opts.on('--power-cpu-max PERCENT', String, "Power Shutdown Maximum CPU (%). Lower limit for peak CPU usage") do |val|
params['cpuMaxCutoffPower'] = val.to_i
end
opts.on('--power-network BYTES', String, "Power Shutdown Network threshold (bytes). Lower limit for average network bandwidth") do |val|
params['networkCutoffPower'] = val.to_i
end
opts.on('--cpu-up-avg PERCENT', String, "CPU Up-size Average CPU (%). Upper limit for CPU usage") do |val|
params['cpuUpAvgStandardCutoffRightSize'] = val.to_i
end
opts.on('--cpu-up-max PERCENT', String, "CPU Up-size Maximum CPU (%). Upper limit for peak CPU usage") do |val|
params['cpuUpMaxStandardCutoffRightSize'] = val.to_i
end
opts.on('--memory-up-avg PERCENT', String, "Memory Up-size Minimum Free Memory (%). Lower limit for average free memory usage") do |val|
params['memoryUpAvgStandardCutoffRightSize'] = val.to_i
end
opts.on('--memory-down-avg PERCENT', String, "Memory Down-size Maximum Free Memory (%). Upper limit for average free memory") do |val|
params['memoryDownAvgStandardCutoffRightSize'] = val.to_i
end
opts.on('--memory-down-max PERCENT', String, "Memory Down-size Maximum Free Memory (%). Upper limit for peak memory usage") do |val|
params['memoryDownMaxStandardCutoffRightSize'] = val.to_i
end
build_standard_update_options(opts, options)
opts. = "Update guidance settings."
end
optparse.parse!(args)
connect(options)
verify_args!(args:args, optparse:optparse, count:0)
payload = parse_payload(options)
if !payload
payload = {}
payload.deep_merge!({object_key => parse_passed_options(options)}) payload.deep_merge!({object_key => params}) end
if payload[object_key].empty?
raise_command_error "Specify at least one option to update.\n#{optparse}"
end
@guidance_settings_interface.setopts(options)
if options[:dry_run]
print_dry_run @guidance_settings_interface.dry.update(payload)
return
end
json_response = @guidance_settings_interface.update(payload)
exit_code, err = 0, nil
render_response(json_response, options, object_key) do
if json_response['success']
print_green_success "Updated guidance settings"
get([] + (options[:remote] ? ["-r",options[:remote]] : []))
else
exit_code, err = 1, "Error updating guidance settings: #{json_response['msg'] || json_response['errors']}"
print_rest_errors(json_response)
end
end
return exit_code, err
end
|