morpheus-cli 4.1.5 → 4.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1534,7 +1534,7 @@ EOT
1534
1534
  def load_appliance_file
1535
1535
  fn = appliances_file_path
1536
1536
  if File.exist? fn
1537
- Morpheus::Logging::DarkPrinter.puts "loading appliances file #{fn}" if Morpheus::Logging.debug?
1537
+ #Morpheus::Logging::DarkPrinter.puts "loading appliances file #{fn}" if Morpheus::Logging.debug?
1538
1538
  return YAML.load_file(fn)
1539
1539
  else
1540
1540
  return {}
@@ -1773,7 +1773,6 @@ EOT
1773
1773
  rescue => err
1774
1774
  # should save before raising atleast..sheesh
1775
1775
  raise err
1776
- # Morpheus::Cli::ErrorHandler.new.handle_error(e)
1777
1776
  app_map[:status] = 'error'
1778
1777
  app_map[:last_check][:error] = err.message
1779
1778
  end
@@ -116,7 +116,7 @@ class Morpheus::Cli::SecurityGroups
116
116
  options = {}
117
117
  optparse = Morpheus::Cli::OptionParser.new do |opts|
118
118
  opts.banner = subcommand_usage("[id]")
119
- build_common_options(opts, options, [:json, :dry_run, :remote])
119
+ build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
120
120
  opts.footer = "Get details about a security group."
121
121
  end
122
122
  optparse.parse!(args)
@@ -124,33 +124,30 @@ class Morpheus::Cli::SecurityGroups
124
124
  raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
125
125
  end
126
126
  connect(options)
127
- begin
128
- @security_groups_interface.setopts(options)
129
-
130
- if options[:dry_run]
131
- if args[0].to_s =~ /\A\d{1,}\Z/
132
- print_dry_run @security_groups_interface.dry.get(args[0].to_i)
133
- else
134
- print_dry_run @security_groups_interface.dry.list({name:args[0]})
135
- end
136
- return 0
137
- end
138
- security_group = find_security_group_by_name_or_id(args[0])
139
- return 1 if security_group.nil?
140
- json_response = nil
127
+ exit_code, err = 0, nil
128
+
129
+ security_group_id = nil
141
130
  if args[0].to_s =~ /\A\d{1,}\Z/
142
- json_response = {'securityGroup' => security_group} # skip redundant request
131
+ security_group_id = args[0].to_i
143
132
  else
144
- json_response = @security_groups_interface.get(security_group['id'])
133
+ security_group = find_security_group_by_name(args[0])
134
+ return 1, "Security Group not found" if security_group.nil?
135
+ security_group_id = security_group['id']
145
136
  end
146
-
147
- if options[:json]
148
- print JSON.pretty_generate(json_response)
149
- print "\n"
150
- return
137
+ @security_groups_interface.setopts(options)
138
+ if options[:dry_run]
139
+ print_dry_run @security_groups_interface.dry.get(security_group_id)
140
+ return exit_code, err
151
141
  end
142
+ json_response = @security_groups_interface.get(security_group_id)
143
+ render_result = render_with_format(json_response, options, 'securityGroup')
144
+ return exit_code, err if render_result
145
+
152
146
  security_group = json_response['securityGroup']
153
- print_h1 "Morpheus Security Group"
147
+ security_group_locations = json_response['locations'] || security_group['locations']
148
+ security_group_rules = json_response['rules'] || security_group['rules']
149
+
150
+ print_h1 "Security Group Details"
154
151
  print cyan
155
152
  description_cols = {
156
153
  "ID" => 'id',
@@ -162,7 +159,7 @@ class Morpheus::Cli::SecurityGroups
162
159
  print_description_list(description_cols, security_group)
163
160
  # print reset,"\n"
164
161
 
165
- if security_group['locations'] && security_group['locations'].size > 0
162
+ if security_group_locations && security_group_locations.size > 0
166
163
  print_h2 "Locations"
167
164
  print cyan
168
165
  location_cols = {
@@ -171,13 +168,13 @@ class Morpheus::Cli::SecurityGroups
171
168
  "EXTERNAL ID" => lambda {|it| it['externalId'] },
172
169
  "RESOURCE POOL" => lambda {|it| it['zonePool'] ? it['zonePool']['name'] : '' }
173
170
  }
174
- puts as_pretty_table(security_group['locations'], location_cols)
171
+ puts as_pretty_table(security_group_locations, location_cols)
175
172
  else
176
173
  print reset,"\n"
177
174
  end
178
175
 
179
- if security_group['rules']
180
- if security_group['rules'].size == 0
176
+ if security_group_rules
177
+ if security_group_rules == 0
181
178
  #print cyan,"No rules.",reset,"\n"
182
179
  else
183
180
  print_h2 "Rules"
@@ -217,15 +214,11 @@ class Morpheus::Cli::SecurityGroups
217
214
  "PROTOCOL" => lambda {|it| it['protocol'] },
218
215
  "PORT RANGE" => lambda {|it| it['portRange'] }
219
216
  }
220
- puts as_pretty_table(security_group['rules'], rule_cols)
217
+ puts as_pretty_table(security_group_rules, rule_cols)
221
218
  end
222
219
  end
223
220
 
224
- return 0
225
- rescue RestClient::Exception => e
226
- print_rest_exception(e, options)
227
- exit 1
228
- end
221
+ return exit_code, err
229
222
  end
230
223
 
231
224
  def add(args)
@@ -442,7 +442,7 @@ class Morpheus::Cli::Shell
442
442
  log_history_command(input)
443
443
  return Morpheus::Cli::SourceCommand.new.handle(input.split[1..-1])
444
444
  end
445
- cmd_result = nil
445
+ exit_code, err = 0, nil
446
446
  begin
447
447
  argv = Shellwords.shellsplit(input)
448
448
  cmd_name = argv[0]
@@ -462,28 +462,28 @@ class Morpheus::Cli::Shell
462
462
  start_benchmark(benchmark_name)
463
463
  end
464
464
  end
465
- cmd_exit_code, cmd_err = Morpheus::Cli::CliRegistry.exec_expression(input)
466
- #cmd_result = Morpheus::Cli::CliRegistry.exec(cmd_name, cmd_args)
467
- #cmd_exit_code, cmd_err = Morpheus::Cli::CliRegistry.parse_command_result(cmd_result)
468
- benchmark_record = stop_benchmark(cmd_exit_code, cmd_err) # if benchmarking?
465
+ exit_code, err = Morpheus::Cli::CliRegistry.exec_expression(input)
466
+ benchmark_record = stop_benchmark(exit_code, err) # if benchmarking?
469
467
  Morpheus::Logging::DarkPrinter.puts(cyan + dark + benchmark_record.msg) if benchmark_record
470
468
  # else
471
469
  # puts_error "#{Morpheus::Terminal.angry_prompt}'#{cmd_name}' is not recognized. Use 'help' to see the list of available commands."
472
470
  # @history_logger.warn "Unrecognized Command #{cmd_name}" if @history_logger
473
- # cmd_result = -1
471
+ # exit_code, err = -1, "Command not recognized"
474
472
  # end
475
473
  rescue Interrupt
476
- # nothing to do
474
+ # user pressed ^C to interrupt a command
477
475
  @history_logger.warn "shell interrupt" if @history_logger
478
476
  print "\nInterrupt. aborting command '#{input}'\n"
477
+ exit_code, err = 9, "aborted command"
479
478
  rescue SystemExit => cmdexit
480
- # nothing to do
479
+ # nothing to do, assume the command that exited printed an error already
481
480
  # print "\n"
482
- cmd_result = cmdexit.status
481
+ exit_code, err = cmdexit.status, "Command exited early."
483
482
  rescue => e
483
+ # some other type of failure..
484
484
  @history_logger.error "#{e.message}" if @history_logger
485
- cmd_result = Morpheus::Cli::ErrorHandler.new(my_terminal.stderr).handle_error(e) # lol
486
- # exit 1
485
+ exit_code, err = Morpheus::Cli::ErrorHandler.new(my_terminal.stderr).handle_error(e) # lol
486
+
487
487
  ensure
488
488
  if @return_to_log_level
489
489
  Morpheus::Logging.set_log_level(@return_to_log_level)
@@ -501,11 +501,7 @@ class Morpheus::Cli::Shell
501
501
  end
502
502
  end
503
503
 
504
- # commands should be a number or nil (treated as 0)
505
- if cmd_result == true
506
- cmd_result = 0
507
- end
508
- return cmd_result
504
+ return exit_code, err
509
505
  end
510
506
 
511
507
  end