morpheus-cli 3.6.8 → 3.6.9
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/account_groups_interface.rb +2 -2
- data/lib/morpheus/api/accounts_interface.rb +4 -7
- data/lib/morpheus/api/api_client.rb +207 -70
- data/lib/morpheus/api/app_templates_interface.rb +7 -28
- data/lib/morpheus/api/apps_interface.rb +14 -21
- data/lib/morpheus/api/archive_buckets_interface.rb +2 -2
- data/lib/morpheus/api/archive_files_interface.rb +6 -6
- data/lib/morpheus/api/auth_interface.rb +14 -1
- data/lib/morpheus/api/blueprints_interface.rb +9 -16
- data/lib/morpheus/api/cloud_datastores_interface.rb +1 -1
- data/lib/morpheus/api/cloud_policies_interface.rb +1 -1
- data/lib/morpheus/api/clouds_interface.rb +18 -21
- data/lib/morpheus/api/cypher_interface.rb +19 -28
- data/lib/morpheus/api/file_copy_request_interface.rb +1 -1
- data/lib/morpheus/api/group_policies_interface.rb +1 -1
- data/lib/morpheus/api/groups_interface.rb +4 -4
- data/lib/morpheus/api/image_builder_boot_scripts_interface.rb +1 -1
- data/lib/morpheus/api/image_builder_image_builds_interface.rb +2 -2
- data/lib/morpheus/api/image_builder_preseed_scripts_interface.rb +1 -1
- data/lib/morpheus/api/instances_interface.rb +17 -23
- data/lib/morpheus/api/logs_interface.rb +7 -10
- data/lib/morpheus/api/network_domains_interface.rb +1 -1
- data/lib/morpheus/api/network_groups_interface.rb +1 -1
- data/lib/morpheus/api/network_pool_servers_interface.rb +1 -1
- data/lib/morpheus/api/network_pools_interface.rb +1 -1
- data/lib/morpheus/api/network_proxies_interface.rb +1 -1
- data/lib/morpheus/api/network_services_interface.rb +1 -1
- data/lib/morpheus/api/networks_interface.rb +1 -1
- data/lib/morpheus/api/old_cypher_interface.rb +55 -0
- data/lib/morpheus/api/packages_interface.rb +1 -1
- data/lib/morpheus/api/policies_interface.rb +1 -1
- data/lib/morpheus/api/setup_interface.rb +1 -1
- data/lib/morpheus/api/storage_providers_interface.rb +1 -1
- data/lib/morpheus/api/whoami_interface.rb +1 -1
- data/lib/morpheus/benchmarking.rb +277 -0
- data/lib/morpheus/cli.rb +6 -22
- data/lib/morpheus/cli/access_token_command.rb +172 -0
- data/lib/morpheus/cli/accounts.rb +5 -0
- data/lib/morpheus/cli/apps.rb +93 -37
- data/lib/morpheus/cli/archives_command.rb +0 -2
- data/lib/morpheus/cli/auth_command.rb +112 -0
- data/lib/morpheus/cli/blueprints_command.rb +50 -13
- data/lib/morpheus/cli/change_password_command.rb +148 -0
- data/lib/morpheus/cli/cli_command.rb +173 -49
- data/lib/morpheus/cli/clouds.rb +15 -5
- data/lib/morpheus/cli/command_error.rb +7 -1
- data/lib/morpheus/cli/{alias_command.rb → commands/standard/alias_command.rb} +79 -51
- data/lib/morpheus/cli/commands/standard/benchmark_command.rb +399 -0
- data/lib/morpheus/cli/commands/standard/coloring_command.rb +60 -0
- data/lib/morpheus/cli/{curl_command.rb → commands/standard/curl_command.rb} +0 -7
- data/lib/morpheus/cli/commands/standard/debug_command.rb +61 -0
- data/lib/morpheus/cli/{echo_command.rb → commands/standard/echo_command.rb} +1 -1
- data/lib/morpheus/cli/{edit_profile_command.rb → commands/standard/edit_profile_command.rb} +0 -0
- data/lib/morpheus/cli/{edit_rc_command.rb → commands/standard/edit_rc_command.rb} +0 -0
- data/lib/morpheus/cli/commands/standard/get_prompt_command.rb +39 -0
- data/lib/morpheus/cli/commands/standard/history_command.rb +76 -0
- data/lib/morpheus/cli/{log_level_command.rb → commands/standard/log_level_command.rb} +1 -1
- data/lib/morpheus/cli/{man_command.rb → commands/standard/man_command.rb} +2 -2
- data/lib/morpheus/cli/commands/standard/rm_command.rb +14 -0
- data/lib/morpheus/cli/commands/standard/set_prompt_command.rb +54 -0
- data/lib/morpheus/cli/{sleep_command.rb → commands/standard/sleep_command.rb} +0 -0
- data/lib/morpheus/cli/{source_command.rb → commands/standard/source_command.rb} +0 -0
- data/lib/morpheus/cli/{ssl_verification_command.rb → commands/standard/ssl_verification_command.rb} +1 -1
- data/lib/morpheus/cli/commands/standard/tee_command.rb +14 -0
- data/lib/morpheus/cli/{version_command.rb → commands/standard/version_command.rb} +0 -0
- data/lib/morpheus/cli/credentials.rb +276 -87
- data/lib/morpheus/cli/cypher_command.rb +333 -214
- data/lib/morpheus/cli/error_handler.rb +12 -2
- data/lib/morpheus/cli/groups.rb +44 -20
- data/lib/morpheus/cli/hosts.rb +39 -16
- data/lib/morpheus/cli/instances.rb +114 -62
- data/lib/morpheus/cli/login.rb +74 -21
- data/lib/morpheus/cli/logout.rb +3 -4
- data/lib/morpheus/cli/mixins/accounts_helper.rb +50 -18
- data/lib/morpheus/cli/mixins/print_helper.rb +207 -42
- data/lib/morpheus/cli/old_cypher_command.rb +414 -0
- data/lib/morpheus/cli/option_parser.rb +6 -1
- data/lib/morpheus/cli/processes_command.rb +3 -0
- data/lib/morpheus/cli/remote.rb +11 -17
- data/lib/morpheus/cli/roles.rb +17 -17
- data/lib/morpheus/cli/security_groups.rb +47 -17
- data/lib/morpheus/cli/shell.rb +139 -79
- data/lib/morpheus/cli/tenants_command.rb +353 -0
- data/lib/morpheus/cli/users.rb +26 -18
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whoami.rb +14 -10
- data/lib/morpheus/formatters.rb +4 -4
- data/lib/morpheus/logging.rb +16 -8
- data/lib/morpheus/terminal.rb +63 -34
- metadata +28 -15
- data/lib/morpheus/cli/coloring_command.rb +0 -45
- data/lib/morpheus/cli/set_prompt_command.rb +0 -51
@@ -696,8 +696,6 @@ class Morpheus::Cli::ArchivesCommand
|
|
696
696
|
print JSON.pretty_generate(json_response)
|
697
697
|
return
|
698
698
|
end
|
699
|
-
# print_h1 "Archive Files"
|
700
|
-
# print_h1 "Archive Files", ["Bucket: [#{archive_bucket['id']}] #{archive_bucket['name']}", "Path: #{search_file_path}"]
|
701
699
|
print_h1 "Archive Files", ["#{archive_bucket['name']}:#{search_file_path}"]
|
702
700
|
print cyan
|
703
701
|
description_cols = {
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'morpheus/cli/cli_command'
|
2
|
+
|
3
|
+
# This provides commands for authentication
|
4
|
+
# This also includes credential management.
|
5
|
+
class Morpheus::Cli::AuthCommand
|
6
|
+
include Morpheus::Cli::CliCommand
|
7
|
+
|
8
|
+
set_command_name :'auth'
|
9
|
+
|
10
|
+
register_subcommands :get
|
11
|
+
# register_subcommands :list # yes plz
|
12
|
+
# register_subcommands :'access-token' => :print_access_token
|
13
|
+
# register_subcommands :'refresh-token' => :print_refresh_token
|
14
|
+
# register_subcommands :'use-refresh-token' => :use_refresh_token
|
15
|
+
register_subcommands :login, :logout
|
16
|
+
register_subcommands :test => :login_test
|
17
|
+
|
18
|
+
|
19
|
+
def initialize()
|
20
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
21
|
+
end
|
22
|
+
|
23
|
+
def connect(options)
|
24
|
+
@api_client = establish_remote_appliance_connection(options.merge({:no_prompt => true, :skip_verify_access_token => true}))
|
25
|
+
# automatically get @appliance_name, @appliance_url, @wallet
|
26
|
+
if !@appliance_name
|
27
|
+
unless options[:quiet]
|
28
|
+
print yellow,"Please specify a Morpheus Appliance with -r or see the command `remote use`#{reset}\n"
|
29
|
+
end
|
30
|
+
return 1
|
31
|
+
end
|
32
|
+
if !@appliance_url
|
33
|
+
unless options[:quiet]
|
34
|
+
print red,"Unable to determine remote appliance url. Review your remote configuration.#{reset}\n"
|
35
|
+
end
|
36
|
+
return 1
|
37
|
+
end
|
38
|
+
#@wallet = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials()
|
39
|
+
if @wallet.nil? || @wallet['access_token'].nil?
|
40
|
+
unless options[:quiet]
|
41
|
+
print_error yellow,"You are not currently logged in to #{display_appliance(@appliance_name, @appliance_url)}",reset,"\n"
|
42
|
+
print_error yellow,"Use the 'login' command.",reset,"\n"
|
43
|
+
end
|
44
|
+
return 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def handle(args)
|
49
|
+
handle_subcommand(args)
|
50
|
+
end
|
51
|
+
|
52
|
+
def get(args)
|
53
|
+
options = {}
|
54
|
+
params = {}
|
55
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
56
|
+
opts.banner = subcommand_usage()
|
57
|
+
build_common_options(opts, options, [:remote, :quiet])
|
58
|
+
opts.footer = "Print your current authentication info.\n" +
|
59
|
+
"This contains tokens that should be kept secret, be careful."
|
60
|
+
end
|
61
|
+
optparse.parse!(args)
|
62
|
+
if args.count != 0
|
63
|
+
raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
|
64
|
+
end
|
65
|
+
connect_result = connect(options)
|
66
|
+
return connect_result if (connect_result.is_a?(Numeric) && connect_result != 0)
|
67
|
+
|
68
|
+
# could fetch and show whoami info as well eh?
|
69
|
+
# extra api call though..
|
70
|
+
|
71
|
+
#print_h1 "Morpheus Credentials", [display_appliance(@appliance_name, @appliance_url)], options
|
72
|
+
print_h1 "Morpheus Credentials", [], options
|
73
|
+
description_cols = {
|
74
|
+
"Remote" => lambda {|wallet| @appliance_name },
|
75
|
+
"Username" => lambda {|wallet| wallet['username'] },
|
76
|
+
"Access Token" => lambda {|wallet| wallet['access_token'] },
|
77
|
+
"Refresh Token" => lambda {|wallet| wallet['refresh_token'] },
|
78
|
+
"Login Date" => lambda {|wallet| format_local_dt(wallet['login_date']) },
|
79
|
+
"Expire Date" => lambda {|wallet| wallet['expire_date'] ? format_local_dt(wallet['expire_date']) : "" },
|
80
|
+
}
|
81
|
+
print cyan
|
82
|
+
puts as_description_list(@wallet, description_cols)
|
83
|
+
print reset
|
84
|
+
return 0
|
85
|
+
end
|
86
|
+
|
87
|
+
# these are all just aliases, heh
|
88
|
+
|
89
|
+
def login(args)
|
90
|
+
::Morpheus::Cli::Login.new.handle(args)
|
91
|
+
end
|
92
|
+
|
93
|
+
def login_test(args)
|
94
|
+
::Morpheus::Cli::Login.new.handle(['--test'] + args)
|
95
|
+
end
|
96
|
+
|
97
|
+
def logout(args)
|
98
|
+
::Morpheus::Cli::Logout.new.handle(args)
|
99
|
+
end
|
100
|
+
|
101
|
+
def print_access_token(args)
|
102
|
+
::Morpheus::Cli::AccessTokenCommand.new.handle(args)
|
103
|
+
end
|
104
|
+
|
105
|
+
def use_refresh_token(args)
|
106
|
+
::Morpheus::Cli::AccessTokenCommand.new.handle(['refresh'] + args)
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
protected
|
111
|
+
|
112
|
+
end
|
@@ -51,7 +51,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
51
51
|
begin
|
52
52
|
params = {}
|
53
53
|
params.merge!(parse_list_options(options))
|
54
|
-
|
54
|
+
@blueprints_interface.setopts(options)
|
55
55
|
if options[:dry_run]
|
56
56
|
print_dry_run @blueprints_interface.dry.list(params)
|
57
57
|
return
|
@@ -111,6 +111,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
111
111
|
connect(options)
|
112
112
|
begin
|
113
113
|
if options[:dry_run]
|
114
|
+
@blueprints_interface.setopts(options)
|
114
115
|
if args[0].to_s =~ /\A\d{1,}\Z/
|
115
116
|
print_dry_run @blueprints_interface.dry.get(args[0].to_i)
|
116
117
|
else
|
@@ -118,6 +119,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
118
119
|
end
|
119
120
|
return
|
120
121
|
end
|
122
|
+
@blueprints_interface.setopts(options)
|
121
123
|
blueprint = find_blueprint_by_name_or_id(args[0])
|
122
124
|
exit 1 if blueprint.nil?
|
123
125
|
|
@@ -218,7 +220,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
218
220
|
#payload = blueprint_payload
|
219
221
|
payload.deep_merge!(params)
|
220
222
|
end
|
221
|
-
|
223
|
+
@blueprints_interface.setopts(options)
|
222
224
|
if options[:dry_run]
|
223
225
|
print_dry_run @blueprints_interface.dry.create(payload)
|
224
226
|
return
|
@@ -292,7 +294,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
292
294
|
return 1
|
293
295
|
end
|
294
296
|
end
|
295
|
-
|
297
|
+
@blueprints_interface.setopts(options)
|
296
298
|
if options[:dry_run]
|
297
299
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
298
300
|
return
|
@@ -396,7 +398,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
396
398
|
payload['blueprint']['visibility'] = options['visibility']
|
397
399
|
end
|
398
400
|
end
|
399
|
-
|
401
|
+
@blueprints_interface.setopts(options)
|
400
402
|
if options[:dry_run]
|
401
403
|
print_dry_run @blueprints_interface.dry.update_permissions(blueprint['id'], payload)
|
402
404
|
return
|
@@ -454,6 +456,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
454
456
|
begin
|
455
457
|
blueprint = find_blueprint_by_name_or_id(blueprint_name)
|
456
458
|
exit 1 if blueprint.nil?
|
459
|
+
@blueprints_interface.setopts(options)
|
457
460
|
if options[:dry_run]
|
458
461
|
print_dry_run @blueprints_interface.dry.save_image(blueprint['id'], image_file)
|
459
462
|
return 0
|
@@ -505,6 +508,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
505
508
|
# unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to duplicate the blueprint #{blueprint['name']}?")
|
506
509
|
# exit
|
507
510
|
# end
|
511
|
+
@blueprints_interface.setopts(options)
|
508
512
|
if options[:dry_run]
|
509
513
|
print_dry_run @blueprints_interface.dry.duplicate(blueprint['id'], payload)
|
510
514
|
return
|
@@ -548,6 +552,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
548
552
|
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the blueprint #{blueprint['name']}?")
|
549
553
|
exit
|
550
554
|
end
|
555
|
+
@blueprints_interface.setopts(options)
|
551
556
|
if options[:dry_run]
|
552
557
|
print_dry_run @blueprints_interface.dry.destroy(blueprint['id'])
|
553
558
|
return
|
@@ -659,7 +664,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
659
664
|
# ok, make api request
|
660
665
|
blueprint["config"]["tiers"] = tiers
|
661
666
|
payload = {blueprint: blueprint}
|
662
|
-
|
667
|
+
@blueprints_interface.setopts(options)
|
663
668
|
if options[:dry_run]
|
664
669
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
665
670
|
return 0
|
@@ -817,7 +822,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
817
822
|
# ok, make api request
|
818
823
|
blueprint["config"]["tiers"] = tiers
|
819
824
|
payload = {blueprint: blueprint}
|
820
|
-
|
825
|
+
@blueprints_interface.setopts(options)
|
821
826
|
if options[:dry_run]
|
822
827
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
823
828
|
return 0
|
@@ -1001,7 +1006,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1001
1006
|
# ok, make api request
|
1002
1007
|
blueprint["config"]["tiers"] = tiers
|
1003
1008
|
payload = {blueprint: blueprint}
|
1004
|
-
|
1009
|
+
@blueprints_interface.setopts(options)
|
1005
1010
|
if options[:dry_run]
|
1006
1011
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1007
1012
|
return
|
@@ -1123,7 +1128,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1123
1128
|
# ok, make api request
|
1124
1129
|
blueprint["config"]["tiers"] = tiers
|
1125
1130
|
payload = {blueprint: blueprint}
|
1126
|
-
|
1131
|
+
@blueprints_interface.setopts(options)
|
1127
1132
|
if options[:dry_run]
|
1128
1133
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1129
1134
|
return
|
@@ -1250,7 +1255,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1250
1255
|
blueprint["config"]["tiers"] = tiers
|
1251
1256
|
payload = blueprint["config"]
|
1252
1257
|
# payload = {blueprint: blueprint}
|
1253
|
-
|
1258
|
+
@blueprints_interface.setopts(options)
|
1254
1259
|
if options[:dry_run]
|
1255
1260
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1256
1261
|
return
|
@@ -1409,7 +1414,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1409
1414
|
blueprint["config"]["tiers"] = tiers
|
1410
1415
|
payload = blueprint["config"]
|
1411
1416
|
# payload = {blueprint: blueprint}
|
1412
|
-
|
1417
|
+
@blueprints_interface.setopts(options)
|
1413
1418
|
if options[:dry_run]
|
1414
1419
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1415
1420
|
return
|
@@ -1473,7 +1478,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1473
1478
|
blueprint["config"]["tiers"] = tiers
|
1474
1479
|
payload = blueprint["config"]
|
1475
1480
|
# payload = {blueprint: blueprint}
|
1476
|
-
|
1481
|
+
@blueprints_interface.setopts(options)
|
1477
1482
|
if options[:dry_run]
|
1478
1483
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1479
1484
|
return
|
@@ -1572,7 +1577,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1572
1577
|
blueprint["config"]["tiers"] = tiers
|
1573
1578
|
payload = blueprint["config"]
|
1574
1579
|
# payload = {blueprint: blueprint}
|
1575
|
-
|
1580
|
+
@blueprints_interface.setopts(options)
|
1576
1581
|
if options[:dry_run]
|
1577
1582
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1578
1583
|
return
|
@@ -1662,7 +1667,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1662
1667
|
blueprint["config"]["tiers"] = tiers
|
1663
1668
|
payload = blueprint["config"]
|
1664
1669
|
# payload = {blueprint: blueprint}
|
1665
|
-
|
1670
|
+
@blueprints_interface.setopts(options)
|
1666
1671
|
if options[:dry_run]
|
1667
1672
|
print_dry_run @blueprints_interface.dry.update(blueprint['id'], payload)
|
1668
1673
|
return
|
@@ -1695,6 +1700,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1695
1700
|
params = {}
|
1696
1701
|
|
1697
1702
|
begin
|
1703
|
+
@blueprints_interface.setopts(options)
|
1698
1704
|
if options[:dry_run]
|
1699
1705
|
print_dry_run @blueprints_interface.dry.list_tiers(params)
|
1700
1706
|
return
|
@@ -1745,6 +1751,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1745
1751
|
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
1746
1752
|
params[k] = options[k] unless options[k].nil?
|
1747
1753
|
end
|
1754
|
+
@blueprints_interface.setopts(options)
|
1748
1755
|
if options[:dry_run]
|
1749
1756
|
print_dry_run @blueprints_interface.dry.list_types(params)
|
1750
1757
|
return
|
@@ -1995,6 +2002,35 @@ class Morpheus::Cli::BlueprintsCommand
|
|
1995
2002
|
"Category" => 'category',
|
1996
2003
|
"Image" => lambda {|it| it['config'] ? (it['config']['image'] == '/assets/apps/template.png' ? '(default)' : it['config']['image']) : '' },
|
1997
2004
|
"Visibility" => 'visibility',
|
2005
|
+
"Tiers" => lambda {|it|
|
2006
|
+
tiers = []
|
2007
|
+
if blueprint["config"]["tiers"].is_a?(Hash)
|
2008
|
+
tiers = blueprint["config"]["tiers"].keys
|
2009
|
+
end
|
2010
|
+
"#{tiers.collect {|it| it.is_a?(Hash) ? it['name'] : it }.join(',')}"
|
2011
|
+
},
|
2012
|
+
"Instances" => lambda {|it|
|
2013
|
+
instances = []
|
2014
|
+
tiers = {}
|
2015
|
+
if blueprint["config"]["tiers"].is_a?(Hash)
|
2016
|
+
tiers = blueprint["config"]["tiers"]
|
2017
|
+
end
|
2018
|
+
sorted_tiers = tiers.collect {|k,v| [k,v] }.sort {|a,b| a[1]['tierIndex'] <=> b[1]['tierIndex'] }
|
2019
|
+
sorted_tiers.each do |tier_obj|
|
2020
|
+
tier_name = tier_obj[0]
|
2021
|
+
tier_config = tier_obj[1]
|
2022
|
+
if tier_config && tier_config['instances']
|
2023
|
+
tier_config['instances'].each_with_index do |instance_config, instance_index|
|
2024
|
+
instances << instance_config
|
2025
|
+
end
|
2026
|
+
end
|
2027
|
+
end
|
2028
|
+
#"(#{instances.count})"
|
2029
|
+
"(#{instances.count}) #{instances.collect {|it| it['instance'] ? it['instance']['type'] : (it['type'] || it['name']) }.join(',')}"
|
2030
|
+
},
|
2031
|
+
# "Containers" => lambda {|it|
|
2032
|
+
# i wish
|
2033
|
+
# },
|
1998
2034
|
"Group Access" => lambda {|it|
|
1999
2035
|
group_access_str = ""
|
2000
2036
|
begin
|
@@ -2018,6 +2054,7 @@ class Morpheus::Cli::BlueprintsCommand
|
|
2018
2054
|
group_access_str
|
2019
2055
|
}
|
2020
2056
|
}
|
2057
|
+
|
2021
2058
|
print_description_list(description_cols, blueprint)
|
2022
2059
|
# print_h2 "Tiers"
|
2023
2060
|
if blueprint["config"] && blueprint["config"]["tiers"] && blueprint["config"]["tiers"].keys.size != 0
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# require 'yaml'
|
2
|
+
require 'io/console'
|
3
|
+
require 'rest_client'
|
4
|
+
require 'optparse'
|
5
|
+
require 'morpheus/cli/cli_command'
|
6
|
+
require 'morpheus/cli/option_types'
|
7
|
+
require 'morpheus/cli/mixins/accounts_helper'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
class Morpheus::Cli::ChangePasswordCommand
|
11
|
+
include Morpheus::Cli::CliCommand
|
12
|
+
include Morpheus::Cli::AccountsHelper
|
13
|
+
|
14
|
+
set_command_name :passwd
|
15
|
+
|
16
|
+
def initialize()
|
17
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
18
|
+
end
|
19
|
+
|
20
|
+
def connect(opts)
|
21
|
+
@api_client = establish_remote_appliance_connection(opts)
|
22
|
+
@whoami_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).whoami
|
23
|
+
@users_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).users
|
24
|
+
@accounts_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).accounts
|
25
|
+
@roles_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).roles
|
26
|
+
end
|
27
|
+
|
28
|
+
def handle(args)
|
29
|
+
change_password(args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def change_password(args)
|
33
|
+
options = {}
|
34
|
+
username = nil
|
35
|
+
new_password = nil
|
36
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
37
|
+
opts.banner = subcommand_usage("[username] [options]")
|
38
|
+
opts.on('--username USERNAME', String, "Username. Default is your own.") do |val|
|
39
|
+
username = val
|
40
|
+
end
|
41
|
+
opts.on('--password VALUE', String, "New password") do |val|
|
42
|
+
new_password = val
|
43
|
+
end
|
44
|
+
build_common_options(opts, options, [:account, :options, :json, :dry_run, :remote, :quiet, :auto_confirm], [:username,:password])
|
45
|
+
opts.footer = "Change your password or the password of another user.\n" +
|
46
|
+
"[username] is optional. This is the username of the user to update. Default is your own.\n" +
|
47
|
+
"Be careful with this command, the default behavior is to update your own password."
|
48
|
+
end
|
49
|
+
optparse.parse!(args)
|
50
|
+
|
51
|
+
if args.count > 1
|
52
|
+
print_error Morpheus::Terminal.angry_prompt
|
53
|
+
puts_error "wrong number of arguments, expected 0-1 and got #{args.count} #{args}\n#{optparse}"
|
54
|
+
return 1
|
55
|
+
end
|
56
|
+
|
57
|
+
connect(options)
|
58
|
+
@current_remote = @appliance_name ? ::Morpheus::Cli::Remote.load_remote(@appliance_name) : ::Morpheus::Cli::Remote.load_active_remote()
|
59
|
+
puts "args is #{args}"
|
60
|
+
begin
|
61
|
+
if args[0]
|
62
|
+
username = args[0]
|
63
|
+
end
|
64
|
+
if username.nil?
|
65
|
+
if !@current_remote
|
66
|
+
raise_command_error "No current appliance, see `remote use`."
|
67
|
+
end
|
68
|
+
if !@current_remote[:username]
|
69
|
+
raise_command_error "You are not currently logged in to #{@current_remote[:name]} - #{@current_remote[:url] || @current_remote[:host]}"
|
70
|
+
end
|
71
|
+
username = @current_remote[:username]
|
72
|
+
end
|
73
|
+
|
74
|
+
account = find_account_from_options(options)
|
75
|
+
account_id = account ? account['id'] : nil
|
76
|
+
|
77
|
+
user = find_user_by_username_or_id(account_id, username)
|
78
|
+
return 1 if user.nil?
|
79
|
+
|
80
|
+
if @current_remote && @current_remote[:username] == username
|
81
|
+
if !options[:quiet]
|
82
|
+
if options[:dry_run]
|
83
|
+
print cyan,bold, "DRY RUN. This is just a dry run, the password is not being updated.",reset,"\n"
|
84
|
+
else
|
85
|
+
print cyan,bold, "WARNING! You are about to update your own password!",reset,"\n"
|
86
|
+
print yellow,bold,"WARNING! You are about to update your own password!",reset,"\n"
|
87
|
+
print reset,bold, "WARNING! You are about to update your own password!",reset,"\n"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
if !options[:quiet]
|
93
|
+
print cyan, "Changing password for #{user['username']}", reset, "\n"
|
94
|
+
end
|
95
|
+
|
96
|
+
if new_password.nil? && options[:options]['password']
|
97
|
+
new_password = options[:options]['password']
|
98
|
+
end
|
99
|
+
if new_password.nil?
|
100
|
+
password_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'password', 'fieldLabel' => 'New Password', 'type' => 'password', 'required' => true}], options[:options], @api_client)
|
101
|
+
new_password = password_prompt['password']
|
102
|
+
confirm_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'passwordConfirmation', 'fieldLabel' => 'Confirm Password', 'type' => 'password', 'required' => true}], options[:options], @api_client)
|
103
|
+
confirm_password = confirm_prompt['passwordConfirmation']
|
104
|
+
if confirm_password != new_password
|
105
|
+
print_red_alert "Confirm password did not match."
|
106
|
+
return 1
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
if new_password.nil? || new_password.empty?
|
111
|
+
print_red_alert "A new password is required"
|
112
|
+
return 1
|
113
|
+
end
|
114
|
+
|
115
|
+
payload = {
|
116
|
+
'user' => {
|
117
|
+
'password' => new_password
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
if options[:dry_run]
|
122
|
+
print_dry_run @users_interface.dry.update(account_id, user['id'], payload)
|
123
|
+
return 0
|
124
|
+
end
|
125
|
+
|
126
|
+
unless options[:yes]
|
127
|
+
unless ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to update the password for user #{user['username']}?", options)
|
128
|
+
return 9, "aborted command"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
json_response = @users_interface.update(account_id, user['id'], payload)
|
133
|
+
if options[:json]
|
134
|
+
puts as_json(json_response)
|
135
|
+
elsif !options[:quiet]
|
136
|
+
print_green_success "Updated password for user #{user['username']}"
|
137
|
+
end
|
138
|
+
return 0
|
139
|
+
rescue RestClient::Exception => e
|
140
|
+
print_rest_exception(e, options)
|
141
|
+
return 1
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
|
148
|
+
end
|