morpheus-cli 3.3.1.4 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/morpheus/api/api_client.rb +28 -0
  3. data/lib/morpheus/api/instance_types_interface.rb +12 -10
  4. data/lib/morpheus/api/instances_interface.rb +4 -0
  5. data/lib/morpheus/api/library_container_scripts_interface.rb +49 -0
  6. data/lib/morpheus/api/library_container_templates_interface.rb +49 -0
  7. data/lib/morpheus/api/library_container_types_interface.rb +65 -0
  8. data/lib/morpheus/api/library_container_upgrades_interface.rb +66 -0
  9. data/lib/morpheus/api/library_instance_types_interface.rb +59 -0
  10. data/lib/morpheus/api/library_layouts_interface.rb +65 -0
  11. data/lib/morpheus/api/servers_interface.rb +4 -0
  12. data/lib/morpheus/api/user_sources_interface.rb +120 -0
  13. data/lib/morpheus/api/virtual_images_interface.rb +7 -0
  14. data/lib/morpheus/cli.rb +12 -1
  15. data/lib/morpheus/cli/accounts.rb +35 -9
  16. data/lib/morpheus/cli/cli_command.rb +82 -2
  17. data/lib/morpheus/cli/curl_command.rb +1 -1
  18. data/lib/morpheus/cli/echo_command.rb +1 -1
  19. data/lib/morpheus/cli/hosts.rb +40 -14
  20. data/lib/morpheus/cli/instance_types.rb +106 -64
  21. data/lib/morpheus/cli/instances.rb +39 -15
  22. data/lib/morpheus/cli/library.rb +1 -1184
  23. data/lib/morpheus/cli/library_container_scripts_command.rb +437 -0
  24. data/lib/morpheus/cli/library_container_templates_command.rb +397 -0
  25. data/lib/morpheus/cli/library_container_types_command.rb +653 -0
  26. data/lib/morpheus/cli/library_instance_types_command.rb +491 -0
  27. data/lib/morpheus/cli/library_layouts_command.rb +650 -0
  28. data/lib/morpheus/cli/library_option_lists_command.rb +476 -0
  29. data/lib/morpheus/cli/library_option_types_command.rb +549 -0
  30. data/lib/morpheus/cli/library_upgrades_command.rb +604 -0
  31. data/lib/morpheus/cli/mixins/library_helper.rb +123 -0
  32. data/lib/morpheus/cli/mixins/print_helper.rb +21 -22
  33. data/lib/morpheus/cli/mixins/provisioning_helper.rb +56 -11
  34. data/lib/morpheus/cli/network_services_command.rb +1 -1
  35. data/lib/morpheus/cli/option_types.rb +12 -2
  36. data/lib/morpheus/cli/power_scheduling_command.rb +1 -1
  37. data/lib/morpheus/cli/shell.rb +120 -22
  38. data/lib/morpheus/cli/sleep_command.rb +45 -0
  39. data/lib/morpheus/cli/user_sources_command.rb +963 -0
  40. data/lib/morpheus/cli/users.rb +33 -2
  41. data/lib/morpheus/cli/version.rb +1 -1
  42. data/lib/morpheus/cli/version_command.rb +1 -1
  43. data/lib/morpheus/cli/virtual_images.rb +93 -39
  44. data/lib/morpheus/formatters.rb +37 -27
  45. data/lib/morpheus/terminal.rb +1 -1
  46. metadata +20 -2
@@ -1,9 +1,11 @@
1
1
  require 'io/console'
2
2
  require 'optparse'
3
3
  require 'morpheus/cli/cli_command'
4
+ require 'morpheus/cli/mixins/provisioning_helper'
4
5
 
5
6
  class Morpheus::Cli::InstanceTypes
6
7
  include Morpheus::Cli::CliCommand
8
+ include Morpheus::Cli::ProvisioningHelper
7
9
 
8
10
  register_subcommands :list, :get
9
11
  alias_subcommand :details, :get
@@ -22,108 +24,148 @@ class Morpheus::Cli::InstanceTypes
22
24
  handle_subcommand(args)
23
25
  end
24
26
 
25
- def get(args)
27
+
28
+ def list(args)
26
29
  options = {}
27
- optparse = OptionParser.new do|opts|
28
- opts.banner = subcommand_usage("[name]")
29
- build_common_options(opts, options, [:json, :dry_run])
30
+ params = {}
31
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
32
+ opts.banner = subcommand_usage()
33
+ build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
34
+ opts.on('--category VALUE', String, "Filter by category") do |val|
35
+ params['category'] = val
36
+ end
37
+ opts.on('--code VALUE', String, "Filter by code") do |val|
38
+ params['code'] = val
39
+ end
40
+ opts.on('--technology VALUE', String, "Filter by technology") do |val|
41
+ params['provisionTypeCode'] = val
42
+ end
43
+ opts.footer = "List instance types."
30
44
  end
31
45
  optparse.parse!(args)
32
- if args.count < 1
33
- puts optparse
34
- exit
46
+ if args.count > 0
47
+ print_error Morpheus::Terminal.angry_prompt
48
+ puts_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.inspect}\n#{optparse}"
49
+ return 1
35
50
  end
36
- name = args[0]
37
51
  connect(options)
38
52
  begin
53
+ # construct payload
54
+ params.merge!(parse_list_options(options))
55
+ # dry run?
39
56
  if options[:dry_run]
40
- print_dry_run @instance_types_interface.dry.get({name: name})
57
+ print_dry_run @instance_types_interface.dry.list(params)
41
58
  return
42
59
  end
43
- json_response = @instance_types_interface.get({name: name})
44
-
60
+ # do it
61
+ json_response = @instance_types_interface.list(params)
62
+ instance_types = json_response['instanceTypes']
63
+ if options[:include_fields]
64
+ json_response = {"instanceTypes" => filter_data(json_response["instanceTypes"], options[:include_fields]) }
65
+ end
66
+ # print result and return output
45
67
  if options[:json]
46
- print JSON.pretty_generate(json_response), "\n"
47
- return
68
+ puts as_json(json_response, options)
69
+ return 0
70
+ elsif options[:csv]
71
+ puts records_as_csv(json_response['instanceTypes'], options)
72
+ return 0
73
+ elsif options[:yaml]
74
+ puts as_yaml(json_response, options)
75
+ return 0
48
76
  end
49
-
50
- instance_type = json_response['instanceTypes'][0]
51
-
52
- if instance_type.nil?
53
- puts yellow,"No instance type found by name #{name}.",reset
77
+ instance_types = json_response['instanceTypes']
78
+ title = "Morpheus Instance Types"
79
+ subtitles = []
80
+ subtitles += parse_list_subtitles(options)
81
+ print_h1 title, subtitles
82
+ if instance_types.empty?
83
+ print yellow,"No instance types found.",reset,"\n"
54
84
  else
55
- print_h1 "Instance Type Details"
56
- versions = instance_type['versions'].join(', ')
57
- print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
58
- layout_names = instance_type['instanceTypeLayouts'].collect { |layout| layout['name'] }.uniq.sort
59
- layout_names.each do |layout_name|
60
- print green, " - #{layout_name}\n",reset
85
+ instance_types.each do |instance_type|
86
+ versions = instance_type['versions'].join(', ')
87
+ print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
88
+ if instance_type['instanceTypeLayouts']
89
+ layout_names = instance_type['instanceTypeLayouts'].collect { |layout| layout['name'] }.uniq.sort
90
+ layout_names.each do |layout_name|
91
+ print green, " - #{layout_name}\n",reset
92
+ end
93
+ end
94
+ end
95
+ if json_response['meta']
96
+ print_results_pagination(json_response, {:label => "instance type", :n_label => "instance types"})
61
97
  end
62
- # instance_type['instanceTypeLayouts'].each do |layout|
63
- # print green, " - #{layout['name']}\n",reset
64
- # end
65
- print reset,"\n"
66
98
  end
67
-
99
+ print reset,"\n"
68
100
  rescue RestClient::Exception => e
69
101
  print_rest_exception(e, options)
70
- exit 1
102
+ return 1
71
103
  end
72
104
  end
73
105
 
74
- def list(args)
106
+ def get(args)
75
107
  options = {}
76
- optparse = OptionParser.new do|opts|
77
- opts.banner = subcommand_usage()
78
- build_common_options(opts, options, [:list, :json, :dry_run])
108
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
109
+ opts.banner = subcommand_usage("[name]")
110
+ build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
111
+ opts.footer = "Get instance type details." + "\n" +
112
+ "[name] is required. This is the name or id of an instance type."
79
113
  end
80
114
  optparse.parse!(args)
115
+ if args.count < 1
116
+ puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 1 and received #{args.count} #{args.inspect}\n#{optparse}"
117
+ return 1
118
+ end
81
119
  connect(options)
82
120
  begin
83
- params = {}
84
- [:phrase, :offset, :max, :sort, :direction].each do |k|
85
- params[k] = options[k] unless options[k].nil?
121
+ instance_type = find_instance_type_by_name_or_id(args[0])
122
+ if instance_type.nil?
123
+ return 1
86
124
  end
87
-
88
125
  if options[:dry_run]
89
- print_dry_run @instance_types_interface.dry.get(params)
126
+ print_dry_run @instance_types_interface.dry.get(instance_type['id'])
90
127
  return
91
128
  end
92
- json_response = @instance_types_interface.get(params)
129
+ json_response = nil
130
+ if args[0].to_s =~ /\A\d{1,}\Z/
131
+ json_response = {'instanceType' => instance_type}
132
+ else
133
+ json_response = @instance_types_interface.get(instance_type['id'])
134
+ instance_type = json_response['instanceType']
135
+ end
93
136
 
137
+ if options[:include_fields]
138
+ json_response = {"instanceType" => filter_data(json_response["instanceType"], options[:include_fields]) }
139
+ end
94
140
  if options[:json]
95
- print JSON.pretty_generate(json_response), "\n"
141
+ puts as_json(json_response, options)
142
+ return 0
143
+ elsif options[:yaml]
144
+ puts as_yaml(json_response, options)
145
+ return 0
146
+ elsif options[:csv]
147
+ puts records_as_csv([json_response['instanceType']], options)
96
148
  return 0
97
149
  end
98
150
 
99
- instance_types = json_response['instanceTypes']
100
- title = "Morpheus Instance Types"
101
- subtitles = []
102
- if params[:phrase]
103
- subtitles << "Search: #{params[:phrase]}".strip
104
- end
105
- print_h1 title, subtitles
106
- if instance_types.empty?
107
- print yellow,"No instance types found.",reset,"\n"
108
- else
109
- instance_types.each do |instance_type|
110
- versions = instance_type['versions'].join(', ')
111
- print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
112
- layout_names = instance_type['instanceTypeLayouts'].collect { |layout| layout['name'] }.uniq.sort
113
- layout_names.each do |layout_name|
114
- print green, " - #{layout_name}\n",reset
115
- end
116
- # instance_type['instanceTypeLayouts'].each do |layout|
117
- # print green, " - #{layout['name']}\n",reset
118
- # end
119
- #print JSON.pretty_generate(instance_type['instanceTypeLayouts'].first), "\n"
151
+ print_h1 "Instance Type Details"
152
+ versions = instance_type['versions'].join(', ')
153
+ print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
154
+ if instance_type['instanceTypeLayouts']
155
+ layout_names = instance_type['instanceTypeLayouts'].collect { |layout| layout['name'] }.uniq.sort
156
+ layout_names.each do |layout_name|
157
+ print green, " - #{layout_name}\n",reset
120
158
  end
159
+ else
160
+ print yellow,"No layouts found for instance type.","\n",reset
121
161
  end
122
162
  print reset,"\n"
123
- return 0
163
+
164
+
124
165
  rescue RestClient::Exception => e
125
166
  print_rest_exception(e, options)
126
- return 1
167
+ exit 1
127
168
  end
128
169
  end
170
+
129
171
  end
@@ -11,7 +11,7 @@ class Morpheus::Cli::Instances
11
11
  include Morpheus::Cli::CliCommand
12
12
  include Morpheus::Cli::ProvisioningHelper
13
13
 
14
- register_subcommands :list, :get, :add, :update, :remove, :logs, :stats, :stop, :start, :restart, :actions, :action, :suspend, :eject, :backup, :backups, :stop_service, :start_service, :restart_service, :resize, :clone, :envs, :setenv, :delenv, :security_groups, :apply_security_groups, :firewall_enable, :firewall_disable, :run_workflow, :import_snapshot, :console, :status_check, {:containers => :list_containers}, :scaling, {:'scaling-update' => :scaling_update}
14
+ register_subcommands :list, :count, :get, :add, :update, :remove, :logs, :stats, :stop, :start, :restart, :actions, :action, :suspend, :eject, :backup, :backups, :stop_service, :start_service, :restart_service, :resize, :clone, :envs, :setenv, :delenv, :security_groups, :apply_security_groups, :firewall_enable, :firewall_disable, :run_workflow, :import_snapshot, :console, :status_check, {:containers => :list_containers}, :scaling, {:'scaling-update' => :scaling_update}
15
15
  # register_subcommands {:'lb-update' => :load_balancer_update}
16
16
  alias_subcommand :details, :get
17
17
  set_default_subcommand :list
@@ -40,7 +40,7 @@ class Morpheus::Cli::Instances
40
40
 
41
41
  def list(args)
42
42
  options = {}
43
- optparse = OptionParser.new do|opts|
43
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
44
44
  opts.banner = subcommand_usage()
45
45
  opts.on( '-g', '--group GROUP', "Group Name or ID" ) do |val|
46
46
  options[:group] = val
@@ -51,7 +51,8 @@ class Morpheus::Cli::Instances
51
51
  opts.on( '-H', '--host HOST', "Host Name or ID" ) do |val|
52
52
  options[:host] = val
53
53
  end
54
- build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
54
+ build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
55
+ opts.footer = "List instances."
55
56
  end
56
57
  optparse.parse!(args)
57
58
  connect(options)
@@ -74,15 +75,13 @@ class Morpheus::Cli::Instances
74
75
  params['serverId'] = host['id']
75
76
  end
76
77
 
77
- [:phrase, :offset, :max, :sort, :direction].each do |k|
78
- params[k] = options[k] unless options[k].nil?
79
- end
78
+ params.merge!(parse_list_options(options))
80
79
 
81
80
  if options[:dry_run]
82
81
  print_dry_run @instances_interface.dry.list(params)
83
82
  return
84
83
  end
85
- json_response = @instances_interface.get(params)
84
+ json_response = @instances_interface.list(params)
86
85
  if options[:json]
87
86
  if options[:include_fields]
88
87
  json_response = {"instances" => filter_data(json_response["instances"], options[:include_fields]) }
@@ -118,9 +117,7 @@ class Morpheus::Cli::Instances
118
117
  if host
119
118
  subtitles << "Host: #{host['name']}".strip
120
119
  end
121
- if params[:phrase]
122
- subtitles << "Search: #{params[:phrase]}".strip
123
- end
120
+ subtitles += parse_list_subtitles(options)
124
121
  print_h1 title, subtitles
125
122
  if instances.empty?
126
123
  print yellow,"No instances found.",reset,"\n"
@@ -180,6 +177,35 @@ class Morpheus::Cli::Instances
180
177
  end
181
178
  end
182
179
 
180
+ def count(args)
181
+ options = {}
182
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
183
+ opts.banner = subcommand_usage("[options]")
184
+ build_common_options(opts, options, [:query, :remote, :dry_run])
185
+ opts.footer = "Get the number of instances."
186
+ end
187
+ optparse.parse!(args)
188
+ connect(options)
189
+ begin
190
+ params = {}
191
+ params.merge!(parse_list_options(options))
192
+ if options[:dry_run]
193
+ print_dry_run @instances_interface.dry.list(params)
194
+ return
195
+ end
196
+ json_response = @instances_interface.list(params)
197
+ # print number only
198
+ if json_response['meta'] && json_response['meta']['total']
199
+ print cyan, json_response['meta']['total'], reset, "\n"
200
+ else
201
+ print yellow, "unknown", reset, "\n"
202
+ end
203
+ rescue RestClient::Exception => e
204
+ print_rest_exception(e, options)
205
+ exit 1
206
+ end
207
+ end
208
+
183
209
  def add(args)
184
210
  options = {}
185
211
  optparse = OptionParser.new do|opts|
@@ -485,7 +511,7 @@ class Morpheus::Cli::Instances
485
511
  opts.on( '-n', '--node NODE_ID', "Scope logs to specific Container or VM" ) do |node_id|
486
512
  options[:node_id] = node_id.to_i
487
513
  end
488
- build_common_options(opts, options, [:list, :json, :csv, :dry_run, :remote])
514
+ build_common_options(opts, options, [:list, :query, :json, :csv, :dry_run, :remote])
489
515
  end
490
516
  optparse.parse!(args)
491
517
  if args.count < 1
@@ -500,9 +526,7 @@ class Morpheus::Cli::Instances
500
526
  container_ids = [options[:node_id]]
501
527
  end
502
528
  params = {}
503
- [:phrase, :offset, :max, :sort, :direction].each do |k|
504
- params[k] = options[k] unless options[k].nil?
505
- end
529
+ params.merge!(parse_list_options(options))
506
530
  params[:query] = params.delete(:phrase) unless params[:phrase].nil?
507
531
  if options[:dry_run]
508
532
  print_dry_run @logs_interface.dry.container_logs(container_ids, params)
@@ -2276,7 +2300,7 @@ private
2276
2300
  end
2277
2301
 
2278
2302
  def find_host_by_name(name)
2279
- results = @servers_interface.get({name: name})
2303
+ results = @servers_interface.list({name: name})
2280
2304
  if results['servers'].empty?
2281
2305
  print_red_alert "Host not found by name #{name}"
2282
2306
  exit 1
@@ -1,1184 +1 @@
1
- require 'io/console'
2
- require 'optparse'
3
- require 'filesize'
4
- require 'morpheus/cli/cli_command'
5
-
6
- class Morpheus::Cli::Library
7
- include Morpheus::Cli::CliCommand
8
-
9
- register_subcommands :list, :get, :add, :update, :remove, :'add-version'
10
- alias_subcommand :details, :get
11
- register_subcommands({:'option-types' => :option_types_list}, :option_types_get, :option_types_add, :option_types_update, :option_types_remove)
12
- register_subcommands({:'option-lists' => :option_lists_list}, :option_lists_get, :option_lists_add, :option_lists_update, :option_lists_remove)
13
-
14
- def initialize()
15
- # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
16
- end
17
-
18
- def connect(opts)
19
- @api_client = establish_remote_appliance_connection(opts)
20
- @custom_instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).custom_instance_types
21
- @provision_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).provision_types
22
- @option_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).option_types
23
- @option_type_lists_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).option_type_lists
24
- end
25
-
26
- def handle(args)
27
- handle_subcommand(args)
28
- end
29
-
30
-
31
- def list(args)
32
- options = {}
33
- optparse = OptionParser.new do|opts|
34
- opts.banner = subcommand_usage()
35
- build_common_options(opts, options, [:list, :dry_run, :json])
36
- end
37
- optparse.parse!(args)
38
- connect(options)
39
- begin
40
- params = {}
41
- [:phrase, :offset, :max, :sort, :direction].each do |k|
42
- params[k] = options[k] unless options[k].nil?
43
- end
44
-
45
- if options[:dry_run]
46
- print_dry_run @custom_instance_types_interface.dry.list(params)
47
- return
48
- end
49
-
50
- json_response = @custom_instance_types_interface.list(params)
51
-
52
- if options[:json]
53
- print JSON.pretty_generate(json_response), "\n"
54
- return
55
- end
56
-
57
- instance_types = json_response['instanceTypes']
58
- print_h1 "Morpheus Custom Instance Types"
59
- if instance_types.empty?
60
- puts yellow,"No instance types currently configured.",reset
61
- else
62
- instance_types.each do |instance_type|
63
- versions = instance_type['versions'].join(', ')
64
- print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
65
- instance_type['instanceTypeLayouts'].each do |layout|
66
- print green, " - #{layout['name']}\n",reset
67
- end
68
- end
69
- end
70
- print reset,"\n"
71
- rescue RestClient::Exception => e
72
- print_rest_exception(e, options)
73
- exit 1
74
- end
75
- end
76
-
77
- def get(args)
78
- options = {}
79
- optparse = OptionParser.new do|opts|
80
- opts.banner = subcommand_usage("[name]")
81
- build_common_options(opts, options, [:json, :dry_run])
82
- end
83
- optparse.parse!(args)
84
- if args.count < 1
85
- puts optparse
86
- exit 1
87
- end
88
-
89
- connect(options)
90
- begin
91
- if options[:dry_run]
92
- if args[0] =~ /code:/
93
- print_dry_run @custom_instance_types_interface.dry.list({code: args[0]})
94
- else
95
- print_dry_run @custom_instance_types_interface.dry.list({name: args[0]})
96
- end
97
- return
98
- end
99
- instance_type = find_custom_instance_type_by_name_or_code(args[0])
100
- exit 1 if instance_type.nil?
101
-
102
- if options[:json]
103
- print JSON.pretty_generate({instanceType: instance_type}), "\n"
104
- return
105
- end
106
- print_h1 "Custom Instance Type Details"
107
- versions = instance_type['versions'].join(', ')
108
- print cyan, "= #{instance_type['name']} (#{instance_type['code']}) - #{versions}\n"
109
- instance_type['instanceTypeLayouts'].each do |layout|
110
- print green, " - #{layout['name']}\n",reset
111
- end
112
- print reset,"\n"
113
-
114
- rescue RestClient::Exception => e
115
- print_rest_exception(e, options)
116
- exit 1
117
- end
118
- end
119
-
120
- def add(args)
121
- options = {}
122
- optparse = OptionParser.new do|opts|
123
- opts.banner = subcommand_usage()
124
- build_common_options(opts, options, [:options, :json, :dry_run])
125
- end
126
- optparse.parse!(args)
127
- connect(options)
128
- begin
129
- params = Morpheus::Cli::OptionTypes.prompt(add_instance_type_option_types, options[:options], @api_client, options[:params])
130
- instance_type_keys = ['name', 'description', 'category', 'visibility', 'environmentPrefix']
131
- instance_type_payload = params.select {|k,v| instance_type_keys.include?(k) }
132
- logo_file = nil
133
- if params['logo']
134
- filename = File.expand_path(params['logo'])
135
- if !File.exists?(filename)
136
- print_red_alert "File not found: #{filename}"
137
- exit 1
138
- end
139
- #instance_type_payload['logo'] = File.new(filename, 'rb')
140
- logo_file = File.new(filename, 'rb')
141
- end
142
- if params['hasAutoScale'] == 'on'
143
- instance_type_payload['hasAutoScale'] = true
144
- end
145
- if params['hasDeployment'] == 'on'
146
- instance_type_payload['hasDeployment'] = true
147
- end
148
- payload = {instanceType: instance_type_payload}
149
- if options[:dry_run]
150
- print_dry_run @custom_instance_types_interface.dry.create(payload)
151
- if logo_file
152
- print_dry_run @custom_instance_types_interface.dry.update_logo(":id", logo_file)
153
- end
154
- return
155
- end
156
- json_response = @custom_instance_types_interface.create(payload)
157
-
158
- if json_response['success']
159
- if logo_file
160
- begin
161
- @custom_instance_types_interface.update_logo(json_response['instanceType']['id'], logo_file)
162
- rescue RestClient::Exception => e
163
- print_red_alert "Failed to save logo!"
164
- print_rest_exception(e, options)
165
- end
166
- end
167
- end
168
-
169
- if options[:json]
170
- print JSON.pretty_generate(json_response), "\n"
171
- return
172
- end
173
-
174
- print_green_success "Added Instance Type #{instance_type_payload['name']}"
175
- unless options[:no_prompt]
176
- if ::Morpheus::Cli::OptionTypes::confirm("Add first version?", options)
177
- puts "\n"
178
- add_version(["code:#{json_response['code']}"])
179
- end
180
- end
181
-
182
- #list([])
183
-
184
- rescue RestClient::Exception => e
185
- print_rest_exception(e, options)
186
- exit 1
187
- end
188
- end
189
-
190
- def update(args)
191
- options = {}
192
- optparse = OptionParser.new do|opts|
193
- opts.banner = subcommand_usage("[name] [options]")
194
- build_common_options(opts, options, [:options, :json, :dry_run])
195
- end
196
- optparse.parse!(args)
197
- if args.count < 1
198
- puts optparse
199
- exit 1
200
- end
201
- connect(options)
202
- begin
203
- instance_type = find_custom_instance_type_by_name_or_code(args[0])
204
- exit 1 if instance_type.nil?
205
- # option_types = update_instance_type_option_types(instance_type)
206
- # params = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
207
- params = options[:options] || {}
208
- instance_type_keys = ['name', 'description', 'category', 'visibility', 'environmentPrefix']
209
- instance_type_payload = params.select {|k,v| instance_type_keys.include?(k) }
210
- logo_file = nil
211
- if params['logo']
212
- filename = File.expand_path(params['logo'])
213
- if !File.exists?(filename)
214
- print_red_alert "File not found: #{filename}"
215
- exit 1
216
- end
217
- #instance_type_payload['logo'] = File.new(filename, 'rb')
218
- logo_file = File.new(filename, 'rb')
219
- end
220
- if params['hasAutoScale'] == 'on'
221
- instance_type_payload['hasAutoScale'] = true
222
- elsif params['hasAutoScale'] == 'off'
223
- instance_type_payload['hasAutoScale'] = false
224
- end
225
- if params['hasDeployment'] == 'on'
226
- instance_type_payload['hasDeployment'] = true
227
- elsif params['hasDeployment'] == 'off'
228
- instance_type_payload['hasDeployment'] = false
229
- end
230
- if instance_type_payload.empty? && logo_file.nil?
231
- puts optparse
232
- option_lines = update_instance_type_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
233
- puts "\nAvailable Options:\n#{option_lines}\n\n"
234
- exit 1
235
- end
236
- if instance_type_payload.empty?
237
- # just updating logo (separate request)
238
- instance_type_payload['name'] = instance_type['name']
239
- end
240
- payload = {instanceType: instance_type_payload}
241
- if options[:dry_run]
242
- print_dry_run @custom_instance_types_interface.dry.update(instance_type['id'], payload)
243
- if logo_file
244
- print_dry_run @custom_instance_types_interface.dry.update_logo(":id", logo_file)
245
- end
246
- return
247
- end
248
- json_response = @custom_instance_types_interface.update(instance_type['id'], payload)
249
-
250
- if json_response['success']
251
- if logo_file
252
- begin
253
- @custom_instance_types_interface.update_logo(json_response['instanceType']['id'], logo_file)
254
- rescue RestClient::Exception => e
255
- print_red_alert "Failed to save logo!"
256
- print_rest_exception(e, options)
257
- end
258
- end
259
- end
260
-
261
- if options[:json]
262
- print JSON.pretty_generate(json_response), "\n"
263
- return
264
- end
265
-
266
- print_green_success "Updated Instance Type #{instance_type_payload['name']}"
267
- #list([])
268
- rescue RestClient::Exception => e
269
- print_rest_exception(e, options)
270
- exit 1
271
- end
272
- end
273
-
274
- def remove(args)
275
- options = {}
276
- optparse = OptionParser.new do|opts|
277
- opts.banner = subcommand_usage("[name]")
278
- build_common_options(opts, options, [:auto_confirm, :json, :dry_run])
279
- end
280
- optparse.parse!(args)
281
- if args.count < 1
282
- puts optparse
283
- exit 1
284
- end
285
- connect(options)
286
-
287
- begin
288
- instance_type = find_custom_instance_type_by_name_or_code(args[0])
289
- exit 1 if instance_type.nil?
290
-
291
- unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the instance type #{instance_type['name']}?", options)
292
- exit
293
- end
294
- if options[:dry_run]
295
- print_dry_run @custom_instance_types_interface.dry.destroy(instance_type['id'])
296
- return
297
- end
298
- json_response = @custom_instance_types_interface.destroy(instance_type['id'])
299
-
300
- if options[:json]
301
- print JSON.pretty_generate(json_response), "\n"
302
- return
303
- end
304
-
305
- print_green_success "Removed Instance Type #{instance_type['name']}"
306
- #list([])
307
- rescue RestClient::Exception => e
308
- print_rest_exception(e, options)
309
- exit 1
310
- end
311
- end
312
-
313
- def add_version(args)
314
- options = {}
315
- optparse = OptionParser.new do|opts|
316
- opts.banner = subcommand_usage("[name]")
317
- build_common_options(opts, options, [:options, :json])
318
- end
319
- optparse.parse!(args)
320
- if args.count < 1
321
- puts optparse
322
- exit 1
323
- end
324
- connect(options)
325
- begin
326
- instance_type = find_custom_instance_type_by_name_or_code(args[0])
327
- exit 1 if instance_type.nil?
328
-
329
- #params = Morpheus::Cli::OptionTypes.prompt(add_version_option_types, options[:options], @api_client, options[:params])
330
- provision_types = @provision_types_interface.get({customSupported: true})['provisionTypes']
331
- if provision_types.empty?
332
- print_red_alert "No available provision types found!"
333
- exit 1
334
- end
335
- provision_type_options = provision_types.collect {|it| { 'name' => it['name'], 'value' => it['code']} }
336
- payload = {'containerType' => {}, 'instanceTypeLayout' => {}, 'instanceType' => {}}
337
-
338
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'instanceTypeLayout', 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Name', 'required' => true, 'description' => 'A name for this layout.'}], options[:options])
339
- payload['instanceTypeLayout']['name'] = v_prompt['instanceTypeLayout']['name']
340
-
341
- # shortName is only available for the first new version
342
- if !instance_type['versions'] || instance_type['versions'].size == 0
343
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'containerType', 'fieldName' => 'shortName', 'type' => 'text', 'fieldLabel' => 'Short Name', 'required' => true, 'description' => 'The short name is a lowercase name with no spaces used for display in your container list.'}], options[:options])
344
- payload['containerType']['shortName'] = v_prompt['containerType']['shortName']
345
- end
346
-
347
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'containerType', 'fieldName' => 'provisionTypeCode', 'type' => 'select', 'selectOptions' => provision_type_options, 'fieldLabel' => 'Technology', 'required' => true, 'description' => 'The type of container technology.'}], options[:options])
348
- payload['containerType']['provisionTypeCode'] = v_prompt['containerType']['provisionTypeCode']
349
- provision_type = provision_types.find {|it| it['code'] == payload['containerType']['provisionTypeCode'] }
350
-
351
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => 'instanceTypeLayout', 'fieldName' => 'instanceVersion', 'type' => 'text', 'fieldLabel' => 'Version', 'required' => true, 'description' => 'A Version Number eg. 0.0.1'}], options[:options])
352
- payload['instanceTypeLayout']['instanceVersion'] = v_prompt['instanceTypeLayout']['instanceVersion']
353
-
354
- custom_option_types = provision_type['customOptionTypes']
355
-
356
- if (!custom_option_types || custom_option_types.empty?)
357
- puts yellow,"Sorry, no options were found for #{provision_type['name']}.",reset
358
- exit 1
359
- end
360
- # prompt custom options for the selected provision type
361
- field_group_name = custom_option_types.first['fieldGroup'] || "#{provision_type['name']} Options"
362
- puts field_group_name
363
- puts "==============="
364
- v_prompt = Morpheus::Cli::OptionTypes.prompt(custom_option_types,options[:options],@api_client, {provisionTypCode: payload['provisionTypeCode']})
365
-
366
- if v_prompt['containerType']
367
- payload['containerType'].merge!(v_prompt['containerType'])
368
- end
369
- if v_prompt['containerType.config']
370
- payload['containerType']['config'] = v_prompt['containerType.config']
371
- end
372
- if v_prompt['instanceTypeLayout']
373
- payload['instanceTypeLayout'].merge!(v_prompt['instanceTypeLayout'])
374
- end
375
- # instanceType.backupType, which is not even persisted on the server?
376
- if v_prompt['instanceType']
377
- payload['instanceType'].merge!(v_prompt['instanceType'])
378
- end
379
-
380
- # puts "PAYLOAD:"
381
- # puts JSON.pretty_generate(payload)
382
- # puts "\nexiting early"
383
- # exit 0
384
-
385
- payload['exposedPorts'] = prompt_exposed_ports(options, @api_client)
386
-
387
- request_payload = payload
388
- json_response = @custom_instance_types_interface.create_version(instance_type['id'], request_payload)
389
-
390
- if options[:json]
391
- print JSON.pretty_generate(json_response), "\n"
392
- return
393
- end
394
-
395
- print_green_success "Added Instance Type Version #{instance_type['name']} - #{payload['instanceTypeLayout']['instanceVersion']}"
396
- #list([])
397
- rescue RestClient::Exception => e
398
- print_rest_exception(e, options)
399
- exit 1
400
- end
401
- end
402
-
403
-
404
- #### Option Type actions
405
-
406
- def option_types_list(args)
407
- options = {}
408
- optparse = OptionParser.new do|opts|
409
- opts.banner = subcommand_usage()
410
- build_common_options(opts, options, [:list, :dry_run, :json])
411
- end
412
- optparse.parse!(args)
413
- connect(options)
414
- begin
415
- params = {}
416
- [:phrase, :offset, :max, :sort, :direction].each do |k|
417
- params[k] = options[k] unless options[k].nil?
418
- end
419
-
420
- if options[:dry_run]
421
- print_dry_run @option_types_interface.dry.list(params)
422
- return
423
- end
424
-
425
- json_response = @option_types_interface.list(params)
426
-
427
- if options[:json]
428
- print JSON.pretty_generate(json_response), "\n"
429
- return
430
- end
431
-
432
- option_types = json_response['optionTypes']
433
- print_h1 "Morpheus Option Types"
434
- if option_types.empty?
435
- print cyan,"No option types found.",reset,"\n"
436
- else
437
- rows = option_types.collect do |option_type|
438
- {
439
- id: option_type['id'],
440
- name: option_type['name'],
441
- type: option_type['type'],
442
- fieldLabel: option_type['fieldLabel'],
443
- fieldName: option_type['fieldName'],
444
- default: option_type['defaultValue'],
445
- required: option_type['required'] ? 'yes' : 'no'
446
- }
447
- end
448
- print cyan
449
- tp rows, [
450
- :id,
451
- :name,
452
- :type,
453
- {:fieldLabel => {:display_name => "Field Label"} },
454
- {:fieldName => {:display_name => "Field Name"} },
455
- :default,
456
- :required
457
- ]
458
- print reset
459
- print_results_pagination(json_response)
460
- end
461
- print reset,"\n"
462
- rescue RestClient::Exception => e
463
- print_rest_exception(e, options)
464
- exit 1
465
- end
466
- end
467
-
468
- def option_types_get(args)
469
- options = {}
470
- optparse = OptionParser.new do|opts|
471
- opts.banner = subcommand_usage("[name]")
472
- build_common_options(opts, options, [:json, :dry_run])
473
- end
474
- optparse.parse!(args)
475
- if args.count < 1
476
- puts optparse
477
- exit 1
478
- end
479
-
480
- connect(options)
481
- begin
482
- if options[:dry_run]
483
- if args[0].to_s =~ /\A\d{1,}\Z/
484
- print_dry_run @option_types_interface.dry.get(args[0].to_i)
485
- else
486
- print_dry_run @option_types_interface.dry.list({name: args[0]})
487
- end
488
- return
489
- end
490
- option_type = find_option_type_by_name_or_id(args[0])
491
- exit 1 if option_type.nil?
492
-
493
- if options[:json]
494
- print JSON.pretty_generate({optionType: option_type}), "\n"
495
- return
496
- end
497
-
498
- print_h1 "Option Type Details"
499
- print cyan
500
- print_description_list({
501
- "ID" => 'id',
502
- "Name" => 'name',
503
- "Description" => 'description',
504
- "Field Name" => 'fieldName',
505
- "Type" => lambda {|it| it['type'].to_s.capitalize },
506
- "Label" => 'fieldLabel',
507
- "Placeholder" => 'placeHolder',
508
- "Default Value" => 'defaultValue'
509
- }, option_type)
510
- print reset,"\n"
511
-
512
- rescue RestClient::Exception => e
513
- print_rest_exception(e, options)
514
- exit 1
515
- end
516
- end
517
-
518
- def option_types_add(args)
519
- # JD: this is annoying because our option_types (for prompting and help)
520
- # are the same type of object being managed here.., options options options
521
- options = {}
522
- optparse = OptionParser.new do|opts|
523
- opts.banner = subcommand_usage("[options]")
524
- build_option_type_options(opts, options, new_option_type_option_types)
525
- build_common_options(opts, options, [:options, :json, :dry_run])
526
- end
527
- optparse.parse!(args)
528
- connect(options)
529
- begin
530
- params = Morpheus::Cli::OptionTypes.prompt(new_option_type_option_types, options[:options], @api_client, options[:params])
531
- if params.key?('required')
532
- params['required'] = ['on','true'].include?(params['required'].to_s)
533
- end
534
- option_type_payload = params
535
- payload = {optionType: option_type_payload}
536
- if options[:dry_run]
537
- print_dry_run @option_types_interface.dry.create(payload)
538
- return
539
- end
540
- json_response = @option_types_interface.create(payload)
541
- if options[:json]
542
- print JSON.pretty_generate(json_response), "\n"
543
- return
544
- end
545
- print_green_success "Added Option Type #{option_type_payload['name']}"
546
- #option_types_list([])
547
- option_types_get([option_type['id']])
548
- rescue RestClient::Exception => e
549
- print_rest_exception(e, options)
550
- exit 1
551
- end
552
- end
553
-
554
- def option_types_update(args)
555
- # JD: this is annoying because our option_types (for prompting and help)
556
- # are the same type of object being managed here.., options options options
557
- options = {}
558
- optparse = OptionParser.new do|opts|
559
- opts.banner = subcommand_usage("[name] [options]")
560
- build_option_type_options(opts, options, update_option_type_option_types)
561
- build_common_options(opts, options, [:options, :json, :dry_run])
562
- end
563
- optparse.parse!(args)
564
- connect(options)
565
- begin
566
- option_type = find_option_type_by_name_or_id(args[0])
567
- exit 1 if option_type.nil?
568
-
569
- #params = options[:options] || {}
570
- params = Morpheus::Cli::OptionTypes.no_prompt(update_option_type_option_types, options[:options], @api_client, options[:params])
571
- if params.empty?
572
- print_red_alert "Specify atleast one option to update"
573
- puts optparse
574
- exit 1
575
- end
576
- if params.key?('required')
577
- params['required'] = ['on','true'].include?(params['required'].to_s)
578
- end
579
- option_type_payload = params
580
- payload = {optionType: option_type_payload}
581
- if options[:dry_run]
582
- print_dry_run @option_types_interface.dry.update(option_type['id'], payload)
583
- return
584
- end
585
- json_response = @option_types_interface.update(option_type['id'], payload)
586
- if options[:json]
587
- print JSON.pretty_generate(json_response), "\n"
588
- return
589
- end
590
- print_green_success "Updated Option Type #{option_type_payload['name']}"
591
- #option_types_list([])
592
- option_types_get([option_type['id']])
593
- rescue RestClient::Exception => e
594
- print_rest_exception(e, options)
595
- exit 1
596
- end
597
- end
598
-
599
- def option_types_remove(args)
600
- options = {}
601
- optparse = OptionParser.new do|opts|
602
- opts.banner = subcommand_usage("[name]")
603
- build_common_options(opts, options, [:auto_confirm, :json, :dry_run])
604
- end
605
- optparse.parse!(args)
606
- if args.count < 1
607
- puts optparse
608
- exit 1
609
- end
610
- connect(options)
611
-
612
- begin
613
- option_type = find_option_type_by_name_or_id(args[0])
614
- exit 1 if option_type.nil?
615
-
616
- unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the option type #{option_type['name']}?", options)
617
- exit
618
- end
619
- if options[:dry_run]
620
- print_dry_run @option_types_interface.dry.destroy(option_type['id'])
621
- return
622
- end
623
- json_response = @option_types_interface.destroy(option_type['id'])
624
-
625
- if options[:json]
626
- print JSON.pretty_generate(json_response), "\n"
627
- return
628
- end
629
-
630
- print_green_success "Removed Option Type #{option_type['name']}"
631
- #list([])
632
- rescue RestClient::Exception => e
633
- print_rest_exception(e, options)
634
- exit 1
635
- end
636
- end
637
-
638
- #### Option Type List actions
639
-
640
- def option_lists_list(args)
641
- options = {}
642
- optparse = Morpheus::Cli::OptionParser.new do|opts|
643
- opts.banner = subcommand_usage()
644
- build_common_options(opts, options, [:list, :dry_run, :json])
645
- opts.footer = "This outputs a list of custom Option List records."
646
- end
647
- optparse.parse!(args)
648
- connect(options)
649
- begin
650
- params = {}
651
- [:phrase, :offset, :max, :sort, :direction].each do |k|
652
- params[k] = options[k] unless options[k].nil?
653
- end
654
-
655
- if options[:dry_run]
656
- print_dry_run @option_type_lists_interface.dry.list(params)
657
- return
658
- end
659
-
660
- json_response = @option_type_lists_interface.list(params)
661
-
662
- if options[:json]
663
- print JSON.pretty_generate(json_response), "\n"
664
- return
665
- end
666
-
667
- option_type_lists = json_response['optionTypeLists']
668
- print_h1 "Morpheus Option Lists"
669
- if option_type_lists.empty?
670
- print cyan,"No option lists found.",reset,"\n"
671
- else
672
- rows = option_type_lists.collect do |option_type_list|
673
- {
674
- id: option_type_list['id'],
675
- name: option_type_list['name'],
676
- description: option_type_list['description'],
677
- type: option_type_list['type'],
678
- size: option_type_list['listItems'] ? option_type_list['listItems'].size : ''
679
- }
680
- end
681
- print cyan
682
- tp rows, [
683
- :id,
684
- :name,
685
- :description,
686
- :type,
687
- :size
688
- ]
689
- print reset
690
- print_results_pagination(json_response)
691
- end
692
- print reset,"\n"
693
- rescue RestClient::Exception => e
694
- print_rest_exception(e, options)
695
- exit 1
696
- end
697
- end
698
-
699
- def option_lists_get(args)
700
- options = {}
701
- optparse = Morpheus::Cli::OptionParser.new do|opts|
702
- opts.banner = subcommand_usage("[name]")
703
- build_common_options(opts, options, [:json, :dry_run])
704
- opts.footer = "This outputs details about a particular Option List."
705
- end
706
- optparse.parse!(args)
707
- if args.count < 1
708
- puts optparse
709
- exit 1
710
- end
711
-
712
- connect(options)
713
- begin
714
- if options[:dry_run]
715
- if args[0].to_s =~ /\A\d{1,}\Z/
716
- print_dry_run @option_type_lists_interface.dry.get(args[0].to_i)
717
- else
718
- print_dry_run @option_type_lists_interface.dry.list({name: args[0]})
719
- end
720
- return
721
- end
722
- option_type_list = find_option_type_list_by_name_or_id(args[0])
723
- exit 1 if option_type_list.nil?
724
-
725
- if options[:json]
726
- print JSON.pretty_generate({optionTypeList: option_type_list}), "\n"
727
- return
728
- end
729
-
730
- print_h1 "Option List Details"
731
- print cyan
732
- if option_type_list['type'] == 'manual'
733
- print_description_list({
734
- "ID" => 'id',
735
- "Name" => 'name',
736
- "Description" => 'description',
737
- "Type" => lambda {|it| it['type'].to_s.capitalize },
738
- }, option_type_list)
739
- print_h2 "Initial Dataset"
740
- print bright_black," #{option_type_list['initialDataset']}","\n",reset
741
- else
742
- print_description_list({
743
- "ID" => 'id',
744
- "Name" => 'name',
745
- "Description" => 'description',
746
- "Type" => lambda {|it| it['type'].to_s.capitalize },
747
- "Source URL" => 'sourceUrl',
748
- "Ignore SSL Errors" => lambda {|it| format_boolean it['ignoreSSLErrors'] },
749
- "Source Method" => lambda {|it| it['sourceMethod'].to_s.upcase },
750
- }, option_type_list)
751
- if !option_type_list['initialDataset'].empty?
752
- print_h2 "Initial Dataset"
753
- print bright_black," #{option_type_list['initialDataset']}","\n",reset
754
- end
755
- if !option_type_list['translationScript'].empty?
756
- print_h2 "Translation Script"
757
- print bright_black," #{option_type_list['translationScript']}","\n",reset
758
- end
759
- end
760
-
761
- print_h2 "List Items"
762
- if option_type_list['listItems']
763
- # puts "\tNAME\tVALUE"
764
- # option_type_list['listItems'].each do |list_item|
765
- # puts "\t#{list_item['name']}\t#{list_item['value']}"
766
- # end
767
- print cyan
768
- tp option_type_list['listItems'], ['name', 'value']
769
- else
770
- puts "No data"
771
- end
772
- print reset,"\n"
773
-
774
- rescue RestClient::Exception => e
775
- print_rest_exception(e, options)
776
- exit 1
777
- end
778
- end
779
-
780
- def option_lists_add(args)
781
- # JD: this is annoying because our option_types (for prompting and help)
782
- # are the same type of object being managed here.., options options options
783
- options = {}
784
- my_option_types = nil
785
- list_type = nil
786
- optparse = OptionParser.new do|opts|
787
- opts.banner = subcommand_usage("[type] [options]")
788
- opts.on( '-t', '--type TYPE', "Option List Type. (rest, manual)" ) do |val|
789
- list_type = val
790
- # options[:options] ||= {}
791
- # options[:options]['type'] = val
792
- end
793
- build_option_type_options(opts, options, new_option_type_list_option_types())
794
- build_common_options(opts, options, [:options, :json, :dry_run])
795
- end
796
- optparse.parse!(args)
797
-
798
- if !list_type
799
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true}], options[:options], @api_client, {})
800
- list_type = v_prompt['type']
801
- end
802
-
803
- connect(options)
804
- begin
805
- params = Morpheus::Cli::OptionTypes.prompt(new_option_type_list_option_types(list_type), options[:options], @api_client, options[:params])
806
- if params.key?('required')
807
- params['required'] = ['on','true'].include?(params['required'].to_s)
808
- end
809
- params['type'] = list_type
810
- list_payload = params
811
- payload = {'optionTypeList' => list_payload}
812
- if options[:dry_run]
813
- print_dry_run @option_type_lists_interface.dry.create(payload)
814
- return
815
- end
816
- json_response = @option_type_lists_interface.create(payload)
817
- if options[:json]
818
- print JSON.pretty_generate(json_response), "\n"
819
- return
820
- end
821
- print_green_success "Added Option List #{list_payload['name']}"
822
- #option_lists_list([])
823
- option_type_list = json_response['optionTypeList']
824
- if option_type_list
825
- option_lists_get([option_type_list['id']])
826
- end
827
- rescue RestClient::Exception => e
828
- print_rest_exception(e, options)
829
- exit 1
830
- end
831
- end
832
-
833
- def option_lists_update(args)
834
- # JD: this is annoying because our option_types (for prompting and help)
835
- # are the same type of object being managed here.., options options options
836
- options = {}
837
- optparse = OptionParser.new do|opts|
838
- opts.banner = subcommand_usage("[name] [options]")
839
- build_option_type_options(opts, options, update_option_type_list_option_types())
840
- build_common_options(opts, options, [:options, :json, :dry_run])
841
- end
842
- optparse.parse!(args)
843
- connect(options)
844
- begin
845
- option_type_list = find_option_type_list_by_name_or_id(args[0])
846
- exit 1 if option_type_list.nil?
847
-
848
- list_type = option_type_list['type']
849
- prompt_options = update_option_type_list_option_types(list_type)
850
- #params = options[:options] || {}
851
- params = Morpheus::Cli::OptionTypes.no_prompt(prompt_options, options[:options], @api_client, options[:params])
852
- if params.empty?
853
- print_red_alert "Specify atleast one option to update"
854
- puts optparse
855
- exit 1
856
- end
857
- if params.key?('required')
858
- params['required'] = ['on','true'].include?(params['required'].to_s)
859
- end
860
- list_payload = params
861
- payload = {optionTypeList: list_payload}
862
- if options[:dry_run]
863
- print_dry_run @option_type_lists_interface.dry.update(option_type_list['id'], payload)
864
- return
865
- end
866
- json_response = @option_type_lists_interface.update(option_type_list['id'], payload)
867
- if options[:json]
868
- print JSON.pretty_generate(json_response), "\n"
869
- return
870
- end
871
- print_green_success "Updated Option List #{list_payload['name']}"
872
- #option_lists_list([])
873
- option_lists_get([option_type_list['id']])
874
- rescue RestClient::Exception => e
875
- print_rest_exception(e, options)
876
- exit 1
877
- end
878
- end
879
-
880
- def option_lists_remove(args)
881
- options = {}
882
- optparse = OptionParser.new do|opts|
883
- opts.banner = subcommand_usage("[name]")
884
- build_common_options(opts, options, [:auto_confirm, :json, :dry_run])
885
- end
886
- optparse.parse!(args)
887
- if args.count < 1
888
- puts optparse
889
- exit 1
890
- end
891
- connect(options)
892
-
893
- begin
894
- option_type_list = find_option_type_list_by_name_or_id(args[0])
895
- exit 1 if option_type_list.nil?
896
-
897
- unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the option type #{option_type_list['name']}?", options)
898
- exit
899
- end
900
- if options[:dry_run]
901
- print_dry_run @option_type_lists_interface.dry.destroy(option_type_list['id'])
902
- return
903
- end
904
- json_response = @option_type_lists_interface.destroy(option_type_list['id'])
905
-
906
- if options[:json]
907
- print JSON.pretty_generate(json_response), "\n"
908
- return
909
- end
910
-
911
- print_green_success "Removed Option List #{option_type_list['name']}"
912
- #option_lists_list([])
913
- rescue RestClient::Exception => e
914
- print_rest_exception(e, options)
915
- exit 1
916
- end
917
- end
918
-
919
- private
920
-
921
- def find_custom_instance_type_by_code(code)
922
- instance_type_results = @custom_instance_types_interface.list({code: code})
923
- if instance_type_results['instanceTypes'].empty?
924
- print_red_alert "Custom Instance Type not found by code #{code}"
925
- return nil
926
- end
927
- return instance_type_results['instanceTypes'][0]
928
- end
929
-
930
- def find_custom_instance_type_by_name(name)
931
- instance_type_results = @custom_instance_types_interface.list({name: name})
932
- instance_types = instance_type_results['instanceTypes']
933
- if instance_types.empty?
934
- print_red_alert "Custom Instance Type not found by name #{name}"
935
- return nil
936
- elsif instance_types.size > 1
937
- print_red_alert "Found #{instance_types.size} instance types by name #{name}"
938
- print red, "\n"
939
- instance_types.each do |instance_type|
940
- print "= #{instance_type['name']} (#{instance_type['code']})\n"
941
- end
942
- print "\n", "Find by code:<code> instead"
943
- print reset,"\n"
944
- return nil
945
- else
946
- return instance_types[0]
947
- end
948
- end
949
-
950
- def find_custom_instance_type_by_name_or_code(val)
951
- if val =~ /code:/
952
- find_custom_instance_type_by_code(val.sub('code:', ''))
953
- else
954
- find_custom_instance_type_by_name(val)
955
- end
956
- end
957
-
958
- def instance_type_categories
959
- [
960
- {'name' => 'Web', 'value' => 'web'},
961
- {'name' => 'SQL', 'value' => 'sql'},
962
- {'name' => 'NoSQL', 'value' => 'nosql'},
963
- {'name' => 'Apps', 'value' => 'apps'},
964
- {'name' => 'Network', 'value' => 'network'},
965
- {'name' => 'Messaging', 'value' => 'messaging'},
966
- {'name' => 'Cache', 'value' => 'cache'},
967
- {'name' => 'OS', 'value' => 'os'},
968
- {'name' => 'Cloud', 'value' => 'cloud'},
969
- {'name' => 'Utility', 'value' => 'utility'}
970
- ]
971
- end
972
-
973
- def add_instance_type_option_types
974
- [
975
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
976
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
977
- {'fieldName' => 'category', 'fieldLabel' => 'Category', 'type' => 'select', 'selectOptions' => instance_type_categories, 'required' => true, 'displayOrder' => 3},
978
- {'fieldName' => 'logo', 'fieldLabel' => 'Icon File', 'type' => 'text', 'displayOrder' => 4},
979
- {'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 5},
980
- {'fieldName' => 'environmentPrefix', 'fieldLabel' => 'Environment Prefix', 'type' => 'text', 'displayOrder' => 6, 'description' => 'Used for exportable environment variables when tying instance types together in app contexts. If not specified a name will be generated.'},
981
- {'fieldName' => 'hasAutoScale', 'fieldLabel' => 'Enable Scaling (Horizontal)', 'type' => 'checkbox', 'displayOrder' => 7},
982
- {'fieldName' => 'hasDeployment', 'fieldLabel' => 'Supports Deployments', 'type' => 'checkbox', 'displayOrder' => 8, 'description' => 'Requires a data volume be configured on each version. Files will be copied into this location.'}
983
- ]
984
- end
985
-
986
- def update_instance_type_option_types(instance_type=nil)
987
- if instance_type
988
- opts = add_instance_type_option_types
989
- opts.find {|opt| opt['fieldName'] == 'name'}['defaultValue'] = instance_type['name']
990
- opts
991
- else
992
- add_instance_type_option_types
993
- end
994
- end
995
-
996
- def add_version_option_types
997
- [
998
- {'fieldName' => 'versionNumber', 'fieldLabel' => 'Version Number', 'type' => 'text', 'required' => true, 'displayOrder' => 1}
999
- ]
1000
- end
1001
-
1002
- def update_version_option_types
1003
- add_version_option_types
1004
- end
1005
-
1006
- def load_balance_protocols
1007
- [
1008
- {'name' => 'None', 'value' => ''},
1009
- {'name' => 'HTTP', 'value' => 'HTTP'},
1010
- {'name' => 'HTTPS', 'value' => 'HTTPS'},
1011
- {'name' => 'TCP', 'value' => 'TCP'}
1012
- ]
1013
- end
1014
-
1015
- # Prompts user for exposed ports array
1016
- # returns array of port objects
1017
- def prompt_exposed_ports(options={}, api_client=nil, api_params={})
1018
- #puts "Configure ports:"
1019
- no_prompt = (options[:no_prompt] || (options[:options] && options[:options][:no_prompt]))
1020
-
1021
- ports = []
1022
- port_index = 0
1023
- has_another_port = options[:options] && options[:options]["exposedPort#{port_index}"]
1024
- add_another_port = has_another_port || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add an exposed port?"))
1025
- while add_another_port do
1026
- field_context = "exposedPort#{port_index}"
1027
-
1028
- port = {}
1029
- #port['name'] ||= "Port #{port_index}"
1030
- port_label = port_index == 0 ? "Port" : "Port [#{port_index+1}]"
1031
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => "#{port_label} Name", 'required' => false, 'description' => 'Choose a name for this port.', 'defaultValue' => port['name']}], options[:options])
1032
- port['name'] = v_prompt[field_context]['name']
1033
-
1034
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'port', 'type' => 'number', 'fieldLabel' => "#{port_label} Number", 'required' => true, 'description' => 'A port number. eg. 8001', 'defaultValue' => (port['port'] ? port['port'].to_i : nil)}], options[:options])
1035
- port['port'] = v_prompt[field_context]['port']
1036
-
1037
- v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldContext' => field_context, 'fieldName' => 'loadBalanceProtocol', 'type' => 'select', 'fieldLabel' => "#{port_label} LB", 'selectOptions' => load_balance_protocols, 'required' => false, 'skipSingleOption' => true, 'description' => 'Choose a load balance protocol.', 'defaultValue' => port['loadBalanceProtocol']}], options[:options])
1038
- port['loadBalanceProtocol'] = v_prompt[field_context]['loadBalanceProtocol']
1039
-
1040
- ports << port
1041
- port_index += 1
1042
- has_another_port = options[:options] && options[:options]["exposedPort#{port_index}"]
1043
- add_another_port = has_another_port || (!no_prompt && Morpheus::Cli::OptionTypes.confirm("Add another exposed port?"))
1044
-
1045
- end
1046
-
1047
-
1048
- return ports
1049
- end
1050
-
1051
- def find_option_type_by_name_or_id(val)
1052
- if val.to_s =~ /\A\d{1,}\Z/
1053
- return find_option_type_by_id(val)
1054
- else
1055
- return find_option_type_by_name(val)
1056
- end
1057
- end
1058
-
1059
- def find_option_type_by_id(id)
1060
- begin
1061
- json_response = @option_types_interface.get(id.to_i)
1062
- return json_response['optionType']
1063
- rescue RestClient::Exception => e
1064
- if e.response && e.response.code == 404
1065
- print_red_alert "Option Type not found by id #{id}"
1066
- exit 1
1067
- else
1068
- raise e
1069
- end
1070
- end
1071
- end
1072
-
1073
- def find_option_type_by_name(name)
1074
- json_results = @option_types_interface.list({name: name.to_s})
1075
- if json_results['optionTypes'].empty?
1076
- print_red_alert "Option Type not found by name #{name}"
1077
- exit 1
1078
- end
1079
- option_type = json_results['optionTypes'][0]
1080
- return option_type
1081
- end
1082
-
1083
- def new_option_type_option_types
1084
- [
1085
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
1086
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
1087
- {'fieldName' => 'fieldName', 'fieldLabel' => 'Field Name', 'type' => 'text', 'required' => true, 'description' => 'This is the input fieldName property that the value gets assigned to.', 'displayOrder' => 3},
1088
- {'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Text', 'value' => 'text'}, {'name' => 'Password', 'value' => 'password'}, {'name' => 'Number', 'value' => 'number'}, {'name' => 'Checkbox', 'value' => 'checkbox'}, {'name' => 'Select', 'value' => 'select'}, {'name' => 'Hidden', 'value' => 'hidden'}], 'defaultValue' => 'text', 'required' => true, 'displayOrder' => 4},
1089
- {'fieldName' => 'fieldLabel', 'fieldLabel' => 'Field Label', 'type' => 'text', 'required' => true, 'description' => 'This is the input label that shows typically to the left of a custom option.', 'displayOrder' => 5},
1090
- {'fieldName' => 'placeHolder', 'fieldLabel' => 'Placeholder', 'type' => 'text', 'displayOrder' => 6},
1091
- {'fieldName' => 'defaultValue', 'fieldLabel' => 'Default Value', 'type' => 'text', 'displayOrder' => 7},
1092
- {'fieldName' => 'required', 'fieldLabel' => 'Required', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 8},
1093
- ]
1094
- end
1095
-
1096
- def update_option_type_option_types
1097
- list = new_option_type_option_types
1098
- list.each {|it|
1099
- it.delete('required')
1100
- it.delete('defaultValue')
1101
- it.delete('skipSingleOption')
1102
- }
1103
- list
1104
- end
1105
-
1106
- def find_option_type_list_by_name_or_id(val)
1107
- if val.to_s =~ /\A\d{1,}\Z/
1108
- return find_option_type_list_by_id(val)
1109
- else
1110
- return find_option_type_list_by_name(val)
1111
- end
1112
- end
1113
-
1114
- def find_option_type_list_by_id(id)
1115
- begin
1116
- json_response = @option_type_lists_interface.get(id.to_i)
1117
- return json_response['optionTypeList']
1118
- rescue RestClient::Exception => e
1119
- if e.response && e.response.code == 404
1120
- print_red_alert "Option List not found by id #{id}"
1121
- exit 1
1122
- else
1123
- raise e
1124
- end
1125
- end
1126
- end
1127
-
1128
- def find_option_type_list_by_name(name)
1129
- json_results = @option_type_lists_interface.list({name: name.to_s})
1130
- if json_results['optionTypeLists'].empty?
1131
- print_red_alert "Option List not found by name #{name}"
1132
- exit 1
1133
- end
1134
- option_type_list = json_results['optionTypeLists'][0]
1135
- return option_type_list
1136
- end
1137
-
1138
- def get_available_option_list_types
1139
- [
1140
- {'name' => 'Rest', 'value' => 'rest'},
1141
- {'name' => 'Manual', 'value' => 'manual'}
1142
- ]
1143
- end
1144
-
1145
- def find_option_list_type(code)
1146
- get_available_option_list_types.find {|it| code == it['value'] || code == it['name'] }
1147
- end
1148
-
1149
- def new_option_type_list_option_types(list_type='rest')
1150
- if list_type.to_s.downcase == 'rest'
1151
- [
1152
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
1153
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
1154
- #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => get_available_option_list_types, 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
1155
- {'fieldName' => 'sourceUrl', 'fieldLabel' => 'Source Url', 'type' => 'text', 'required' => true, 'description' => "A REST URL can be used to fetch list data and is cached in the appliance database.", 'displayOrder' => 4},
1156
- {'fieldName' => 'ignoreSSLErrors', 'fieldLabel' => 'Ignore SSL Errors', 'type' => 'checkbox', 'defaultValue' => 'off', 'displayOrder' => 5},
1157
- {'fieldName' => 'sourceMethod', 'fieldLabel' => 'Source Method', 'type' => 'select', 'selectOptions' => [{'name' => 'GET', 'value' => 'GET'}, {'name' => 'POST', 'value' => 'POST'}], 'defaultValue' => 'GET', 'required' => true, 'displayOrder' => 6},
1158
- {'fieldName' => 'initialDataset', 'fieldLabel' => 'Initial Dataset', 'type' => 'code-editor', 'description' => "Create an initial json dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'. However, if there is a translation script, that will also be passed through.", 'displayOrder' => 7},
1159
- {'fieldName' => 'translationScript', 'fieldLabel' => 'Translation Script', 'type' => 'code-editor', 'description' => "Create a js script to translate the result data object into an Array containing objects with properties name, and value. The input data is provided as data and the result should be put on the global variable results.", 'displayOrder' => 8},
1160
- ]
1161
- elsif list_type.to_s.downcase == 'manual'
1162
- [
1163
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
1164
- {'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 2},
1165
- #{'fieldName' => 'type', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Rest', 'value' => 'rest'}, {'name' => 'Manual', 'value' => 'manual'}], 'defaultValue' => 'rest', 'required' => true, 'displayOrder' => 3},
1166
- {'fieldName' => 'initialDataset', 'fieldLabel' => 'Dataset', 'type' => 'code-editor', 'required' => true, 'description' => "Create an initial JSON or CSV dataset to be used as the collection for this option list. It should be a list containing objects with properties 'name', and 'value'.", 'displayOrder' => 4},
1167
- ]
1168
- else
1169
- print_red_alert "Unknown Option List type '#{list_type}'"
1170
- exit 1
1171
- end
1172
- end
1173
-
1174
- def update_option_type_list_option_types(list_type='rest')
1175
- list = new_option_type_list_option_types(list_type)
1176
- list.each {|it|
1177
- it.delete('required')
1178
- it.delete('defaultValue')
1179
- it.delete('skipSingleOption')
1180
- }
1181
- list
1182
- end
1183
-
1184
- end
1
+ # this is not used anymore..