morpheus-cli 0.1.1 → 0.9.0
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/lib/morpheus/api/accounts_interface.rb +55 -0
- data/lib/morpheus/api/api_client.rb +48 -3
- data/lib/morpheus/api/apps_interface.rb +13 -13
- data/lib/morpheus/api/{zones_interface.rb → clouds_interface.rb} +10 -10
- data/lib/morpheus/api/deploy_interface.rb +4 -4
- data/lib/morpheus/api/groups_interface.rb +3 -3
- data/lib/morpheus/api/instance_types_interface.rb +2 -2
- data/lib/morpheus/api/instances_interface.rb +35 -19
- data/lib/morpheus/api/key_pairs_interface.rb +60 -0
- data/lib/morpheus/api/license_interface.rb +29 -0
- data/lib/morpheus/api/load_balancers_interface.rb +72 -0
- data/lib/morpheus/api/logs_interface.rb +37 -0
- data/lib/morpheus/api/options_interface.rb +20 -0
- data/lib/morpheus/api/provision_types_interface.rb +27 -0
- data/lib/morpheus/api/roles_interface.rb +73 -0
- data/lib/morpheus/api/security_group_rules_interface.rb +3 -3
- data/lib/morpheus/api/security_groups_interface.rb +5 -5
- data/lib/morpheus/api/servers_interface.rb +67 -3
- data/lib/morpheus/api/task_sets_interface.rb +46 -0
- data/lib/morpheus/api/tasks_interface.rb +72 -0
- data/lib/morpheus/api/users_interface.rb +72 -0
- data/lib/morpheus/cli.rb +27 -4
- data/lib/morpheus/cli/accounts.rb +306 -0
- data/lib/morpheus/cli/apps.rb +58 -1
- data/lib/morpheus/cli/cli_command.rb +87 -0
- data/lib/morpheus/cli/cli_registry.rb +6 -1
- data/lib/morpheus/cli/{zones.rb → clouds.rb} +99 -70
- data/lib/morpheus/cli/credentials.rb +23 -11
- data/lib/morpheus/cli/error_handler.rb +31 -11
- data/lib/morpheus/cli/groups.rb +1 -0
- data/lib/morpheus/cli/hosts.rb +567 -0
- data/lib/morpheus/cli/instances.rb +588 -292
- data/lib/morpheus/cli/key_pairs.rb +393 -0
- data/lib/morpheus/cli/license.rb +118 -0
- data/lib/morpheus/cli/load_balancers.rb +366 -0
- data/lib/morpheus/cli/mixins/accounts_helper.rb +193 -0
- data/lib/morpheus/cli/option_types.rb +260 -0
- data/lib/morpheus/cli/roles.rb +164 -0
- data/lib/morpheus/cli/security_group_rules.rb +4 -9
- data/lib/morpheus/cli/shell.rb +108 -0
- data/lib/morpheus/cli/tasks.rb +370 -0
- data/lib/morpheus/cli/users.rb +325 -0
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/workflows.rb +100 -0
- data/lib/morpheus/formatters.rb +43 -0
- data/morpheus-cli.gemspec +1 -1
- metadata +33 -10
- data/lib/morpheus/cli/servers.rb +0 -265
data/lib/morpheus/cli/apps.rb
CHANGED
@@ -158,6 +158,54 @@ class Morpheus::Cli::Apps
|
|
158
158
|
list([])
|
159
159
|
end
|
160
160
|
|
161
|
+
def logs(args)
|
162
|
+
options = {}
|
163
|
+
optparse = OptionParser.new do|opts|
|
164
|
+
opts.banner = "Usage: morpheus apps logs [name] [options]"
|
165
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
166
|
+
end
|
167
|
+
if args.count < 1
|
168
|
+
puts "\n#{optparse.banner}\n\n"
|
169
|
+
return
|
170
|
+
end
|
171
|
+
optparse.parse(args)
|
172
|
+
connect(options)
|
173
|
+
begin
|
174
|
+
app = find_app_by_name(args[0])
|
175
|
+
containers = []
|
176
|
+
app['appTiers'].each do |app_tier|
|
177
|
+
app_tier['appInstances'].each do |app_instance|
|
178
|
+
containers += app_instance['instance']['containers']
|
179
|
+
end
|
180
|
+
end
|
181
|
+
logs = @logs_interface.container_logs(containers, { max: options[:max] || 100, offset: options[:offset] || 0, query: options[:phrase]})
|
182
|
+
if options[:json]
|
183
|
+
puts logs
|
184
|
+
else
|
185
|
+
logs['data'].reverse.each do |log_entry|
|
186
|
+
log_level = ''
|
187
|
+
case log_entry['level']
|
188
|
+
when 'INFO'
|
189
|
+
log_level = "#{blue}#{bold}INFO#{reset}"
|
190
|
+
when 'DEBUG'
|
191
|
+
log_level = "#{white}#{bold}DEBUG#{reset}"
|
192
|
+
when 'WARN'
|
193
|
+
log_level = "#{yellow}#{bold}WARN#{reset}"
|
194
|
+
when 'ERROR'
|
195
|
+
log_level = "#{red}#{bold}ERROR#{reset}"
|
196
|
+
when 'FATAL'
|
197
|
+
log_level = "#{red}#{bold}FATAL#{reset}"
|
198
|
+
end
|
199
|
+
puts "[#{log_entry['ts']}] #{log_level} - #{log_entry['message']}"
|
200
|
+
end
|
201
|
+
print reset,"\n"
|
202
|
+
end
|
203
|
+
rescue RestClient::Exception => e
|
204
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
205
|
+
exit 1
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
161
209
|
def stats(args)
|
162
210
|
if args.count < 1
|
163
211
|
puts "\nUsage: morpheus apps stats [name]\n\n"
|
@@ -400,7 +448,7 @@ class Morpheus::Cli::Apps
|
|
400
448
|
|
401
449
|
json_response = @apps_interface.get(params)
|
402
450
|
apps = json_response['apps']
|
403
|
-
print "\n" ,cyan, bold, "Morpheus
|
451
|
+
print "\n" ,cyan, bold, "Morpheus Apps\n","==================", reset, "\n\n"
|
404
452
|
if apps.empty?
|
405
453
|
puts yellow,"No apps currently configured.",reset
|
406
454
|
else
|
@@ -580,6 +628,15 @@ EOF
|
|
580
628
|
end
|
581
629
|
|
582
630
|
private
|
631
|
+
|
632
|
+
def find_app_by_name(name)
|
633
|
+
app_results = @apps_interface.get({name: name})
|
634
|
+
if app_results['apps'].empty?
|
635
|
+
puts "Instance not found by name #{name}"
|
636
|
+
exit 1
|
637
|
+
end
|
638
|
+
return app_results['apps'][0]
|
639
|
+
end
|
583
640
|
def find_group_by_name(name)
|
584
641
|
group_results = @groups_interface.get(name)
|
585
642
|
if group_results['groups'].empty?
|
@@ -10,10 +10,97 @@ module Morpheus
|
|
10
10
|
klass.extend ClassMethods
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.accountScopeOptions(opts,options)
|
14
|
+
opts.on('-a','--account ACCOUNT', "Account Name") do |val|
|
15
|
+
options[:account_name] = val
|
16
|
+
end
|
17
|
+
opts.on('-A','--account-id ID', "Account ID") do |val|
|
18
|
+
options[:account_id] = val
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.genericOptions(opts,options)
|
23
|
+
opts.on( '-O', '--option OPTION', "Option" ) do |option|
|
24
|
+
custom_option_args = option.split('=')
|
25
|
+
custom_options = options[:options] || {}
|
26
|
+
option_name_args = custom_option_args[0].split('.')
|
27
|
+
if option_name_args.count > 1
|
28
|
+
nested_options = custom_options
|
29
|
+
option_name_args.each_with_index do |name_element,index|
|
30
|
+
if index < option_name_args.count - 1
|
31
|
+
nested_options[name_element] = nested_options[name_element] || {}
|
32
|
+
nested_options = nested_options[name_element]
|
33
|
+
else
|
34
|
+
nested_options[name_element] = custom_option_args[1]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
custom_options[custom_option_args[0]] = custom_option_args[1]
|
39
|
+
end
|
40
|
+
|
41
|
+
options[:options] = custom_options
|
42
|
+
end
|
43
|
+
opts.on('-C','--nocolor', "ANSI") do
|
44
|
+
Term::ANSIColor::coloring = false
|
45
|
+
end
|
46
|
+
opts.on( '-h', '--help', "Prints this help" ) do
|
47
|
+
puts opts
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
opts.on('-j','--json', "JSON Output") do |json|
|
51
|
+
options[:json] = true
|
52
|
+
end
|
53
|
+
opts.on( '-y', '--yes', "Auto Confirm" ) do
|
54
|
+
options[:yes] = true
|
55
|
+
end
|
56
|
+
opts.on( '-m', '--max MAX', "Max Results" ) do |max|
|
57
|
+
options[:max] = max.to_i
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on( '-o', '--offset OFFSET', "Offset Results" ) do |offset|
|
61
|
+
options[:offset] = offset.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
opts.on( '-r', '--remote REMOTE', "Remote Appliance" ) do |remote|
|
65
|
+
options[:remote] = remote
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on( '-U', '--url REMOTE', "API Url" ) do |remote|
|
69
|
+
options[:remote_url] = remote
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on( '-u', '--username USERNAME', "Username" ) do |remote|
|
73
|
+
options[:remote_username] = remote
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on( '-p', '--password PASSWORD', "Password" ) do |remote|
|
77
|
+
options[:remote_password] = remote
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on( '-T', '--token ACCESS_TOKEN', "Access Token" ) do |remote|
|
81
|
+
options[:remote_token] = remote
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on( '-s', '--search PHRASE', "Search Phrase" ) do |phrase|
|
85
|
+
options[:phrase] = phrase
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on( '', '--sort ORDER', "Sort Order" ) do |v|
|
89
|
+
options[:sort] = v
|
90
|
+
end
|
91
|
+
|
92
|
+
opts.on( '', '--desc', "Reverse Sort Order" ) do |v|
|
93
|
+
options[:direction] = "desc"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
13
98
|
module ClassMethods
|
14
99
|
def cli_command_name(cmd_name)
|
15
100
|
Morpheus::Cli::CliRegistry.add(self, cmd_name)
|
16
101
|
end
|
102
|
+
|
103
|
+
|
17
104
|
end
|
18
105
|
end
|
19
106
|
end
|
@@ -14,7 +14,12 @@ module Morpheus
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def exec(command_name, args)
|
17
|
-
|
17
|
+
# begin
|
18
|
+
Term::ANSIColor::coloring = STDOUT.isatty
|
19
|
+
instance.get(command_name).new.handle(args)
|
20
|
+
# rescue SystemExit, Interrupt
|
21
|
+
# puts "Interrupted..."
|
22
|
+
# end
|
18
23
|
end
|
19
24
|
|
20
25
|
def add(klass, command_name=nil)
|
@@ -4,25 +4,40 @@ require 'rest_client'
|
|
4
4
|
require 'term/ansicolor'
|
5
5
|
require 'optparse'
|
6
6
|
require 'morpheus/cli/cli_command'
|
7
|
+
require 'morpheus/cli/option_types'
|
8
|
+
require 'json'
|
7
9
|
|
8
|
-
class Morpheus::Cli::
|
9
|
-
|
10
|
+
class Morpheus::Cli::Clouds
|
11
|
+
include Morpheus::Cli::CliCommand
|
10
12
|
include Term::ANSIColor
|
11
13
|
def initialize()
|
12
14
|
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
13
|
-
|
14
|
-
@zones_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).zones
|
15
|
-
@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
|
16
|
-
@zone_types = @zones_interface.zone_types['zoneTypes']
|
15
|
+
|
17
16
|
end
|
18
17
|
|
19
|
-
|
18
|
+
|
19
|
+
def connect(opts)
|
20
|
+
if opts[:remote]
|
21
|
+
@appliance_url = opts[:remote]
|
22
|
+
@appliance_name = opts[:remote]
|
23
|
+
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
24
|
+
else
|
25
|
+
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
26
|
+
end
|
27
|
+
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
28
|
+
@clouds_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).clouds
|
29
|
+
@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
|
30
|
+
@cloud_types = @clouds_interface.cloud_types['zoneTypes']
|
20
31
|
if @access_token.empty?
|
21
32
|
print red,bold, "\nInvalid Credentials. Unable to acquire access token. Please verify your credentials and try again.\n\n",reset
|
22
33
|
return 1
|
23
34
|
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def handle(args)
|
38
|
+
|
24
39
|
if args.empty?
|
25
|
-
puts "\nUsage: morpheus
|
40
|
+
puts "\nUsage: morpheus clouds [list,add,remove,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]\n\n"
|
26
41
|
return
|
27
42
|
end
|
28
43
|
|
@@ -42,28 +57,32 @@ class Morpheus::Cli::Zones
|
|
42
57
|
when 'apply_security_groups'
|
43
58
|
apply_security_groups(args[1..-1])
|
44
59
|
else
|
45
|
-
puts "\nUsage: morpheus
|
60
|
+
puts "\nUsage: morpheus clouds [list,add,remove,firewall_disable,firewall_enable,security_groups,apply_security_groups] [name]\n\n"
|
61
|
+
exit 127 #Command now foud exit code
|
46
62
|
end
|
47
63
|
end
|
48
64
|
|
49
65
|
def add(args)
|
50
66
|
if args.count < 1
|
51
|
-
puts "\nUsage: morpheus
|
52
|
-
|
67
|
+
puts "\nUsage: morpheus clouds add [name] --group GROUP --type TYPE\n\n"
|
68
|
+
exit 1
|
53
69
|
end
|
70
|
+
options = {}
|
54
71
|
params = {zone_type: 'standard'}
|
55
72
|
optparse = OptionParser.new do|opts|
|
56
73
|
opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
|
57
74
|
params[:group] = group
|
58
75
|
end
|
59
|
-
opts.on( '-t', '--type TYPE', "
|
76
|
+
opts.on( '-t', '--type TYPE', "Cloud Type" ) do |zone_type|
|
60
77
|
params[:zone_type] = zone_type
|
61
78
|
end
|
62
79
|
opts.on( '-d', '--description DESCRIPTION', "Description (optional)" ) do |desc|
|
63
80
|
params[:description] = desc
|
64
81
|
end
|
82
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
65
83
|
end
|
66
|
-
optparse.parse(args)
|
84
|
+
optparse.parse!(args)
|
85
|
+
connect(options)
|
67
86
|
zone = {name: args[0], description: params[:description]}
|
68
87
|
if !params[:group].nil?
|
69
88
|
group = find_group_by_name(params[:group])
|
@@ -73,26 +92,32 @@ class Morpheus::Cli::Zones
|
|
73
92
|
end
|
74
93
|
|
75
94
|
if !params[:zone_type].nil?
|
76
|
-
|
95
|
+
cloud_type = cloud_type_for_name(params[:zone_type])
|
96
|
+
zone['zoneType'] = {code: cloud_type['code']}
|
77
97
|
end
|
78
98
|
|
79
99
|
begin
|
80
|
-
|
100
|
+
zone.merge!(Morpheus::Cli::OptionTypes.prompt(cloud_type['optionTypes'],options[:options],@api_client))
|
101
|
+
@clouds_interface.create(zone)
|
81
102
|
rescue => e
|
82
|
-
if e.response.code == 400
|
103
|
+
if e.response and e.response.code == 400
|
83
104
|
error = JSON.parse(e.response.to_s)
|
84
|
-
|
105
|
+
if options[:json]
|
106
|
+
print JSON.pretty_generate(error)
|
107
|
+
else
|
108
|
+
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
109
|
+
end
|
85
110
|
else
|
86
111
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
87
112
|
end
|
88
|
-
|
113
|
+
exit 1
|
89
114
|
end
|
90
115
|
list([])
|
91
116
|
end
|
92
117
|
|
93
118
|
def remove(args)
|
94
119
|
if args.count < 2
|
95
|
-
puts "\nUsage: morpheus
|
120
|
+
puts "\nUsage: morpheus clouds remove [name] --group GROUP\n\n"
|
96
121
|
return
|
97
122
|
end
|
98
123
|
|
@@ -101,50 +126,50 @@ class Morpheus::Cli::Zones
|
|
101
126
|
opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
|
102
127
|
params[:group] = group
|
103
128
|
end
|
129
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,params)
|
104
130
|
end
|
105
131
|
optparse.parse(args)
|
106
|
-
|
132
|
+
connect(params)
|
107
133
|
if !params[:group].nil?
|
108
134
|
group = find_group_by_name(params[:group])
|
109
135
|
if !group.nil?
|
110
136
|
params[:groupId] = group['id']
|
111
137
|
else
|
112
138
|
puts "\nGroup #{params[:group]} not found!"
|
113
|
-
|
139
|
+
exit 1
|
114
140
|
end
|
115
|
-
else params[:group].nil?
|
116
|
-
puts "\nUsage: morpheus zones remove [name] --group GROUP"
|
117
|
-
return
|
118
141
|
end
|
119
142
|
|
120
143
|
|
121
144
|
begin
|
122
|
-
zone_results = @
|
145
|
+
zone_results = @clouds_interface.get({name: args[0]})
|
123
146
|
if zone_results['zones'].empty?
|
124
147
|
puts "Zone not found by name #{args[0]}"
|
125
|
-
|
148
|
+
exit 1
|
126
149
|
end
|
127
|
-
@
|
150
|
+
@clouds_interface.destroy(zone_results['zones'][0]['id'])
|
128
151
|
list([])
|
129
152
|
rescue RestClient::Exception => e
|
130
|
-
if e.response.code == 400
|
153
|
+
if e.response.code == 400 or e.response.code == 500
|
131
154
|
error = JSON.parse(e.response.to_s)
|
132
|
-
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
155
|
+
::Morpheus::Cli::ErrorHandler.new.print_errors(error,params)
|
133
156
|
else
|
134
157
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
135
158
|
end
|
136
|
-
|
159
|
+
exit 1
|
137
160
|
end
|
138
161
|
end
|
139
162
|
|
140
163
|
def list(args)
|
141
|
-
options
|
164
|
+
options={}
|
142
165
|
optparse = OptionParser.new do|opts|
|
143
166
|
opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
|
144
167
|
options[:group] = group
|
145
168
|
end
|
169
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
146
170
|
end
|
147
171
|
optparse.parse(args)
|
172
|
+
connect(options)
|
148
173
|
begin
|
149
174
|
params = {}
|
150
175
|
if !options[:group].nil?
|
@@ -154,36 +179,40 @@ class Morpheus::Cli::Zones
|
|
154
179
|
end
|
155
180
|
end
|
156
181
|
|
157
|
-
json_response = @
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
182
|
+
json_response = @clouds_interface.get(params)
|
183
|
+
clouds = json_response['zones']
|
184
|
+
if options[:json]
|
185
|
+
print JSON.pretty_generate(json_response)
|
186
|
+
print "\n"
|
162
187
|
else
|
163
|
-
|
164
|
-
|
188
|
+
print "\n" ,cyan, bold, "Morpheus Clouds\n","==================", reset, "\n\n"
|
189
|
+
if clouds.empty?
|
190
|
+
puts yellow,"No clouds currently configured.",reset
|
191
|
+
else
|
192
|
+
clouds.each do |zone|
|
193
|
+
print cyan, "= #{zone['name']} (#{cloud_type_for_id(zone['zoneTypeId'])}) - #{zone['description']}\n"
|
194
|
+
end
|
165
195
|
end
|
196
|
+
print reset,"\n\n"
|
166
197
|
end
|
167
|
-
print reset,"\n\n"
|
168
|
-
|
169
198
|
rescue => e
|
170
199
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
171
|
-
|
200
|
+
exit 1
|
172
201
|
end
|
173
202
|
end
|
174
203
|
|
175
204
|
def firewall_disable(args)
|
176
205
|
if args.count < 1
|
177
|
-
puts "\nUsage: morpheus
|
206
|
+
puts "\nUsage: morpheus clouds firewall_disable [name]\n\n"
|
178
207
|
return
|
179
208
|
end
|
180
209
|
begin
|
181
|
-
zone_results = @
|
210
|
+
zone_results = @clouds_interface.get({name: args[0]})
|
182
211
|
if zone_results['zones'].empty?
|
183
212
|
puts "Zone not found by name #{args[0]}"
|
184
|
-
|
213
|
+
exit 1
|
185
214
|
end
|
186
|
-
@
|
215
|
+
@clouds_interface.firewall_disable(zone_results['zones'][0]['id'])
|
187
216
|
security_groups([args[0]])
|
188
217
|
rescue RestClient::Exception => e
|
189
218
|
if e.response.code == 400
|
@@ -192,22 +221,22 @@ class Morpheus::Cli::Zones
|
|
192
221
|
else
|
193
222
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
194
223
|
end
|
195
|
-
|
224
|
+
exit 1
|
196
225
|
end
|
197
226
|
end
|
198
227
|
|
199
228
|
def firewall_enable(args)
|
200
229
|
if args.count < 1
|
201
|
-
puts "\nUsage: morpheus
|
230
|
+
puts "\nUsage: morpheus clouds firewall_enable [name]\n\n"
|
202
231
|
return
|
203
232
|
end
|
204
233
|
begin
|
205
|
-
zone_results = @
|
234
|
+
zone_results = @clouds_interface.get({name: args[0]})
|
206
235
|
if zone_results['zones'].empty?
|
207
236
|
puts "Zone not found by name #{args[0]}"
|
208
|
-
|
237
|
+
exit 1
|
209
238
|
end
|
210
|
-
@
|
239
|
+
@clouds_interface.firewall_enable(zone_results['zones'][0]['id'])
|
211
240
|
security_groups([args[0]])
|
212
241
|
rescue RestClient::Exception => e
|
213
242
|
if e.response.code == 400
|
@@ -216,24 +245,24 @@ class Morpheus::Cli::Zones
|
|
216
245
|
else
|
217
246
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
218
247
|
end
|
219
|
-
|
248
|
+
exit 1
|
220
249
|
end
|
221
250
|
end
|
222
251
|
|
223
252
|
def security_groups(args)
|
224
253
|
if args.count < 1
|
225
|
-
puts "\nUsage: morpheus
|
254
|
+
puts "\nUsage: morpheus clouds security_groups [name]\n\n"
|
226
255
|
return
|
227
256
|
end
|
228
257
|
begin
|
229
|
-
zone_results = @
|
258
|
+
zone_results = @clouds_interface.get({name: args[0]})
|
230
259
|
if zone_results['zones'].empty?
|
231
260
|
puts "Zone not found by name #{args[0]}"
|
232
|
-
|
261
|
+
exit 1
|
233
262
|
end
|
234
263
|
|
235
264
|
zone_id = zone_results['zones'][0]['id']
|
236
|
-
json_response = @
|
265
|
+
json_response = @clouds_interface.security_groups(zone_id)
|
237
266
|
|
238
267
|
securityGroups = json_response['securityGroups']
|
239
268
|
print "\n" ,cyan, bold, "Morpheus Security Groups for Zone:#{zone_id}\n","==================", reset, "\n\n"
|
@@ -254,17 +283,17 @@ class Morpheus::Cli::Zones
|
|
254
283
|
else
|
255
284
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
256
285
|
end
|
257
|
-
|
286
|
+
exit 1
|
258
287
|
end
|
259
288
|
end
|
260
289
|
|
261
290
|
def apply_security_groups(args)
|
262
291
|
usage = <<-EOF
|
263
|
-
Usage: morpheus
|
292
|
+
Usage: morpheus clouds apply_security_groups [name] [options]
|
264
293
|
EOF
|
265
294
|
if args.count < 1
|
266
295
|
puts usage
|
267
|
-
|
296
|
+
exit 1
|
268
297
|
end
|
269
298
|
|
270
299
|
options = {}
|
@@ -292,13 +321,13 @@ EOF
|
|
292
321
|
end
|
293
322
|
|
294
323
|
begin
|
295
|
-
zone_results = @
|
324
|
+
zone_results = @clouds_interface.get({name: args[0]})
|
296
325
|
if zone_results['zones'].empty?
|
297
326
|
puts "Zone not found by name #{args[0]}"
|
298
|
-
|
327
|
+
exit 1
|
299
328
|
end
|
300
329
|
|
301
|
-
@
|
330
|
+
@clouds_interface.apply_security_groups(zone_results['zones'][0]['id'], options)
|
302
331
|
security_groups([args[0]])
|
303
332
|
rescue RestClient::Exception => e
|
304
333
|
if e.response.code == 400
|
@@ -307,15 +336,15 @@ EOF
|
|
307
336
|
else
|
308
337
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
309
338
|
end
|
310
|
-
|
339
|
+
exit 1
|
311
340
|
end
|
312
341
|
end
|
313
342
|
|
314
|
-
|
343
|
+
private
|
315
344
|
|
316
|
-
def
|
317
|
-
if !@
|
318
|
-
zone_type = @
|
345
|
+
def cloud_type_for_id(id)
|
346
|
+
if !@cloud_types.empty?
|
347
|
+
zone_type = @cloud_types.find { |z| z['id'].to_i == id.to_i}
|
319
348
|
if !zone_type.nil?
|
320
349
|
return zone_type['name']
|
321
350
|
end
|
@@ -323,11 +352,11 @@ EOF
|
|
323
352
|
return nil
|
324
353
|
end
|
325
354
|
|
326
|
-
def
|
327
|
-
if !@
|
328
|
-
zone_type = @
|
355
|
+
def cloud_type_for_name(name)
|
356
|
+
if !@cloud_types.empty?
|
357
|
+
zone_type = @cloud_types.find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
|
329
358
|
if !zone_type.nil?
|
330
|
-
return zone_type
|
359
|
+
return zone_type
|
331
360
|
end
|
332
361
|
end
|
333
362
|
return nil
|