Class: Morpheus::Cli::NetworkProxiesCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand, InfrastructureHelper
Defined in:
lib/morpheus/cli/commands/network_proxies_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_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

#initializeNetworkProxiesCommand

set_default_subcommand :list



13
14
15
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 13

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

Instance Method Details

#add(args) ⇒ Object



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
202
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 156

def add(args)
  options = {}
  ip_range_list = nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on('--name VALUE', String, "Name for this network proxy") do |val|
      options['name'] = val
    end
    opts.on('--proxy-host VALUE', String, "Proxy Host") do |val|
      options['proxyHost'] = val
    end
    opts.on('--proxy-port VALUE', String, "Proxy Port") do |val|
      options['proxyPort'] = val
    end
    opts.on('--proxy-user VALUE', String, "Proxy User") do |val|
      options['proxyUser'] = val
    end
    opts.on('--proxy-password VALUE', String, "Proxy Password") do |val|
      options['proxyPassword'] = val
    end
    opts.on('--proxy-domain VALUE', String, "Proxy Domain") do |val|
      options['proxyDomain'] = val
    end
    opts.on('--proxy-workstation VALUE', String, "Proxy Workstation") do |val|
      options['proxyWorkstation'] = val
    end
    opts.on('--visibility [private|public]', String, "Visibility") do |val|
      options['visibility'] = val
    end
    opts.on('--tenant ID', String, "Tenant Account ID") do |val|
      options['tenant'] = val
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :quiet, :remote])
    opts.footer = "Create a new network proxy." + "\n" +
                  "[name] is required and can be passed as --name instead."
  end
  optparse.parse!(args)
  if args.count > 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 0-1 and got #{args.count}\n#{optparse}"
    return 1
  end
  connect(options)
  begin
    # merge -O options into normally parsed options
    options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

    # support [name] as first argument
    if args[0]
      options['name'] = args[0]
    end

    # construct payload
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      # prompt for network options
      payload = {
        'networkProxy' => {
          # 'config' => {}
        }
      }
      
      # allow arbitrary -O options
      payload['networkProxy'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

      # Name
      if options['name']
        payload['networkProxy']['name'] = options['name']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this network proxy.'}], options)
        payload['networkProxy']['name'] = v_prompt['name']
      end
      
      # Proxy Host
      if options['proxyHost'] != nil
        payload['networkProxy']['proxyHost'] = options['proxyHost']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyHost', 'fieldLabel' => 'Proxy Host', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        payload['networkProxy']['proxyHost'] = v_prompt['proxyHost'] unless v_prompt['proxyHost'].nil?
      end

      # Proxy Port
      if options['proxyPort'] != nil
        payload['networkProxy']['proxyPort'] = options['proxyPort']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPort', 'fieldLabel' => 'Proxy Port', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        payload['networkProxy']['proxyPort'] = v_prompt['proxyPort'] unless v_prompt['proxyPort'].nil?
      end

      # Proxy Username
      if options['proxyUser'] != nil
        payload['networkProxy']['proxyUser'] = options['proxyUser']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyUser', 'fieldLabel' => 'Proxy Username', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        payload['networkProxy']['proxyUser'] = v_prompt['proxyUser'] unless v_prompt['proxyUser'].nil?
      end

      # Proxy Password
      if options['proxyPassword'] != nil
        payload['networkProxy']['proxyPassword'] = options['proxyPassword']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPassword', 'fieldLabel' => 'Proxy Password', 'type' => 'password', 'required' => false, 'description' => ''}], options)
        payload['networkProxy']['proxyPassword'] = v_prompt['proxyPassword'] unless v_prompt['proxyPassword'].nil?
      end

      # Proxy Domain
      if options['proxyDomain'] != nil
        payload['networkProxy']['proxyDomain'] = options['proxyDomain']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyDomain', 'fieldLabel' => 'Proxy Domain', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        payload['networkProxy']['proxyDomain'] = v_prompt['proxyDomain'] unless v_prompt['proxyDomain'].nil?
      end

      # Proxy Workstation
      if options['proxyWorkstation'] != nil
        payload['networkProxy']['proxyWorkstation'] = options['proxyWorkstation']
      else
        v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyWorkstation', 'fieldLabel' => 'Proxy Workstation', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        payload['networkProxy']['proxyWorkstation'] = v_prompt['proxyWorkstation'] unless v_prompt['proxyWorkstation'].nil?
      end

      # Visibility
      if options['visibility']
        payload['networkProxy']['visibility'] = options['visibility'].to_s.downcase
      else
        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)
        payload['networkProxy']['visibility'] = v_prompt['visibility'].to_s.downcase
      end

      # Tenant
      if options['tenant']
        payload['networkProxy']['account'] = {'id' => options['tenant'].to_i}
      else
        begin
          available_accounts = @api_client.accounts.list({max:10000})['accounts'].collect {|it| {'name' => it['name'], 'value' => it['id'], 'id' => it['id']}}
           = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tenant', 'fieldLabel' => 'Tenant', 'type' => 'select', 'selectOptions' => available_accounts, 'required' => false, 'description' => 'Tenant'}], options)
          if ['tenant']
            payload['networkProxy']['account'] = {'id' => ['tenant']}
          end
        rescue
          puts "failed to load list of available tenants: #{ex.message}"
        end
      end

    end

    @network_proxies_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @network_proxies_interface.dry.create(payload)
      return
    end
    json_response = @network_proxies_interface.create(payload)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      network_proxy = json_response['networkProxy']
      print_green_success "Added network proxy #{network_proxy['name']}"
      get([network_proxy['id']])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#connect(opts) ⇒ Object



17
18
19
20
21
22
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 17

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @network_proxies_interface = @api_client.network_proxies
  @clouds_interface = @api_client.clouds
  @options_interface = @api_client.options
end

#get(args) ⇒ Object



93
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
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
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 93

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[network-proxy]")
    build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "Get details about a network proxy." + "\n" +
                  "[network-proxy] is required. This is the name or id of a network proxy."
  end
  optparse.parse!(args)
  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "#{command_name} missing argument: [network-proxy]\n#{optparse}"
    return 1
  end
  connect(options)
  begin
    @network_proxies_interface.setopts(options)
    if options[:dry_run]
      if args[0].to_s =~ /\A\d{1,}\Z/
        print_dry_run @network_proxies_interface.dry.get(args[0].to_i)
      else
        print_dry_run @network_proxies_interface.dry.list({name:args[0]})
      end
      return
    end
    network_proxy = find_network_proxy_by_name_or_id(args[0])
    return 1 if network_proxy.nil?
    json_response = {'networkProxy' => network_proxy}  # skip redundant request
    # json_response = @network_proxies_interface.get(network_proxy['id'])
    network_proxy = json_response['networkProxy']
    if options[:json]
      puts as_json(json_response, options, "networkProxy")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "networkProxy")
      return 0
    elsif options[:csv]
      puts records_as_csv([network_proxy], options)
      return 0
    end
    print_h1 "Network Proxy Details"
    print cyan
    description_cols = {
      "ID" => 'id',
      "Name" => lambda {|it| it['name'] },
      "Proxy Host" => lambda {|it| it['proxyHost'] },
      "Proxy Port" => lambda {|it| it['proxyPort'] },
      "Proxy Username" => lambda {|it| it['proxyUser'] },
      "Proxy Password" => lambda {|it| it['proxyPassword'] }, # masked
      "Proxy Domain" => lambda {|it| it['proxyDomain'] },
      "Proxy Workstation" => lambda {|it| it['proxyWorkstation'] },
      "Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
      "Tenant" => lambda {|it| it['account'] ? it['account']['name'] : '' },
    }
    print_description_list(description_cols, network_proxy)
    print reset,"\n"
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#handle(args) ⇒ Object



24
25
26
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 24

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 28

def list(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :json, :dry_run, :remote])
    opts.footer = "List network proxies."
  end
  optparse.parse!(args)
  connect(options)
  begin
    params.merge!(parse_list_options(options))
    @network_proxies_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @network_proxies_interface.dry.list(params)
      return
    end
    json_response = @network_proxies_interface.list(params)
    network_proxies = json_response["networkProxies"]
    if options[:json]
      puts as_json(json_response, options, "networkProxies")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "networkProxies")
      return 0
    elsif options[:csv]
      puts records_as_csv(network_proxies, options)
      return 0
    end
    title = "Morpheus Network Proxies"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles
    if network_proxies.empty?
      print cyan,"No network proxies found.",reset,"\n"
    else
      rows = network_proxies.collect {|network_proxy| 
        row = {
          id: network_proxy['id'],
          name: network_proxy['name'], 
          host: network_proxy['proxyHost'], 
          port: network_proxy['proxyPort'], 
          visibility: network_proxy['visibility'].to_s.capitalize, 
          tenant: network_proxy['account'] ? network_proxy['account']['name'] : '', 
          owner: network_proxy['owner'] ? network_proxy['owner']['name'] : '', 
        }
        row
      }
      columns = [:id, :name, :host, :port, :visibility, :tenant]
      if options[:include_fields]
        columns = options[:include_fields]
      end
      print cyan
      print as_pretty_table(rows, columns, options)
      print reset
      print_results_pagination(json_response, {:label => "network proxy", :n_label => "network proxies"})
    end
    print reset,"\n"
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#remove(args) ⇒ Object



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 490

def remove(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[network-proxy]")
    build_common_options(opts, options, [:account, :auto_confirm, :json, :dry_run, :remote])
    opts.footer = "Delete a network proxy." + "\n" +
                  "[network-proxy] is required. This is the name or id of a network proxy."
  end
  optparse.parse!(args)

  if args.count < 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "#{command_name} missing argument: [network-proxy]\n#{optparse}"
    return 1
  end

  connect(options)
  begin
    network_proxy = find_network_proxy_by_name_or_id(args[0])
    return 1 if network_proxy.nil?

    unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the network proxy: #{network_proxy['name']}?")
      return 9, "aborted command"
    end
    @network_proxies_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @network_proxies_interface.dry.destroy(network_proxy['id'])
      return 0
    end
    json_response = @network_proxies_interface.destroy(network_proxy['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      print_green_success "Removed network proxy #{network_proxy['name']}"
      # list([])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end

#update(args) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/morpheus/cli/commands/network_proxies_command.rb', line 325

def update(args)
  options = {}
  ip_range_list = nil
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[network-proxy] [options]")
    opts.on('--name VALUE', String, "Name for this network proxy") do |val|
      options['name'] = val
    end
    opts.on('--proxy-host VALUE', String, "Proxy Host") do |val|
      options['proxyHost'] = val
    end
    opts.on('--proxy-port VALUE', String, "Proxy Port") do |val|
      options['proxyPort'] = val
    end
    opts.on('--proxy-user VALUE', String, "Proxy User") do |val|
      options['proxyUser'] = val
    end
    opts.on('--proxy-password VALUE', String, "Proxy Password") do |val|
      options['proxyPassword'] = val
    end
    opts.on('--proxy-domain VALUE', String, "Proxy Domain") do |val|
      options['proxyDomain'] = val
    end
    opts.on('--proxy-workstation VALUE', String, "Proxy Workstation") do |val|
      options['proxyWorkstation'] = val
    end
    opts.on('--visibility [private|public]', String, "Visibility") do |val|
      options['visibility'] = val
    end
    opts.on('--tenant ID', String, "Tenant Account ID") do |val|
      options['tenant'] = val
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
    opts.footer = "Update a network proxy." + "\n" +
                  "[network-proxy] is required. This is the id of a network proxy."
  end
  optparse.parse!(args)
  if args.count != 1
    print_error Morpheus::Terminal.angry_prompt
    puts_error  "wrong number of arguments, expected 1 and got #{args.count}\n#{optparse}"
    return 1
  end
  connect(options)

  begin
    network_proxy = find_network_proxy_by_name_or_id(args[0])
    return 1 if network_proxy.nil?
    
    # merge -O options into normally parsed options
    options.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

    # construct payload
    payload = nil
    if options[:payload]
      payload = options[:payload]
    else
      # prompt for network options
      payload = {
        'networkProxy' => {
        }
      }
      
      # allow arbitrary -O options
      payload['networkProxy'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]

      # Name
      if options['name']
        payload['networkProxy']['name'] = options['name']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Name for this network proxy.'}], options)
        # payload['networkProxy']['name'] = v_prompt['name']
      end
      
      # Proxy Host
      if options['proxyHost'] != nil
        payload['networkProxy']['proxyHost'] = options['proxyHost']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyHost', 'fieldLabel' => 'Proxy Host', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        # payload['networkProxy']['proxyHost'] = v_prompt['proxyHost'] unless v_prompt['proxyHost'].nil?
      end

      # Proxy Port
      if options['proxyPort'] != nil
        payload['networkProxy']['proxyPort'] = options['proxyPort']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPort', 'fieldLabel' => 'Proxy Port', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        # payload['networkProxy']['proxyPort'] = v_prompt['proxyPort'] unless v_prompt['proxyPort'].nil?
      end

      # Proxy Username
      if options['proxyUser'] != nil
        payload['networkProxy']['proxyUser'] = options['proxyUser']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyUser', 'fieldLabel' => 'Proxy Username', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        # payload['networkProxy']['proxyUser'] = v_prompt['proxyUser'] unless v_prompt['proxyUser'].nil?
      end

      # Proxy Password
      if options['proxyPassword'] != nil
        payload['networkProxy']['proxyPassword'] = options['proxyPassword']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyPassword', 'fieldLabel' => 'Proxy Password', 'type' => 'password', 'required' => false, 'description' => ''}], options)
        # payload['networkProxy']['proxyPassword'] = v_prompt['proxyPassword'] unless v_prompt['proxyPassword'].nil?
      end

      # Proxy Domain
      if options['proxyDomain'] != nil
        payload['networkProxy']['proxyDomain'] = options['proxyDomain']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyDomain', 'fieldLabel' => 'Proxy Domain', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        # payload['networkProxy']['proxyDomain'] = v_prompt['proxyDomain'] unless v_prompt['proxyDomain'].nil?
      end

      # Proxy Workstation
      if options['proxyWorkstation'] != nil
        payload['networkProxy']['proxyWorkstation'] = options['proxyWorkstation']
      else
        # v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'proxyWorkstation', 'fieldLabel' => 'Proxy Workstation', 'type' => 'text', 'required' => false, 'description' => ''}], options)
        # payload['networkProxy']['proxyWorkstation'] = v_prompt['proxyWorkstation'] unless v_prompt['proxyWorkstation'].nil?
      end

      # Visibility
      if options['visibility']
        payload['networkProxy']['visibility'] = options['visibility'].to_s.downcase
      else
        # 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)
        # payload['networkProxy']['visibility'] = v_prompt['visibility'].to_s.downcase
      end

      # Tenant
      if options['tenant']
        payload['networkProxy']['account'] = {'id' => options['tenant'].to_i}
      else
        # begin
        #   available_accounts = @api_client.accounts.list({max:10000})['accounts'].collect {|it| {'name' => it['name'], 'value' => it['id'], 'id' => it['id']}}
        #   account_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tenant', 'fieldLabel' => 'Tenant', 'type' => 'select', 'selectOptions' => available_accounts, 'required' => false, 'description' => 'Tenant'}], options)
        #   if account_prompt['tenant']
        #     payload['networkProxy']['account'] = {'id' => account_prompt['tenant']}
        #   end
        # rescue
        #   puts "failed to load list of available tenants: #{ex.message}"
        # end
      end

    end
    @network_proxies_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @network_proxies_interface.dry.update(network_proxy["id"], payload)
      return
    end
    json_response = @network_proxies_interface.update(network_proxy["id"], payload)
    if options[:json]
      puts as_json(json_response)
    else
      network_proxy = json_response['networkProxy']
      print_green_success "Updated network proxy #{network_proxy['name']}"
      get([network_proxy['id']])
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    return 1
  end
end