Class: Morpheus::Cli::Apps

Inherits:
Object
  • Object
show all
Includes:
CliCommand, ProvisioningHelper
Defined in:
lib/morpheus/cli/apps.rb

Instance Method Summary collapse

Methods included from ProvisioningHelper

#find_cloud_by_id, #find_cloud_by_name, #find_cloud_from_options, #find_group_by_id, #find_group_by_name, #find_group_from_options, #find_instance_type_by_code, #get_available_clouds, #get_available_groups, included, #instance_context_options, #prompt_network_interfaces, #prompt_new_instance, #prompt_resize_volumes, #prompt_volumes, #reject_networking_option_types, #reject_service_plan_option_types, #reject_volume_option_types

Methods included from CliCommand

#build_common_options, included

Constructor Details

#initialize ⇒ Apps

Returns a new instance of Apps.



14
15
16
# File 'lib/morpheus/cli/apps.rb', line 14

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

Instance Method Details

#add(args) ⇒ Object



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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/morpheus/cli/apps.rb', line 116

def add(args)
	usage = "Usage: morpheus apps add"
   options = {}
   optparse = OptionParser.new do|opts|
     opts.banner = usage
     opts.on( '-g', '--group GROUP', "Group Name" ) do |val|
			options[:group_name] = val
		end
		opts.on( '-G', '--group-id ID', "Group Id" ) do |val|
			options[:group_id] = val
		end
     build_common_options(opts, options, [:options, :json, :dry_run])
   end
   optparse.parse(args)
   connect(options)
   begin
 		
 		# use active group by default
		if !options[:group_name] && !options[:group_id]
			options[:group_id] = @active_groups[@appliance_name.to_sym]
		end
		group = find_group_from_options(options)

		payload = {
			'app' => {}
		}

		v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Enter a name for this app'}], options[:options])
		payload['app']['name'] = v_prompt['name']
		v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false}], options[:options])
		payload['app']['description'] = v_prompt['description']
		if group
			payload['app']['site'] = {id: group["id"]}
		else
			v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'fieldLabel' => 'Group', 'type' => 'select', 'selectOptions' => get_available_groups(), 'required' => true}], options[:options])
			payload['app']['site'] = {id: v_prompt["group"]}
		end

		# todo: allow adding instances with creation..

     if options[:dry_run]
       print_dry_run("POST #{@appliance_url}/api/apps", payload)
       return
     end
     json_response = @apps_interface.create(payload)
     if options[:json]
       print JSON.pretty_generate(json_response)
       print "\n"
     else
       print_green_success "Added app #{payload['app']['name']}"
       list([])
       # details_options = [payload['app']['name']]
       # details(details_options)
     end

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

#add_instance(args) ⇒ Object



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

def add_instance(args)
	usage = "Usage: morpheus apps add-instance [name] [instance] [tier]"
   options = {}
   optparse = OptionParser.new do|opts|
     opts.banner = usage
     build_common_options(opts, options, [:options, :json, :dry_run])
   end
   optparse.parse(args)
   if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	# optional [tier] and [instance] arguments
	if args[1] && args[1] !~ /\A\-/
		options[:instance_name] = args[1]
		if args[2] && args[2] !~ /\A\-/
			options[:tier_name] = args[2]
		end
	end
   connect(options)
   begin
 		
 		app = find_app_by_name_or_id(args[0])

 		# Only supports adding an existing instance right now..

 		payload = {}

 		if options[:instance_name]
 			instance = find_instance_by_name_or_id(options[:instance_name])
 		else
 			v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instance', 'fieldLabel' => 'Instance', 'type' => 'text', 'required' => true, 'description' => 'Enter the instance name or id'}], options[:options])
 			instance = find_instance_by_name_or_id(v_prompt['instance'])
 		end
 		payload[:instanceId] = instance['id']

 		if options[:tier_name]
 			payload[:tierName] = options[:tier_name]
 		else
 			v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tier', 'fieldLabel' => 'Tier', 'type' => 'text', 'required' => true, 'description' => 'Enter the name of the tier'}], options[:options])
 			payload[:tierName] = v_prompt['tier']
 		end

     if options[:dry_run]
       print_dry_run("POST #{@appliance_url}/api/apps/#{app['id']}/add-instance", payload)
       return
     end
     json_response = @apps_interface.add_instance(app['id'], payload)
     if options[:json]
       print JSON.pretty_generate(json_response)
       print "\n"
     else
       print_green_success "Added instance #{instance['name']} to app #{app['name']}"
       list([])
       # details_options = [app['name']]
       # details(details_options)
     end

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

#apply_security_groups(args) ⇒ Object



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# File 'lib/morpheus/cli/apps.rb', line 687

def apply_security_groups(args)
	usage = <<-EOF
Usage: morpheus apps apply_security_groups [name]
EOF

	options = {}
	clear_or_secgroups_specified = false
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		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
		opts.on( '-h', '--help', "Prints this help" ) do
			puts opts
			exit
		end
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	if !clear_or_secgroups_specified 
		puts usage
		exit 1
	end

	connect(options)

	begin
		app_results = @apps_interface.get({name: args[0]})
		if app_results['apps'].empty?
			print_red_alert "App not found by name #{args[0]}"
			exit 1
		end

		@apps_interface.apply_security_groups(app_results['apps'][0]['id'], options)
		security_groups([args[0]])
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#connect(opts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/morpheus/cli/apps.rb', line 18

def connect(opts)
	@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
	if @access_token.empty?
		print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
		exit 1
	end
	@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
	@apps_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).apps
	@instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
	@instances_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instances
   @options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).options
	@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
	@logs_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).logs
	@active_groups = ::Morpheus::Cli::Groups.load_group_file
end

#details(args) ⇒ Object



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

def details(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps details [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)
	begin
		app = find_app_by_name_or_id(args[0])
		if options[:json]
			print JSON.pretty_generate({app: app})
			return
		end
		
		print "\n" ,cyan, bold, "App Details\n","==================", reset, "\n\n"
		print cyan
		puts "ID: #{app['id']}"
		puts "Name: #{app['name']}"
		puts "Description: #{app['description']}"
		puts "Account: #{app['account'] ? app['account']['name'] : ''}"
		# puts "Group: #{app['siteId']}"
		
		stats = app['stats']
		print cyan, "Memory: \t#{Filesize.from("#{stats['usedMemory']} B").pretty} / #{Filesize.from("#{stats['maxMemory']} B").pretty}\n"
		print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset

		app_tiers = app['appTiers']
		if app_tiers.empty?
			puts yellow, "This app is empty", reset
		else
			app_tiers.each do |app_tier|
				print "\n" ,cyan, bold, "Tier: #{app_tier['tier']['name']}\n","==================", reset, "\n\n"
				print cyan
				instances = (app_tier['appInstances'] || []).collect {|it| it['instance']}
				if instances.empty?
					puts yellow, "This tier is empty", reset
				else
					instance_table = instances.collect do |instance|
						status_string = instance['status']
						if status_string == 'running'
							status_string = "#{green}#{status_string.upcase}#{cyan}"
						elsif status_string == 'stopped' or status_string == 'failed'
							status_string = "#{red}#{status_string.upcase}#{cyan}"
						elsif status_string == 'unknown'
							status_string = "#{white}#{status_string.upcase}#{cyan}"
						else
							status_string = "#{yellow}#{status_string.upcase}#{cyan}"
						end
						connection_string = ''
						if !instance['connectionInfo'].nil? && instance['connectionInfo'].empty? == false
							connection_string = "#{instance['connectionInfo'][0]['ip']}:#{instance['connectionInfo'][0]['port']}"
						end
						{id: instance['id'], name: instance['name'], connection: connection_string, environment: instance['instanceContext'], nodes: instance['containers'].count, status: status_string, type: instance['instanceType']['name'], group: !instance['group'].nil? ? instance['group']['name'] : nil, cloud: !instance['cloud'].nil? ? instance['cloud']['name'] : nil}
					end
					tp instance_table, :id, :name, :cloud, :type, :environment, :nodes, :connection, :status
				end
			end
		end
		print cyan

		print reset,"\n"

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

#firewall_disable(args) ⇒ Object

def stop(args) options = {} optparse = OptionParser.new do|opts| opts.banner = "Usage: morpheus apps stop [name]" build_common_options(opts, options, [:json]) end optparse.parse(args) if args.count < 1 puts "\n#Morpheus::Cli::Apps.optparseoptparse.banner\n\n" exit 1 end connect(options) begin app_results = @apps_interface.get(args[0]) if app_results.empty? print_red_alert "App not found by name #args[0]" exit 1 end @apps_interface.stop(app_results[0]['id']) list([]) rescue RestClient::Exception => e print_rest_exception(e, options) exit 1 end end

def start(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps start [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)
	begin
		app_results = @apps_interface.get({name: args[0]})
		if app_results['apps'].empty?
			print_red_alert "App not found by name #{args[0]}"
			exit 1
		end
		@apps_interface.start(app_results['apps'][0]['id'])
		list([])
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

def restart(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps restart [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)
	begin
		app_results = @apps_interface.get({name: args[0]})
		if app_results['apps'].empty?
			print_red_alert "App not found by name #{args[0]}"
			exit 1
		end
		@apps_interface.restart(app_results['apps'][0]['id'])
		list([])
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end


592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/morpheus/cli/apps.rb', line 592

def firewall_disable(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps firewall_disable [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)

	begin
		app_results = @apps_interface.get({name: args[0]})
		if app_results['apps'].empty?
			print_red_alert "App not found by name #{args[0]}"
			exit 1
		end
		@apps_interface.firewall_disable(app_results['apps'][0]['id'])
		security_groups([args[0]])
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#firewall_enable(args) ⇒ Object



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

def firewall_enable(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps firewall_enable [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)

	begin
		app_results = @apps_interface.get({name: args[0]})
		if app_results['apps'].empty?
			print_red_alert "App not found by name #{args[0]}"
			exit 1
		end
		@apps_interface.firewall_enable(app_results['apps'][0]['id'])
		security_groups([args[0]])
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

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

def handle(args) 
	usage = "Usage: morpheus apps [list,details,add,update,remove,add-instance,remove-instance,logs,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]"
	case args[0]
		when 'list'
			list(args[1..-1])
		when 'details'
			details(args[1..-1])
		when 'add'
			add(args[1..-1])
		when 'update'
			update(args[1..-1])
		when 'remove'
			remove(args[1..-1])
		when 'add-instance'
			add_instance(args[1..-1])
		when 'remove-instance'
			remove_instance(args[1..-1])
		when 'stop'
			stop(args[1..-1])
		when 'start'
			start(args[1..-1])
		when 'restart'
			restart(args[1..-1])
		when 'logs'
			logs(args[1..-1])
		# when 'stats'
		# 	stats(args[1..-1])
		# when 'envs'
		# 	envs(args[1..-1])
		# when 'setenv'
		# 	setenv(args[1..-1])	
		# when 'delenv'
		# 	delenv(args[1..-1])
		when 'firewall_disable'
			firewall_disable(args[1..-1])	
		when 'firewall_enable'
			firewall_enable(args[1..-1])	
		when 'security_groups'	
			security_groups(args[1..-1])	
		when 'apply_security_groups'	
			apply_security_groups(args[1..-1])		
		else
			puts "\n#{usage}\n\n"
			exit 127
	end
end

#list(args) ⇒ Object



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

def list(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps list"
		build_common_options(opts, options, [:list, :json])
	end
	optparse.parse(args)
	connect(options)
	begin
     params = {}
		[:phrase, :offset, :max, :sort, :direction].each do |k|
			params[k] = options[k] unless options[k].nil?
		end

		json_response = @apps_interface.get(params)
		
		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
			return
		end
		apps = json_response['apps']
		print "\n" ,cyan, bold, "Morpheus Apps\n","==================", reset, "\n\n"
		if apps.empty?
			puts yellow,"No apps currently configured.",reset
		else
			print_apps_table(apps)
		end
		print reset,"\n\n"
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#logs(args) ⇒ Object



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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/morpheus/cli/apps.rb', line 459

def logs(args) 
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps logs [name]"
		build_common_options(opts, options, [:list, :json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)
	begin
		app = find_app_by_name_or_id(args[0])
		containers = []
		app['appTiers'].each do |app_tier|
			app_tier['appInstances'].each do |app_instance|
				containers += app_instance['instance']['containers']
			end
		end
		params = {}
		[:phrase, :offset, :max, :sort, :direction].each do |k|
			params[k] = options[k] unless options[k].nil?
		end
		logs = @logs_interface.container_logs(containers, params)
		if options[:json]
			print JSON.pretty_generate(logs)
			print "\n"
		else
			logs['data'].reverse.each do |log_entry|
				log_level = ''
				case log_entry['level']
					when 'INFO'
						log_level = "#{blue}#{bold}INFO#{reset}"
					when 'DEBUG'
						log_level = "#{white}#{bold}DEBUG#{reset}"
					when 'WARN'
						log_level = "#{yellow}#{bold}WARN#{reset}"
					when 'ERROR'
						log_level = "#{red}#{bold}ERROR#{reset}"
					when 'FATAL'
						log_level = "#{red}#{bold}FATAL#{reset}"
				end
				puts "[#{log_entry['ts']}] #{log_level} - #{log_entry['message']}"
			end
			print reset,"\n"
		end
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#remove(args) ⇒ Object



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

def remove(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps remove [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)

	begin
		app = find_app_by_name_or_id(args[0])
		unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove the app '#{app['name']}'?", options)
			exit 1
		end
		@apps_interface.destroy(app_results['app']['id'])
		list([])
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#remove_instance(args) ⇒ Object



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

def remove_instance(args)
	usage = "Usage: morpheus apps remove-instance [name] [instance]"
   options = {}
   optparse = OptionParser.new do|opts|
     opts.banner = usage
     build_common_options(opts, options, [:options, :json, :dry_run])
   end
   optparse.parse(args)
   if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	# optional [tier] and [instance] arguments
	if args[1] && args[1] !~ /\A\-/
		options[:instance_name] = args[1]
	end
   connect(options)
   begin
 		
 		app = find_app_by_name_or_id(args[0])

 		payload = {}

 		if options[:instance_name]
 			instance = find_instance_by_name_or_id(options[:instance_name])
 		else
 			v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instance', 'fieldLabel' => 'Instance', 'type' => 'text', 'required' => true, 'description' => 'Enter the instance name or id'}], options[:options])
 			instance = find_instance_by_name_or_id(v_prompt['instance'])
 		end
 		payload[:instanceId] = instance['id']

     if options[:dry_run]
       print_dry_run("POST #{@appliance_url}/api/apps/#{app['id']}/remove-instance", payload)
       return
     end

     json_response = @apps_interface.remove_instance(app['id'], payload)

     if options[:json]
       print JSON.pretty_generate(json_response)
       print "\n"
     else
       print_green_success "Removed instance #{instance['name']} from app #{app['name']}"
       list([])
       # details_options = [app['name']]
       # details(details_options)
     end

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

#security_groups(args) ⇒ Object



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/morpheus/cli/apps.rb', line 646

def security_groups(args)
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = "Usage: morpheus apps security_groups [name]"
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)
	if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
	connect(options)

	begin
		app_results = @apps_interface.get({name: args[0]})
		if app_results['apps'].empty?
			print_red_alert "App not found by name #{args[0]}"
			exit 1
		end

		app_id = app_results['apps'][0]['id']
		json_response = @apps_interface.security_groups(app_id)

		securityGroups = json_response['securityGroups']
		print "\n" ,cyan, bold, "Morpheus Security Groups for App:#{app_id}\n","==================", reset, "\n\n"
		print cyan, "Firewall Enabled=#{json_response['firewallEnabled']}\n\n"
		if securityGroups.empty?
			puts yellow,"No security groups currently applied.",reset
		else
			securityGroups.each do |securityGroup|
				print cyan, "=  #{securityGroup['id']} (#{securityGroup['name']}) - (#{securityGroup['description']})\n"
			end
		end
		print reset,"\n\n"

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

#update(args) ⇒ Object



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

def update(args)
	usage = "Usage: morpheus apps update [name] [options]"
   options = {}
   optparse = OptionParser.new do|opts|
     opts.banner = usage
     build_common_options(opts, options, [:options, :json, :dry_run])
   end
   optparse.parse(args)
   if args.count < 1
		puts "\n#{optparse.banner}\n\n"
		exit 1
	end
   connect(options)

   begin
 		
 		app = find_app_by_name_or_id(args[0])

		# group = find_group_from_options(options)

		payload = {
			'app' => {id: app["id"]}
		}

		update_app_option_types = [
			{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Enter a name for this app'},
			{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false}
		]

		params = options[:options] || {}

     if params.empty?
       puts "\n#{usage}\n"
       option_lines = update_app_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
       puts "\nAvailable Options:\n#{option_lines}\n\n"
       exit 1
     end

     #puts "parsed params is : #{params.inspect}"
     app_keys = ['name', 'description']
     params = params.select {|k,v| app_keys.include?(k) }
     payload['app'].merge!(params)

     if options[:dry_run]
       print_dry_run("PUT #{@appliance_url}/api/apps/#{app['id']}", payload)
       return
     end
     json_response = @apps_interface.update(app["id"], payload)
     if options[:json]
       print JSON.pretty_generate(json_response)
       print "\n"
     else
       print_green_success "Updated app #{app['name']}"
       list([])
       # details_options = [payload['app']['name']]
       # details(details_options)
     end

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