Class: Morpheus::Cli::NetworkPoolServersCommand
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
#_get, #_get_type, #connect, #get, #get_type, included, #list, #list_types, #registered_interfaces, #render_response_for_get_type, #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_option_context_map, #rest_perms_config, #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
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
Instance Method Details
#add(args) ⇒ Object
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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/morpheus/cli/commands/network_pool_servers_command.rb', line 25
def add(args)
options = {}
ip_range_list = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
opts.on('--name VALUE', String, "Name for this network pool server") do |val|
options['name'] = val
end
opts.on('--type VALUE', String, "Type of network pool server") do |val|
options['type'] = val
end
opts.on('--enabled [on|off]', String, "Can be used to disable") do |val|
options[:options]['enabled'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s.empty?
end
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
opts. = "Create a new network pool server." + "\n" +
"[name] is required and can be passed as --name instead."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, max: 1)
connect(options)
begin
options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
if args[0]
options['name'] = args[0]
end
payload = nil
if options[:payload]
payload = options[:payload]
else
payload = {
'networkPoolServer' => {
}
}
payload['networkPoolServer'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
if options['name']
payload['networkPoolServer']['name'] = options['name']
else
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this network pool server.'}], options)
payload['networkPoolServer']['name'] = v_prompt['name']
end
network_type_id = nil
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => 'Pool Server Type', 'type' => 'select', 'optionSource' => 'networkPoolServerTypes', 'required' => true, 'description' => 'Choose a network pool server type.'}], options, @api_client, {})
network_type_id = v_prompt['type']
if network_type_id.nil? || network_type_id.to_s.empty?
print_red_alert "Pool Server Type not found by id '#{options['type']}'"
return 1
end
network_pool_server_type = @network_pool_servers_interface.get_type(network_type_id.to_i)['networkPoolServerType']
payload['networkPoolServer']['type'] = network_pool_server_type['code']
option_result = Morpheus::Cli::OptionTypes.prompt(network_pool_server_type['optionTypes'], options[:options].deep_merge({:context_map => {'networkPoolServer' => ''}}), @api_client, {}, options[:no_prompt], true)
payload['networkPoolServer'].deep_merge!(option_result)
end
@network_pool_servers_interface.setopts(options)
if options[:dry_run]
print_dry_run @network_pool_servers_interface.dry.create(payload)
return
end
json_response = @network_pool_servers_interface.create(payload)
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
elsif !options[:quiet]
network_pool_server = json_response['networkPoolServer']
print_green_success "Added network pool server #{network_pool_server['name']}"
_get(network_pool_server['id'], {}, options)
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#handle(args) ⇒ Object
21
22
23
|
# File 'lib/morpheus/cli/commands/network_pool_servers_command.rb', line 21
def handle(args)
handle_subcommand(args)
end
|
#remove(args) ⇒ Object
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/morpheus/cli/commands/network_pool_servers_command.rb', line 203
def remove(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[network-pool-server]")
build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :remote])
opts. = "Delete a network pool server." + "\n" +
"[network-pool-server] is required. This is the name or id of a network pool server."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count: 1)
connect(options)
begin
network_pool_server = find_network_pool_server_by_name_or_id(args[0])
return 1 if network_pool_server.nil?
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the network pool server: #{network_pool_server['name']}?")
return 9, "aborted command"
end
@network_pool_servers_interface.setopts(options)
if options[:dry_run]
print_dry_run @network_pool_servers_interface.dry.destroy(network_pool_server['id'])
return 0
end
json_response = @network_pool_servers_interface.destroy(network_pool_server['id'])
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
else
print_green_success "Removed network pool server #{network_pool_server['name']}"
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return 1
end
end
|
#update(args) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/morpheus/cli/commands/network_pool_servers_command.rb', line 118
def update(args)
options = {}
ip_range_list = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[network-pool-server] [options]")
opts.on('--name VALUE', String, "Name for this network pool server") do |val|
options['name'] = val
end
opts.on('--enabled [on|off]', String, "Can be used to enable or disable it") do |val|
options[:options]['enabled'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s.empty?
end
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
opts. = "Update a network pool server." + "\n" +
"[network-pool-server] is required. This is the id of a network pool server."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count: 1)
connect(options)
begin
network_pool_server = find_network_pool_server_by_name_or_id(args[0])
return 1 if network_pool_server.nil?
options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
payload = nil
if options[:payload]
payload = options[:payload]
else
payload = {
'networkPoolServer' => {
}
}
payload['networkPoolServer'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
if options['name']
payload['networkPoolServer']['name'] = options['name']
else
end
if options['type']
payload['networkPoolServer']['type'] = {'id' => options['type'].to_i }
end
end
@network_pool_servers_interface.setopts(options)
if options[:dry_run]
print_dry_run @network_pool_servers_interface.dry.update(network_pool_server["id"], payload)
return
end
json_response = @network_pool_servers_interface.update(network_pool_server["id"], payload)
if options[:json]
puts as_json(json_response)
else
network_pool_server = json_response['networkPoolServer']
print_green_success "Updated network pool server #{network_pool_server['name']}"
_get(network_pool_server['id'], {}, options)
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
return 1
end
end
|