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.
- checksums.yaml +4 -4
- data/lib/morpheus/api/api_client.rb +28 -0
- data/lib/morpheus/api/instance_types_interface.rb +12 -10
- data/lib/morpheus/api/instances_interface.rb +4 -0
- data/lib/morpheus/api/library_container_scripts_interface.rb +49 -0
- data/lib/morpheus/api/library_container_templates_interface.rb +49 -0
- data/lib/morpheus/api/library_container_types_interface.rb +65 -0
- data/lib/morpheus/api/library_container_upgrades_interface.rb +66 -0
- data/lib/morpheus/api/library_instance_types_interface.rb +59 -0
- data/lib/morpheus/api/library_layouts_interface.rb +65 -0
- data/lib/morpheus/api/servers_interface.rb +4 -0
- data/lib/morpheus/api/user_sources_interface.rb +120 -0
- data/lib/morpheus/api/virtual_images_interface.rb +7 -0
- data/lib/morpheus/cli.rb +12 -1
- data/lib/morpheus/cli/accounts.rb +35 -9
- data/lib/morpheus/cli/cli_command.rb +82 -2
- data/lib/morpheus/cli/curl_command.rb +1 -1
- data/lib/morpheus/cli/echo_command.rb +1 -1
- data/lib/morpheus/cli/hosts.rb +40 -14
- data/lib/morpheus/cli/instance_types.rb +106 -64
- data/lib/morpheus/cli/instances.rb +39 -15
- data/lib/morpheus/cli/library.rb +1 -1184
- data/lib/morpheus/cli/library_container_scripts_command.rb +437 -0
- data/lib/morpheus/cli/library_container_templates_command.rb +397 -0
- data/lib/morpheus/cli/library_container_types_command.rb +653 -0
- data/lib/morpheus/cli/library_instance_types_command.rb +491 -0
- data/lib/morpheus/cli/library_layouts_command.rb +650 -0
- data/lib/morpheus/cli/library_option_lists_command.rb +476 -0
- data/lib/morpheus/cli/library_option_types_command.rb +549 -0
- data/lib/morpheus/cli/library_upgrades_command.rb +604 -0
- data/lib/morpheus/cli/mixins/library_helper.rb +123 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +21 -22
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +56 -11
- data/lib/morpheus/cli/network_services_command.rb +1 -1
- data/lib/morpheus/cli/option_types.rb +12 -2
- data/lib/morpheus/cli/power_scheduling_command.rb +1 -1
- data/lib/morpheus/cli/shell.rb +120 -22
- data/lib/morpheus/cli/sleep_command.rb +45 -0
- data/lib/morpheus/cli/user_sources_command.rb +963 -0
- data/lib/morpheus/cli/users.rb +33 -2
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/version_command.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +93 -39
- data/lib/morpheus/formatters.rb +37 -27
- data/lib/morpheus/terminal.rb +1 -1
- metadata +20 -2
@@ -0,0 +1,491 @@
|
|
1
|
+
require 'io/console'
|
2
|
+
require 'optparse'
|
3
|
+
require 'filesize'
|
4
|
+
require 'morpheus/cli/cli_command'
|
5
|
+
require 'morpheus/cli/mixins/library_helper'
|
6
|
+
|
7
|
+
class Morpheus::Cli::LibraryInstanceTypesCommand
|
8
|
+
include Morpheus::Cli::CliCommand
|
9
|
+
include Morpheus::Cli::LibraryHelper
|
10
|
+
|
11
|
+
set_command_name :'library-instance-types'
|
12
|
+
register_subcommands :list, :get, :add, :update, :remove
|
13
|
+
register_subcommands({:'update-logo' => :update_logo})
|
14
|
+
|
15
|
+
def initialize()
|
16
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect(opts)
|
20
|
+
@api_client = establish_remote_appliance_connection(opts)
|
21
|
+
@library_instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).library_instance_types
|
22
|
+
@provision_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).provision_types
|
23
|
+
@option_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).option_types
|
24
|
+
@option_type_lists_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).option_type_lists
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle(args)
|
28
|
+
handle_subcommand(args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def list(args)
|
32
|
+
options = {}
|
33
|
+
params = {}
|
34
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
35
|
+
opts.banner = subcommand_usage()
|
36
|
+
opts.on('--category VALUE', String, "Filter by category") do |val|
|
37
|
+
params['category'] = val
|
38
|
+
end
|
39
|
+
opts.on('--code VALUE', String, "Filter by code") do |val|
|
40
|
+
params['code'] = val
|
41
|
+
end
|
42
|
+
opts.on('--technology VALUE', String, "Filter by technology") do |val|
|
43
|
+
params['provisionTypeCode'] = val
|
44
|
+
end
|
45
|
+
build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
46
|
+
opts.footer = "List instance types."
|
47
|
+
end
|
48
|
+
optparse.parse!(args)
|
49
|
+
if args.count > 0
|
50
|
+
print_error Morpheus::Terminal.angry_prompt
|
51
|
+
puts_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.inspect}\n#{optparse}"
|
52
|
+
return 1
|
53
|
+
end
|
54
|
+
connect(options)
|
55
|
+
begin
|
56
|
+
# construct payload
|
57
|
+
params.merge!(parse_list_options(options))
|
58
|
+
# dry run?
|
59
|
+
if options[:dry_run]
|
60
|
+
print_dry_run @library_instance_types_interface.dry.list(params)
|
61
|
+
return
|
62
|
+
end
|
63
|
+
# do it
|
64
|
+
json_response = @library_instance_types_interface.list(params)
|
65
|
+
if options[:include_fields]
|
66
|
+
json_response = {"instanceTypes" => filter_data(json_response["instanceTypes"], options[:include_fields]) }
|
67
|
+
end
|
68
|
+
if options[:json]
|
69
|
+
puts as_json(json_response, options)
|
70
|
+
return 0
|
71
|
+
elsif options[:csv]
|
72
|
+
puts records_as_csv(json_response['instanceTypes'], options)
|
73
|
+
return 0
|
74
|
+
elsif options[:yaml]
|
75
|
+
puts as_yaml(json_response, options)
|
76
|
+
return 0
|
77
|
+
end
|
78
|
+
instance_types = json_response['instanceTypes']
|
79
|
+
title = "Morpheus Library - Instance Types"
|
80
|
+
subtitles = []
|
81
|
+
subtitles += parse_list_subtitles(options)
|
82
|
+
print_h1 title, subtitles
|
83
|
+
if instance_types.empty?
|
84
|
+
print cyan,"No instance types found.",reset,"\n"
|
85
|
+
else
|
86
|
+
print_instance_types_table(instance_types, options)
|
87
|
+
print_results_pagination(json_response, {:label => "instance type", :n_label => "instance types"})
|
88
|
+
# print_results_pagination(json_response)
|
89
|
+
end
|
90
|
+
print reset,"\n"
|
91
|
+
rescue RestClient::Exception => e
|
92
|
+
print_rest_exception(e, options)
|
93
|
+
return 1
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def get(args)
|
98
|
+
options = {}
|
99
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
100
|
+
opts.banner = subcommand_usage("[name]")
|
101
|
+
build_common_options(opts, options, [:json, :yaml, :csv, :fields, :dry_run, :remote])
|
102
|
+
end
|
103
|
+
optparse.parse!(args)
|
104
|
+
if args.count < 1
|
105
|
+
puts optparse
|
106
|
+
return 1
|
107
|
+
end
|
108
|
+
connect(options)
|
109
|
+
id_list = parse_id_list(args)
|
110
|
+
return run_command_for_each_arg(id_list) do |arg|
|
111
|
+
_get(arg, options)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def _get(id, options)
|
116
|
+
|
117
|
+
begin
|
118
|
+
instance_type = find_instance_type_by_name_or_id(id)
|
119
|
+
if instance_type.nil?
|
120
|
+
return 1
|
121
|
+
end
|
122
|
+
if options[:dry_run]
|
123
|
+
print_dry_run @library_instance_types_interface.dry.get(instance_type['id'])
|
124
|
+
return
|
125
|
+
end
|
126
|
+
json_response = nil
|
127
|
+
if id.to_s =~ /\A\d{1,}\Z/
|
128
|
+
json_response = {'instanceType' => instance_type}
|
129
|
+
else
|
130
|
+
json_response = @library_instance_types_interface.get(instance_type['id'])
|
131
|
+
instance_type = json_response['instanceType']
|
132
|
+
end
|
133
|
+
|
134
|
+
if options[:include_fields]
|
135
|
+
json_response = {"instanceType" => filter_data(json_response["instanceType"], options[:include_fields]) }
|
136
|
+
end
|
137
|
+
if options[:json]
|
138
|
+
puts as_json(json_response, options)
|
139
|
+
return 0
|
140
|
+
elsif options[:yaml]
|
141
|
+
puts as_yaml(json_response, options)
|
142
|
+
return 0
|
143
|
+
elsif options[:csv]
|
144
|
+
puts records_as_csv([json_response['instanceType']], options)
|
145
|
+
return 0
|
146
|
+
end
|
147
|
+
|
148
|
+
print_h1 "Instance Type Details"
|
149
|
+
print cyan
|
150
|
+
description_cols = {
|
151
|
+
"ID" => lambda {|it| it['id'] },
|
152
|
+
"Name" => lambda {|it| it['name'] },
|
153
|
+
"Code" => lambda {|it| it['code'] },
|
154
|
+
"Description" => lambda {|it| it['description'] },
|
155
|
+
"Technology" => lambda {|it| format_instance_type_technology(it) },
|
156
|
+
"Category" => lambda {|it| it['category'].to_s.capitalize },
|
157
|
+
# "Logo" => lambda {|it| it['logo'].to_s },
|
158
|
+
"Visiblity" => lambda {|it| it['visibility'].to_s.capitalize },
|
159
|
+
"Environment Prefix" => lambda {|it| it['environmentPrefix'] },
|
160
|
+
"Enable Settings" => lambda {|it| format_boolean it['hasSettings'] },
|
161
|
+
"Enable Scaling" => lambda {|it| format_boolean it['hasAutoScale'] },
|
162
|
+
"Supports Deployments" => lambda {|it| format_boolean it['hasDeployment'] },
|
163
|
+
"Featured" => lambda {|it| format_boolean it['featured'] },
|
164
|
+
"Owner" => lambda {|it| it['account'] ? it['account']['name'] : '' },
|
165
|
+
# "Active" => lambda {|it| format_boolean it['active'] },
|
166
|
+
# "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
167
|
+
# "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) }
|
168
|
+
}
|
169
|
+
print_description_list(description_cols, instance_type)
|
170
|
+
|
171
|
+
instance_type_option_types = instance_type['optionTypes']
|
172
|
+
if instance_type_option_types && instance_type_option_types.size > 0
|
173
|
+
print_h2 "Option Types"
|
174
|
+
columns = [
|
175
|
+
{"ID" => lambda {|it| it['id'] } },
|
176
|
+
{"NAME" => lambda {|it| it['name'] } },
|
177
|
+
{"TYPE" => lambda {|it| it['type'] } },
|
178
|
+
{"FIELD NAME" => lambda {|it| it['fieldName'] } },
|
179
|
+
{"FIELD LABEL" => lambda {|it| it['fieldLabel'] } },
|
180
|
+
{"DEFAULT" => lambda {|it| it['defaultValue'] } },
|
181
|
+
{"REQUIRED" => lambda {|it| format_boolean it['required'] } },
|
182
|
+
]
|
183
|
+
print as_pretty_table(instance_type_option_types, columns)
|
184
|
+
else
|
185
|
+
# print yellow,"No option types found for this layout.","\n",reset
|
186
|
+
end
|
187
|
+
|
188
|
+
instance_type_evars = instance_type['environmentVariables']
|
189
|
+
if instance_type_evars && instance_type_evars.size > 0
|
190
|
+
print_h2 "Environment Variables"
|
191
|
+
evar_columns = [
|
192
|
+
{"NAME" => lambda {|it| it['name'] } },
|
193
|
+
{"VALUE" => lambda {|it| it['defaultValue'] } },
|
194
|
+
{"TYPE" => lambda {|it| it['valueType'].to_s.capitalize } },
|
195
|
+
{"EXPORT" => lambda {|it| format_boolean it['export'] } },
|
196
|
+
{"MASKED" => lambda {|it| format_boolean it['mask'] } },
|
197
|
+
]
|
198
|
+
print as_pretty_table(instance_type_evars, evar_columns)
|
199
|
+
else
|
200
|
+
# print yellow,"No environment variables found for this instance type.","\n",reset
|
201
|
+
end
|
202
|
+
|
203
|
+
print_h2 "Layouts"
|
204
|
+
|
205
|
+
instance_type_layouts = instance_type['instanceTypeLayouts']
|
206
|
+
|
207
|
+
if instance_type_layouts && instance_type_layouts.size > 0
|
208
|
+
# match UI sorting [version desc, name asc]
|
209
|
+
# or use something simpler like one of these
|
210
|
+
# instance_type_layouts = instance_type_layouts.sort { |a,b| a['name'] <=> b['name'] }
|
211
|
+
# instance_type_layouts = instance_type_layouts.sort { |a,b| a['sortOrder'] <=> b['sortOrder'] }
|
212
|
+
instance_type_layouts = instance_type_layouts.sort do |a,b|
|
213
|
+
a_array = a['instanceVersion'].to_s.split('.').collect {|vn| vn.to_i * -1 }
|
214
|
+
while a_array.size < 5
|
215
|
+
a_array << 0
|
216
|
+
end
|
217
|
+
a_array << a['name']
|
218
|
+
b_array = b['instanceVersion'].to_s.split('.').collect {|vn| vn.to_i * -1 }
|
219
|
+
while b_array.size < 5
|
220
|
+
b_array << 0
|
221
|
+
end
|
222
|
+
b_array << b['name']
|
223
|
+
a_array <=> b_array
|
224
|
+
end
|
225
|
+
layout_columns = [
|
226
|
+
{"ID" => lambda {|layout| layout['id'] } },
|
227
|
+
{"NAME" => lambda {|layout| layout['name'] } },
|
228
|
+
{"VERSION" => lambda {|layout| layout['instanceVersion'] } },
|
229
|
+
{"TECHNOLOGY" => lambda {|layout|
|
230
|
+
layout['provisionType'] ? layout['provisionType']['name'] : ''
|
231
|
+
} },
|
232
|
+
{"DESCRIPTION" => lambda {|layout| layout['description'] } }
|
233
|
+
]
|
234
|
+
print as_pretty_table(instance_type_layouts, layout_columns)
|
235
|
+
else
|
236
|
+
print yellow,"No layouts found for this instance type.","\n",reset
|
237
|
+
end
|
238
|
+
|
239
|
+
print reset,"\n"
|
240
|
+
|
241
|
+
rescue RestClient::Exception => e
|
242
|
+
print_rest_exception(e, options)
|
243
|
+
return 1
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def add(args)
|
248
|
+
options = {}
|
249
|
+
params = {}
|
250
|
+
logo_file = nil
|
251
|
+
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
252
|
+
opts.banner = subcommand_usage()
|
253
|
+
build_option_type_options(opts, options, add_instance_type_option_types())
|
254
|
+
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
|
255
|
+
opts.footer = "Create a new instance type."
|
256
|
+
end
|
257
|
+
optparse.parse!(args)
|
258
|
+
connect(options)
|
259
|
+
begin
|
260
|
+
payload = nil
|
261
|
+
if options[:payload]
|
262
|
+
payload = options[:payload]
|
263
|
+
else
|
264
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_instance_type_option_types, options[:options], @api_client, options[:params])
|
265
|
+
params.deep_merge!(v_prompt)
|
266
|
+
if params['logo']
|
267
|
+
filename = File.expand_path(params['logo'])
|
268
|
+
if !File.exists?(filename)
|
269
|
+
print_red_alert "File not found: #{filename}"
|
270
|
+
exit 1
|
271
|
+
end
|
272
|
+
logo_file = File.new(filename, 'rb')
|
273
|
+
params.delete('logo')
|
274
|
+
end
|
275
|
+
params['hasSettings'] = ['on','true','1'].include?(params['hasSettings'].to_s) if params.key?('hasSettings')
|
276
|
+
params['hasAutoScale'] = ['on','true','1'].include?(params['hasAutoScale'].to_s) if params.key?('hasAutoScale')
|
277
|
+
params['hasDeployment'] = ['on','true','1'].include?(params['hasDeployment'].to_s) if params.key?('hasDeployment')
|
278
|
+
payload = {instanceType: params}
|
279
|
+
if options[:dry_run]
|
280
|
+
print_dry_run @library_instance_types_interface.dry.create(payload)
|
281
|
+
if logo_file
|
282
|
+
print_dry_run @library_instance_types_interface.dry.update_logo(":id", logo_file)
|
283
|
+
end
|
284
|
+
return
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
json_response = @library_instance_types_interface.create(payload)
|
289
|
+
|
290
|
+
if json_response['success']
|
291
|
+
if logo_file
|
292
|
+
begin
|
293
|
+
@library_instance_types_interface.update_logo(json_response['instanceType']['id'], logo_file)
|
294
|
+
rescue RestClient::Exception => e
|
295
|
+
print_red_alert "Failed to save logo!"
|
296
|
+
print_rest_exception(e, options)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
if options[:json]
|
302
|
+
print JSON.pretty_generate(json_response), "\n"
|
303
|
+
return
|
304
|
+
end
|
305
|
+
|
306
|
+
print_green_success "Added Instance Type #{params['name']}"
|
307
|
+
|
308
|
+
#list([])
|
309
|
+
|
310
|
+
rescue RestClient::Exception => e
|
311
|
+
print_rest_exception(e, options)
|
312
|
+
exit 1
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def update(args)
|
317
|
+
options = {}
|
318
|
+
params = {}
|
319
|
+
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
320
|
+
opts.banner = subcommand_usage("[name] [options]")
|
321
|
+
build_option_type_options(opts, options, update_instance_type_option_types())
|
322
|
+
build_common_options(opts, options, [:options, :json, :dry_run, :remote])
|
323
|
+
opts.footer = "Update an instance type." + "\n" +
|
324
|
+
"[name] is required. This is the name or id of a instance type."
|
325
|
+
end
|
326
|
+
optparse.parse!(args)
|
327
|
+
if args.count < 1
|
328
|
+
puts optparse
|
329
|
+
exit 1
|
330
|
+
end
|
331
|
+
connect(options)
|
332
|
+
begin
|
333
|
+
instance_type = find_instance_type_by_name_or_id(args[0])
|
334
|
+
exit 1 if instance_type.nil?
|
335
|
+
payload = nil
|
336
|
+
if options[:payload]
|
337
|
+
payload = options[:payload]
|
338
|
+
else
|
339
|
+
# option_types = update_instance_type_option_types(instance_type)
|
340
|
+
# params = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
|
341
|
+
params.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) }) if options[:options]
|
342
|
+
params['hasSettings'] = ['on','true','1'].include?(params['hasSettings'].to_s) if params.key?('hasSettings')
|
343
|
+
params['hasAutoScale'] = ['on','true','1'].include?(params['hasAutoScale'].to_s) if params.key?('hasAutoScale')
|
344
|
+
params['hasDeployment'] = ['on','true','1'].include?(params['hasDeployment'].to_s) if params.key?('hasDeployment')
|
345
|
+
if params.empty?
|
346
|
+
puts optparse
|
347
|
+
#option_lines = update_instance_type_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
|
348
|
+
#puts "\nAvailable Options:\n#{option_lines}\n\n"
|
349
|
+
exit 1
|
350
|
+
end
|
351
|
+
payload = {'instanceType' => params}
|
352
|
+
end
|
353
|
+
|
354
|
+
if options[:dry_run]
|
355
|
+
print_dry_run @library_instance_types_interface.dry.update(instance_type['id'], payload)
|
356
|
+
return
|
357
|
+
end
|
358
|
+
|
359
|
+
json_response = @library_instance_types_interface.update(instance_type['id'], payload)
|
360
|
+
|
361
|
+
if options[:json]
|
362
|
+
print JSON.pretty_generate(json_response), "\n"
|
363
|
+
return
|
364
|
+
end
|
365
|
+
|
366
|
+
print_green_success "Updated Instance Type #{params['name'] || instance_type['name']}"
|
367
|
+
#list([])
|
368
|
+
rescue RestClient::Exception => e
|
369
|
+
print_rest_exception(e, options)
|
370
|
+
exit 1
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
def update_logo(args)
|
375
|
+
options = {}
|
376
|
+
params = {}
|
377
|
+
filename = nil
|
378
|
+
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
379
|
+
opts.banner = subcommand_usage("[name] [file]")
|
380
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
381
|
+
opts.footer = "Update the logo for an instance type." + "\n" +
|
382
|
+
"[name] is required. This is the name or id of a instance type." + "\n" +
|
383
|
+
"[file] is required. This is the path of the logo file"
|
384
|
+
end
|
385
|
+
optparse.parse!(args)
|
386
|
+
if args.count < 2
|
387
|
+
puts optparse
|
388
|
+
exit 1
|
389
|
+
end
|
390
|
+
connect(options)
|
391
|
+
layout_id = args[0]
|
392
|
+
filename = args[1]
|
393
|
+
begin
|
394
|
+
instance_type = find_instance_type_by_name_or_id(layout_id)
|
395
|
+
exit 1 if instance_type.nil?
|
396
|
+
logo_file = nil
|
397
|
+
if filename == 'null'
|
398
|
+
filename = 'null' # clear it
|
399
|
+
else
|
400
|
+
filename = File.expand_path(filename)
|
401
|
+
if !File.exists?(filename)
|
402
|
+
print_red_alert "File not found: #{filename}"
|
403
|
+
exit 1
|
404
|
+
end
|
405
|
+
logo_file = File.new(filename, 'rb')
|
406
|
+
end
|
407
|
+
if options[:dry_run]
|
408
|
+
print_dry_run @library_instance_types_interface.dry.update_logo(instance_type['id'], logo_file)
|
409
|
+
return
|
410
|
+
end
|
411
|
+
json_response = @library_instance_types_interface.update_logo(instance_type['id'], logo_file)
|
412
|
+
if options[:json]
|
413
|
+
print JSON.pretty_generate(json_response), "\n"
|
414
|
+
return
|
415
|
+
end
|
416
|
+
print_green_success "Updated Instance Type #{instance_type['name']} logo"
|
417
|
+
#list([])
|
418
|
+
rescue RestClient::Exception => e
|
419
|
+
print_rest_exception(e, options)
|
420
|
+
exit 1
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
def remove(args)
|
425
|
+
options = {}
|
426
|
+
optparse = Morpheus::Cli::OptionParser.new do|opts|
|
427
|
+
opts.banner = subcommand_usage("[name]")
|
428
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
429
|
+
opts.footer = "Delete an instance type."
|
430
|
+
end
|
431
|
+
optparse.parse!(args)
|
432
|
+
if args.count < 1
|
433
|
+
puts optparse
|
434
|
+
exit 1
|
435
|
+
end
|
436
|
+
connect(options)
|
437
|
+
|
438
|
+
begin
|
439
|
+
instance_type = find_instance_type_by_name_or_id(args[0])
|
440
|
+
exit 1 if instance_type.nil?
|
441
|
+
|
442
|
+
unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the instance type #{instance_type['name']}?", options)
|
443
|
+
exit
|
444
|
+
end
|
445
|
+
if options[:dry_run]
|
446
|
+
print_dry_run @library_instance_types_interface.dry.destroy(instance_type['id'])
|
447
|
+
return
|
448
|
+
end
|
449
|
+
json_response = @library_instance_types_interface.destroy(instance_type['id'])
|
450
|
+
|
451
|
+
if options[:json]
|
452
|
+
print JSON.pretty_generate(json_response), "\n"
|
453
|
+
return
|
454
|
+
end
|
455
|
+
|
456
|
+
print_green_success "Removed Instance Type #{instance_type['name']}"
|
457
|
+
#list([])
|
458
|
+
rescue RestClient::Exception => e
|
459
|
+
print_rest_exception(e, options)
|
460
|
+
exit 1
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
private
|
465
|
+
|
466
|
+
def add_instance_type_option_types
|
467
|
+
[
|
468
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
|
469
|
+
{'fieldName' => 'code', 'fieldLabel' => 'Code', 'type' => 'text', 'required' => true, 'displayOrder' => 2, 'description' => 'Useful shortcode for provisioning naming schemes and export reference.'},
|
470
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'displayOrder' => 3},
|
471
|
+
{'fieldName' => 'category', 'fieldLabel' => 'Category', 'type' => 'select', 'optionSource' => 'categories', 'required' => true, 'displayOrder' => 4},
|
472
|
+
{'fieldName' => 'logo', 'fieldLabel' => 'Icon File', 'type' => 'text', 'displayOrder' => 5},
|
473
|
+
{'fieldName' => 'visibility', 'fieldLabel' => 'Visibility', 'type' => 'select', 'selectOptions' => [{'name' => 'Private', 'value' => 'private'}, {'name' => 'Public', 'value' => 'public'}], 'defaultValue' => 'private', 'displayOrder' => 6},
|
474
|
+
{'fieldName' => 'environmentPrefix', 'fieldLabel' => 'Environment Prefix', 'type' => 'text', 'displayOrder' => 7, 'description' => 'Used for exportable environment variables when tying instance types together in app contexts. If not specified a name will be generated.'},
|
475
|
+
{'fieldName' => 'hasSettings', 'fieldLabel' => 'Enable Settings', 'type' => 'checkbox', 'displayOrder' => 8},
|
476
|
+
{'fieldName' => 'hasAutoScale', 'fieldLabel' => 'Enable Scaling (Horizontal)', 'type' => 'checkbox', 'displayOrder' => 9},
|
477
|
+
{'fieldName' => 'hasDeployment', 'fieldLabel' => 'Supports Deployments', 'type' => 'checkbox', 'displayOrder' => 10, 'description' => 'Requires a data volume be configured on each version. Files will be copied into this location.'}
|
478
|
+
]
|
479
|
+
end
|
480
|
+
|
481
|
+
def update_instance_type_option_types(instance_type=nil)
|
482
|
+
opts = add_instance_type_option_types
|
483
|
+
opts = opts.reject {|it| ["logo"].include? it['fieldName'] }
|
484
|
+
if instance_type
|
485
|
+
opts = add_instance_type_option_types
|
486
|
+
opts.find {|opt| opt['fieldName'] == 'name'}['defaultValue'] = instance_type['name']
|
487
|
+
end
|
488
|
+
opts
|
489
|
+
end
|
490
|
+
|
491
|
+
end
|