Class: Morpheus::Cli::NetworkServicesCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::NetworkServicesCommand
- Includes:
- CliCommand, InfrastructureHelper
- Defined in:
- lib/morpheus/cli/commands/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, #find_network_by_id, #find_network_by_name, #find_network_by_name_or_id, #find_network_group_by_id, #find_network_group_by_name, #find_network_group_by_name_or_id, #find_network_type_by_id, #find_network_type_by_name, #find_network_type_by_name_or_id, #find_resource_pool_by_id, #find_resource_pool_by_name, #find_resource_pool_by_name_or_id, #find_resource_pool_group_by_id, #find_resource_pool_group_by_name, #find_resource_pool_group_by_name_or_id, #find_subnet_by_id, #find_subnet_by_name, #find_subnet_by_name_or_id, #find_subnet_type_by_id, #find_subnet_type_by_name, #find_subnet_type_by_name_or_id, #format_network_pool_server_status, #get_available_cloud_types, #groups_interface, included, #network_groups_interface, #network_pool_server_column_definitions, #network_pool_server_list_column_definitions, #network_pool_server_type_column_definitions, #network_pool_server_type_list_column_definitions, #network_types_interface, #networks_interface, #prompt_for_network, #prompt_for_networks, #prompt_for_pools, #prompt_for_subnets, #resource_pool_groups_interface, #resource_pools_interface, #subnet_types_interface, #subnets_interface
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_payload, #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, #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_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_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
Constructor Details
#initialize ⇒ NetworkServicesCommand
set_default_subcommand :list
14 15 16 |
# File 'lib/morpheus/cli/commands/network_services_command.rb', line 14 def initialize() # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance end |
Instance Method Details
#connect(opts) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/morpheus/cli/commands/network_services_command.rb', line 18 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
25 26 27 |
# File 'lib/morpheus/cli/commands/network_services_command.rb', line 25 def handle(args) handle_subcommand(args) end |
#list(args) ⇒ Object
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/morpheus/cli/commands/network_services_command.rb', line 29 def list(args) = {} params = {} optparse = Morpheus::Cli::OptionParser.new do |opts| opts. = subcommand_usage() (opts, , [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote]) opts. = "List network services (Integrations)." end optparse.parse!(args) connect() begin params.merge!(()) @network_services_interface.setopts() 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 [:json] puts as_json(json_response, , "networkServices") return 0 elsif [:yaml] puts as_yaml(json_response, , "networkServices") return 0 elsif [:csv] puts records_as_csv(network_services, ) return 0 end title = "Morpheus Network Services" subtitles = [] subtitles += parse_list_subtitles() 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['typeName'] || network_service['type'], } row } columns = [:id, :name, :type] if [:include_fields] columns = [:include_fields] end print cyan print as_pretty_table(rows, columns, ) print reset if json_response['meta'] print_results_pagination(json_response, {:label => "network service", :n_label => "network services"}) else print_results_pagination({'meta'=>{'total'=>rows.size,'size'=>rows.size,'max'=>[:max] || rows.size,'offset'=>0}}, {:label => "network service", :n_label => "network services"}) end end print reset,"\n" return 0 rescue RestClient::Exception => e print_rest_exception(e, ) exit 1 end end |