Class: Morpheus::Cli::Roles

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

Instance Method Summary collapse

Methods included from AccountsHelper

#find_account_by_id, #find_account_by_name, #find_account_from_options, #find_role_by_id, #find_role_by_name, #find_user_by_id, #find_user_by_username, included, #print_accounts_table, #print_roles_table, #print_users_table

Methods included from CliCommand

#build_common_options, included

Constructor Details

#initializeRoles

Returns a new instance of Roles.



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

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

Instance Method Details

#add(args) ⇒ Object



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

def add(args)
	usage = "Usage: morpheus roles add [options]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:options, :json])
	end
	optparse.parse(args)

	connect(options)
	begin

		 = (options)
		 =  ? ['id'] : nil

		params = Morpheus::Cli::OptionTypes.prompt(add_role_option_types, options[:options], @api_client, options[:params])

		#puts "parsed params is : #{params.inspect}"
		role_keys = ['authority', 'description', 'instanceLimits']
		role_payload = params.select {|k,v| role_keys.include?(k) }
		if !role_payload['instanceLimits']
			role_payload['instanceLimits'] = {}
			role_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
			role_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
			role_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
		end
		if params['baseRole'].to_s != ''
			base_role = find_role_by_name(, params['baseRole'])
			exit 1 if base_role.nil?
			role_payload['baseRoleId'] = base_role['id']
		end
		request_payload = {role: role_payload}
		response = @roles_interface.create(, request_payload)

		if 
			print_green_success "Added role #{role_payload['authority']} to account #{['name']}"
		else
			print_green_success "Added role #{role_payload['authority']}"
		end

		details_options = [role_payload["authority"]]
		if 
			details_options.push "--account-id", ['id'].to_s
		end
		details(details_options)

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

#connect(opts) ⇒ Object



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

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)
	@users_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).users
	@accounts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).accounts
	@roles_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).roles
	@active_groups = ::Morpheus::Cli::Groups.load_group_file
	@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
	@options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).options
	#@clouds_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
	@instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types

end

#details(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
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
# File 'lib/morpheus/cli/roles.rb', line 116

def details(args)
	usage = "Usage: morpheus roles details [name]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		opts.on(nil,'--feature-access', "Display Feature Access") do |val|
			options[:include_feature_access] = true
		end
		opts.on(nil,'--group-access', "Display Group Access") do
			options[:include_group_access] = true
		end
		opts.on(nil,'--cloud-access', "Display Cloud Access") do
			options[:include_cloud_access] = true
		end
		opts.on(nil,'--instance-type-access', "Display Instance Type Access") do
			options[:include_instance_type_access] = true
		end
		opts.on(nil,'--all-access', "Display All Access Lists") do
			options[:include_feature_access] = true
			options[:include_group_access] = true
			options[:include_cloud_access] = true
			options[:include_instance_type_access] = true
		end
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 1
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		json_response = @roles_interface.get(, role['id'])
		role = json_response['role']

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print "\n" ,cyan, bold, "Role Details\n","==================", reset, "\n\n"
			print cyan
			puts "ID: #{role['id']}"
			puts "Name: #{role['authority']}"
			puts "Description: #{role['description']}"
			puts "Scope: #{role['scope']}"
			puts "Owner: #{role['owner'] ? role['owner']['name'] : nil}"
			puts "Date Created: #{format_local_dt(role['dateCreated'])}"
			puts "Last Updated: #{format_local_dt(role['lastUpdated'])}"

			print "\n" ,cyan, bold, "Role Instance Limits\n","==================", reset, "\n\n"
			print cyan
			puts "Max Storage (bytes): #{role['instanceLimits'] ? role['instanceLimits']['maxStorage'] : 0}"
			puts "Max Memory (bytes): #{role['instanceLimits'] ? role['instanceLimits']['maxMemory'] : 0}"
			puts "CPU Count: #{role['instanceLimits'] ? role['instanceLimits']['maxCpu'] : 0}"

			print "\n" ,cyan, bold, "Feature Access\n","==================", reset, "\n\n"
			print cyan

			if options[:include_feature_access]
				rows = json_response['featurePermissions'].collect do |it|
		      {
		      	code: it['code'], 
		        name: it['name'], 
		        access: get_access_string(it['access']), 
		      }
		    end
		    tp rows, [:code, :name, :access]
		  else
		  	puts "Use --feature-access to list feature access"
		  end

	    print "\n" ,cyan, bold, "Group Access\n","==================", reset, "\n\n"
			print cyan
			
			puts "Global Group Access: #{get_access_string(json_response['globalSiteAccess'])}\n\n"
			if json_response['globalSiteAccess'] == 'custom'
				if options[:include_group_access]
					rows = json_response['sites'].collect do |it|
			      {
			        name: it['name'], 
			        access: get_access_string(it['access']), 
			      }
			    end
			    tp rows, [:name, :access]
				else
					puts "Use --group-access to list custom access"
				end
			end

			print "\n" ,cyan, bold, "Cloud Access\n","==================", reset, "\n\n"
			print cyan
			
			puts "Global Cloud Access: #{get_access_string(json_response['globalZoneAccess'])}\n\n"
			if json_response['globalZoneAccess'] == 'custom'
				if options[:include_cloud_access]
					rows = json_response['zones'].collect do |it|
			      {
			        name: it['name'], 
			        access: get_access_string(it['access']), 
			      }
			    end
			    tp rows, [:name, :access]
				else
					puts "Use --cloud-access to list custom access"
				end
			end

			print "\n" ,cyan, bold, "Instance Type Access\n","==================", reset, "\n\n"
			print cyan
			
			puts "Global Instance Type Access: #{get_access_string(json_response['globalInstanceTypeAccess'])}\n\n"
			if json_response['globalInstanceTypeAccess'] == 'custom'
				if options[:include_instance_type_access]
					rows = json_response['instanceTypePermissions'].collect do |it|
			      {
			        name: it['name'], 
			        access: get_access_string(it['access']), 
			      }
			    end
			    tp rows, [:name, :access]
				else
					puts "Use --instance-type-access to list custom access"
				end
			end

			print reset,"\n\n"
		end
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#handle(args) ⇒ Object



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

def handle(args)
	usage = "Usage: morpheus roles [list,details,add,update,remove,update-feature-access,update-global-group-access,update-group-access,update-global-cloud-access,update-cloud-access,update-global-instance-type-access,update-instance-type-access] [name]"
	if args.empty?
		puts "\n#{usage}\n\n"
		exit 1
	end

	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 'update-feature-access'
			update_feature_access(args[1..-1])
		when 'update-global-group-access'
			update_global_group_access(args[1..-1])
		when 'update-group-access'
			update_group_access(args[1..-1])
		when 'update-global-cloud-access'
			update_global_cloud_access(args[1..-1])
		when 'update-cloud-access'
			update_cloud_access(args[1..-1])
		when 'update-global-instance-type-access'
			update_global_instance_type_access(args[1..-1])
		when 'update-instance-type-access'
			update_instance_type_access(args[1..-1])
		else
			puts "\n#{usage}\n\n"
			exit 127
	end
end

#list(args) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/morpheus/cli/roles.rb', line 75

def list(args)
	usage = "Usage: morpheus roles list"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:list, :json])
	end
	optparse.parse(args)

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil
		
		params = {}
		[:phrase, :offset, :max, :sort, :direction].each do |k|
			params[k] = options[k] unless options[k].nil?
		end
		
		json_response = @roles_interface.list(, params)
		roles = json_response['roles']
		
		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print "\n" ,cyan, bold, "Morpheus Roles\n","==================", reset, "\n\n"
			if roles.empty?
				puts yellow,"No roles found.",reset
			else
				print_roles_table(roles)
			end
			print reset,"\n\n"
		end
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#remove(args) ⇒ Object



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

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

	connect(options)
	begin

		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?
		unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the role #{role['authority']}?")
			exit
		end
		json_response = @roles_interface.destroy(, role['id'])
		
		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} removed"
		end
		
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update(args) ⇒ Object



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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/morpheus/cli/roles.rb', line 311

def update(args)
	usage = "Usage: morpheus roles update [name] [options]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:options, :json])
	end
	optparse.parse(args)

	if args.count < 1
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]

	connect(options)
	
	begin

		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		#params = Morpheus::Cli::OptionTypes.prompt(update_role_option_types, options[:options], @api_client, options[:params])
		params = options[:options] || {}

		if params.empty?
			puts "\n#{usage}\n\n"
			option_lines = update_role_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}"
		role_keys = ['authority', 'description', 'instanceLimits']
		role_payload = params.select {|k,v| role_keys.include?(k) }
		if !role_payload['instanceLimits']
			role_payload['instanceLimits'] = {}
			role_payload['instanceLimits']['maxStorage'] = params['instanceLimits.maxStorage'].to_i if params['instanceLimits.maxStorage'].to_s.strip != ''
			role_payload['instanceLimits']['maxMemory'] = params['instanceLimits.maxMemory'].to_i if params['instanceLimits.maxMemory'].to_s.strip != ''
			role_payload['instanceLimits']['maxCpu'] = params['instanceLimits.maxCpu'].to_i if params['instanceLimits.maxCpu'].to_s.strip != ''
		end
		request_payload = {role: role_payload}
		response = @roles_interface.update(, role['id'], request_payload)
		
		print_green_success "Updated role #{role_payload['authority']}"

		details_options = [role_payload["authority"] || role['authority']]
		if 
			details_options.push "--account-id", ['id'].to_s
		end
		details(details_options)

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

#update_cloud_access(args) ⇒ Object



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

def update_cloud_access(args)
	usage = "Usage: morpheus roles update-cloud-access [name] [cloud_name] [full|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		opts.on( '-g', '--group GROUP', "Group to find cloud in" ) do |val|
			options[:group] = val
		end
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 2
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	cloud_name = args[1]
	access_value = args[2].to_s.downcase
	if !['full', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		role_json = @roles_interface.get(, role['id'])
		
		if role_json['globalZoneAccess'] != 'custom'
			print "\n", red, "Global Cloud Access is currently: #{role_json['globalZoneAccess'].capitalize}"
			print "\n", "You must first set it to Custom via `morpheus roles update-global-cloud-access \"#{name}\" custom`"
			print "\n\n", reset
			exit 1
		end

		group_id = nil
		if !options[:group].nil?
			group_id = find_group_id_by_name(options[:group])
		else
			group_id = @active_groups[@appliance_name.to_sym]	
		end

		if group_id.nil?
			print_red_alert "Group not found or specified!"
			exit 1
		end

		cloud_id = find_cloud_id_by_name(group_id, cloud_name)
		exit 1 if cloud_id.nil?
		params = {cloudId: cloud_id, access: access_value}
		json_response = @roles_interface.update_cloud(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} global cloud access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update_feature_access(args) ⇒ Object



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/roles.rb', line 413

def update_feature_access(args)
	usage = "Usage: morpheus roles update-feature-access [name] [code] [full|read|custom|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 3
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	permission_code = args[1]
	access_value = args[2].to_s.downcase
	if !['full', 'read', 'custom', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		params = {permissionCode: permission_code, access: access_value}
		json_response = @roles_interface.update_permission(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} feature access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update_global_cloud_access(args) ⇒ Object



565
566
567
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
608
# File 'lib/morpheus/cli/roles.rb', line 565

def update_global_cloud_access(args)
	usage = "Usage: morpheus roles update-global-cloud-access [name] [full|custom|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 2
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	access_value = args[1].to_s.downcase
	if !['full', 'custom', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		params = {permissionCode: 'ComputeZone', access: access_value}
		json_response = @roles_interface.update_permission(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} global cloud access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update_global_group_access(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
# File 'lib/morpheus/cli/roles.rb', line 459

def update_global_group_access(args)
	usage = "Usage: morpheus roles update-global-group-access [name] [full|read|custom|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 2
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	access_value = args[1].to_s.downcase
	if !['full', 'read', 'custom', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		params = {permissionCode: 'ComputeSite', access: access_value}
		json_response = @roles_interface.update_permission(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} global group access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update_global_instance_type_access(args) ⇒ Object



682
683
684
685
686
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
# File 'lib/morpheus/cli/roles.rb', line 682

def update_global_instance_type_access(args)
	usage = "Usage: morpheus roles update-global-instance-type-access [name] [full|custom|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 2
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	access_value = args[1].to_s.downcase
	if !['full', 'custom', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end


	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		params = {permissionCode: 'InstanceType', access: access_value}
		json_response = @roles_interface.update_permission(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} global instance type access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update_group_access(args) ⇒ Object



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

def update_group_access(args)
	usage = "Usage: morpheus roles update-group-access [name] [group_name] [full|read|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 2
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	group_name = args[1]
	access_value = args[2].to_s.downcase
	if !['full', 'read', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		role_json = @roles_interface.get(, role['id'])
		
		if role_json['globalSiteAccess'] != 'custom'
			print "\n", red, "Global Group Access is currently: #{role_json['globalSiteAccess'].capitalize}"
			print "\n", "You must first set it to Custom via `morpheus roles update-global-group-access \"#{name}\" custom`"
			print "\n\n", reset
			exit 1
		end

		# group_id = find_group_id_by_name(group_name)
		# exit 1 if group_id.nil?
		group = find_group_by_name(group_name)
		exit 1 if group.nil?
		group_id = group['id']

		params = {groupId: group_id, access: access_value}
		json_response = @roles_interface.update_group(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} global group access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end

#update_instance_type_access(args) ⇒ Object



728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
# File 'lib/morpheus/cli/roles.rb', line 728

def update_instance_type_access(args)
	usage = "Usage: morpheus roles update-instance-type-access [name] [instance_type_name] [full|none]"
	options = {}
	optparse = OptionParser.new do|opts|
		opts.banner = usage
		build_common_options(opts, options, [:json])
	end
	optparse.parse(args)

	if args.count < 2
		puts "\n#{usage}\n\n"
		exit 1
	end
	name = args[0]
	instance_type_name = args[1]
	access_value = args[2].to_s.downcase
	if !['full', 'none'].include?(access_value)
		puts "\n#{usage}\n\n"
		exit 1
	end

	connect(options)
	begin
		
		 = (options)
		 =  ? ['id'] : nil

		role = find_role_by_name(, name)
		exit 1 if role.nil?

		role_json = @roles_interface.get(, role['id'])
		
		if role_json['globalInstanceTypeAccess'] != 'custom'
			print "\n", red, "Global Instance Type Access is currently: #{role_json['globalInstanceTypeAccess'].capitalize}"
			print "\n", "You must first set it to Custom via `morpheus roles update-global-instance-type-access \"#{name}\" custom`"
			print "\n\n", reset
			exit 1
		end

		instance_type = find_instance_type_by_name(instance_type_name)
		exit 1 if instance_type.nil?

		params = {instanceTypeId: instance_type['id'], access: access_value}
		json_response = @roles_interface.update_instance_type(, role['id'], params)

		if options[:json]
			print JSON.pretty_generate(json_response)
			print "\n"
		else
			print_green_success "Role #{role['authority']} global instance type access updated"
		end
			
	rescue RestClient::Exception => e
		print_rest_exception(e, options)
		exit 1
	end
end