Class: Morpheus::Cli::NetworkServicesCommand
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
#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_server_type_by_id, #find_network_server_type_by_name, #find_network_server_type_by_name_or_code, #find_network_server_type_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_server_type_column_definitions, #network_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_standard_add_many_options, #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, #execute_api, #execute_api_payload, #execute_api_request, #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_each_payload, #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_options, #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
set_default_subcommand :list
14
15
16
|
# File 'lib/morpheus/cli/commands/network_services_command.rb', line 14
def initialize()
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.options
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)
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. = "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']
(json_response, {:label => "network service", :n_label => "network services"})
else
({'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
|
#refresh(args) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/morpheus/cli/commands/network_services_command.rb', line 94
def refresh(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
opts. = "Refresh a network integration/server.\n" +
"[name] is required. This is the name or id of a network server/integration."
end
optparse.parse!(args)
if args.count < 1
puts optparse
exit 1
end
connect(options)
begin
server = find_network_server_by_name_or_id(args[0])
if !server
exit 1
end
@network_services_interface.setopts(options)
if options[:dry_run]
print_dry_run @network_services_interface.dry.refresh(server['id'])
return
end
json_response = @network_services_interface.refresh(server['id'])
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
elsif !options[:quiet]
print_green_success "Refreshing #{server["name"]}"
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|