Class: Morpheus::Cli::LoadBalancerVirtualServers

Inherits:
Object
  • Object
show all
Includes:
CliCommand, LoadBalancersHelper, RestCommand, SecondaryRestCommand
Defined in:
lib/morpheus/cli/commands/load_balancer_virtual_servers.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from LoadBalancersHelper

#find_load_balancer_by_id, #find_load_balancer_by_name, #find_load_balancer_by_name_or_id, #find_load_balancer_type_by_id, #find_load_balancer_type_by_name, #find_load_balancer_type_by_name_or_id, #get_available_load_balancer_types, included, #load_balancer_label, #load_balancer_label_plural, #load_balancer_list_key, #load_balancer_object_key, #load_balancer_type_for_id, #load_balancer_type_for_name, #load_balancer_type_for_name_or_id, #load_balancer_type_label, #load_balancer_type_label_plural, #load_balancer_type_list_key, #load_balancer_type_object_key, #load_balancer_types_interface, #load_balancers_interface

Methods included from SecondaryRestCommand

#_get, #add, #get, included, #registered_interfaces, #remove, #render_response_for_get, #rest_find_by_name_or_id, #rest_parent_arg, #rest_parent_column_definitions, #rest_parent_find_by_name_or_id, #rest_parent_has_name, #rest_parent_interface, #rest_parent_interface_name, #rest_parent_key, #rest_parent_label, #rest_parent_label_plural, #rest_parent_list_column_definitions, #rest_parent_list_key, #rest_parent_name, #rest_parent_object_key, #rest_parent_param, #update

Methods included from RestCommand

#_get, #add, #connect, #get, #handle, included, #registered_interfaces, #remove, #render_response_for_get, #rest_arg, #rest_column_definitions, #rest_find_by_name_or_id, #rest_has_name, #rest_has_type, #rest_interface, #rest_interface_name, #rest_key, #rest_label, #rest_label_plural, #rest_list_column_definitions, #rest_list_key, #rest_name, #rest_object_key, #rest_type_arg, #rest_type_column_definitions, #rest_type_find_by_name_or_id, #rest_type_interface, #rest_type_interface_name, #rest_type_key, #rest_type_label, #rest_type_label_plural, #rest_type_list_column_definitions, #rest_type_list_key, #rest_type_name, #rest_type_object_key, #update

Methods included from CliCommand

#apply_options, #build_common_options, #build_get_options, #build_option_type_options, #build_standard_add_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, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #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_subcommand_description, #handle, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_list_options, #parse_list_subtitles, #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

#list(args) ⇒ Object

overridden to provide global list functionality without requiring parent argument



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
# File 'lib/morpheus/cli/commands/load_balancer_virtual_servers.rb', line 21

def list(args)
  parent_id, parent_record = nil, nil
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[#{rest_parent_arg}] [search]")
    build_list_options(opts, options, params)
    opts.footer = "List \#{rest_label_plural.downcase}.\n[\#{rest_parent_arg}] is optional. This is the \#{rest_parent_has_name ? 'name or id' : 'id'} of \#{a_or_an(rest_parent_label)} \#{rest_parent_label.downcase}.\n[search] is optional. This is a search phrase to filter the results.\n"
  end
  optparse.parse!(args)
  parent_id = args[0]
  connect(options)
  if parent_id
    args = args[1..-1]
    parent_record = rest_parent_find_by_name_or_id(parent_id)
    if parent_record.nil?
      return 1, "#{rest_parent_label} not found for '#{parent_id}"
    end
    parent_id = parent_record['id']
  end
  parse_list_options!(args, options, params)
  rest_interface.setopts(options)
  if options[:dry_run]
    print_dry_run rest_interface.dry.list(parent_id, params)
    return
  end
  json_response = rest_interface.list(parent_id, params)
  render_response(json_response, options, rest_list_key) do
    records = json_response[rest_list_key]
    print_h1 "Morpheus #{rest_label_plural}"
    if records.nil? || records.empty?
      print cyan,"No #{rest_label_plural.downcase} found.",reset,"\n"
    else
      print as_pretty_table(records, rest_list_column_definitions(options).upcase_keys!, options)
      print_results_pagination(json_response) if json_response['meta']
    end
    print reset,"\n"
  end
  return 0, nil
end