morpheus-cli 4.1.8 → 4.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/api_client.rb +24 -0
  4. data/lib/morpheus/api/{old_cypher_interface.rb → budgets_interface.rb} +10 -11
  5. data/lib/morpheus/api/cloud_datastores_interface.rb +7 -0
  6. data/lib/morpheus/api/cloud_resource_pools_interface.rb +2 -2
  7. data/lib/morpheus/api/cypher_interface.rb +18 -12
  8. data/lib/morpheus/api/health_interface.rb +72 -0
  9. data/lib/morpheus/api/instances_interface.rb +1 -1
  10. data/lib/morpheus/api/library_instance_types_interface.rb +7 -0
  11. data/lib/morpheus/api/log_settings_interface.rb +6 -0
  12. data/lib/morpheus/api/network_security_servers_interface.rb +30 -0
  13. data/lib/morpheus/api/price_sets_interface.rb +42 -0
  14. data/lib/morpheus/api/prices_interface.rb +68 -0
  15. data/lib/morpheus/api/provisioning_settings_interface.rb +29 -0
  16. data/lib/morpheus/api/servers_interface.rb +1 -1
  17. data/lib/morpheus/api/service_plans_interface.rb +34 -11
  18. data/lib/morpheus/api/task_sets_interface.rb +8 -0
  19. data/lib/morpheus/api/tasks_interface.rb +8 -0
  20. data/lib/morpheus/cli.rb +6 -3
  21. data/lib/morpheus/cli/appliance_settings_command.rb +13 -5
  22. data/lib/morpheus/cli/approvals_command.rb +1 -1
  23. data/lib/morpheus/cli/apps.rb +88 -28
  24. data/lib/morpheus/cli/backup_settings_command.rb +1 -1
  25. data/lib/morpheus/cli/blueprints_command.rb +2 -0
  26. data/lib/morpheus/cli/budgets_command.rb +672 -0
  27. data/lib/morpheus/cli/cli_command.rb +13 -2
  28. data/lib/morpheus/cli/cli_registry.rb +1 -0
  29. data/lib/morpheus/cli/clusters.rb +40 -274
  30. data/lib/morpheus/cli/commands/standard/benchmark_command.rb +114 -66
  31. data/lib/morpheus/cli/commands/standard/coloring_command.rb +12 -0
  32. data/lib/morpheus/cli/commands/standard/curl_command.rb +31 -6
  33. data/lib/morpheus/cli/commands/standard/echo_command.rb +8 -3
  34. data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +1 -1
  35. data/lib/morpheus/cli/containers_command.rb +37 -24
  36. data/lib/morpheus/cli/cypher_command.rb +191 -150
  37. data/lib/morpheus/cli/health_command.rb +903 -0
  38. data/lib/morpheus/cli/hosts.rb +43 -32
  39. data/lib/morpheus/cli/instances.rb +119 -68
  40. data/lib/morpheus/cli/jobs_command.rb +1 -1
  41. data/lib/morpheus/cli/library_instance_types_command.rb +61 -11
  42. data/lib/morpheus/cli/library_option_types_command.rb +2 -2
  43. data/lib/morpheus/cli/log_settings_command.rb +46 -3
  44. data/lib/morpheus/cli/logs_command.rb +24 -17
  45. data/lib/morpheus/cli/mixins/accounts_helper.rb +2 -0
  46. data/lib/morpheus/cli/mixins/logs_helper.rb +73 -19
  47. data/lib/morpheus/cli/mixins/print_helper.rb +29 -1
  48. data/lib/morpheus/cli/mixins/provisioning_helper.rb +554 -96
  49. data/lib/morpheus/cli/mixins/whoami_helper.rb +13 -1
  50. data/lib/morpheus/cli/networks_command.rb +3 -0
  51. data/lib/morpheus/cli/option_types.rb +83 -53
  52. data/lib/morpheus/cli/price_sets_command.rb +543 -0
  53. data/lib/morpheus/cli/prices_command.rb +669 -0
  54. data/lib/morpheus/cli/processes_command.rb +0 -2
  55. data/lib/morpheus/cli/provisioning_settings_command.rb +237 -0
  56. data/lib/morpheus/cli/remote.rb +9 -4
  57. data/lib/morpheus/cli/reports_command.rb +10 -4
  58. data/lib/morpheus/cli/roles.rb +93 -38
  59. data/lib/morpheus/cli/security_groups.rb +10 -0
  60. data/lib/morpheus/cli/service_plans_command.rb +736 -0
  61. data/lib/morpheus/cli/tasks.rb +220 -8
  62. data/lib/morpheus/cli/tenants_command.rb +3 -16
  63. data/lib/morpheus/cli/users.rb +2 -25
  64. data/lib/morpheus/cli/version.rb +1 -1
  65. data/lib/morpheus/cli/whitelabel_settings_command.rb +18 -18
  66. data/lib/morpheus/cli/whoami.rb +28 -10
  67. data/lib/morpheus/cli/workflows.rb +488 -36
  68. data/lib/morpheus/formatters.rb +22 -0
  69. data/morpheus-cli.gemspec +1 -0
  70. metadata +28 -5
  71. data/lib/morpheus/cli/accounts.rb +0 -335
  72. data/lib/morpheus/cli/old_cypher_command.rb +0 -412
@@ -228,7 +228,7 @@ module Morpheus
228
228
  nested_options = nested_options[name_element]
229
229
  else
230
230
  val = custom_option_args[1]
231
- if val.to_s[0] == '{' && val.to_s[-1] == '}'
231
+ if (val.to_s[0] == '{' && val.to_s[-1] == '}') || (val.to_s[0] == '[' && val.to_s[-1] == ']')
232
232
  begin
233
233
  val = JSON.parse(val)
234
234
  rescue
@@ -240,7 +240,7 @@ module Morpheus
240
240
  end
241
241
  else
242
242
  val = custom_option_args[1]
243
- if val.to_s[0] == '{' && val.to_s[-1] == '}'
243
+ if (val.to_s[0] == '{' && val.to_s[-1] == '}') || (val.to_s[0] == '[' && val.to_s[-1] == ']')
244
244
  begin
245
245
  val = JSON.parse(val)
246
246
  rescue
@@ -897,6 +897,7 @@ module Morpheus
897
897
  end
898
898
 
899
899
  # parse the parameters provided by the common :list options
900
+ # this includes the :query options too via parse_query_options().
900
901
  # returns Hash of params the format {"phrase": => "foobar", "max": 100}
901
902
  def parse_list_options(options={})
902
903
  list_params = {}
@@ -908,6 +909,16 @@ module Morpheus
908
909
  end
909
910
  end
910
911
  # arbitrary filters
912
+ list_params.merge!(parse_query_options(options))
913
+
914
+ return list_params
915
+ end
916
+
917
+ # parse the parameters provided by the common :query (:query_filters) options
918
+ # returns Hash of params the format {"phrase": => "foobar", "max": 100}
919
+ def parse_query_options(options={})
920
+ list_params = {}
921
+ # arbitrary filters
911
922
  if options[:query_filters]
912
923
  options[:query_filters].each do |k, v|
913
924
  if k
@@ -80,6 +80,7 @@ module Morpheus
80
80
  elsif has_command?(command_name)
81
81
  instance.get(command_name).new.handle(args)
82
82
  else
83
+ # todo: need to just return error instead of raise
83
84
  raise Morpheus::Cli::CommandError.new("'#{command_name}' is not a command. See 'morpheus --help'.")
84
85
  end
85
86
  end
@@ -41,7 +41,7 @@ class Morpheus::Cli::Clusters
41
41
  @servers_interface = @api_client.servers
42
42
  @server_types_interface = @api_client.server_types
43
43
  @options_interface = @api_client.options
44
- @active_group_id = Morpheus::Cli::Groups.active_group
44
+ @active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
45
45
  @provision_types_interface = @api_client.provision_types
46
46
  @service_plans_interface = @api_client.service_plans
47
47
  @user_groups_interface = @api_client.user_groups
@@ -837,6 +837,21 @@ class Morpheus::Cli::Clusters
837
837
  options = {}
838
838
  optparse = Morpheus::Cli::OptionParser.new do |opts|
839
839
  opts.banner = subcommand_usage("[cluster]")
840
+ opts.on('--start TIMESTAMP','--start TIMESTAMP', "Start timestamp. Default is 30 days ago.") do |val|
841
+ options[:start] = parse_time(val) #.utc.iso8601
842
+ end
843
+ opts.on('--end TIMESTAMP','--end TIMESTAMP', "End timestamp. Default is now.") do |val|
844
+ options[:end] = parse_time(val) #.utc.iso8601
845
+ end
846
+ opts.on('--level VALUE', String, "Log Level. DEBUG,INFO,WARN,ERROR") do |val|
847
+ params['level'] = params['level'] ? [params['level'], val].flatten : val
848
+ end
849
+ opts.on('--table', '--table', "Format ouput as a table.") do
850
+ options[:table] = true
851
+ end
852
+ opts.on('-a', '--all', "Display all details: entire message." ) do
853
+ options[:details] = true
854
+ end
840
855
  build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
841
856
  end
842
857
  optparse.parse!(args)
@@ -848,28 +863,39 @@ class Morpheus::Cli::Clusters
848
863
  cluster = find_cluster_by_name_or_id(args[0])
849
864
  params = {}
850
865
  params.merge!(parse_list_options(options))
851
- params[:query] = params.delete(:phrase) unless params[:phrase].nil?
866
+ params['query'] = params.delete('phrase') if params['phrase']
867
+ params['startMs'] = (options[:start].to_i * 1000) if options[:start]
868
+ params['endMs'] = (options[:end].to_i * 1000) if options[:end]
852
869
  @logs_interface.setopts(options)
853
870
  if options[:dry_run]
854
871
  print_dry_run @logs_interface.dry.cluster_logs(cluster['id'], params)
855
872
  return
856
873
  end
857
874
  json_response = @logs_interface.cluster_logs(cluster['id'], params)
858
- render_result = render_with_format(json_response, options, 'data')
875
+ render_result = json_response['logs'] ? render_with_format(json_response, options, 'logs') : render_with_format(json_response, options, 'data')
859
876
  return 0 if render_result
860
877
 
861
878
  logs = json_response
862
879
  title = "Cluster Logs: #{cluster['name']}"
863
880
  subtitles = parse_list_subtitles(options)
881
+ if options[:start]
882
+ subtitles << "Start: #{options[:start]}".strip
883
+ end
884
+ if options[:end]
885
+ subtitles << "End: #{options[:end]}".strip
886
+ end
864
887
  if params[:query]
865
888
  subtitles << "Search: #{params[:query]}".strip
866
889
  end
867
- # todo: startMs, endMs, sorts insteaad of sort..etc
890
+ if params['level']
891
+ subtitles << "Level: #{params['level']}"
892
+ end
893
+ logs = json_response['data'] || json_response['logs']
868
894
  print_h1 title, subtitles, options
869
- if logs['data'].empty?
895
+ if logs.empty?
870
896
  puts "#{cyan}No logs found.#{reset}"
871
897
  else
872
- logs['data'].each do |log_entry|
898
+ logs.each do |log_entry|
873
899
  log_level = ''
874
900
  case log_entry['level']
875
901
  when 'INFO'
@@ -923,7 +949,7 @@ class Morpheus::Cli::Clusters
923
949
  payload['permissions'].deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
924
950
  end
925
951
  else
926
- payload = {"permissions" => prompt_permissions(options)}
952
+ payload = {"permissions" => prompt_permissions(options.merge({:available_plans => namespace_service_plans}))}
927
953
  end
928
954
 
929
955
  @clusters_interface.setopts(options)
@@ -2623,7 +2649,7 @@ class Morpheus::Cli::Clusters
2623
2649
  opts.on('--active [on|off]', String, "Enable datastore") do |val|
2624
2650
  options[:active] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
2625
2651
  end
2626
- add_perms_options(opts, options, ['planAccess', 'groupAccessDefaults'])
2652
+ add_perms_options(opts, options, ['plans', 'groupDefaults'])
2627
2653
  build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
2628
2654
  opts.footer = "Update a cluster datastore.\n" +
2629
2655
  "[cluster] is required. This is the name or id of an existing cluster.\n" +
@@ -2655,7 +2681,7 @@ class Morpheus::Cli::Clusters
2655
2681
  payload = {'datastore' => {}}
2656
2682
  payload['datastore']['active'] = options[:active].nil? ? (Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'active', 'fieldLabel' => 'Active', 'type' => 'checkbox', 'description' => 'Datastore Active', 'defaultValue' => true}], options[:options], @api_client))['active'] == 'on' : options[:active]
2657
2683
 
2658
- perms = prompt_permissions(options, datastore['owner']['id'] == current_user['accountId'] ? ['planAccess', 'groupAccessDefaults'] : ['planAccess', 'groupAccessDefaults', 'visibility', 'tenants'])
2684
+ perms = prompt_permissions(options.merge({:available_plans => namespace_service_plans}), datastore['owner']['id'] == current_user['accountId'] ? ['plans', 'groupDefaults'] : ['plans', 'groupDefaults', 'visibility', 'tenants'])
2659
2685
  perms_payload = {}
2660
2686
  perms_payload['resourcePermissions'] = perms['resourcePermissions'] if !perms['resourcePermissions'].nil?
2661
2687
  perms_payload['tenantPermissions'] = perms['tenantPermissions'] if !perms['tenantPermissions'].nil?
@@ -3102,7 +3128,7 @@ class Morpheus::Cli::Clusters
3102
3128
  return 1 if cluster.nil?
3103
3129
  params = {}
3104
3130
  params.merge!(parse_list_options(options))
3105
- # params[:query] = params.delete(:phrase) unless params[:phrase].nil?
3131
+ # params['query'] = params.delete('phrase') if params['phrase']
3106
3132
  @clusters_interface.setopts(options)
3107
3133
  if options[:dry_run]
3108
3134
  print_dry_run @clusters_interface.dry.history(cluster['id'], params)
@@ -3234,7 +3260,6 @@ class Morpheus::Cli::Clusters
3234
3260
  return 1 if cluster.nil?
3235
3261
  params = {}
3236
3262
  params.merge!(parse_list_options(options))
3237
- params[:query] = params.delete(:phrase) unless params[:phrase].nil?
3238
3263
  @clusters_interface.setopts(options)
3239
3264
  if options[:dry_run]
3240
3265
  print_dry_run @clusters_interface.dry.history_details(cluster['id'], process_id, params)
@@ -3643,7 +3668,9 @@ class Morpheus::Cli::Clusters
3643
3668
  end
3644
3669
 
3645
3670
  def namespace_service_plans
3646
- @service_plans_interface.list({'provisionable' => 'any', 'provisionTypeId' => @provision_types_interface.list({'code' => 'docker'})['provisionTypes'].first['id']})['servicePlans'] rescue []
3671
+ @service_plans_interface.list({'provisionable' => 'any', 'provisionTypeId' => @provision_types_interface.list({'code' => 'docker'})['provisionTypes'].first['id']})['servicePlans'].collect {|it|
3672
+ {"name" => it["name"], "value" => it["id"]}
3673
+ } rescue []
3647
3674
  end
3648
3675
 
3649
3676
  def get_cloud_type(id)
@@ -3848,66 +3875,6 @@ class Morpheus::Cli::Clusters
3848
3875
  end
3849
3876
  end
3850
3877
 
3851
- def add_perms_options(opts, options, excludes = [])
3852
- if !excludes.include?('groupAccess')
3853
- opts.on('--group-access-all [on|off]', String, "Toggle Access for all groups.") do |val|
3854
- options[:groupAccessAll] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
3855
- end
3856
- opts.on('--group-access LIST', Array, "Group Access, comma separated list of group IDs.") do |list|
3857
- if list.size == 1 && list[0] == 'null' # hacky way to clear it
3858
- options[:groupAccessList] = []
3859
- else
3860
- options[:groupAccessList] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
3861
- end
3862
- end
3863
- if !excludes.include?('groupAccessDefaults')
3864
- opts.on('--group-defaults LIST', Array, "Group Default Selection, comma separated list of group IDs") do |list|
3865
- if list.size == 1 && list[0] == 'null' # hacky way to clear it
3866
- options[:groupDefaultsList] = []
3867
- else
3868
- options[:groupDefaultsList] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
3869
- end
3870
- end
3871
- end
3872
- end
3873
-
3874
- if !excludes.include?('planAccess')
3875
- opts.on('--plan-access-all [on|off]', String, "Toggle Access for all service plans.") do |val|
3876
- options[:planAccessAll] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
3877
- end
3878
- opts.on('--plan-access LIST', Array, "Service Plan Access, comma separated list of plan IDs.") do |list|
3879
- if list.size == 1 && list[0] == 'null' # hacky way to clear it
3880
- options[:planAccessList] = []
3881
- else
3882
- options[:planAccessList] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
3883
- end
3884
- end
3885
- opts.on('--plan-defaults LIST', Array, "Plan Default Selection, comma separated list of plan IDs") do |list|
3886
- if list.size == 1 && list[0] == 'null' # hacky way to clear it
3887
- options[:planDefaultsList] = []
3888
- else
3889
- options[:planDefaultsList] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
3890
- end
3891
- end
3892
- end
3893
-
3894
- if !excludes.include?('visibility')
3895
- opts.on('--visibility [private|public]', String, "Visibility") do |val|
3896
- options[:visibility] = val
3897
- end
3898
- end
3899
-
3900
- if !excludes.include?('tenants')
3901
- opts.on('--tenants LIST', Array, "Tenant Access, comma separated list of account IDs") do |list|
3902
- if list.size == 1 && list[0] == 'null' # hacky way to clear it
3903
- options[:tenants] = []
3904
- else
3905
- options[:tenants] = list.collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
3906
- end
3907
- end
3908
- end
3909
- end
3910
-
3911
3878
  def prompt_resource_pool(group, cloud, service_plan, provision_type, options)
3912
3879
  resource_pool = nil
3913
3880
 
@@ -3962,7 +3929,7 @@ class Morpheus::Cli::Clusters
3962
3929
  rtn['description'] = options[:description] || Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'description' => 'Namespace Description', 'required' => false}], options[:options], @api_client)['description']
3963
3930
  rtn['active'] = options[:active].nil? ? (Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'active', 'fieldLabel' => 'Active', 'type' => 'checkbox', 'description' => 'Namespace Active', 'defaultValue' => true}], options[:options], @api_client))['active'] == 'on' : options[:active]
3964
3931
 
3965
- perms = prompt_permissions(options)
3932
+ perms = prompt_permissions(options.merge({:available_plans => namespace_service_plans}))
3966
3933
  if perms['resourcePool'] && !perms['resourcePool']['visibility'].nil?
3967
3934
  rtn['visibility'] = perms['resourcePool']['visibility']
3968
3935
  perms.delete('resourcePool')
@@ -3971,147 +3938,6 @@ class Morpheus::Cli::Clusters
3971
3938
  rtn
3972
3939
  end
3973
3940
 
3974
- def prompt_permissions(options, excludes = [])
3975
- all_groups = nil
3976
- group_access = nil
3977
- all_plans = nil
3978
- plan_access = nil
3979
-
3980
- # Group Access
3981
- if !excludes.include?('groupAccess')
3982
- if !options[:groupAccessAll].nil?
3983
- all_groups = options[:groupAccessAll]
3984
- end
3985
-
3986
- if !options[:groupAccessList].empty?
3987
- group_access = options[:groupAccessList].collect {|site_id| {'id' => site_id.to_i}} || []
3988
- elsif !options[:no_prompt]
3989
- available_groups = get_available_groups
3990
-
3991
- if available_groups.empty?
3992
- #print_red_alert "No available groups"
3993
- #exit 1
3994
- elsif available_groups.count > 1
3995
- available_groups.unshift({"id" => '0', "name" => "All", "value" => "all"})
3996
-
3997
- # default to all
3998
- group_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group Access', 'selectOptions' => available_groups, 'required' => false, 'description' => 'Add Group Access.'}], options[:options], @api_client, {})['group']
3999
-
4000
- if !group_id.nil?
4001
- if group_id == 'all'
4002
- all_groups = true
4003
- else
4004
- group_access = (excludes.include?('groupAccessDefaults') ? [{'id' => group_id}] : [{'id' => group_id, 'default' => Morpheus::Cli::OptionTypes.confirm("Set '#{available_groups.find{|it| it['id'] == group_id}['name']}' as default?", {:default => false})}])
4005
- end
4006
- available_groups = available_groups.reject {|it| it['value'] == group_id}
4007
-
4008
- while !group_id.nil? && !available_groups.empty? && Morpheus::Cli::OptionTypes.confirm("Add another group access?", {:default => false})
4009
- group_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'type' => 'select', 'fieldLabel' => 'Group Access', 'selectOptions' => available_groups, 'required' => false, 'description' => 'Add Group Access.'}], options[:options], @api_client, {})['group']
4010
-
4011
- if !group_id.nil?
4012
- if group_id == 'all'
4013
- all_groups = true
4014
- else
4015
- group_access ||= []
4016
- group_access << (excludes.include?('groupAccessDefaults') ? {'id' => group_id} : {'id' => group_id, 'default' => Morpheus::Cli::OptionTypes.confirm("Set '#{available_groups.find{|it| it['id'] == group_id}['name']}' as default?", {:default => false})})
4017
- end
4018
- available_groups = available_groups.reject {|it| it['value'] == group_id}
4019
- end
4020
- end
4021
- end
4022
- end
4023
- end
4024
- end
4025
-
4026
- # Plan Access
4027
- if !excludes.include?('planAccess')
4028
- if !options[:planAccessAll].nil?
4029
- all_plans = options[:planAccessAll]
4030
- end
4031
-
4032
- if !options[:planAccessList].empty?
4033
- plan_access = options[:planAccessList].collect {|plan_id| {'id' => plan_id.to_i}}
4034
- elsif !options[:no_prompt]
4035
- available_plans = namespace_service_plans.collect {|it| {'id' => it['id'], 'name' => it['name'], 'value' => it['id']} }
4036
-
4037
- if available_plans.empty?
4038
- #print_red_alert "No available plans"
4039
- #exit 1
4040
- elsif !available_plans.empty? && !options[:no_prompt]
4041
- available_plans.unshift({"id" => '0', "name" => "All", "value" => "all"})
4042
-
4043
- # default to all
4044
- plan_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'plan', 'type' => 'select', 'fieldLabel' => 'Service Plan Access', 'selectOptions' => available_plans, 'required' => false, 'description' => 'Add Service Plan Access.'}], options[:options], @api_client, {})['plan']
4045
-
4046
- if !plan_id.nil?
4047
- if plan_id == 'all'
4048
- all_plans = true
4049
- else
4050
- plan_access = [{'id' => plan_id, 'default' => Morpheus::Cli::OptionTypes.confirm("Set '#{available_plans.find{|it| it['id'] == plan_id}['name']}' as default?", {:default => false})}]
4051
- end
4052
-
4053
- available_plans = available_plans.reject {|it| it['value'] == plan_id}
4054
-
4055
- while !plan_id.nil? && !available_plans.empty? && Morpheus::Cli::OptionTypes.confirm("Add another service plan access?", {:default => false})
4056
- plan_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'plan', 'type' => 'select', 'fieldLabel' => 'Service Plan Access', 'selectOptions' => available_plans, 'required' => false, 'description' => 'Add Service Plan Access.'}], options[:options], @api_client, {})['plan']
4057
-
4058
- if !plan_id.nil?
4059
- if plan_id == 'all'
4060
- all_plans = true
4061
- else
4062
- plan_access ||= []
4063
- plan_access << {'id' => plan_id, 'default' => Morpheus::Cli::OptionTypes.confirm("Set '#{available_plans.find{|it| it['id'] == plan_id}['name']}' as default?", {:default => false})}
4064
- end
4065
- available_plans = available_plans.reject {|it| it['value'] == plan_id}
4066
- end
4067
- end
4068
- end
4069
- end
4070
- end
4071
- end
4072
-
4073
- resource_perms = {}
4074
- resource_perms['all'] = all_groups if !all_groups.nil?
4075
- resource_perms['sites'] = group_access if !group_access.nil?
4076
- resource_perms['allPlans'] = all_plans if !all_plans.nil?
4077
- resource_perms['plans'] = plan_access if !plan_access.nil?
4078
-
4079
- permissions = {'resourcePermissions' => resource_perms}
4080
-
4081
- available_accounts = @accounts_interface.list()['accounts'].collect {|it| {'name' => it['name'], 'value' => it['id']}}
4082
- accounts = []
4083
-
4084
- # Prompts for multi tenant
4085
- if available_accounts.count > 1
4086
- visibility = options[:visibility] || Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'visibility', 'fieldLabel' => 'Tenant Permissions Visibility', 'type' => 'select', 'defaultValue' => 'private', 'required' => true, 'selectOptions' => [{'name' => 'Private', 'value' => 'private'},{'name' => 'Public', 'value' => 'public'}]}], options[:options], @api_client, {})['visibility']
4087
-
4088
- permissions['resourcePool'] = {'visibility' => visibility}
4089
-
4090
- # Tenants
4091
- if !excludes.include?('tenants')
4092
- if !options[:tenants].nil?
4093
- accounts = options[:tenants].collect {|id| id.to_i}
4094
- elsif !options[:no_prompt]
4095
- account_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'account_id', 'type' => 'select', 'fieldLabel' => 'Add Tenant', 'selectOptions' => available_accounts, 'required' => false, 'description' => 'Add Tenant Permissions.'}], options[:options], @api_client, {})['account_id']
4096
-
4097
- if !account_id.nil?
4098
- accounts << account_id
4099
- available_accounts = available_accounts.reject {|it| it['value'] == account_id}
4100
-
4101
- while !available_accounts.empty? && (account_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'account_id', 'type' => 'select', 'fieldLabel' => 'Add Another Tenant', 'selectOptions' => available_accounts, 'required' => false, 'description' => 'Add Tenant Permissions.'}], options[:options], @api_client, {})['account_id'])
4102
- if !account_id.nil?
4103
- accounts << account_id
4104
- available_accounts = available_accounts.reject {|it| it['value'] == account_id}
4105
- end
4106
- end
4107
- end
4108
- end
4109
- permissions['tenantPermissions'] = {'accounts' => accounts}
4110
- end
4111
- end
4112
- permissions
4113
- end
4114
-
4115
3941
  def update_wiki_page_option_types
4116
3942
  [
4117
3943
  {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => false, 'displayOrder' => 1, 'description' => 'The name of the wiki page for this instance. Default is the instance name.'},
@@ -4120,64 +3946,4 @@ class Morpheus::Cli::Clusters
4120
3946
  ]
4121
3947
  end
4122
3948
 
4123
- def print_permissions(permissions)
4124
- if permissions.nil?
4125
- print_h2 "Permissions"
4126
- print yellow,"No permissions found.",reset,"\n"
4127
- else
4128
- if !permissions['resourcePermissions'].nil?
4129
- print_h2 "Group Access"
4130
- rows = []
4131
- if permissions['resourcePermissions']['all']
4132
- rows.push({group: 'All'})
4133
- end
4134
- if permissions['resourcePermissions']['sites']
4135
- permissions['resourcePermissions']['sites'].each do |site|
4136
- rows.push({group: site['name'], default: site['default'] ? 'Yes' : ''})
4137
- end
4138
- end
4139
- if rows.empty?
4140
- print yellow,"No group access",reset,"\n"
4141
- else
4142
- columns = [:group, :default]
4143
- print cyan
4144
- print as_pretty_table(rows, columns)
4145
- end
4146
-
4147
- print_h2 "Plan Access"
4148
- rows = []
4149
- if permissions['resourcePermissions']['allPlans']
4150
- rows.push({plan: 'All'})
4151
- end
4152
- if permissions['resourcePermissions']['plans']
4153
- permissions['resourcePermissions']['plans'].each do |plan|
4154
- rows.push({plan: plan['name'], default: plan['default'] ? 'Yes' : ''})
4155
- end
4156
- end
4157
- if rows.empty?
4158
- print yellow,"No plan access",reset,"\n"
4159
- else
4160
- columns = [:plan, :default]
4161
- print cyan
4162
- print as_pretty_table(rows, columns)
4163
- end
4164
-
4165
- if !permissions['tenantPermissions'].nil?
4166
- print_h2 "Tenant Permissions"
4167
- if !permissions['resourcePool'].nil?
4168
- print cyan
4169
- print "Visibility: #{permissions['resourcePool']['visibility'].to_s.capitalize}".center(20)
4170
- print "\n"
4171
- end
4172
- if !permissions['tenantPermissions'].nil?
4173
- print cyan
4174
- print "Accounts: #{permissions['tenantPermissions']['accounts'].join(', ')}".center(20)
4175
- print "\n"
4176
- end
4177
- end
4178
- print "\n"
4179
- end
4180
- end
4181
- end
4182
-
4183
3949
  end