morpheus-cli 5.3.0.3 → 5.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +1 -1
- data/README.md +1 -3
- data/lib/morpheus/api/api_client.rb +48 -14
- data/lib/morpheus/api/certificate_types_interface.rb +14 -0
- data/lib/morpheus/api/certificates_interface.rb +9 -0
- data/lib/morpheus/api/integration_types_interface.rb +14 -0
- data/lib/morpheus/api/integrations_interface.rb +7 -22
- data/lib/morpheus/api/network_services_interface.rb +14 -0
- data/lib/morpheus/api/read_interface.rb +23 -0
- data/lib/morpheus/api/rest_interface.rb +12 -10
- data/lib/morpheus/api/roles_interface.rb +7 -0
- data/lib/morpheus/api/servers_interface.rb +7 -0
- data/lib/morpheus/api/user_settings_interface.rb +38 -18
- data/lib/morpheus/api/vdi_allocations_interface.rb +9 -0
- data/lib/morpheus/api/vdi_apps_interface.rb +9 -0
- data/lib/morpheus/api/vdi_gateways_interface.rb +9 -0
- data/lib/morpheus/api/vdi_interface.rb +28 -0
- data/lib/morpheus/api/vdi_pools_interface.rb +19 -0
- data/lib/morpheus/cli.rb +9 -2
- data/lib/morpheus/cli/apps.rb +59 -75
- data/lib/morpheus/cli/catalog_item_types_command.rb +13 -13
- data/lib/morpheus/cli/certificates_command.rb +575 -0
- data/lib/morpheus/cli/cli_command.rb +61 -6
- data/lib/morpheus/cli/clouds.rb +1 -0
- data/lib/morpheus/cli/clusters.rb +1 -1
- data/lib/morpheus/cli/commands/standard/man_command.rb +4 -5
- data/lib/morpheus/cli/hosts.rb +245 -224
- data/lib/morpheus/cli/instances.rb +150 -167
- data/lib/morpheus/cli/integrations_command.rb +588 -41
- data/lib/morpheus/cli/login.rb +7 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +33 -18
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +3 -3
- data/lib/morpheus/cli/mixins/vdi_helper.rb +246 -0
- data/lib/morpheus/cli/network_routers_command.rb +22 -9
- data/lib/morpheus/cli/networks_command.rb +2 -2
- data/lib/morpheus/cli/option_types.rb +34 -33
- data/lib/morpheus/cli/remote.rb +1 -1
- data/lib/morpheus/cli/reports_command.rb +4 -1
- data/lib/morpheus/cli/roles.rb +215 -55
- data/lib/morpheus/cli/subnets_command.rb +11 -2
- data/lib/morpheus/cli/user_settings_command.rb +268 -57
- data/lib/morpheus/cli/vdi_allocations_command.rb +159 -0
- data/lib/morpheus/cli/vdi_apps_command.rb +317 -0
- data/lib/morpheus/cli/vdi_command.rb +359 -0
- data/lib/morpheus/cli/vdi_gateways_command.rb +290 -0
- data/lib/morpheus/cli/vdi_pools_command.rb +571 -0
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/rest_client.rb +30 -0
- data/lib/morpheus/terminal.rb +15 -7
- metadata +18 -2
@@ -0,0 +1,359 @@
|
|
1
|
+
require 'morpheus/cli/cli_command'
|
2
|
+
|
3
|
+
# CLI command for the VDI (Persona)
|
4
|
+
class Morpheus::Cli::VdiCommand
|
5
|
+
include Morpheus::Cli::CliCommand
|
6
|
+
include Morpheus::Cli::OptionSourceHelper
|
7
|
+
|
8
|
+
# set_command_name :'desktops'
|
9
|
+
set_command_name :'vdi'
|
10
|
+
set_command_description "Virtual Desktop Persona: View and allocate your own virtual desktops"
|
11
|
+
|
12
|
+
register_subcommands :list, :get, :allocate, :open
|
13
|
+
|
14
|
+
def connect(opts)
|
15
|
+
@api_client = establish_remote_appliance_connection(opts)
|
16
|
+
@vdi_interface = @api_client.vdi
|
17
|
+
end
|
18
|
+
|
19
|
+
def handle(args)
|
20
|
+
handle_subcommand(args)
|
21
|
+
end
|
22
|
+
|
23
|
+
def list(args)
|
24
|
+
options = {}
|
25
|
+
params = {}
|
26
|
+
ref_ids = []
|
27
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
28
|
+
opts.banner = subcommand_usage("[search]")
|
29
|
+
build_standard_list_options(opts, options)
|
30
|
+
opts.footer = "List available virtual desktops (VDI pool)."
|
31
|
+
end
|
32
|
+
optparse.parse!(args)
|
33
|
+
connect(options)
|
34
|
+
# verify_args!(args:args, optparse:optparse, count:0)
|
35
|
+
if args.count > 0
|
36
|
+
options[:phrase] = args.join(" ")
|
37
|
+
end
|
38
|
+
params.merge!(parse_list_options(options))
|
39
|
+
@vdi_interface.setopts(options)
|
40
|
+
if options[:dry_run]
|
41
|
+
print_dry_run @vdi_interface.dry.list(params)
|
42
|
+
return
|
43
|
+
end
|
44
|
+
json_response = @vdi_interface.list(params)
|
45
|
+
vdi_pools = json_response[vdi_desktop_list_key]
|
46
|
+
render_response(json_response, options, vdi_desktop_list_key) do
|
47
|
+
print_h1 "Morpheus Virtual Desktops", parse_list_subtitles(options), options
|
48
|
+
if vdi_pools.empty?
|
49
|
+
print cyan,"No virtual desktops found.",reset,"\n"
|
50
|
+
else
|
51
|
+
list_columns = {
|
52
|
+
# "ID" => lambda {|it| it['id'] },
|
53
|
+
"Name" => lambda {|it| it['name'] },
|
54
|
+
"Status" => lambda {|it| format_virtual_desktop_status(it) },
|
55
|
+
}
|
56
|
+
#list_columns["Config"] = lambda {|it| truncate_string(it['config'], 100) }
|
57
|
+
print as_pretty_table(vdi_pools, list_columns.upcase_keys!, options)
|
58
|
+
print_results_pagination(json_response)
|
59
|
+
|
60
|
+
end
|
61
|
+
print reset,"\n"
|
62
|
+
end
|
63
|
+
return 0, nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def get(args)
|
67
|
+
params = {}
|
68
|
+
options = {}
|
69
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
70
|
+
opts.banner = subcommand_usage("[name]")
|
71
|
+
build_standard_get_options(opts, options)
|
72
|
+
opts.footer = <<-EOT
|
73
|
+
Get details about a specific virtual desktop.
|
74
|
+
[name] is required. This is the name or id of a virtual desktop (VDI pool).
|
75
|
+
EOT
|
76
|
+
end
|
77
|
+
optparse.parse!(args)
|
78
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
79
|
+
connect(options)
|
80
|
+
params.merge!(parse_query_options(options))
|
81
|
+
id_list = parse_id_list(args)
|
82
|
+
return run_command_for_each_arg(id_list) do |arg|
|
83
|
+
_get(arg, params, options)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def _get(id, params, options)
|
88
|
+
vdi_pool = nil
|
89
|
+
if id.to_s !~ /\A\d{1,}\Z/
|
90
|
+
vdi_pool = find_vdi_pool_by_name(id)
|
91
|
+
return 1, "Virtual desktop not found for #{id}" if vdi_pool.nil?
|
92
|
+
id = vdi_pool['id']
|
93
|
+
end
|
94
|
+
@vdi_interface.setopts(options)
|
95
|
+
if options[:dry_run]
|
96
|
+
print_dry_run @vdi_interface.dry.get(id, params)
|
97
|
+
return
|
98
|
+
end
|
99
|
+
json_response = @vdi_interface.get(id, params)
|
100
|
+
vdi_pool = json_response[vdi_desktop_object_key]
|
101
|
+
render_response(json_response, options, vdi_desktop_object_key) do
|
102
|
+
print_h1 "Virtual Desktop Details", [], options
|
103
|
+
print cyan
|
104
|
+
show_columns = {
|
105
|
+
#"ID" => lambda {|it| it['id'] },
|
106
|
+
"Name" => lambda {|it| it['name'] },
|
107
|
+
"Status" => lambda {|it| it['status'] },
|
108
|
+
#"Allocation ID" => lambda {|it| it['allocation']['id'] rescue '' },
|
109
|
+
# todo: more allocation info can be shown here perhaps...
|
110
|
+
}
|
111
|
+
#show_columns.delete("Allocation ID") unless vdi_pool['allocation'] && vdi_pool['allocation']['id']
|
112
|
+
print as_description_list(vdi_pool, show_columns, options)
|
113
|
+
print reset,"\n"
|
114
|
+
end
|
115
|
+
return 0, nil
|
116
|
+
end
|
117
|
+
|
118
|
+
def allocate(args)
|
119
|
+
options = {}
|
120
|
+
params = {}
|
121
|
+
payload = {}
|
122
|
+
pool_id = nil
|
123
|
+
|
124
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
125
|
+
opts.banner = subcommand_usage("[desktop] [options]")
|
126
|
+
opts.on('--desktop DESKTOP', String, "Virtual Desktop Name or ID") do |val|
|
127
|
+
pool_id = val.to_s
|
128
|
+
end
|
129
|
+
build_standard_update_options(opts, options)
|
130
|
+
opts.footer = <<-EOT
|
131
|
+
Allocate a virtual desktop for use.
|
132
|
+
[desktop] is required, this is name or id of a virtual desktop (VDI Pool).
|
133
|
+
EOT
|
134
|
+
end
|
135
|
+
optparse.parse!(args)
|
136
|
+
verify_args!(args:args, optparse:optparse, min:0)
|
137
|
+
connect(options)
|
138
|
+
if args.count > 0
|
139
|
+
pool_id = args.join(" ")
|
140
|
+
end
|
141
|
+
|
142
|
+
# prompt for Virtual Desktop (VDI Pool) to allocate
|
143
|
+
vdi_pool = nil
|
144
|
+
if pool_id
|
145
|
+
vdi_pool = find_vdi_pool_by_name_or_id(pool_id)
|
146
|
+
return [1, "Virtual Desktop not found"] if vdi_pool.nil?
|
147
|
+
pool_id = vdi_pool['id']
|
148
|
+
elsif
|
149
|
+
vdi_pool_option_type = {'fieldName' => 'desktop', 'fieldLabel' => 'Virtual Desktop', 'type' => 'select', 'optionSource' => lambda { |api_client, api_params|
|
150
|
+
# @options_interface.options_for_source("vdiPools", {})['data']
|
151
|
+
@vdi_interface.list({max:10000})[vdi_desktop_list_key].collect {|it|
|
152
|
+
{'name' => it['name'], 'value' => it['id']}
|
153
|
+
} }, 'required' => true, 'description' => 'Virtual Desktop (VDI pool) name or id'}
|
154
|
+
pool_id = Morpheus::Cli::OptionTypes.prompt([vdi_pool_option_type], options[:options], @api_client, options[:params])['desktop']
|
155
|
+
vdi_pool = find_vdi_pool_by_name_or_id(pool_id.to_s)
|
156
|
+
return [1, "Virtual Desktop not found"] if vdi_pool.nil?
|
157
|
+
pool_id = vdi_pool['id']
|
158
|
+
end
|
159
|
+
|
160
|
+
payload = {}
|
161
|
+
if options[:payload]
|
162
|
+
payload = options[:payload]
|
163
|
+
end
|
164
|
+
payload.deep_merge!(parse_passed_options(options))
|
165
|
+
|
166
|
+
@vdi_interface.setopts(options)
|
167
|
+
if options[:dry_run]
|
168
|
+
print_dry_run @vdi_interface.dry.allocate(vdi_pool['id'], payload, params)
|
169
|
+
return
|
170
|
+
end
|
171
|
+
json_response = @vdi_interface.allocate(vdi_pool['id'], payload, params)
|
172
|
+
vdi_pool = json_response[vdi_desktop_object_key]
|
173
|
+
render_response(json_response, options) do
|
174
|
+
print_green_success "Allocated virtual desktop '#{vdi_pool['name']}'"
|
175
|
+
#_get([vdi_pool['id']] + (options[:remote] ? ["-r",options[:remote]] : []))
|
176
|
+
end
|
177
|
+
return 0, nil
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
def open(args)
|
182
|
+
options = {}
|
183
|
+
params = {}
|
184
|
+
payload = {}
|
185
|
+
pool_id = nil
|
186
|
+
|
187
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
188
|
+
opts.banner = subcommand_usage("[desktop] [options]")
|
189
|
+
opts.on('--desktop DESKTOP', String, "Virtual Desktop Name or ID") do |val|
|
190
|
+
pool_id = val.to_s
|
191
|
+
end
|
192
|
+
build_standard_update_options(opts, options)
|
193
|
+
opts.footer = <<-EOT
|
194
|
+
Open a virtual desktop console in your web browser.
|
195
|
+
[desktop] is required, this is name or id of a virtual desktop (VDI Pool).
|
196
|
+
EOT
|
197
|
+
end
|
198
|
+
optparse.parse!(args)
|
199
|
+
verify_args!(args:args, optparse:optparse, min:0)
|
200
|
+
connect(options)
|
201
|
+
if args.count > 0
|
202
|
+
pool_id = args.join(" ")
|
203
|
+
end
|
204
|
+
|
205
|
+
# prompt for Virtual Desktop (VDI Pool) to allocate
|
206
|
+
vdi_pool = nil
|
207
|
+
if pool_id
|
208
|
+
vdi_pool = find_vdi_pool_by_name_or_id(pool_id)
|
209
|
+
return [1, "Virtual Desktop not found"] if vdi_pool.nil?
|
210
|
+
pool_id = vdi_pool['id']
|
211
|
+
elsif
|
212
|
+
vdi_pool_option_type = {'fieldName' => 'desktop', 'fieldLabel' => 'Virtual Desktop', 'type' => 'select', 'optionSource' => lambda { |api_client, api_params|
|
213
|
+
# @options_interface.options_for_source("vdiPools", {})['data']
|
214
|
+
@vdi_interface.list({max:10000})[vdi_desktop_list_key].collect {|it|
|
215
|
+
{'name' => it['name'], 'value' => it['id']}
|
216
|
+
} }, 'required' => true, 'description' => 'Virtual Desktop (VDI pool) name or id'}
|
217
|
+
pool_id = Morpheus::Cli::OptionTypes.prompt([vdi_pool_option_type], options[:options], @api_client, options[:params])['desktop']
|
218
|
+
vdi_pool = find_vdi_pool_by_name_or_id(pool_id.to_s)
|
219
|
+
return [1, "Virtual Desktop not found"] if vdi_pool.nil?
|
220
|
+
pool_id = vdi_pool['id']
|
221
|
+
end
|
222
|
+
|
223
|
+
# find allocation ID
|
224
|
+
# if not found, prompt to allocate now before opening a link to the terminal URL
|
225
|
+
allocation_id = nil
|
226
|
+
if vdi_pool['allocation']
|
227
|
+
allocation_id = vdi_pool['allocation']['id']
|
228
|
+
# could check vdi_pool['allocation']['status']
|
229
|
+
else
|
230
|
+
puts cyan + "You are not currently allocated desktop '#{vdi_pool['name']}'" + reset
|
231
|
+
# could check vdi_pool['status'] and error if not 'available'
|
232
|
+
if !options[:no_prompt]
|
233
|
+
if ::Morpheus::Cli::OptionTypes::confirm("Would you like to allocate this desktop for use now?", options.merge({default: true}))
|
234
|
+
# allocate([vdi_pool['id']])
|
235
|
+
json_response = @vdi_interface.allocate(vdi_pool['id'], {}, {})
|
236
|
+
vdi_pool = json_response[vdi_desktop_object_key]
|
237
|
+
allocation_id = vdi_pool['allocation']['id']
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
if allocation_id.nil?
|
243
|
+
print_red_alert "You must first allocate virtual desktop '#{vdi_pool['name']}'"
|
244
|
+
print_red_alert "Try `vdi allocate \"#{vdi_pool['name']}\"`"
|
245
|
+
return 1, "No allocation"
|
246
|
+
end
|
247
|
+
|
248
|
+
link = "#{@appliance_url}/login/oauth-redirect?access_token=#{@access_token}\\&redirectUri=/vdi/terminal/#{allocation_id}"
|
249
|
+
|
250
|
+
if options[:dry_run]
|
251
|
+
puts Morpheus::Util.open_url_command(link)
|
252
|
+
return 0
|
253
|
+
end
|
254
|
+
return Morpheus::Util.open_url(link)
|
255
|
+
|
256
|
+
end
|
257
|
+
|
258
|
+
private
|
259
|
+
|
260
|
+
def vdi_desktop_object_key
|
261
|
+
# 'vdiPool'
|
262
|
+
'desktop'
|
263
|
+
end
|
264
|
+
|
265
|
+
def vdi_desktop_list_key
|
266
|
+
# 'vdiPools'
|
267
|
+
'desktops'
|
268
|
+
end
|
269
|
+
|
270
|
+
def find_vdi_pool_by_name_or_id(val)
|
271
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
272
|
+
return find_vdi_pool_by_id(val)
|
273
|
+
else
|
274
|
+
return find_vdi_pool_by_name(val)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# this returns optionTypes and list does not..
|
279
|
+
def find_vdi_pool_by_id(id)
|
280
|
+
begin
|
281
|
+
json_response = @vdi_interface.get(id.to_i)
|
282
|
+
return json_response[vdi_desktop_object_key]
|
283
|
+
rescue RestClient::Exception => e
|
284
|
+
if e.response && e.response.code == 404
|
285
|
+
print_red_alert "Virtual Desktop not found by id '#{id}'"
|
286
|
+
else
|
287
|
+
raise e
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def find_vdi_pool_by_name(name)
|
293
|
+
json_response = @vdi_interface.list({name: name.to_s})
|
294
|
+
vdi_pools = json_response[vdi_desktop_list_key]
|
295
|
+
if vdi_pools.empty?
|
296
|
+
print_red_alert "Virtual Desktop not found by name '#{name}'"
|
297
|
+
return nil
|
298
|
+
elsif vdi_pools.size > 1
|
299
|
+
print_red_alert "#{vdi_pools.size} virtual desktops found by name '#{name}'"
|
300
|
+
puts_error as_pretty_table(vdi_pools, [:id, :name], {color:red})
|
301
|
+
print_red_alert "Try using ID instead"
|
302
|
+
print reset,"\n"
|
303
|
+
return nil
|
304
|
+
else
|
305
|
+
return vdi_pools[0]
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
# def format_vdi_pool_status(vdi_pool, return_color=cyan)
|
310
|
+
# out = ""
|
311
|
+
# status_string = vdi_pool['status'].to_s.downcase
|
312
|
+
# if status_string
|
313
|
+
# if ['available'].include?(status_string)
|
314
|
+
# out << "#{green}#{status_string.upcase}"
|
315
|
+
# elsif ['unavailable'].include?(status_string)
|
316
|
+
# out << "#{red}#{status_string.upcase}"
|
317
|
+
# else
|
318
|
+
# out << "#{return_color}#{status_string.upcase}"
|
319
|
+
# end
|
320
|
+
# end
|
321
|
+
# out + return_color
|
322
|
+
# end
|
323
|
+
|
324
|
+
def format_virtual_desktop_status(vdi_pool, return_color=cyan)
|
325
|
+
out = ""
|
326
|
+
# status_string = vdi_pool['status'].to_s.downcase
|
327
|
+
# status_string = ""
|
328
|
+
# if vdi_pool['allocation']
|
329
|
+
# status_string = vdi_pool['allocation']['status'].to_s.downcase
|
330
|
+
# else
|
331
|
+
# # show pool status eg. AVAILABLE or UNAVAILABLE
|
332
|
+
# status_string = vdi_pool['status'].to_s.downcase
|
333
|
+
# end
|
334
|
+
status_string = vdi_pool['allocationStatus'].to_s.downcase
|
335
|
+
if vdi_pool['allocation'].nil?
|
336
|
+
status_string = vdi_pool['status'].to_s.downcase
|
337
|
+
# if status_string == 'available'
|
338
|
+
# status_string = 'unallocated'
|
339
|
+
# end
|
340
|
+
end
|
341
|
+
|
342
|
+
if status_string
|
343
|
+
if ['available', 'reserved'].include?(status_string)
|
344
|
+
out << "#{green}#{status_string.upcase}"
|
345
|
+
# elsif ['preparing'].include?(status_string)
|
346
|
+
# out << "#{yellow}#{status_string.upcase}"
|
347
|
+
# elsif ['reserved', 'shutdown'].include?(status_string)
|
348
|
+
# out << "#{yellow}#{status_string.upcase}"
|
349
|
+
elsif ['failed'].include?(status_string)
|
350
|
+
out << "#{red}#{status_string.upcase}"
|
351
|
+
else
|
352
|
+
out << "#{return_color}#{status_string.upcase}"
|
353
|
+
end
|
354
|
+
end
|
355
|
+
out + return_color
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
end
|
@@ -0,0 +1,290 @@
|
|
1
|
+
require 'morpheus/cli/cli_command'
|
2
|
+
|
3
|
+
# CLI command VDI Gateway management
|
4
|
+
# UI is Tools: VDI Gateways
|
5
|
+
# API is /vdi-gateways and returns vdiGateways
|
6
|
+
class Morpheus::Cli::VdiGatewaysCommand
|
7
|
+
include Morpheus::Cli::CliCommand
|
8
|
+
include Morpheus::Cli::VdiHelper
|
9
|
+
include Morpheus::Cli::OptionSourceHelper
|
10
|
+
|
11
|
+
set_command_name :'vdi-gateways'
|
12
|
+
set_command_description "View and manage VDI gateways"
|
13
|
+
|
14
|
+
register_subcommands :list, :get, :add, :update, :remove
|
15
|
+
|
16
|
+
def connect(opts)
|
17
|
+
@api_client = establish_remote_appliance_connection(opts)
|
18
|
+
@vdi_gateways_interface = @api_client.vdi_gateways
|
19
|
+
@vdi_apps_interface = @api_client.vdi_apps
|
20
|
+
@vdi_gateways_interface = @api_client.vdi_gateways
|
21
|
+
@option_types_interface = @api_client.option_types
|
22
|
+
end
|
23
|
+
|
24
|
+
def handle(args)
|
25
|
+
handle_subcommand(args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def list(args)
|
29
|
+
options = {}
|
30
|
+
params = {}
|
31
|
+
ref_ids = []
|
32
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
33
|
+
opts.banner = subcommand_usage("[search]")
|
34
|
+
build_standard_list_options(opts, options)
|
35
|
+
opts.footer = "List VDI gateways."
|
36
|
+
end
|
37
|
+
optparse.parse!(args)
|
38
|
+
connect(options)
|
39
|
+
if args.count > 0
|
40
|
+
options[:phrase] = args.join(" ")
|
41
|
+
end
|
42
|
+
params.merge!(parse_list_options(options))
|
43
|
+
@vdi_gateways_interface.setopts(options)
|
44
|
+
if options[:dry_run]
|
45
|
+
print_dry_run @vdi_gateways_interface.dry.list(params)
|
46
|
+
return
|
47
|
+
end
|
48
|
+
json_response = @vdi_gateways_interface.list(params)
|
49
|
+
render_response(json_response, options, vdi_gateway_list_key) do
|
50
|
+
vdi_gateways = json_response[vdi_gateway_list_key]
|
51
|
+
print_h1 "Morpheus VDI Gateways", parse_list_subtitles(options), options
|
52
|
+
if vdi_gateways.empty?
|
53
|
+
print cyan,"No VDI gateways found.",reset,"\n"
|
54
|
+
else
|
55
|
+
print as_pretty_table(vdi_gateways, vdi_gateway_list_column_definitions.upcase_keys!, options)
|
56
|
+
print_results_pagination(json_response)
|
57
|
+
end
|
58
|
+
print reset,"\n"
|
59
|
+
end
|
60
|
+
return 0, nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def get(args)
|
64
|
+
params = {}
|
65
|
+
options = {}
|
66
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
67
|
+
opts.banner = subcommand_usage("[gateway]")
|
68
|
+
build_standard_get_options(opts, options)
|
69
|
+
opts.footer = <<-EOT
|
70
|
+
Get details about a specific VDI gateway.
|
71
|
+
[gateway] is required. This is the name or id of a VDI gateway.
|
72
|
+
EOT
|
73
|
+
end
|
74
|
+
optparse.parse!(args)
|
75
|
+
verify_args!(args:args, optparse:optparse, min:1)
|
76
|
+
connect(options)
|
77
|
+
params.merge!(parse_query_options(options))
|
78
|
+
id_list = parse_id_list(args)
|
79
|
+
return run_command_for_each_arg(id_list) do |arg|
|
80
|
+
_get(arg, params, options)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def _get(id, params, options)
|
85
|
+
vdi_gateway = nil
|
86
|
+
if id.to_s !~ /\A\d{1,}\Z/
|
87
|
+
vdi_gateway = find_vdi_gateway_by_name(id)
|
88
|
+
return 1, "VDI gateway not found for #{id}" if vdi_gateway.nil?
|
89
|
+
id = vdi_gateway['id']
|
90
|
+
end
|
91
|
+
@vdi_gateways_interface.setopts(options)
|
92
|
+
if options[:dry_run]
|
93
|
+
print_dry_run @vdi_gateways_interface.dry.get(id, params)
|
94
|
+
return
|
95
|
+
end
|
96
|
+
json_response = @vdi_gateways_interface.get(id, params)
|
97
|
+
vdi_gateway = json_response[vdi_gateway_object_key]
|
98
|
+
config = vdi_gateway['config'] || {}
|
99
|
+
# export just the config as json or yaml (default)
|
100
|
+
if options[:show_config]
|
101
|
+
unless options[:json] || options[:yaml] || options[:csv]
|
102
|
+
options[:yaml] = true
|
103
|
+
end
|
104
|
+
return render_with_format(config, options)
|
105
|
+
end
|
106
|
+
render_response(json_response, options, vdi_gateway_object_key) do
|
107
|
+
print_h1 "VDI Gateway Details", [], options
|
108
|
+
print cyan
|
109
|
+
show_columns = vdi_gateway_column_definitions
|
110
|
+
show_columns.delete("VDI Apps") unless vdi_gateway['apps']
|
111
|
+
show_columns.delete("VDI Gateway") unless vdi_gateway['gateway']
|
112
|
+
show_columns.delete("Guest Console Jump Host") unless vdi_gateway['guestConsoleJumpHost']
|
113
|
+
show_columns.delete("Guest Console Jump Port") unless vdi_gateway['guestConsoleJumpPort']
|
114
|
+
show_columns.delete("Guest Console Jump Username") unless vdi_gateway['guestConsoleJumpUsername']
|
115
|
+
show_columns.delete("Guest Console Jump Password") unless vdi_gateway['guestConsoleJumpPassword']
|
116
|
+
show_columns.delete("Guest Console Jump Keypair") unless vdi_gateway['guestConsoleJumpKeypair']
|
117
|
+
print_description_list(show_columns, vdi_gateway)
|
118
|
+
|
119
|
+
|
120
|
+
print reset,"\n"
|
121
|
+
end
|
122
|
+
return 0, nil
|
123
|
+
end
|
124
|
+
|
125
|
+
def add(args)
|
126
|
+
options = {}
|
127
|
+
params = {}
|
128
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
129
|
+
opts.banner = subcommand_usage("[name] [options]")
|
130
|
+
build_option_type_options(opts, options, add_vdi_gateway_option_types)
|
131
|
+
build_standard_add_options(opts, options)
|
132
|
+
opts.footer = <<-EOT
|
133
|
+
Create a new VDI gateway.
|
134
|
+
EOT
|
135
|
+
end
|
136
|
+
optparse.parse!(args)
|
137
|
+
verify_args!(args:args, optparse:optparse, min:0, max:1)
|
138
|
+
options[:options]['name'] = args[0] if args[0]
|
139
|
+
connect(options)
|
140
|
+
payload = {}
|
141
|
+
if options[:payload]
|
142
|
+
payload = options[:payload]
|
143
|
+
payload.deep_merge!({vdi_gateway_object_key => parse_passed_options(options)})
|
144
|
+
else
|
145
|
+
payload.deep_merge!({vdi_gateway_object_key => parse_passed_options(options)})
|
146
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt(add_vdi_gateway_option_types, options[:options], @api_client, options[:params])
|
147
|
+
params.deep_merge!(v_prompt)
|
148
|
+
params.booleanize!
|
149
|
+
payload[vdi_gateway_object_key].deep_merge!(params)
|
150
|
+
end
|
151
|
+
@vdi_gateways_interface.setopts(options)
|
152
|
+
if options[:dry_run]
|
153
|
+
print_dry_run @vdi_gateways_interface.dry.create(payload)
|
154
|
+
return 0, nil
|
155
|
+
end
|
156
|
+
json_response = @vdi_gateways_interface.create(payload)
|
157
|
+
vdi_gateway = json_response[vdi_gateway_object_key]
|
158
|
+
render_response(json_response, options, vdi_gateway_object_key) do
|
159
|
+
print_green_success "Added VDI gateway #{vdi_gateway['name']}"
|
160
|
+
return _get(vdi_gateway["id"], {}, options)
|
161
|
+
end
|
162
|
+
return 0, nil
|
163
|
+
end
|
164
|
+
|
165
|
+
def update(args)
|
166
|
+
options = {}
|
167
|
+
params = {}
|
168
|
+
payload = {}
|
169
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
170
|
+
opts.banner = subcommand_usage("[gateway] [options]")
|
171
|
+
build_option_type_options(opts, options, update_vdi_gateway_option_types)
|
172
|
+
build_standard_update_options(opts, options)
|
173
|
+
opts.footer = <<-EOT
|
174
|
+
Update a VDI gateway.
|
175
|
+
[gateway] is required. This is the name or id of a VDI gateway.
|
176
|
+
EOT
|
177
|
+
end
|
178
|
+
optparse.parse!(args)
|
179
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
180
|
+
connect(options)
|
181
|
+
vdi_gateway = find_vdi_gateway_by_name_or_id(args[0])
|
182
|
+
return 1 if vdi_gateway.nil?
|
183
|
+
payload = {}
|
184
|
+
if options[:payload]
|
185
|
+
payload = options[:payload]
|
186
|
+
payload.deep_merge!({vdi_gateway_object_key => parse_passed_options(options)})
|
187
|
+
else
|
188
|
+
payload.deep_merge!({vdi_gateway_object_key => parse_passed_options(options)})
|
189
|
+
v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_vdi_gateway_option_types, options[:options], @api_client, options[:params])
|
190
|
+
v_prompt.deep_compact!
|
191
|
+
params.deep_merge!(v_prompt)
|
192
|
+
params.booleanize!
|
193
|
+
payload.deep_merge!({vdi_gateway_object_key => params})
|
194
|
+
if payload[vdi_gateway_object_key].empty? # || options[:no_prompt]
|
195
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
@vdi_gateways_interface.setopts(options)
|
199
|
+
if options[:dry_run]
|
200
|
+
print_dry_run @vdi_gateways_interface.dry.update(vdi_gateway['id'], payload)
|
201
|
+
return
|
202
|
+
end
|
203
|
+
json_response = @vdi_gateways_interface.update(vdi_gateway['id'], payload)
|
204
|
+
vdi_gateway = json_response[vdi_gateway_object_key]
|
205
|
+
render_response(json_response, options, vdi_gateway_object_key) do
|
206
|
+
print_green_success "Updated VDI gateway #{vdi_gateway['name']}"
|
207
|
+
return _get(vdi_gateway["id"], {}, options)
|
208
|
+
end
|
209
|
+
return 0, nil
|
210
|
+
end
|
211
|
+
|
212
|
+
def remove(args)
|
213
|
+
options = {}
|
214
|
+
params = {}
|
215
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
216
|
+
opts.banner = subcommand_usage("[gateway] [options]")
|
217
|
+
build_standard_remove_options(opts, options)
|
218
|
+
opts.footer = <<-EOT
|
219
|
+
Delete a VDI gateway.
|
220
|
+
[gateway] is required. This is the name or id of a VDI gateway.
|
221
|
+
EOT
|
222
|
+
end
|
223
|
+
optparse.parse!(args)
|
224
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
225
|
+
connect(options)
|
226
|
+
vdi_gateway = find_vdi_gateway_by_name_or_id(args[0])
|
227
|
+
return 1 if vdi_gateway.nil?
|
228
|
+
@vdi_gateways_interface.setopts(options)
|
229
|
+
if options[:dry_run]
|
230
|
+
print_dry_run @vdi_gateways_interface.dry.destroy(vdi_gateway['id'], params)
|
231
|
+
return
|
232
|
+
end
|
233
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the VDI gateway #{vdi_gateway['name']}?")
|
234
|
+
return 9, "aborted command"
|
235
|
+
end
|
236
|
+
json_response = @vdi_gateways_interface.destroy(vdi_gateway['id'], params)
|
237
|
+
render_response(json_response, options) do
|
238
|
+
print_green_success "Removed VDI gateway #{vdi_gateway['name']}"
|
239
|
+
end
|
240
|
+
return 0, nil
|
241
|
+
end
|
242
|
+
|
243
|
+
private
|
244
|
+
|
245
|
+
def vdi_gateway_list_column_definitions()
|
246
|
+
|
247
|
+
{
|
248
|
+
"ID" => 'id',
|
249
|
+
"Name" => 'name',
|
250
|
+
# "Description" => 'description',
|
251
|
+
"Gateway URL" => 'gatewayUrl',
|
252
|
+
"API Key" => 'apiKey',
|
253
|
+
# "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
254
|
+
# "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
|
255
|
+
}
|
256
|
+
end
|
257
|
+
|
258
|
+
def vdi_gateway_column_definitions()
|
259
|
+
{
|
260
|
+
"ID" => 'id',
|
261
|
+
"Name" => 'name',
|
262
|
+
"Description" => 'description',
|
263
|
+
"Gateway URL" => 'gatewayUrl',
|
264
|
+
"API Key" => 'apiKey',
|
265
|
+
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
|
266
|
+
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
|
267
|
+
}
|
268
|
+
end
|
269
|
+
|
270
|
+
def add_vdi_gateway_option_types
|
271
|
+
[
|
272
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Choose a unique name for the VDI Gateway'},
|
273
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'description' => 'Description'},
|
274
|
+
{'fieldName' => 'gatewayUrl', 'fieldLabel' => 'Gateway URL', 'type' => 'text', 'required' => true, 'description' => 'URL of the VDI Gateway'},
|
275
|
+
]
|
276
|
+
end
|
277
|
+
|
278
|
+
def update_vdi_gateway_option_types
|
279
|
+
list = add_vdi_gateway_option_types.collect {|it|
|
280
|
+
it.delete('required')
|
281
|
+
it.delete('defaultValue')
|
282
|
+
it
|
283
|
+
}
|
284
|
+
list = list.reject {|it| ["type"].include? it['fieldName'] }
|
285
|
+
list
|
286
|
+
end
|
287
|
+
|
288
|
+
# finders are in VdiHelper mixin
|
289
|
+
|
290
|
+
end
|