Class: Morpheus::Cli::NetworkServicesCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::NetworkServicesCommand
- Includes:
- CliCommand, InfrastructureHelper
- Defined in:
- lib/morpheus/cli/network_services_command.rb
Instance Attribute Summary
Attributes included from CliCommand
Instance Method Summary collapse
- #connect(opts) ⇒ Object
- #handle(args) ⇒ Object
-
#initialize ⇒ NetworkServicesCommand
constructor
set_default_subcommand :list.
- #list(args) ⇒ Object
Methods included from InfrastructureHelper
#cloud_type_for_id, #cloud_type_for_name, #cloud_type_for_name_or_id, #clouds_interface, #find_cloud_by_id, #find_cloud_by_name, #find_cloud_by_name_or_id, #find_group_by_id, #find_group_by_name, #find_group_by_name_or_id, #get_available_cloud_types, #groups_interface, included
Methods included from CliCommand
#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #print, #print_error, #puts, #puts_error, #raise_command_error, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Constructor Details
#initialize ⇒ NetworkServicesCommand
set_default_subcommand :list
19 20 21 |
# File 'lib/morpheus/cli/network_services_command.rb', line 19 def initialize() # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance end |
Instance Method Details
#connect(opts) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/morpheus/cli/network_services_command.rb', line 23 def connect(opts) @api_client = establish_remote_appliance_connection(opts) @network_services_interface = @api_client.network_services @clouds_interface = @api_client.clouds @options_interface = @api_client. end |
#handle(args) ⇒ Object
30 31 32 |
# File 'lib/morpheus/cli/network_services_command.rb', line 30 def handle(args) handle_subcommand(args) end |
#list(args) ⇒ Object
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/morpheus/cli/network_services_command.rb', line 34 def list(args) = {} params = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage() (opts, , [:list, :json, :yaml, :csv, :fields, :json, :dry_run, :remote]) opts. = "List network services." end optparse.parse!(args) connect() begin [:phrase, :offset, :max, :sort, :direction].each do |k| params[k] = [k] unless [k].nil? end if [:dry_run] print_dry_run @network_services_interface.dry.list(params) return end json_response = @network_services_interface.list(params) network_services = json_response["networkServices"] if [:include_fields] json_response = {"networkServices" => filter_data(network_services, [:include_fields]) } end if [:json] puts as_json(json_response, ) return 0 elsif [:yaml] puts as_yaml(json_response, ) return 0 elsif [:csv] puts records_as_csv(network_services, ) return 0 end title = "Morpheus Network Services" subtitles = [] if params[:phrase] subtitles << "Search: #{params[:phrase]}".strip end print_h1 title, subtitles if network_services.empty? print cyan,"No network services found.",reset,"\n" else rows = network_services.collect {|network_service| row = { id: network_service['id'], name: network_service['name'], type: network_service['type'] ? network_service['type']['name'] : '', } row } columns = [:id, :name, :type] if [:include_fields] columns = [:include_fields] end print cyan print as_pretty_table(rows, columns, ) print reset print_results_pagination(json_response, {:label => "network service", :n_label => "network services"}) end print reset,"\n" return 0 rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |