Class: Morpheus::Cli::Clouds

Inherits:
Object
  • Object
show all
Includes:
CliCommand, InfrastructureHelper
Defined in:
lib/morpheus/cli/clouds.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, #get_available_cloud_types, #groups_interface, included

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #print_to_file, #puts, #puts_error, #raise_command_error, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!

Constructor Details

#initializeClouds



17
18
19
# File 'lib/morpheus/cli/clouds.rb', line 17

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

Instance Method Details

#_get(arg, options = {}) ⇒ Object



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
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
# File 'lib/morpheus/cli/clouds.rb', line 154

def _get(arg, options={})
  begin
    if options[:dry_run]
      @clouds_interface.setopts(options)
      if arg.to_s =~ /\A\d{1,}\Z/
        print_dry_run @clouds_interface.dry.get(arg.to_i)
      else
        print_dry_run @clouds_interface.dry.get({name:arg})
      end
      return
    end
    cloud = find_cloud_by_name_or_id(arg)
    #json_response = {'zone' => cloud}
    # if options[:dry_run]
    #   print_dry_run @clouds_interface.dry.get(cloud['id'])
    #   return
    # end
    @clouds_interface.setopts(options)
    json_response = @clouds_interface.get(cloud['id'])
    cloud = json_response['zone']
    cloud_stats = cloud['stats']
    # serverCounts moved to zone.stats.serverCounts
    server_counts = nil
    if cloud_stats
      server_counts = cloud_stats['serverCounts']
    else
      server_counts = json_response['serverCounts'] # legacy
    end
    if options[:json]
      puts as_json(json_response, options, 'zone')
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, 'zone')
      return 0
    end
    if options[:csv]
      puts records_as_csv([json_response['zone']], options)
      return 0
    end
    cloud_type = cloud_type_for_id(cloud['zoneTypeId'])
    print_h1 "Cloud Details"
    print cyan
    description_cols = {
      "ID" => 'id',
      "Name" => 'name',
      "Type" => lambda {|it| cloud_type ? cloud_type['name'] : '' },
      "Code" => 'code',
      "Location" => 'location',
      "Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
      "Groups" => lambda {|it| it['groups'].collect {|g| g.instance_of?(Hash) ? g['name'] : g.to_s }.join(', ') },
      "Enabled" => lambda {|it| format_boolean(it['enabled']) },
      "Status" => lambda {|it| format_cloud_status(it) }
    }
    print_description_list(description_cols, cloud)
    
    print_h2 "Cloud Servers"
    print cyan
    if server_counts
      print "Container Hosts: #{server_counts['containerHost']}".center(20)
      print "Hypervisors: #{server_counts['hypervisor']}".center(20)
      print "Bare Metal: #{server_counts['baremetal']}".center(20)
      print "Virtual Machines: #{server_counts['vm']}".center(20)
      print "Unmanaged: #{server_counts['unmanaged']}".center(20)
      print "\n"
    end

    print reset,"\n"

    #puts instance
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#add(args) ⇒ Object



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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/morpheus/cli/clouds.rb', line 229

def add(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name] --group GROUP --type TYPE")
    opts.on( '-g', '--group GROUP', "Group Name" ) do |val|
      params[:group] = val
    end
    opts.on( '-t', '--type TYPE', "Cloud Type" ) do |val|
      params[:zone_type] = val
    end
    opts.on( '-d', '--description DESCRIPTION', "Description (optional)" ) do |desc|
      params[:description] = desc
    end
    opts.on( '--certificate-provider CODE', String, "Certificate Provider. Default is 'internal'" ) do |val|
      params[:certificate_provider] = val
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  # if args.count < 1
  #   puts optparse
  #   exit 1
  # end
  connect(options)

  begin
    payload = nil
    if options[:payload]
      payload = options[:payload]
      # support -O OPTION switch on top of --payload
      if options[:options]
        payload['zone'] ||= {}
        payload['zone'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
      end
    else
      cloud_payload = {name: args[0], description: params[:description]}
      # use active group by default
      params[:group] ||= @active_group_id

      # Group
      group_id = nil
      group = params[:group] ? find_group_by_name_or_id(params[:group]) : nil
      if group
        group_id = group["id"]
      else
        # print_red_alert "Group not found or specified!"
        # exit 1
        groups_dropdown = @groups_interface.get({})['groups'].collect {|it| {'name' => it["name"], 'value' => it["id"]} }
        group_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group', 'selectOptions' => groups_dropdown, 'required' => true, 'description' => 'Select Group.'}],options[:options],@api_client,{})
        group_id = group_prompt['group']
      end
      cloud_payload['groupId'] = group_id
      # todo: pass groups as an array instead

      # Cloud Name

      if args[0]
        cloud_payload[:name] = args[0]
        options[:options]['name'] = args[0] # to skip prompt
      elsif !options[:no_prompt]
        # name_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true}], options[:options])
        # cloud_payload[:name] = name_prompt['name']
      end

      # Cloud Type

      cloud_type = nil
      if params[:zone_type]
        cloud_type = cloud_type_for_name(params[:zone_type])
      elsif !options[:no_prompt]
        # print_red_alert "Cloud Type not found or specified!"
        # exit 1
        cloud_types_dropdown = cloud_types_for_dropdown
        cloud_type_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Cloud Type', 'selectOptions' => cloud_types_dropdown, 'required' => true, 'description' => 'Select Cloud Type.'}],options[:options],@api_client,{})
        cloud_type_code = cloud_type_prompt['type']
        cloud_type = cloud_type_for_name(cloud_type_code) # this does work
      end
      if !cloud_type
        print_red_alert "A cloud type is required."
        exit 1
      end
      cloud_payload[:zoneType] = {code: cloud_type['code']}

      cloud_payload['config'] ||= {}
      if params[:certificate_provider]
        cloud_payload['config']['certificateProvider'] = params[:certificate_provider]
      else
        cloud_payload['config']['certificateProvider'] = 'internal'
      end

      all_option_types = add_cloud_option_types(cloud_type)
      params = Morpheus::Cli::OptionTypes.prompt(all_option_types, options[:options], @api_client, {zoneTypeId: cloud_type['id']})
      # some optionTypes have fieldContext='zone', so move those to the root level of the zone payload
      if params['zone'].is_a?(Hash)
        cloud_payload.deep_merge!(params.delete('zone'))
      end
      cloud_payload.deep_merge!(params)
      payload = {zone: cloud_payload}
    end
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.create(payload)
      return
    end
    json_response = @clouds_interface.create(payload)
    cloud = json_response['zone']
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      #list([])
      get([cloud["id"]])
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#apply_security_groups(args) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/morpheus/cli/clouds.rb', line 568

def apply_security_groups(args)
  options = {}
  clear_or_secgroups_specified = false
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name] [-s] [--clear]")
    opts.on( '-c', '--clear', "Clear all security groups" ) do
      options[:securityGroupIds] = []
      clear_or_secgroups_specified = true
    end
    opts.on( '-s', '--secgroups SECGROUPS', "Apply the specified comma separated security group ids" ) do |secgroups|
      options[:securityGroupIds] = secgroups.split(",")
      clear_or_secgroups_specified = true
    end
    build_common_options(opts, options, [:json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if !clear_or_secgroups_specified
    puts optparse
    exit
  end
  connect(options)
  begin
    cloud = find_cloud_by_name_or_id(args[0])
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.apply_security_groups(cloud['id'])
      return
    end
    json_response = @clouds_interface.apply_security_groups(cloud['id'], options)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
      return
    end
    security_groups([args[0]])
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#connect(opts) ⇒ Object



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

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @clouds_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).clouds
  @groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
  @active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
  # preload stuff
  get_available_cloud_types()
end

#count(args) ⇒ Object



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
# File 'lib/morpheus/cli/clouds.rb', line 104

def count(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[options]")
    build_common_options(opts, options, [:query, :remote, :dry_run])
    opts.footer = "Get the number of clouds."
  end
  optparse.parse!(args)
  connect(options)
  begin
    params = {}
    params.merge!(parse_list_options(options))
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.get(params)
      return
    end
    json_response = @clouds_interface.get(params)
    # print number only
    if json_response['meta'] && json_response['meta']['total']
      print cyan, json_response['meta']['total'], reset, "\n"
    else
      print yellow, "unknown", reset, "\n"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#firewall_disable(args) ⇒ Object



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
# File 'lib/morpheus/cli/clouds.rb', line 455

def firewall_disable(args)
  options = {}
  clear_or_secgroups_specified = false
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return
  end
  connect(options)
  begin
    cloud = find_cloud_by_name_or_id(args[0])
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.firewall_disable(cloud['id'])
      return
    end
    json_response = @clouds_interface.firewall_disable(cloud['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
      return
    end
    security_groups([args[0]])
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#firewall_enable(args) ⇒ Object



488
489
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
# File 'lib/morpheus/cli/clouds.rb', line 488

def firewall_enable(args)
  options = {}
  clear_or_secgroups_specified = false
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return
  end
  connect(options)
  begin
    cloud = find_cloud_by_name_or_id(args[0])
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.firewall_enable(cloud['id'])
      return
    end
    json_response = @clouds_interface.firewall_enable(cloud['id'])
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
      return
    end
    security_groups([args[0]])
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#get(args) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/morpheus/cli/clouds.rb', line 134

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "Get details about a cloud.\n" +
                  "[name] is required. This is the name or id of a cloud."
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  id_list = parse_id_list(args)
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, options)
  end
end

#handle(args) ⇒ Object



30
31
32
# File 'lib/morpheus/cli/clouds.rb', line 30

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/clouds.rb', line 34

def list(args)
  options={}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
      options[:group] = group
    end
    opts.on( '-t', '--type TYPE', "Cloud Type" ) do |val|
      options[:zone_type] = val
    end
    build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "List clouds."
  end
  optparse.parse!(args)
  connect(options)
  begin
    if options[:zone_type]
      cloud_type = cloud_type_for_name(options[:zone_type])
      params[:type] = cloud_type['code']
    end
    if !options[:group].nil?
      group = find_group_by_name(options[:group])
      if !group.nil?
        params['groupId'] = group['id']
      end
    end

    params.merge!(parse_list_options(options))
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.get(params)
      return 0
    end

    json_response = @clouds_interface.get(params)
    if options[:json]
      puts as_json(json_response, options, "zones")
      return 0
    elsif options[:yaml]
      puts as_yaml(json_response, options, "zones")
      return 0
    elsif options[:csv]
      puts records_as_csv(json_response['zones'], options)
    else
      clouds = json_response['zones']
      title = "Morpheus Clouds"
      subtitles = []
      if group
        subtitles << "Group: #{group['name']}".strip
      end
      if cloud_type
        subtitles << "Type: #{cloud_type['name']}".strip
      end
      subtitles += parse_list_subtitles(options)
      print_h1 title, subtitles
      if clouds.empty?
        print cyan,"No clouds found.",reset,"\n"
      else
        print_clouds_table(clouds, options)
        print_results_pagination(json_response)
      end
      print reset,"\n"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#list_cloud_types(args) ⇒ Object



609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/morpheus/cli/clouds.rb', line 609

def list_cloud_types(args)
  options={}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    build_common_options(opts, options, [:json, :dry_run, :remote])
  end
  optparse.parse!(args)
  connect(options)
  begin
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.cloud_types({})
      return 0
    end
    cloud_types = get_available_cloud_types() # @clouds_interface.dry.cloud_types({})['zoneTypes']
    if options[:json]
      puts as_json({zoneTypes: cloud_types}, options)
    else
      print_h1 "Morpheus Cloud Types", options
      if cloud_types.empty?
        print yellow,"No instances found.",reset,"\n"
      else
        print cyan
        cloud_types = cloud_types.select {|it| it['enabled'] }
        rows = cloud_types.collect do |cloud_type|
          {id: cloud_type['id'], name: cloud_type['name'], code: cloud_type['code']}
        end
        #print "\n"
        puts as_pretty_table(rows, [:id, :name, :code], options)
        #print_results_pagination({size:rows.size,total:rows.size})
        #print "\n"
      end
      #print reset,"\n"
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#remove(args) ⇒ Object



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
# File 'lib/morpheus/cli/clouds.rb', line 419

def remove(args)
  options = {}
  query_params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    opts.on( '-f', '--force', "Force Remove" ) do
      query_params[:force] = 'on'
    end
    build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return
  end
  connect(options)
  begin
    cloud = find_cloud_by_name_or_id(args[0])
    unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the cloud #{cloud['name']}?")
      exit
    end
    @clouds_interface.setopts(options)
    json_response = @clouds_interface.destroy(cloud['id'], query_params)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      print_green_success "Removed cloud #{cloud['name']}"
      #list([])
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#security_groups(args) ⇒ Object



521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/morpheus/cli/clouds.rb', line 521

def security_groups(args)
  options = {}
  clear_or_secgroups_specified = false
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    return
  end
  connect(options)
  begin
    cloud = find_cloud_by_name_or_id(args[0])
    zone_id = cloud['id']
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.security_groups(zone_id)
      return
    end
    json_response = @clouds_interface.security_groups(zone_id)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
      return
    end
    securityGroups = json_response['securityGroups']
    print_h1 "Morpheus Security Groups for Cloud: #{cloud['name']}"
    print cyan
    print_description_list({"Firewall Enabled" => lambda {|it| format_boolean it['firewallEnabled'] } }, json_response)
    if securityGroups.empty?
      print yellow,"\n","No security groups currently applied.",reset,"\n"
    else
      print "\n"
      securityGroups.each do |securityGroup|
        print cyan, "=  #{securityGroup['id']} (#{securityGroup['name']}) - (#{securityGroup['description']})\n"
      end
    end
    print reset,"\n"

  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#update(args) ⇒ Object



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
# File 'lib/morpheus/cli/clouds.rb', line 349

def update(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[name] [options]")
    # opts.on( '-g', '--group GROUP', "Group Name" ) do |val|
    #   params[:group] = val
    # end
    # opts.on( '-t', '--type TYPE', "Cloud Type" ) do |val|
    #   params[:zone_type] = val
    # end
    # opts.on( '-d', '--description DESCRIPTION', "Description (optional)" ) do |desc|
    #   params[:description] = desc
    # end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
  end
  optparse.parse!(args)
  if args.count < 1
    puts optparse
    exit 1
  end
  connect(options)
  begin
    cloud = find_cloud_by_name_or_id(args[0])
    return 1 if cloud.nil?
    payload = nil
    if options[:payload]
      payload = options[:payload]
      # support -O OPTION switch on top of --payload
      if options[:options]
        payload['zone'] ||= {}
        payload['zone'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
      end
    else
      cloud_type = cloud_type_for_id(cloud['zoneTypeId'])
      cloud_payload = {}
      all_option_types = update_cloud_option_types(cloud_type)
      #params = Morpheus::Cli::OptionTypes.prompt(all_option_types, options[:options], @api_client, {zoneTypeId: cloud_type['id']})
      params = options[:options] || {}
      if params.empty?
        puts_error optparse.banner
        puts_error format_available_options(all_option_types)
        exit 1
      end
      # some optionTypes have fieldContext='zone', so move those to the root level of the zone payload
      if params['zone'].is_a?(Hash)
        cloud_payload.merge!(params.delete('zone'))
      end
      cloud_payload.merge!(params)
      payload = {zone: cloud_payload}
    end
    @clouds_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @clouds_interface.dry.update(cloud['id'], payload)
      return
    end
    json_response = @clouds_interface.update(cloud['id'], payload)
    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    else
      #list([])
      get([cloud["id"]])
    end
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end