Class: Morpheus::Cli::NetworkServicesCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand, InfrastructureHelper
Defined in:
lib/morpheus/cli/network_services_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

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_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, #get_available_cloud_types, #groups_interface, included, #network_groups_interface, #network_types_interface, #networks_interface, #prompt_for_network, #prompt_for_networks, #prompt_for_subnets, #subnet_types_interface, #subnets_interface

Methods included from CliCommand

#apply_options, #build_common_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, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #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

#initializeNetworkServicesCommand

set_default_subcommand :list



18
19
20
# File 'lib/morpheus/cli/network_services_command.rb', line 18

def initialize()
  # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
end

Instance Method Details

#connect(opts) ⇒ Object



22
23
24
25
26
27
# File 'lib/morpheus/cli/network_services_command.rb', line 22

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.options
end

#handle(args) ⇒ Object



29
30
31
# File 'lib/morpheus/cli/network_services_command.rb', line 29

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



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
93
94
95
96
# File 'lib/morpheus/cli/network_services_command.rb', line 33

def list(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "List network services (Integrations)."
  end
  optparse.parse!(args)
  connect(options)
  begin
    params.merge!(parse_list_options(options))
    @network_services_interface.setopts(options)
    if options[: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 options[:json]
      puts as_json(json_response, options, "networkServices")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "networkServices")
      return 0
    elsif options[:csv]
      puts records_as_csv(network_services, options)
      return 0
    end
    title = "Morpheus Network Services"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    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 options[:include_fields]
        columns = options[:include_fields]
      end
      print cyan
      print as_pretty_table(rows, columns, options)
      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'=>options[: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, options)
    exit 1
  end
end