Class: Morpheus::Cli::Groups
Constant Summary
collapse
- @@groups =
nil
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Class Method Summary
collapse
Instance Method Summary
collapse
#find_available_user_option, #find_cloud_option, #find_group_option, #find_tenant_option, #get_available_user_options, #get_cloud_options, #get_group_options, #get_tenant_options, included, #load_option_source_data, #options_interface, #parse_cloud_id_list, #parse_group_id_list, #parse_option_source_id_list, #parse_project_id_list, #parse_tenant_id_list, #parse_user_id_list
#cloud_type_for_id, #cloud_type_for_name, #cloud_type_for_name_or_id, #clouds_interface, #find_cloud_by_id, #find_cloud_by_name, #find_cloud_by_name_or_id, #find_group_by_id, #find_group_by_name, #find_group_by_name_or_id, #find_network_by_id, #find_network_by_name, #find_network_by_name_or_id, #find_network_group_by_id, #find_network_group_by_name, #find_network_group_by_name_or_id, #find_network_server_type_by_id, #find_network_server_type_by_name, #find_network_server_type_by_name_or_code, #find_network_server_type_by_name_or_id, #find_network_type_by_id, #find_network_type_by_name, #find_network_type_by_name_or_id, #find_resource_pool_by_id, #find_resource_pool_by_name, #find_resource_pool_by_name_or_id, #find_resource_pool_group_by_id, #find_resource_pool_group_by_name, #find_resource_pool_group_by_name_or_id, #find_subnet_by_id, #find_subnet_by_name, #find_subnet_by_name_or_id, #find_subnet_type_by_id, #find_subnet_type_by_name, #find_subnet_type_by_name_or_id, #format_network_pool_server_status, #get_available_cloud_types, #groups_interface, included, #network_groups_interface, #network_pool_server_column_definitions, #network_pool_server_list_column_definitions, #network_pool_server_type_column_definitions, #network_pool_server_type_list_column_definitions, #network_server_type_column_definitions, #network_server_type_list_column_definitions, #network_types_interface, #networks_interface, #prompt_for_network, #prompt_for_networks, #prompt_for_pools, #prompt_for_subnets, #resource_pool_groups_interface, #resource_pools_interface, #subnet_types_interface, #subnets_interface
#account_column_definitions, #account_users_interface, #accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_all_user_ids, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #find_user_group_by_id, #find_user_group_by_name, #find_user_group_by_name_or_id, #format_access_string, #format_role_type, #format_user_role_names, #format_user_status, #get_access_color, #get_access_string, included, #list_account_column_definitions, #list_user_column_definitions, #list_user_group_column_definitions, #role_column_definitions, #roles_interface, #subtenant_role_column_definitions, #user_column_definitions, #user_group_column_definitions, #user_groups_interface
Methods included from CliCommand
#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands
Constructor Details
#initialize ⇒ Groups
Returns a new instance of Groups.
14
15
16
|
# File 'lib/morpheus/cli/commands/groups.rb', line 14
def initialize()
end
|
Class Method Details
.active_group(appliance_name = nil) ⇒ Object
Provides the current active group information (just the ID right now)
758
759
760
761
762
763
764
765
766
|
# File 'lib/morpheus/cli/commands/groups.rb', line 758
def active_group(appliance_name=nil)
if appliance_name == nil
appliance_name, appliance_url = Morpheus::Cli::Remote.active_appliance
end
if !appliance_name
return nil
end
return active_groups_map[appliance_name.to_sym]
end
|
.active_group_id(appliance_name = nil) ⇒ Object
769
770
771
|
# File 'lib/morpheus/cli/commands/groups.rb', line 769
def active_group_id(appliance_name=nil)
active_group(appliance_name)
end
|
.active_groups ⇒ Object
753
754
755
|
# File 'lib/morpheus/cli/commands/groups.rb', line 753
def active_groups
active_groups_map
end
|
.active_groups_map ⇒ Object
Provides the current active group information
749
750
751
|
# File 'lib/morpheus/cli/commands/groups.rb', line 749
def active_groups_map
@@groups ||= load_group_file || {}
end
|
.clear_active_group(appliance_name) ⇒ Object
779
780
781
782
783
|
# File 'lib/morpheus/cli/commands/groups.rb', line 779
def clear_active_group(appliance_name)
the_groups = active_groups_map
the_groups.delete(appliance_name.to_sym)
save_groups(the_groups)
end
|
.groups_file_path ⇒ Object
795
796
797
|
# File 'lib/morpheus/cli/commands/groups.rb', line 795
def groups_file_path
return File.join(Morpheus::Cli.home_directory, "groups")
end
|
.load_group_file ⇒ Object
785
786
787
788
789
790
791
792
793
|
# File 'lib/morpheus/cli/commands/groups.rb', line 785
def load_group_file
fn = groups_file_path
if File.exist? fn
return YAML.load_file(fn)
else
{}
end
end
|
.save_groups(groups_map) ⇒ Object
799
800
801
802
803
804
805
806
807
|
# File 'lib/morpheus/cli/commands/groups.rb', line 799
def save_groups(groups_map)
fn = groups_file_path
if !Dir.exist?(File.dirname(fn))
FileUtils.mkdir_p(File.dirname(fn))
end
File.open(fn, 'w') {|f| f.write groups_map.to_yaml } FileUtils.chmod(0600, fn)
@@groups = groups_map
end
|
.set_active_group(appliance_name, group_id) ⇒ Object
773
774
775
776
777
|
# File 'lib/morpheus/cli/commands/groups.rb', line 773
def set_active_group(appliance_name, group_id)
the_groups = active_groups_map
the_groups[appliance_name.to_sym] = group_id
save_groups(the_groups)
end
|
Instance Method Details
#_get(id, options = {}) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/morpheus/cli/commands/groups.rb', line 114
def _get(id, options={})
params = {}
group = nil
if id.to_s !~ /\A\d{1,}\Z/
group = find_group_by_name_or_id(id, options[:include_tenants])
id = group['id']
end
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.get(id.to_i, params)
return
end
json_response = @groups_interface.get(id.to_i, params)
render_response(json_response, options, 'group') do
group = json_response['group']
group_stats = group['stats']
server_counts = nil
instance_counts = nil
if group_stats
instance_counts = group_stats['instanceCounts']
server_counts = group_stats['serverCounts']
end
is_active = @active_group_id && (@active_group_id == group['id'])
print_h1 "Group Details"
print cyan
description_cols = {
"ID" => 'id',
"Name" => 'name',
"Code" => 'code',
"Location" => 'location',
"Labels" => lambda {|it| format_list(it['labels'], '') rescue '' },
"Clouds" => lambda {|it| it['zones'].collect {|z| z['name'] }.join(', ') },
"Tenant" => lambda {|it| it['account'] ? it['account']['name'] : '' },
}
print_description_list(description_cols, group)
if server_counts
print_h2 "Group Stats"
print cyan
print "Clouds: #{group['zones'].size}".center(20)
print "Instances: #{instance_counts['all']}".center(20) if instance_counts
print "Hosts: #{server_counts['host']}".center(20)
print "Virtual Machines: #{server_counts['vm']}".center(20)
print "Bare Metal: #{server_counts['baremetal']}".center(20)
print "\n"
end
if is_active
print "\n"
print cyan, "=> This is the active group", reset, "\n" end
print reset,"\n"
return 0, nil
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#add(args) ⇒ Object
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# File 'lib/morpheus/cli/commands/groups.rb', line 186
def add(args)
options = {}
params = {}
use_it = false
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name]")
build_option_type_options(opts, options, add_group_option_types())
opts.on( '--use', '--use', "Make this the current active group" ) do
use_it = true
end
build_standard_add_options(opts, options)
opts. = "Create a new group."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, max:1)
connect(options)
begin
group_payload = {}
if args[0]
group_payload[:name] = args[0]
options[:options]['name'] = args[0] end
if params[:location]
group_payload[:name] = params[:location]
options[:options]['location'] = params[:location] end
all_option_types = add_group_option_types()
params = Morpheus::Cli::OptionTypes.prompt(all_option_types, options[:options], @api_client, {})
group_payload.merge!(params)
payload = {group: group_payload}
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.create(payload)
return
end
json_response = @groups_interface.create(payload)
group = json_response['group']
if use_it
::Morpheus::Cli::Groups.set_active_group(@appliance_name, group['id'])
end
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
else
print_green_success "Added group #{group['name']}"
list([])
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#add_cloud(args) ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/morpheus/cli/commands/groups.rb', line 295
def add_cloud(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name]", "CLOUD")
build_standard_update_options(opts, options)
opts. = "Add a cloud to a group."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:2)
connect(options)
begin
group = find_group_by_name_or_id(args[0])
cloud = find_cloud_by_name_or_id(args[1])
current_zones = group['zones']
found_zone = current_zones.find {|it| it["id"] == cloud["id"] }
if found_zone
print_red_alert "Cloud #{cloud['name']} is already in group #{group['name']}."
exit 1
end
new_zones = current_zones + [{'id' => cloud['id']}]
payload = {group: {id: group["id"], zones: new_zones}}
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.update_zones(group["id"], payload)
return
end
json_response = @groups_interface.update_zones(group["id"], payload)
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
else
print_green_success "Added cloud #{cloud["name"]} to group #{group['name']}"
get([group["id"]])
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#connect(opts) ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/morpheus/cli/commands/groups.rb', line 18
def connect(opts)
@api_client = establish_remote_appliance_connection(opts)
@groups_interface = @api_client.groups
@clouds_interface = @api_client.clouds
@options_interface = @api_client.options
@accounts_interface = @api_client.accounts
@account_users_interface = @api_client.account_users
@active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
end
|
#get(args) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/morpheus/cli/commands/groups.rb', line 92
def get(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name]")
opts.on('--include-tenants','--include-tenants', "Include sub tenant groups when finding group by name") do
options[:include_tenants] = true
end
build_standard_get_options(opts, options)
opts. = <<-EOT
Get details about a group.
[name] is required. This is the name or id of a group. Supports 1-N arguments.
EOT
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, min:1)
connect(options)
id_list = parse_id_list(args)
return run_command_for_each_arg(id_list) do |arg|
_get(arg, options)
end
end
|
#handle(args) ⇒ Object
28
29
30
|
# File 'lib/morpheus/cli/commands/groups.rb', line 28
def handle(args)
handle_subcommand(args)
end
|
#list(args) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/morpheus/cli/commands/groups.rb', line 32
def list(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage()
opts.on('-l', '--labels LABEL', String, "Filter by labels, can match any of the values") do |val|
add_query_parameter(params, 'labels', parse_labels(val))
end
opts.on('--all-labels LABEL', String, "Filter by labels, must match all of the values") do |val|
add_query_parameter(params, 'allLabels', parse_labels(val))
end
opts.on('--include-tenants','--include-tenants', "Include sub tenant groups") do
options[:include_tenants] = true
params['includeTenants'] = true
end
opts.on('--tenant TENANT', String, "Tenant Name or ID" ) do |val|
options[:tenant] = val
end
build_standard_list_options(opts, options)
opts. = "List groups."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:0)
connect(options)
if options[:tenant]
if options[:tenant].to_s !~ /\A\d{1,}\Z/
account = find_account_by_name_or_id(options[:tenant])
if account.nil?
return 1, "Tenant not found by name: #{options[:tenant]}"
else
params['tenantId'] = account['id']
end
else
params['tenantId'] = options[:tenant]
end
end
params.merge!(parse_list_options(options))
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.list(params)
return 0, nil
end
json_response = @groups_interface.list(params)
exit_code, err = 0, nil
render_response(json_response, options, "groups") do
groups = json_response['groups']
subtitles = []
subtitles += parse_list_subtitles(options)
print_h1 "Morpheus Groups", subtitles, options
if groups.empty?
print cyan,"No groups found.",reset,"\n"
else
print_groups_table(groups, options)
(json_response)
end
print reset,"\n"
end
return exit_code, err
end
|
#print_current(args) ⇒ Object
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
# File 'lib/morpheus/cli/commands/groups.rb', line 481
def print_current(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage()
build_common_options(opts, options, [:remote])
opts. = "Print the name of the current active group"
end
optparse.parse!(args)
connect(options)
group = @active_group_id ? find_group_by_name_or_id(@active_group_id) : nil
if group
print cyan,group['name'].to_s,"\n",reset
else
print yellow,"No active group. See `groups use`","\n",reset
return false
end
end
|
#remove(args) ⇒ Object
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
# File 'lib/morpheus/cli/commands/groups.rb', line 377
def remove(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name]")
build_standard_remove_options(opts, options)
opts. = "Delete a group."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
begin
group = find_group_by_name_or_id(args[0])
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the group #{group['name']}?")
exit
end
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.destroy(group['id'])
return
end
json_response = @groups_interface.destroy(group['id'])
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
elsif !options[:quiet]
print_green_success "Removed group #{group['name']}"
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#remove_cloud(args) ⇒ Object
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
# File 'lib/morpheus/cli/commands/groups.rb', line 336
def remove_cloud(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name] [cloud]")
build_standard_update_options(opts, options)
opts. = "Remove a cloud from a group."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:2)
connect(options)
begin
group = find_group_by_name_or_id(args[0])
cloud = find_cloud_by_name_or_id(args[1])
current_zones = group['zones']
found_zone = current_zones.find {|it| it["id"] == cloud["id"] }
if !found_zone
print_red_alert "Cloud #{cloud['name']} is not in group #{group['name']}."
exit 1
end
new_zones = current_zones.reject {|it| it["id"] == cloud["id"] }
payload = {group: {id: group["id"], zones: new_zones}}
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.update_zones(group["id"], payload)
return
end
json_response = @groups_interface.update_zones(group["id"], payload)
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
else
print_green_success "Removed cloud #{cloud['name']} from group #{group['name']}"
get([group["id"]])
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#unuse(args) ⇒ Object
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
|
# File 'lib/morpheus/cli/commands/groups.rb', line 455
def unuse(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage()
opts. = "" +
"This will clear the current active group.\n" +
"You will be prompted for a Group during provisioning."
build_common_options(opts, options, [:quiet, :remote])
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:0)
connect(options.merge({:skip_verify_access_token => true, :skip_login => true}))
exit_code, err = 0, nil
if @active_group_id
::Morpheus::Cli::Groups.clear_active_group(@appliance_name)
print_green_success "Group is no longer active."
return 0, nil
else
print reset,"You are not using any group",reset,"\n"
end
return exit_code, err
end
|
#update(args) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/morpheus/cli/commands/groups.rb', line 244
def update(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name] [options]")
build_option_type_options(opts, options, update_group_option_types())
build_standard_update_options(opts, options)
opts. = "Update a group."
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
begin
group = find_group_by_name_or_id(args[0])
group_payload = {}
params = options[:options] || {}
if params.empty?
raise_command_error "Specify at least one option to update.\n#{optparse}"
end
if params.key?('labels')
params['labels'] = parse_labels(params['labels'])
end
group_payload.merge!(params)
payload = {group: group_payload}
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.update(group['id'], payload)
return
end
json_response = @groups_interface.update(group['id'], payload)
if options[:json]
print JSON.pretty_generate(json_response)
print "\n"
else
get([group["id"]])
end
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#update_wiki(args) ⇒ Object
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
|
# File 'lib/morpheus/cli/commands/groups.rb', line 609
def update_wiki(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[group] [options]")
build_option_type_options(opts, options, update_wiki_page_option_types)
opts.on('--file FILE', "File containing the wiki content. This can be used instead of --content") do |filename|
full_filename = File.expand_path(filename)
if File.exist?(full_filename)
params['content'] = File.read(full_filename)
else
print_red_alert "File not found: #{full_filename}"
return 1
end
if !params['name']
params['name'] = File.basename(full_filename)
end
end
opts.on(nil, '--clear', "Clear current page content") do |val|
params['content'] = ""
end
build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
end
optparse.parse!(args)
if args.count != 1
puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 1 and received #{args.count} #{args.inspect}\n#{optparse}"
return 1
end
connect(options)
begin
group = find_group_by_name_or_id(args[0])
return 1 if group.nil?
passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
payload = nil
if options[:payload]
payload = options[:payload]
payload.deep_merge!({'page' => passed_options}) unless passed_options.empty?
else
payload = {
'page' => {
}
}
payload.deep_merge!({'page' => passed_options}) unless passed_options.empty?
params.deep_merge!(passed_options)
if params.empty?
raise_command_error "Specify at least one option to update.\n#{optparse}"
end
payload.deep_merge!({'page' => params}) unless params.empty?
end
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.update_wiki(group["id"], payload)
return
end
json_response = @groups_interface.update_wiki(group["id"], payload)
if options[:json]
puts as_json(json_response, options)
else
print_green_success "Updated wiki page for group #{group['name']}"
wiki([group['id']])
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#update_wiki_page_option_types ⇒ Object
811
812
813
814
815
816
817
|
# File 'lib/morpheus/cli/commands/groups.rb', line 811
def update_wiki_page_option_types
[
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => false, 'displayOrder' => 1, 'description' => 'The name of the wiki page for this instance. Default is the instance name.'},
{'fieldName' => 'content', 'fieldLabel' => 'Content', 'type' => 'textarea', 'required' => false, 'displayOrder' => 3, 'description' => 'The content (markdown) of the wiki page.'}
]
end
|
#use(args) ⇒ Object
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
# File 'lib/morpheus/cli/commands/groups.rb', line 412
def use(args)
options = {}
optparse = Morpheus::Cli::OptionParser.new do|opts|
opts.banner = subcommand_usage("[name]")
opts. = <<-EOT
This sets the active group.
The active group will be auto-selected for use during provisioning.
[name] is required. This is the name or id of a group.
EOT
build_common_options(opts, options, [:quiet, :remote])
end
optparse.parse!(args)
verify_args!(args:args, optparse:optparse, count:1)
connect(options)
group = find_group_option(args[0]) if !group
raise_command_error "Group not found by name #{args[0]}"
end
exit_code, err = 0, nil
is_already_active = @active_group_id == group['id']
if is_already_active
unless options[:quiet]
print reset,"Already using the group #{group['name']}","\n",reset
end
else
::Morpheus::Cli::Groups.set_active_group(@appliance_name, group['id'])
unless options[:quiet]
print cyan,"Switched active group to #{group['name']}","\n",reset
end
end
if is_already_active
print_green_success "Group #{group['name']} is still active"
else
print_green_success "Group #{group['name']} is now active"
end
return 0
end
|
#view_wiki(args) ⇒ Object
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
|
# File 'lib/morpheus/cli/commands/groups.rb', line 578
def view_wiki(args)
params = {}
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[id]")
build_common_options(opts, options, [:dry_run, :remote])
opts. = "View group wiki page in a web browser" + "\n" +
"[group] is required. This is the name or id of an group."
end
optparse.parse!(args)
if args.count != 1
raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
end
connect(options)
begin
group = find_group_by_name_or_id(args[0])
return 1 if group.nil?
link = "#{@appliance_url}/login/oauth-redirect?access_token=#{@access_token}\\&redirectUri=/infrastructure/groups/#{group['id']}#!wiki"
if options[:dry_run]
puts Morpheus::Util.open_url_command(link)
return 0
end
return Morpheus::Util.open_url(link)
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|
#wiki(args) ⇒ Object
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
# File 'lib/morpheus/cli/commands/groups.rb', line 500
def wiki(args)
options = {}
params = {}
open_wiki_link = false
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[group]")
opts.on('--view', '--view', "View wiki page in web browser.") do
open_wiki_link = true
end
build_common_options(opts, options, [:json, :dry_run, :remote])
opts. = "View wiki page details for an group." + "\n" +
"[group] is required. This is the name or id of an group."
end
optparse.parse!(args)
if args.count != 1
puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 1 and received #{args.count} #{args.inspect}\n#{optparse}"
return 1
end
connect(options)
begin
group = find_group_by_name_or_id(args[0])
return 1 if group.nil?
@groups_interface.setopts(options)
if options[:dry_run]
print_dry_run @groups_interface.dry.wiki(group["id"], params)
return
end
json_response = @groups_interface.wiki(group["id"], params)
page = json_response['page']
render_result = render_with_format(json_response, options, 'page')
return 0 if render_result
if page
print_h1 "Group Wiki Page: #{group['name']}"
print cyan
print_description_list({
"Page ID" => 'id',
"Name" => 'name',
"Created" => lambda {|it| format_local_dt(it['dateCreated']) },
"Created By" => lambda {|it| it['createdBy'] ? it['createdBy']['username'] : '' },
"Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
"Updated By" => lambda {|it| it['updatedBy'] ? it['updatedBy']['username'] : '' }
}, page)
print reset,"\n"
print_h2 "Page Content"
print cyan, page['content'], reset, "\n"
else
print "\n"
print cyan, "No wiki page found.", reset, "\n"
end
print reset,"\n"
if open_wiki_link
return view_wiki([args[0]])
end
return 0
rescue RestClient::Exception => e
print_rest_exception(e, options)
exit 1
end
end
|