morpheus-cli 3.1.1 → 3.1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/morpheus/api/api_client.rb +40 -0
- data/lib/morpheus/api/cloud_policies_interface.rb +47 -0
- data/lib/morpheus/api/group_policies_interface.rb +47 -0
- data/lib/morpheus/api/network_domains_interface.rb +47 -0
- data/lib/morpheus/api/network_groups_interface.rb +47 -0
- data/lib/morpheus/api/network_pool_servers_interface.rb +47 -0
- data/lib/morpheus/api/network_pools_interface.rb +47 -0
- data/lib/morpheus/api/network_proxies_interface.rb +47 -0
- data/lib/morpheus/api/network_services_interface.rb +47 -0
- data/lib/morpheus/api/networks_interface.rb +54 -0
- data/lib/morpheus/api/policies_interface.rb +63 -0
- data/lib/morpheus/cli.rb +8 -4
- data/lib/morpheus/cli/cli_command.rb +36 -1
- data/lib/morpheus/cli/instances.rb +3 -25
- data/lib/morpheus/cli/network_domains_command.rb +571 -0
- data/lib/morpheus/cli/network_groups_command.rb +602 -0
- data/lib/morpheus/cli/network_pool_servers_command.rb +430 -0
- data/lib/morpheus/cli/network_pools_command.rb +495 -0
- data/lib/morpheus/cli/network_proxies_command.rb +594 -0
- data/lib/morpheus/cli/network_services_command.rb +148 -0
- data/lib/morpheus/cli/networks_command.rb +855 -0
- data/lib/morpheus/cli/option_types.rb +3 -3
- data/lib/morpheus/cli/policies_command.rb +847 -0
- data/lib/morpheus/cli/remote.rb +0 -1
- data/lib/morpheus/cli/roles.rb +2 -2
- data/lib/morpheus/cli/version.rb +1 -1
- metadata +20 -2
@@ -0,0 +1,594 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'optparse'
|
3
|
+
require 'filesize'
|
4
|
+
require 'table_print'
|
5
|
+
require 'morpheus/cli/cli_command'
|
6
|
+
require 'morpheus/cli/mixins/infrastructure_helper'
|
7
|
+
|
8
|
+
class Morpheus::Cli::NetworkProxiesCommand
|
9
|
+
include Morpheus::Cli::CliCommand
|
10
|
+
include Morpheus::Cli::InfrastructureHelper
|
11
|
+
|
12
|
+
set_command_name :'network-proxies'
|
13
|
+
|
14
|
+
register_subcommands :list, :get, :add, :update, :remove #, :generate_proxy
|
15
|
+
|
16
|
+
# set_default_subcommand :list
|
17
|
+
|
18
|
+
def initialize()
|
19
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
20
|
+
end
|
21
|
+
|
22
|
+
def connect(opts)
|
23
|
+
@api_client = establish_remote_appliance_connection(opts)
|
24
|
+
@network_proxies_interface = @api_client.network_proxies
|
25
|
+
@clouds_interface = @api_client.clouds
|
26
|
+
@options_interface = @api_client.options
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle(args)
|
30
|
+
handle_subcommand(args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def list(args)
|
34
|
+
options = {}
|
35
|
+
params = {}
|
36
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
37
|
+
opts.banner = subcommand_usage()
|
38
|
+
build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
|
39
|
+
opts.footer = "List network proxies."
|
40
|
+
end
|
41
|
+
optparse.parse!(args)
|
42
|
+
connect(options)
|
43
|
+
begin
|
44
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
45
|
+
params[k] = options[k] unless options[k].nil?
|
46
|
+
end
|
47
|
+
if options[:dry_run]
|
48
|
+
print_dry_run @network_proxies_interface.dry.list(params)
|
49
|
+
return
|
50
|
+
end
|
51
|
+
json_response = @network_proxies_interface.list(params)
|
52
|
+
network_proxies = json_response["networkProxies"]
|
53
|
+
if options[:include_fields]
|
54
|
+
json_response = {"networkProxies" => filter_data(network_proxies, options[:include_fields]) }
|
55
|
+
end
|
56
|
+
if options[:json]
|
57
|
+
puts as_json(json_response, options)
|
58
|
+
return 0
|
59
|
+
elsif options[:yaml]
|
60
|
+
puts as_yaml(json_response, options)
|
61
|
+
return 0
|
62
|
+
elsif options[:csv]
|
63
|
+
puts records_as_csv(network_proxies, options)
|
64
|
+
return 0
|
65
|
+
end
|
66
|
+
title = "Morpheus Network Proxies"
|
67
|
+
subtitles = []
|
68
|
+
if params[:phrase]
|
69
|
+
subtitles << "Search: #{params[:phrase]}".strip
|
70
|
+
end
|
71
|
+
print_h1 title, subtitles
|
72
|
+
if network_proxies.empty?
|
73
|
+
print cyan,"No network proxies found.",reset,"\n"
|
74
|
+
else
|
75
|
+
rows = network_proxies.collect {|network_proxy|
|
76
|
+
row = {
|
77
|
+
id: network_proxy['id'],
|
78
|
+
name: network_proxy['name'],
|
79
|
+
host: network_proxy['proxyHost'],
|
80
|
+
port: network_proxy['proxyPort'],
|
81
|
+
visibility: network_proxy['visibility'].to_s.capitalize,
|
82
|
+
tenant: network_proxy['account'] ? network_proxy['account']['name'] : '',
|
83
|
+
owner: network_proxy['owner'] ? network_proxy['owner']['name'] : '',
|
84
|
+
}
|
85
|
+
row
|
86
|
+
}
|
87
|
+
columns = [:id, :name, :host, :port, :visibility, :tenant]
|
88
|
+
if options[:include_fields]
|
89
|
+
columns = options[:include_fields]
|
90
|
+
end
|
91
|
+
print cyan
|
92
|
+
print as_pretty_table(rows, columns, options)
|
93
|
+
print reset
|
94
|
+
print_results_pagination(json_response, {:label => "network proxy", :n_label => "network proxies"})
|
95
|
+
end
|
96
|
+
print reset,"\n"
|
97
|
+
return 0
|
98
|
+
rescue RestClient::Exception => e
|
99
|
+
print_rest_exception(e, options)
|
100
|
+
exit 1
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def get(args)
|
105
|
+
options = {}
|
106
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
107
|
+
opts.banner = subcommand_usage("[network-proxy]")
|
108
|
+
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
|
109
|
+
opts.footer = "Get details about a network proxy." + "\n" +
|
110
|
+
"[network-proxy] is required. This is the name or id of a network proxy."
|
111
|
+
end
|
112
|
+
optparse.parse!(args)
|
113
|
+
if args.count != 1
|
114
|
+
print_error Morpheus::Terminal.angry_prompt
|
115
|
+
puts_error "#{command_name} missing argument: [network-proxy]\n#{optparse}"
|
116
|
+
return 1
|
117
|
+
end
|
118
|
+
connect(options)
|
119
|
+
begin
|
120
|
+
if options[:dry_run]
|
121
|
+
if args[0].to_s =~ /\A\d{1,}\Z/
|
122
|
+
print_dry_run @network_proxies_interface.dry.get(args[0].to_i)
|
123
|
+
else
|
124
|
+
print_dry_run @network_proxies_interface.dry.list({name:args[0]})
|
125
|
+
end
|
126
|
+
return
|
127
|
+
end
|
128
|
+
network_proxy = find_network_proxy_by_name_or_id(args[0])
|
129
|
+
return 1 if network_proxy.nil?
|
130
|
+
json_response = {'networkProxy' => network_proxy} # skip redundant request
|
131
|
+
# json_response = @network_proxies_interface.get(network_proxy['id'])
|
132
|
+
network_proxy = json_response['networkProxy']
|
133
|
+
if options[:include_fields]
|
134
|
+
json_response = {'networkProxy' => filter_data(network_proxy, options[:include_fields]) }
|
135
|
+
end
|
136
|
+
if options[:json]
|
137
|
+
puts as_json(json_response, options)
|
138
|
+
return 0
|
139
|
+
elsif options[:yaml]
|
140
|
+
puts as_yaml(json_response, options)
|
141
|
+
return 0
|
142
|
+
elsif options[:csv]
|
143
|
+
puts records_as_csv([network_proxy], options)
|
144
|
+
return 0
|
145
|
+
end
|
146
|
+
print_h1 "Network Proxy Details"
|
147
|
+
print cyan
|
148
|
+
description_cols = {
|
149
|
+
"ID" => 'id',
|
150
|
+
"Name" => lambda {|it| it['name'] },
|
151
|
+
"Proxy Host" => lambda {|it| it['proxyHost'] },
|
152
|
+
"Proxy Port" => lambda {|it| it['proxyPort'] },
|
153
|
+
"Proxy Username" => lambda {|it| it['proxyUser'] },
|
154
|
+
"Proxy Password" => lambda {|it| it['proxyPassword'] }, # masked
|
155
|
+
"Proxy Domain" => lambda {|it| it['proxyDomain'] },
|
156
|
+
"Proxy Workstation" => lambda {|it| it['proxyWorkstation'] },
|
157
|
+
"Proxy Host" => lambda {|it| it['proxyHost'] },
|
158
|
+
"Proxy Host" => lambda {|it| it['proxyHost'] },
|
159
|
+
"Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
|
160
|
+
"Tenant" => lambda {|it| it['account'] ? it['account']['name'] : '' },
|
161
|
+
}
|
162
|
+
print_description_list(description_cols, network_proxy)
|
163
|
+
print reset,"\n"
|
164
|
+
return 0
|
165
|
+
rescue RestClient::Exception => e
|
166
|
+
print_rest_exception(e, options)
|
167
|
+
return 1
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def add(args)
|
172
|
+
options = {}
|
173
|
+
ip_range_list = nil
|
174
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
175
|
+
opts.banner = subcommand_usage()
|
176
|
+
opts.on('--name VALUE', String, "Name for this network proxy") do |val|
|
177
|
+
options['name'] = val
|
178
|
+
end
|
179
|
+
opts.on('--proxy-host VALUE', String, "Proxy Host") do |val|
|
180
|
+
options['proxyHost'] = val
|
181
|
+
end
|
182
|
+
opts.on('--proxy-port VALUE', String, "Proxy Port") do |val|
|
183
|
+
options['proxyPort'] = val
|
184
|
+
end
|
185
|
+
opts.on('--proxy-user VALUE', String, "Proxy User") do |val|
|
186
|
+
options['proxyUser'] = val
|
187
|
+
end
|
188
|
+
opts.on('--proxy-password VALUE', String, "Proxy Password") do |val|
|
189
|
+
options['proxyPassword'] = val
|
190
|
+
end
|
191
|
+
opts.on('--proxy-domain VALUE', String, "Proxy Domain") do |val|
|
192
|
+
options['proxyDomain'] = val
|
193
|
+
end
|
194
|
+
opts.on('--proxy-workstation VALUE', String, "Proxy Workstation") do |val|
|
195
|
+
options['proxyWorkstation'] = val
|
196
|
+
end
|
197
|
+
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
198
|
+
options['visibility'] = val
|
199
|
+
end
|
200
|
+
opts.on('--tenant ID', String, "Tenant Account ID") do |val|
|
201
|
+
options['tenant'] = val
|
202
|
+
end
|
203
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
|
204
|
+
opts.footer = "Create a new network proxy." + "\n" +
|
205
|
+
"[name] is required and can be passed as --name instead."
|
206
|
+
end
|
207
|
+
optparse.parse!(args)
|
208
|
+
if args.count > 1
|
209
|
+
print_error Morpheus::Terminal.angry_prompt
|
210
|
+
puts_error "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
|
211
|
+
return 1
|
212
|
+
end
|
213
|
+
connect(options)
|
214
|
+
begin
|
215
|
+
# merge -O options into normally parsed options
|
216
|
+
options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
217
|
+
|
218
|
+
# support [name] as first argument
|
219
|
+
if args[0]
|
220
|
+
options['name'] = args[0]
|
221
|
+
end
|
222
|
+
|
223
|
+
# construct payload
|
224
|
+
payload = nil
|
225
|
+
if options[:payload]
|
226
|
+
payload = options[:payload]
|
227
|
+
else
|
228
|
+
# prompt for network options
|
229
|
+
payload = {
|
230
|
+
'networkProxy' => {
|
231
|
+
# 'config' => {}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
|
235
|
+
# allow arbitrary -O options
|
236
|
+
payload['networkProxy'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
237
|
+
|
238
|
+
# Name
|
239
|
+
if options['name']
|
240
|
+
payload['networkProxy']['name'] = options['name']
|
241
|
+
else
|
242
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this network proxy.'}], options)
|
243
|
+
payload['networkProxy']['name'] = v_prompt['name']
|
244
|
+
end
|
245
|
+
|
246
|
+
# Proxy Host
|
247
|
+
if options['proxyHost'] != nil
|
248
|
+
payload['networkProxy']['proxyHost'] = options['proxyHost']
|
249
|
+
else
|
250
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyHost', 'fieldLabel' => 'Proxy Host', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
251
|
+
payload['networkProxy']['proxyHost'] = v_prompt['proxyHost'] unless v_prompt['proxyHost'].nil?
|
252
|
+
end
|
253
|
+
|
254
|
+
# Proxy Port
|
255
|
+
if options['proxyPort'] != nil
|
256
|
+
payload['networkProxy']['proxyPort'] = options['proxyPort']
|
257
|
+
else
|
258
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPort', 'fieldLabel' => 'Proxy Port', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
259
|
+
payload['networkProxy']['proxyPort'] = v_prompt['proxyPort'] unless v_prompt['proxyPort'].nil?
|
260
|
+
end
|
261
|
+
|
262
|
+
# Proxy Username
|
263
|
+
if options['proxyUser'] != nil
|
264
|
+
payload['networkProxy']['proxyUser'] = options['proxyUser']
|
265
|
+
else
|
266
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyUser', 'fieldLabel' => 'Proxy Username', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
267
|
+
payload['networkProxy']['proxyUser'] = v_prompt['proxyUser'] unless v_prompt['proxyUser'].nil?
|
268
|
+
end
|
269
|
+
|
270
|
+
# Proxy Password
|
271
|
+
if options['proxyPassword'] != nil
|
272
|
+
payload['networkProxy']['proxyPassword'] = options['proxyPassword']
|
273
|
+
else
|
274
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPassword', 'fieldLabel' => 'Proxy Password', 'type' => 'password', 'required' => false, 'description' => ''}], options)
|
275
|
+
payload['networkProxy']['proxyPassword'] = v_prompt['proxyPassword'] unless v_prompt['proxyPassword'].nil?
|
276
|
+
end
|
277
|
+
|
278
|
+
# Proxy Domain
|
279
|
+
if options['proxyDomain'] != nil
|
280
|
+
payload['networkProxy']['proxyDomain'] = options['proxyDomain']
|
281
|
+
else
|
282
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyDomain', 'fieldLabel' => 'Proxy Domain', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
283
|
+
payload['networkProxy']['proxyDomain'] = v_prompt['proxyDomain'] unless v_prompt['proxyDomain'].nil?
|
284
|
+
end
|
285
|
+
|
286
|
+
# Proxy Workstation
|
287
|
+
if options['proxyWorkstation'] != nil
|
288
|
+
payload['networkProxy']['proxyWorkstation'] = options['proxyWorkstation']
|
289
|
+
else
|
290
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyWorkstation', 'fieldLabel' => 'Proxy Workstation', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
291
|
+
payload['networkProxy']['proxyWorkstation'] = v_prompt['proxyWorkstation'] unless v_prompt['proxyWorkstation'].nil?
|
292
|
+
end
|
293
|
+
|
294
|
+
# Visibility
|
295
|
+
if options['visibility']
|
296
|
+
payload['networkProxy']['visibility'] = options['visibility'].to_s.downcase
|
297
|
+
else
|
298
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'},{'name' => 'Public', 'value' => 'public'}], 'required' => false, 'description' => 'Visibility', 'defaultValue' => 'private'}], options)
|
299
|
+
payload['networkProxy']['visibility'] = v_prompt['visibility'].to_s.downcase
|
300
|
+
end
|
301
|
+
|
302
|
+
# Tenant
|
303
|
+
if options['tenant']
|
304
|
+
payload['networkProxy']['account'] = {'id' => options['tenant'].to_i}
|
305
|
+
else
|
306
|
+
begin
|
307
|
+
available_accounts = @api_client.accounts.list({max:10000})['accounts'].collect {|it| {'name' => it['name'], 'value' => it['id'], 'id' => it['id']}}
|
308
|
+
account_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tenant', 'fieldLabel' => 'Tenant', 'type' => 'select', 'selectOptions' => available_accounts, 'required' => false, 'description' => 'Tenant'}], options)
|
309
|
+
if account_prompt['tenant']
|
310
|
+
payload['networkProxy']['account'] = {'id' => account_prompt['tenant']}
|
311
|
+
end
|
312
|
+
rescue
|
313
|
+
puts "failed to load list of available tenants: #{ex.message}"
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
|
320
|
+
if options[:dry_run]
|
321
|
+
print_dry_run @network_proxies_interface.dry.create(payload)
|
322
|
+
return
|
323
|
+
end
|
324
|
+
json_response = @network_proxies_interface.create(payload)
|
325
|
+
if options[:json]
|
326
|
+
print JSON.pretty_generate(json_response)
|
327
|
+
print "\n"
|
328
|
+
elsif !options[:quiet]
|
329
|
+
network_proxy = json_response['networkProxy']
|
330
|
+
print_green_success "Added network proxy #{network_proxy['name']}"
|
331
|
+
get([network_proxy['id']])
|
332
|
+
end
|
333
|
+
return 0
|
334
|
+
rescue RestClient::Exception => e
|
335
|
+
print_rest_exception(e, options)
|
336
|
+
exit 1
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def update(args)
|
341
|
+
options = {}
|
342
|
+
ip_range_list = nil
|
343
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
344
|
+
opts.banner = subcommand_usage("[network-proxy] [options]")
|
345
|
+
opts.on('--name VALUE', String, "Name for this network proxy") do |val|
|
346
|
+
options['name'] = val
|
347
|
+
end
|
348
|
+
opts.on('--proxy-host VALUE', String, "Proxy Host") do |val|
|
349
|
+
options['proxyHost'] = val
|
350
|
+
end
|
351
|
+
opts.on('--proxy-port VALUE', String, "Proxy Port") do |val|
|
352
|
+
options['proxyPort'] = val
|
353
|
+
end
|
354
|
+
opts.on('--proxy-user VALUE', String, "Proxy User") do |val|
|
355
|
+
options['proxyUser'] = val
|
356
|
+
end
|
357
|
+
opts.on('--proxy-password VALUE', String, "Proxy Password") do |val|
|
358
|
+
options['proxyPassword'] = val
|
359
|
+
end
|
360
|
+
opts.on('--proxy-domain VALUE', String, "Proxy Domain") do |val|
|
361
|
+
options['proxyDomain'] = val
|
362
|
+
end
|
363
|
+
opts.on('--proxy-workstation VALUE', String, "Proxy Workstation") do |val|
|
364
|
+
options['proxyWorkstation'] = val
|
365
|
+
end
|
366
|
+
opts.on('--visibility [private|public]', String, "Visibility") do |val|
|
367
|
+
options['visibility'] = val
|
368
|
+
end
|
369
|
+
opts.on('--tenant ID', String, "Tenant Account ID") do |val|
|
370
|
+
options['tenant'] = val
|
371
|
+
end
|
372
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
373
|
+
opts.footer = "Update a network proxy." + "\n" +
|
374
|
+
"[network-proxy] is required. This is the id of a network proxy."
|
375
|
+
end
|
376
|
+
optparse.parse!(args)
|
377
|
+
if args.count != 1
|
378
|
+
print_error Morpheus::Terminal.angry_prompt
|
379
|
+
puts_error "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
|
380
|
+
return 1
|
381
|
+
end
|
382
|
+
connect(options)
|
383
|
+
|
384
|
+
begin
|
385
|
+
network_proxy = find_network_proxy_by_name_or_id(args[0])
|
386
|
+
return 1 if network_proxy.nil?
|
387
|
+
|
388
|
+
# merge -O options into normally parsed options
|
389
|
+
options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
390
|
+
|
391
|
+
# construct payload
|
392
|
+
payload = nil
|
393
|
+
if options[:payload]
|
394
|
+
payload = options[:payload]
|
395
|
+
else
|
396
|
+
# prompt for network options
|
397
|
+
payload = {
|
398
|
+
'networkProxy' => {
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
# allow arbitrary -O options
|
403
|
+
payload['networkProxy'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
404
|
+
|
405
|
+
# Name
|
406
|
+
if options['name']
|
407
|
+
payload['networkProxy']['name'] = options['name']
|
408
|
+
else
|
409
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this network proxy.'}], options)
|
410
|
+
# payload['networkProxy']['name'] = v_prompt['name']
|
411
|
+
end
|
412
|
+
|
413
|
+
# Proxy Host
|
414
|
+
if options['proxyHost'] != nil
|
415
|
+
payload['networkProxy']['proxyHost'] = options['proxyHost']
|
416
|
+
else
|
417
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyHost', 'fieldLabel' => 'Proxy Host', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
418
|
+
# payload['networkProxy']['proxyHost'] = v_prompt['proxyHost'] unless v_prompt['proxyHost'].nil?
|
419
|
+
end
|
420
|
+
|
421
|
+
# Proxy Port
|
422
|
+
if options['proxyPort'] != nil
|
423
|
+
payload['networkProxy']['proxyPort'] = options['proxyPort']
|
424
|
+
else
|
425
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPort', 'fieldLabel' => 'Proxy Port', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
426
|
+
# payload['networkProxy']['proxyPort'] = v_prompt['proxyPort'] unless v_prompt['proxyPort'].nil?
|
427
|
+
end
|
428
|
+
|
429
|
+
# Proxy Username
|
430
|
+
if options['proxyUser'] != nil
|
431
|
+
payload['networkProxy']['proxyUser'] = options['proxyUser']
|
432
|
+
else
|
433
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyUser', 'fieldLabel' => 'Proxy Username', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
434
|
+
# payload['networkProxy']['proxyUser'] = v_prompt['proxyUser'] unless v_prompt['proxyUser'].nil?
|
435
|
+
end
|
436
|
+
|
437
|
+
# Proxy Password
|
438
|
+
if options['proxyPassword'] != nil
|
439
|
+
payload['networkProxy']['proxyPassword'] = options['proxyPassword']
|
440
|
+
else
|
441
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPassword', 'fieldLabel' => 'Proxy Password', 'type' => 'password', 'required' => false, 'description' => ''}], options)
|
442
|
+
# payload['networkProxy']['proxyPassword'] = v_prompt['proxyPassword'] unless v_prompt['proxyPassword'].nil?
|
443
|
+
end
|
444
|
+
|
445
|
+
# Proxy Domain
|
446
|
+
if options['proxyDomain'] != nil
|
447
|
+
payload['networkProxy']['proxyDomain'] = options['proxyDomain']
|
448
|
+
else
|
449
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyDomain', 'fieldLabel' => 'Proxy Domain', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
450
|
+
# payload['networkProxy']['proxyDomain'] = v_prompt['proxyDomain'] unless v_prompt['proxyDomain'].nil?
|
451
|
+
end
|
452
|
+
|
453
|
+
# Proxy Workstation
|
454
|
+
if options['proxyWorkstation'] != nil
|
455
|
+
payload['networkProxy']['proxyWorkstation'] = options['proxyWorkstation']
|
456
|
+
else
|
457
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyWorkstation', 'fieldLabel' => 'Proxy Workstation', 'type' => 'text', 'required' => false, 'description' => ''}], options)
|
458
|
+
# payload['networkProxy']['proxyWorkstation'] = v_prompt['proxyWorkstation'] unless v_prompt['proxyWorkstation'].nil?
|
459
|
+
end
|
460
|
+
|
461
|
+
# Visibility
|
462
|
+
if options['visibility']
|
463
|
+
payload['networkProxy']['visibility'] = options['visibility'].to_s.downcase
|
464
|
+
else
|
465
|
+
# v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'},{'name' => 'Public', 'value' => 'public'}], 'required' => false, 'description' => 'Visibility', 'defaultValue' => 'private'}], options)
|
466
|
+
# payload['networkProxy']['visibility'] = v_prompt['visibility'].to_s.downcase
|
467
|
+
end
|
468
|
+
|
469
|
+
# Tenant
|
470
|
+
if options['tenant']
|
471
|
+
payload['networkProxy']['account'] = {'id' => options['tenant'].to_i}
|
472
|
+
else
|
473
|
+
# begin
|
474
|
+
# available_accounts = @api_client.accounts.list({max:10000})['accounts'].collect {|it| {'name' => it['name'], 'value' => it['id'], 'id' => it['id']}}
|
475
|
+
# account_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tenant', 'fieldLabel' => 'Tenant', 'type' => 'select', 'selectOptions' => available_accounts, 'required' => false, 'description' => 'Tenant'}], options)
|
476
|
+
# if account_prompt['tenant']
|
477
|
+
# payload['networkProxy']['account'] = {'id' => account_prompt['tenant']}
|
478
|
+
# end
|
479
|
+
# rescue
|
480
|
+
# puts "failed to load list of available tenants: #{ex.message}"
|
481
|
+
# end
|
482
|
+
end
|
483
|
+
|
484
|
+
end
|
485
|
+
|
486
|
+
if options[:dry_run]
|
487
|
+
print_dry_run @network_proxies_interface.dry.update(network_proxy["id"], payload)
|
488
|
+
return
|
489
|
+
end
|
490
|
+
json_response = @network_proxies_interface.update(network_proxy["id"], payload)
|
491
|
+
if options[:json]
|
492
|
+
puts as_json(json_response)
|
493
|
+
else
|
494
|
+
network_proxy = json_response['networkProxy']
|
495
|
+
print_green_success "Updated network proxy #{network_proxy['name']}"
|
496
|
+
get([network_proxy['id']])
|
497
|
+
end
|
498
|
+
return 0
|
499
|
+
rescue RestClient::Exception => e
|
500
|
+
print_rest_exception(e, options)
|
501
|
+
return 1
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
def remove(args)
|
506
|
+
options = {}
|
507
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
508
|
+
opts.banner = subcommand_usage("[network-proxy]")
|
509
|
+
build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :remote])
|
510
|
+
opts.footer = "Delete a network proxy." + "\n" +
|
511
|
+
"[network-proxy] is required. This is the name or id of a network proxy."
|
512
|
+
end
|
513
|
+
optparse.parse!(args)
|
514
|
+
|
515
|
+
if args.count < 1
|
516
|
+
print_error Morpheus::Terminal.angry_prompt
|
517
|
+
puts_error "#{command_name} missing argument: [network-proxy]\n#{optparse}"
|
518
|
+
return 1
|
519
|
+
end
|
520
|
+
|
521
|
+
connect(options)
|
522
|
+
begin
|
523
|
+
network_proxy = find_network_proxy_by_name_or_id(args[0])
|
524
|
+
return 1 if network_proxy.nil?
|
525
|
+
|
526
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the network proxy: #{network_proxy['name']}?")
|
527
|
+
return 9, "aborted command"
|
528
|
+
end
|
529
|
+
if options[:dry_run]
|
530
|
+
print_dry_run @network_proxies_interface.dry.destroy(network_proxy['id'])
|
531
|
+
return 0
|
532
|
+
end
|
533
|
+
json_response = @network_proxies_interface.destroy(network_proxy['id'])
|
534
|
+
if options[:json]
|
535
|
+
print JSON.pretty_generate(json_response)
|
536
|
+
print "\n"
|
537
|
+
else
|
538
|
+
print_green_success "Removed network proxy #{network_proxy['name']}"
|
539
|
+
# list([])
|
540
|
+
end
|
541
|
+
return 0
|
542
|
+
rescue RestClient::Exception => e
|
543
|
+
print_rest_exception(e, options)
|
544
|
+
return 1
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
private
|
549
|
+
|
550
|
+
|
551
|
+
def find_network_proxy_by_name_or_id(val)
|
552
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
553
|
+
return find_network_proxy_by_id(val)
|
554
|
+
else
|
555
|
+
return find_network_proxy_by_name(val)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
def find_network_proxy_by_id(id)
|
560
|
+
begin
|
561
|
+
json_response = @network_proxies_interface.get(id.to_i)
|
562
|
+
return json_response['networkProxy']
|
563
|
+
rescue RestClient::Exception => e
|
564
|
+
if e.response && e.response.code == 404
|
565
|
+
print_red_alert "Network Proxy not found by id #{id}"
|
566
|
+
return nil
|
567
|
+
else
|
568
|
+
raise e
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
def find_network_proxy_by_name(name)
|
574
|
+
json_response = @network_proxies_interface.list({name: name.to_s})
|
575
|
+
network_proxies = json_response['networkProxies']
|
576
|
+
if network_proxies.empty?
|
577
|
+
print_red_alert "Network Proxy not found by name #{name}"
|
578
|
+
return nil
|
579
|
+
elsif network_proxies.size > 1
|
580
|
+
print_red_alert "#{network_proxies.size} network proxies found by name #{name}"
|
581
|
+
# print_networks_table(networks, {color: red})
|
582
|
+
rows = network_proxies.collect do |network_proxy|
|
583
|
+
{id: it['id'], name: it['name']}
|
584
|
+
end
|
585
|
+
print red
|
586
|
+
tp rows, [:id, :name]
|
587
|
+
print reset,"\n"
|
588
|
+
return nil
|
589
|
+
else
|
590
|
+
return network_proxies[0]
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|
594
|
+
end
|