morpheus-cli 2.10.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/morpheus +27 -32
- data/lib/morpheus/api/accounts_interface.rb +36 -47
- data/lib/morpheus/api/api_client.rb +141 -110
- data/lib/morpheus/api/app_templates_interface.rb +56 -72
- data/lib/morpheus/api/apps_interface.rb +111 -132
- data/lib/morpheus/api/auth_interface.rb +30 -0
- data/lib/morpheus/api/clouds_interface.rb +71 -76
- data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
- data/lib/morpheus/api/dashboard_interface.rb +10 -17
- data/lib/morpheus/api/deploy_interface.rb +60 -72
- data/lib/morpheus/api/deployments_interface.rb +53 -71
- data/lib/morpheus/api/groups_interface.rb +55 -45
- data/lib/morpheus/api/instance_types_interface.rb +19 -23
- data/lib/morpheus/api/instances_interface.rb +179 -177
- data/lib/morpheus/api/key_pairs_interface.rb +11 -17
- data/lib/morpheus/api/license_interface.rb +18 -23
- data/lib/morpheus/api/load_balancers_interface.rb +54 -69
- data/lib/morpheus/api/logs_interface.rb +25 -29
- data/lib/morpheus/api/options_interface.rb +13 -17
- data/lib/morpheus/api/provision_types_interface.rb +19 -22
- data/lib/morpheus/api/roles_interface.rb +75 -94
- data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
- data/lib/morpheus/api/security_groups_interface.rb +39 -51
- data/lib/morpheus/api/servers_interface.rb +113 -115
- data/lib/morpheus/api/setup_interface.rb +31 -0
- data/lib/morpheus/api/task_sets_interface.rb +36 -38
- data/lib/morpheus/api/tasks_interface.rb +56 -69
- data/lib/morpheus/api/users_interface.rb +67 -76
- data/lib/morpheus/api/virtual_images_interface.rb +61 -61
- data/lib/morpheus/api/whoami_interface.rb +12 -15
- data/lib/morpheus/cli.rb +71 -60
- data/lib/morpheus/cli/accounts.rb +254 -315
- data/lib/morpheus/cli/alias_command.rb +219 -0
- data/lib/morpheus/cli/app_templates.rb +264 -272
- data/lib/morpheus/cli/apps.rb +608 -671
- data/lib/morpheus/cli/cli_command.rb +259 -21
- data/lib/morpheus/cli/cli_registry.rb +99 -14
- data/lib/morpheus/cli/clouds.rb +599 -372
- data/lib/morpheus/cli/config_file.rb +126 -0
- data/lib/morpheus/cli/credentials.rb +141 -117
- data/lib/morpheus/cli/dashboard_command.rb +48 -56
- data/lib/morpheus/cli/deployments.rb +254 -268
- data/lib/morpheus/cli/deploys.rb +150 -142
- data/lib/morpheus/cli/error_handler.rb +38 -0
- data/lib/morpheus/cli/groups.rb +551 -179
- data/lib/morpheus/cli/hosts.rb +862 -617
- data/lib/morpheus/cli/instance_types.rb +103 -95
- data/lib/morpheus/cli/instances.rb +1335 -1009
- data/lib/morpheus/cli/key_pairs.rb +82 -90
- data/lib/morpheus/cli/library.rb +498 -499
- data/lib/morpheus/cli/license.rb +83 -101
- data/lib/morpheus/cli/load_balancers.rb +314 -300
- data/lib/morpheus/cli/login.rb +66 -44
- data/lib/morpheus/cli/logout.rb +47 -46
- data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
- data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
- data/lib/morpheus/cli/option_parser.rb +35 -0
- data/lib/morpheus/cli/option_types.rb +232 -192
- data/lib/morpheus/cli/recent_activity_command.rb +61 -65
- data/lib/morpheus/cli/remote.rb +446 -199
- data/lib/morpheus/cli/roles.rb +884 -906
- data/lib/morpheus/cli/security_group_rules.rb +213 -203
- data/lib/morpheus/cli/security_groups.rb +237 -192
- data/lib/morpheus/cli/shell.rb +338 -231
- data/lib/morpheus/cli/tasks.rb +326 -308
- data/lib/morpheus/cli/users.rb +457 -462
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/version_command.rb +16 -18
- data/lib/morpheus/cli/virtual_images.rb +526 -345
- data/lib/morpheus/cli/whoami.rb +125 -111
- data/lib/morpheus/cli/workflows.rb +338 -185
- data/lib/morpheus/formatters.rb +8 -1
- data/lib/morpheus/logging.rb +1 -1
- data/lib/morpheus/rest_client.rb +17 -8
- metadata +9 -3
- data/lib/morpheus/api/custom_instance_types.rb +0 -55
data/lib/morpheus/cli/license.rb
CHANGED
@@ -5,112 +5,94 @@ require 'table_print'
|
|
5
5
|
require 'morpheus/cli/cli_command'
|
6
6
|
|
7
7
|
class Morpheus::Cli::License
|
8
|
-
|
8
|
+
include Morpheus::Cli::CliCommand
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
10
|
+
register_subcommands :get, :apply
|
11
|
+
alias_subcommand :details, :get
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@appliance_name = opts[:remote]
|
18
|
-
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
19
|
-
else
|
20
|
-
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
21
|
-
end
|
22
|
-
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
23
|
-
@license_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).license
|
24
|
-
|
25
|
-
if @access_token.empty?
|
26
|
-
print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
|
27
|
-
exit 1
|
28
|
-
end
|
29
|
-
end
|
13
|
+
def initialize()
|
14
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
15
|
+
end
|
30
16
|
|
17
|
+
def connect(opts)
|
18
|
+
@api_client = establish_remote_appliance_connection(opts)
|
19
|
+
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
20
|
+
@license_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).license
|
21
|
+
end
|
31
22
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
return
|
36
|
-
end
|
23
|
+
def handle(args)
|
24
|
+
handle_subcommand(args)
|
25
|
+
end
|
37
26
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
27
|
+
def get(args)
|
28
|
+
options = {}
|
29
|
+
optparse = OptionParser.new do|opts|
|
30
|
+
opts.banner = subcommand_usage()
|
31
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
32
|
+
end
|
33
|
+
optparse.parse!(args)
|
34
|
+
connect(options)
|
35
|
+
begin
|
36
|
+
if options[:dry_run]
|
37
|
+
print_dry_run @license_interface.dry.get()
|
38
|
+
return
|
39
|
+
end
|
40
|
+
license = @license_interface.get()
|
41
|
+
if options[:json]
|
42
|
+
puts JSON.pretty_generate(license)
|
43
|
+
else
|
44
|
+
if license['license'].nil?
|
45
|
+
puts "No License Currently Applied to the appliance."
|
46
|
+
exit 1
|
47
|
+
else
|
48
|
+
print "\n", cyan, "License\n=======\n"
|
49
|
+
max_memory = Filesize.from("#{license['license']['maxMemory']} B").pretty
|
50
|
+
max_storage = Filesize.from("#{license['license']['maxStorage']} B").pretty
|
51
|
+
used_memory = Filesize.from("#{license['usedMemory']} B").pretty
|
52
|
+
puts "Account: #{license['license']['accountName']}"
|
53
|
+
puts "Start Date: #{license['license']['startDate']}"
|
54
|
+
puts "End Date: #{license['license']['endDate']}"
|
55
|
+
puts "Memory: #{used_memory} / #{max_memory}"
|
56
|
+
puts "Max Storage: #{max_storage}"
|
57
|
+
end
|
58
|
+
print reset,"\n"
|
59
|
+
end
|
60
|
+
rescue RestClient::Exception => e
|
61
|
+
print_rest_exception(e, options)
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
end
|
48
65
|
|
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
|
-
rescue RestClient::Exception => e
|
81
|
-
print_rest_exception(e, options)
|
82
|
-
exit 1
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def apply(args)
|
87
|
-
key = args[0]
|
88
|
-
options = {}
|
89
|
-
account_name = nil
|
90
|
-
optparse = OptionParser.new do|opts|
|
91
|
-
opts.banner = "Usage: morpheus license apply [key]"
|
92
|
-
build_common_options(opts, options, [:json, :remote])
|
93
|
-
end
|
94
|
-
if args.count < 1
|
95
|
-
puts "\n#{optparse.banner}\n\n"
|
96
|
-
exit 1
|
97
|
-
end
|
98
|
-
optparse.parse(args)
|
99
|
-
|
100
|
-
connect(options)
|
101
|
-
|
102
|
-
begin
|
103
|
-
license_results = @license_interface.apply(key)
|
104
|
-
|
105
|
-
if options[:json]
|
106
|
-
puts JSON.pretty_generate(license_results)
|
107
|
-
else
|
108
|
-
puts "License applied successfully!"
|
109
|
-
end
|
110
|
-
rescue RestClient::Exception => e
|
111
|
-
print_rest_exception(e, options)
|
112
|
-
exit 1
|
113
|
-
end
|
114
|
-
end
|
66
|
+
def apply(args)
|
67
|
+
options = {}
|
68
|
+
account_name = nil
|
69
|
+
optparse = OptionParser.new do|opts|
|
70
|
+
opts.banner = subcommand_usage("[key]")
|
71
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
72
|
+
end
|
73
|
+
optparse.parse!(args)
|
74
|
+
connect(options)
|
75
|
+
begin
|
76
|
+
if args[0]
|
77
|
+
key = args[0]
|
78
|
+
else
|
79
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'licenseKey', 'fieldLabel' => 'License Key', 'type' => 'text', 'required' => true}], options[:options])
|
80
|
+
instance_name = v_prompt['licenseKey'] || ''
|
81
|
+
end
|
82
|
+
if options[:dry_run]
|
83
|
+
print_dry_run @license_interface.dry.apply(key)
|
84
|
+
return
|
85
|
+
end
|
86
|
+
license_results = @license_interface.apply(key)
|
87
|
+
if options[:json]
|
88
|
+
puts JSON.pretty_generate(license_results)
|
89
|
+
else
|
90
|
+
puts "License applied successfully!"
|
91
|
+
end
|
92
|
+
rescue RestClient::Exception => e
|
93
|
+
print_rest_exception(e, options)
|
94
|
+
return false
|
95
|
+
end
|
96
|
+
end
|
115
97
|
|
116
98
|
end
|
@@ -6,331 +6,345 @@ require 'table_print'
|
|
6
6
|
require 'morpheus/cli/cli_command'
|
7
7
|
|
8
8
|
class Morpheus::Cli::LoadBalancers
|
9
|
-
|
9
|
+
include Morpheus::Cli::CliCommand
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
end
|
11
|
+
register_subcommands :list, :get, :add, :update, :remove, {:types => :lb_types}
|
12
|
+
alias_subcommand :details, :get
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@appliance_name = opts[:remote]
|
19
|
-
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
20
|
-
else
|
21
|
-
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
22
|
-
end
|
23
|
-
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
24
|
-
@load_balancers_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).load_balancers
|
25
|
-
|
26
|
-
if @access_token.empty?
|
27
|
-
print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
|
28
|
-
exit 1
|
29
|
-
end
|
30
|
-
end
|
14
|
+
def initialize()
|
15
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
16
|
+
end
|
31
17
|
|
18
|
+
def connect(opts)
|
19
|
+
@api_client = establish_remote_appliance_connection(opts)
|
20
|
+
@load_balancers_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).load_balancers
|
21
|
+
end
|
32
22
|
|
33
|
-
def handle(args)
|
34
|
-
if args.empty?
|
35
|
-
puts "\nUsage: morpheus load-balancers [list,add, update,remove, details, lb-types]\n\n"
|
36
|
-
return
|
37
|
-
end
|
38
23
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when 'add'
|
43
|
-
add(args[1..-1])
|
44
|
-
when 'update'
|
45
|
-
# update(args[1..-1])
|
46
|
-
when 'details'
|
47
|
-
details(args[1..-1])
|
48
|
-
when 'remove'
|
49
|
-
remove(args[1..-1])
|
50
|
-
when 'lb-types'
|
51
|
-
lb_types(args[1..-1])
|
52
|
-
else
|
53
|
-
puts "\nUsage: morpheus load-balancers [list,add, update,remove, details, lb-types]\n\n"
|
54
|
-
exit 127
|
55
|
-
end
|
56
|
-
end
|
24
|
+
def handle(args)
|
25
|
+
handle_subcommand(args)
|
26
|
+
end
|
57
27
|
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
28
|
+
def list(args)
|
29
|
+
options = {}
|
30
|
+
optparse = OptionParser.new do|opts|
|
31
|
+
opts.banner = subcommand_usage()
|
32
|
+
build_common_options(opts, options, [:list, :json, :dry_run, :remote])
|
33
|
+
end
|
34
|
+
optparse.parse!(args)
|
35
|
+
connect(options)
|
36
|
+
begin
|
37
|
+
params = {}
|
38
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
39
|
+
params[k] = options[k] unless options[k].nil?
|
40
|
+
end
|
41
|
+
if options[:dry_run]
|
42
|
+
print_dry_run @load_balancers_interface.dry.get(params)
|
43
|
+
return
|
44
|
+
end
|
45
|
+
json_response = @load_balancers_interface.get(params)
|
46
|
+
if options[:json]
|
47
|
+
print JSON.pretty_generate(json_response)
|
48
|
+
else
|
49
|
+
lbs = json_response['loadBalancers']
|
50
|
+
print "\n" ,cyan, bold, "Morpheus Load Balancers\n","==================", reset, "\n\n"
|
51
|
+
if lbs.empty?
|
52
|
+
puts yellow,"No load balancers currently configured.",reset
|
53
|
+
else
|
54
|
+
print cyan
|
55
|
+
lb_table_data = lbs.collect do |lb|
|
56
|
+
{name: lb['name'], id: lb['id'], type: lb['type']['name']}
|
57
|
+
end
|
58
|
+
tp lb_table_data, :id, :name, :type
|
59
|
+
end
|
60
|
+
print reset,"\n"
|
61
|
+
end
|
62
|
+
rescue RestClient::Exception => e
|
63
|
+
print_rest_exception(e, options)
|
64
|
+
exit 1
|
65
|
+
end
|
66
|
+
end
|
95
67
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
68
|
+
def get(args)
|
69
|
+
options = {}
|
70
|
+
optparse = OptionParser.new do|opts|
|
71
|
+
opts.banner = subcommand_usage("[name]")
|
72
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
73
|
+
end
|
74
|
+
optparse.parse!(args)
|
75
|
+
if args.count < 1
|
76
|
+
puts optparse
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
lb_name = args[0]
|
80
|
+
connect(options)
|
81
|
+
begin
|
82
|
+
if options[:dry_run]
|
83
|
+
if lb_name.to_s =~ /\A\d{1,}\Z/
|
84
|
+
print_dry_run @load_balancers_interface.dry.get(lb_name.to_i)
|
85
|
+
else
|
86
|
+
print_dry_run @load_balancers_interface.dry.get({name:lb_name})
|
87
|
+
end
|
88
|
+
return
|
89
|
+
end
|
90
|
+
lb = find_lb_by_name_or_id(lb_name)
|
91
|
+
exit 1 if lb.nil?
|
92
|
+
lb_type = load_balancer_type_for_name_or_id(lb['type']['code'])
|
93
|
+
if options[:json]
|
94
|
+
puts JSON.pretty_generate({loadBalancer: lb})
|
95
|
+
else
|
96
|
+
print "\n", cyan, "Lb #{lb['name']} - #{lb['type']['name']}\n\n"
|
97
|
+
# lb_type['optionTypes'].sort { |x,y| x['displayOrder'].to_i <=> y['displayOrder'].to_i }.each do |optionType|
|
98
|
+
# puts " #{optionType['fieldLabel']} : " + (optionType['type'] == 'password' ? "#{task['taskOptions'][optionType['fieldName']] ? '************' : ''}" : "#{task['taskOptions'][optionType['fieldName']] || optionType['defaultValue']}")
|
99
|
+
# end
|
100
|
+
print reset,"\n\n"
|
101
|
+
end
|
102
|
+
rescue RestClient::Exception => e
|
103
|
+
print_rest_exception(e, options)
|
104
|
+
exit 1
|
105
|
+
end
|
106
|
+
end
|
111
107
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
108
|
+
def update(args)
|
109
|
+
lb_name = args[0]
|
110
|
+
options = {}
|
111
|
+
account_name = nil
|
112
|
+
optparse = OptionParser.new do|opts|
|
113
|
+
opts.banner = subcommand_usage("[name] [options]")
|
114
|
+
build_common_options(opts, options, [:options, :json, :dry_run, :remote])
|
115
|
+
end
|
116
|
+
optparse.parse!(args)
|
117
|
+
if args.count < 1
|
118
|
+
puts optparse
|
119
|
+
exit 1
|
120
|
+
end
|
121
|
+
connect(options)
|
122
|
+
begin
|
128
123
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
account_name = nil
|
133
|
-
optparse = OptionParser.new do|opts|
|
134
|
-
opts.banner = "Usage: morpheus tasks update [task] [options]"
|
135
|
-
build_common_options(opts, options, [:options, :json, :remote])
|
136
|
-
end
|
137
|
-
if args.count < 1
|
138
|
-
puts "\n#{optparse.banner}\n\n"
|
139
|
-
exit 1
|
140
|
-
end
|
141
|
-
optparse.parse(args)
|
124
|
+
lb = find_lb_by_name_or_id(lb_name)
|
125
|
+
exit 1 if lb.nil?
|
126
|
+
lb_type = load_balancer_type_for_name_or_id(lb['type']['code'])
|
142
127
|
|
143
|
-
|
144
|
-
|
145
|
-
begin
|
128
|
+
#params = Morpheus::Cli::OptionTypes.prompt(add_load_balancer_option_types, options[:options], @api_client, options[:params]) # options[:params] is mysterious
|
129
|
+
params = options[:options] || {}
|
146
130
|
|
131
|
+
if params.empty?
|
132
|
+
puts optparse
|
133
|
+
option_lines = update_task_option_types(lb_type).collect {|it| "\t-O #{it['fieldContext'] ? (it['fieldContext'] + '.') : ''}#{it['fieldName']}=\"value\"" }.join("\n")
|
134
|
+
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
135
|
+
exit 1
|
136
|
+
end
|
147
137
|
|
148
|
-
|
149
|
-
|
150
|
-
|
138
|
+
# todo: fix this...
|
139
|
+
#puts "parsed params is : #{params.inspect}"
|
140
|
+
lb_keys = ['name']
|
141
|
+
changes_payload = (params.select {|k,v| task_keys.include?(k) })
|
142
|
+
task_payload = task
|
143
|
+
if changes_payload
|
144
|
+
task_payload.merge!(changes_payload)
|
145
|
+
end
|
146
|
+
puts params
|
147
|
+
if params['taskOptions']
|
148
|
+
task_payload['taskOptions'].merge!(params['taskOptions'])
|
149
|
+
end
|
150
|
+
payload = {task: task_payload}
|
151
|
+
if options[:dry_run]
|
152
|
+
print_dry_run @load_balancers_interface.dry.update(task['id'], payload)
|
153
|
+
return
|
154
|
+
end
|
155
|
+
response = @load_balancers_interface.update(task['id'], payload)
|
156
|
+
if options[:json]
|
157
|
+
print JSON.pretty_generate(json_response)
|
158
|
+
if !response['success']
|
159
|
+
exit 1
|
160
|
+
end
|
161
|
+
else
|
162
|
+
print "\n", cyan, "Task #{response['task']['name']} updated", reset, "\n\n"
|
163
|
+
end
|
164
|
+
rescue RestClient::Exception => e
|
165
|
+
print_rest_exception(e, options)
|
166
|
+
exit 1
|
167
|
+
end
|
168
|
+
end
|
151
169
|
|
152
|
-
#params = Morpheus::Cli::OptionTypes.prompt(add_user_option_types, options[:options], @api_client, options[:params]) # options[:params] is mysterious
|
153
|
-
params = options[:options] || {}
|
154
170
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
171
|
+
def lb_types(args)
|
172
|
+
options = {}
|
173
|
+
optparse = OptionParser.new do|opts|
|
174
|
+
opts.banner = subcommand_usage()
|
175
|
+
build_common_options(opts, options, [:json, :dry_run, :remote])
|
176
|
+
end
|
177
|
+
optparse.parse!(args)
|
178
|
+
connect(options)
|
179
|
+
begin
|
180
|
+
if options[:dry_run]
|
181
|
+
print_dry_run @load_balancers_interface.dry.load_balancer_types()
|
182
|
+
return
|
183
|
+
end
|
184
|
+
json_response = @load_balancers_interface.load_balancer_types()
|
185
|
+
if options[:json]
|
186
|
+
print JSON.pretty_generate(json_response)
|
187
|
+
else
|
188
|
+
lb_types = json_response['loadBalancerTypes']
|
189
|
+
print "\n" ,cyan, bold, "Morpheus Load Balancer Types\n","============================", reset, "\n\n"
|
190
|
+
if lb_types.nil? || lb_types.empty?
|
191
|
+
puts yellow,"No lb types currently exist on this appliance. This could be a seed issue.",reset
|
192
|
+
else
|
193
|
+
print cyan
|
194
|
+
lb_table_data = lb_types.collect do |lb_type|
|
195
|
+
{name: lb_type['name'], id: lb_type['id'], code: lb_type['code']}
|
196
|
+
end
|
197
|
+
tp lb_table_data, :id, :name, :code
|
198
|
+
end
|
161
199
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
puts params
|
170
|
-
if params['taskOptions']
|
171
|
-
task_payload['taskOptions'].merge!(params['taskOptions'])
|
172
|
-
end
|
200
|
+
print reset,"\n"
|
201
|
+
end
|
202
|
+
rescue RestClient::Exception => e
|
203
|
+
print_rest_exception(e, options)
|
204
|
+
exit 1
|
205
|
+
end
|
206
|
+
end
|
173
207
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
208
|
+
# JD: This is broken.. copied from tasks? should optionTypes exist?
|
209
|
+
def add(args)
|
210
|
+
lb_type_name = nil
|
211
|
+
options = {}
|
212
|
+
optparse = OptionParser.new do|opts|
|
213
|
+
opts.banner = subcommand_usage("[name] -t LB_TYPE")
|
214
|
+
opts.on( '-t', '--type LB_TYPE', "Load Balancer Type" ) do |val|
|
215
|
+
lb_type_name = val
|
216
|
+
end
|
217
|
+
build_common_options(opts, options, [:options, :json, :dry_run, :remote])
|
218
|
+
end
|
219
|
+
optparse.parse!(args)
|
220
|
+
lb_name = args[0]
|
221
|
+
if args.count < 1
|
222
|
+
puts optparse
|
223
|
+
exit 1
|
224
|
+
end
|
225
|
+
if lb_type_name.nil?
|
226
|
+
puts optparse
|
227
|
+
exit 1
|
228
|
+
end
|
229
|
+
connect(options)
|
230
|
+
begin
|
231
|
+
lb_type = load_balancer_type_for_name_or_id(lb_type_name)
|
232
|
+
if lb_type.nil?
|
233
|
+
print_red_alert "LB Type #{lb_type_name} not found!"
|
234
|
+
exit 1
|
235
|
+
end
|
189
236
|
|
237
|
+
payload = {loadBalancer: {name: lb_name, type: {code: lb_type['code'], id: lb_type['id']}}}
|
190
238
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
lb_types = json_response['loadBalancerTypes']
|
205
|
-
print "\n" ,cyan, bold, "Morpheus Load Balancer Types\n","============================", reset, "\n\n"
|
206
|
-
if lb_types.nil? || lb_types.empty?
|
207
|
-
puts yellow,"No lb types currently exist on this appliance. This could be a seed issue.",reset
|
208
|
-
else
|
209
|
-
print cyan
|
210
|
-
lb_table_data = lb_types.collect do |lb_type|
|
211
|
-
{name: lb_type['name'], id: lb_type['id'], code: lb_type['code']}
|
212
|
-
end
|
213
|
-
tp lb_table_data, :id, :name, :code
|
214
|
-
end
|
239
|
+
# todo: The options available here are specific by type...
|
240
|
+
#input_options = Morpheus::Cli::OptionTypes.prompt(lb_type['optionTypes'],options[:options],@api_client, options[:params])
|
241
|
+
json_response = @load_balancers_interface.create(payload)
|
242
|
+
if options[:json]
|
243
|
+
print JSON.pretty_generate(json_response)
|
244
|
+
else
|
245
|
+
print "\n", cyan, "LB #{json_response['loadBalancer']['name']} created successfully", reset, "\n\n"
|
246
|
+
end
|
247
|
+
rescue RestClient::Exception => e
|
248
|
+
print_rest_exception(e, options)
|
249
|
+
exit 1
|
250
|
+
end
|
251
|
+
end
|
215
252
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
253
|
+
def remove(args)
|
254
|
+
lb_name = args[0]
|
255
|
+
options = {}
|
256
|
+
optparse = OptionParser.new do|opts|
|
257
|
+
opts.banner = subcommand_usage("[name]")
|
258
|
+
build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :remote])
|
259
|
+
end
|
260
|
+
optparse.parse!(args)
|
261
|
+
if args.count < 1
|
262
|
+
puts optparse
|
263
|
+
exit 1
|
264
|
+
end
|
265
|
+
connect(options)
|
266
|
+
begin
|
267
|
+
lb = find_lb_by_name_or_id(lb_name)
|
268
|
+
exit 1 if lb.nil?
|
269
|
+
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the load balancer #{lb['name']}?")
|
270
|
+
exit
|
271
|
+
end
|
272
|
+
if options[:dry_run]
|
273
|
+
print_dry_run @load_balancers_interface.dry.destroy(lb['id'])
|
274
|
+
return
|
275
|
+
end
|
276
|
+
json_response = @load_balancers_interface.destroy(lb['id'])
|
277
|
+
if options[:json]
|
278
|
+
print JSON.pretty_generate(json_response), "\n"
|
279
|
+
else
|
280
|
+
print "\n", cyan, "Load Balancer #{lb['name']} removed", reset, "\n\n"
|
281
|
+
end
|
282
|
+
rescue RestClient::Exception => e
|
283
|
+
print_rest_exception(e, options)
|
284
|
+
exit 1
|
285
|
+
end
|
286
|
+
end
|
225
287
|
|
226
|
-
def add(args)
|
227
|
-
lb_name = args[0]
|
228
|
-
lb_type_name = nil
|
229
|
-
options = {}
|
230
|
-
optparse = OptionParser.new do|opts|
|
231
|
-
opts.banner = "Usage: morpheus load-balancers add [lb] -t LB_TYPE"
|
232
|
-
opts.on( '-t', '--type LB_TYPE', "Lb Type" ) do |val|
|
233
|
-
lb_type_name = val
|
234
|
-
end
|
235
|
-
build_common_options(opts, options, [:options, :json, :remote])
|
236
|
-
end
|
237
|
-
if args.count < 1
|
238
|
-
puts "\n#{optparse.banner}\n\n"
|
239
|
-
exit 1
|
240
|
-
end
|
241
|
-
optparse.parse(args)
|
242
|
-
connect(options)
|
243
288
|
|
244
|
-
|
245
|
-
puts "LB Type must be specified...\n#{optparse.banner}"
|
246
|
-
exit 1
|
247
|
-
end
|
289
|
+
private
|
248
290
|
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
begin
|
257
|
-
json_response = @load_balancers_interface.create(payload)
|
258
|
-
if options[:json]
|
259
|
-
print JSON.pretty_generate(json_response)
|
260
|
-
else
|
261
|
-
print "\n", cyan, "LB #{json_response['loadBalancer']['name']} created successfully", reset, "\n\n"
|
262
|
-
end
|
263
|
-
rescue RestClient::Exception => e
|
264
|
-
print_rest_exception(e, options)
|
265
|
-
exit 1
|
266
|
-
end
|
267
|
-
end
|
291
|
+
def find_lb_by_name_or_id(val)
|
292
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
293
|
+
return find_lb_by_id(val)
|
294
|
+
else
|
295
|
+
return find_lb_by_name(val)
|
296
|
+
end
|
297
|
+
end
|
268
298
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
connect(options)
|
282
|
-
begin
|
283
|
-
lb = find_lb_by_name(lb_name)
|
284
|
-
exit 1 if lb.nil?
|
285
|
-
unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the load balancer #{lb['name']}?")
|
286
|
-
exit
|
287
|
-
end
|
288
|
-
json_response = @load_balancers_interface.destroy(lb['id'])
|
289
|
-
if options[:json]
|
290
|
-
print JSON.pretty_generate(json_response)
|
291
|
-
else
|
292
|
-
print "\n", cyan, "Load Balancer #{lb['name']} removed", reset, "\n\n"
|
293
|
-
end
|
294
|
-
rescue RestClient::Exception => e
|
295
|
-
print_rest_exception(e, options)
|
296
|
-
exit 1
|
297
|
-
end
|
298
|
-
end
|
299
|
+
def find_lb_by_id(id)
|
300
|
+
begin
|
301
|
+
json_response = @load_balancers_interface.get(id.to_i)
|
302
|
+
return json_response['loadBalancer']
|
303
|
+
rescue RestClient::Exception => e
|
304
|
+
if e.response && e.response.code == 404
|
305
|
+
print_red_alert "Load Balancer not found by id #{id}"
|
306
|
+
else
|
307
|
+
raise e
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
299
311
|
|
312
|
+
def find_lb_by_name(name)
|
313
|
+
lbs = @load_balancers_interface.get({name: name.to_s})['loadBalancers']
|
314
|
+
if lbs.empty?
|
315
|
+
print_red_alert "Load Balancer not found by name #{name}"
|
316
|
+
return nil
|
317
|
+
elsif lbs.size > 1
|
318
|
+
print_red_alert "#{lbs.size} load balancers found by name #{name}"
|
319
|
+
#print_lbs_table(lbs, {color: red})
|
320
|
+
print reset,"\n\n"
|
321
|
+
return nil
|
322
|
+
else
|
323
|
+
return lbs[0]
|
324
|
+
end
|
325
|
+
end
|
300
326
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
result = results['loadBalancers'][0]
|
308
|
-
elsif val.to_i.to_s == val
|
309
|
-
results = @load_balancers_interface.get(val.to_i)
|
310
|
-
result = results['loadBalancer']
|
311
|
-
end
|
312
|
-
if result.nil?
|
313
|
-
print_red_alert "LB not found by '#{val}'"
|
314
|
-
return nil
|
315
|
-
end
|
316
|
-
return result
|
317
|
-
end
|
327
|
+
def get_available_load_balancer_types(refresh=false)
|
328
|
+
if !@available_load_balancer_types || refresh
|
329
|
+
@available_load_balancer_types = @load_balancers_interface.load_balancer_types['loadBalancerTypes']
|
330
|
+
end
|
331
|
+
return @available_load_balancer_types
|
332
|
+
end
|
318
333
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
end
|
334
|
+
def load_balancer_type_for_name_or_id(val)
|
335
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
336
|
+
return load_balancer_type_for_id(val)
|
337
|
+
else
|
338
|
+
return load_balancer_type_for_name(val)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
def load_balancer_type_for_id(id)
|
343
|
+
return get_available_load_balancer_types().find { |z| z['id'].to_i == id.to_i}
|
344
|
+
end
|
345
|
+
|
346
|
+
def load_balancer_type_for_name(name)
|
347
|
+
return get_available_load_balancer_types().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
|
348
|
+
end
|
335
349
|
|
336
350
|
end
|