morpheus-cli 4.1.5 → 4.1.6
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/api_client.rb +4 -4
- data/lib/morpheus/api/network_subnets_interface.rb +1 -0
- data/lib/morpheus/api/security_groups_interface.rb +1 -1
- data/lib/morpheus/api/{network_subnet_types_interface.rb → subnet_types_interface.rb} +3 -3
- data/lib/morpheus/api/subnets_interface.rb +1 -1
- data/lib/morpheus/cli/appliance_settings_command.rb +1 -3
- data/lib/morpheus/cli/cli_command.rb +4 -0
- data/lib/morpheus/cli/credentials.rb +4 -5
- data/lib/morpheus/cli/error_handler.rb +8 -8
- data/lib/morpheus/cli/groups.rb +1 -1
- data/lib/morpheus/cli/license.rb +6 -12
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +375 -0
- data/lib/morpheus/cli/monitoring_alerts_command.rb +0 -2
- data/lib/morpheus/cli/network_groups_command.rb +116 -75
- data/lib/morpheus/cli/networks_command.rb +65 -767
- data/lib/morpheus/cli/remote.rb +1 -2
- data/lib/morpheus/cli/security_groups.rb +26 -33
- data/lib/morpheus/cli/shell.rb +12 -16
- data/lib/morpheus/cli/subnets_command.rb +708 -0
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/whitelabel_settings_command.rb +1 -3
- data/lib/morpheus/cli.rb +1 -0
- data/lib/morpheus/terminal.rb +1 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c550fa0412be48d0457ca10f54822e7b77e25bb515e6c5cb6092d43f9aee66a6
|
4
|
+
data.tar.gz: a8949f6a0ace1bc99f6a327ebe30e8f9678c9922c9a3d8a776543475c94141f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e33763b7980a60312a7479d0104dab355e34c8a01e7a561b98a18468360a975dbbc26fabc2f61ac7f0506be8e8c4f3dbc8fc998d23cd6b1481cdedbb341d1a
|
7
|
+
data.tar.gz: 6e64c4f697547bbad0fcba6e9aeb6ec218daf37491d5b0ebb4b309ac523a3389aeb621e6c9265035c6233bc3b0b7189d36d5ba9c08133d2d104430135802d598
|
@@ -490,12 +490,12 @@ class Morpheus::APIClient
|
|
490
490
|
Morpheus::NetworkTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
491
491
|
end
|
492
492
|
|
493
|
-
def
|
494
|
-
Morpheus::
|
493
|
+
def subnets
|
494
|
+
Morpheus::SubnetsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
495
495
|
end
|
496
496
|
|
497
|
-
def
|
498
|
-
Morpheus::
|
497
|
+
def subnet_types
|
498
|
+
Morpheus::SubnetTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
|
499
499
|
end
|
500
500
|
|
501
501
|
def network_groups
|
@@ -15,7 +15,7 @@ class Morpheus::SecurityGroupsInterface < Morpheus::APIClient
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def get(id, params={})
|
18
|
-
url = "#{@base_url}/api/security-groups"
|
18
|
+
url = "#{@base_url}/api/security-groups/#{id}"
|
19
19
|
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
20
20
|
|
21
21
|
if options.is_a?(Hash)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'morpheus/api/api_client'
|
2
2
|
|
3
|
-
class Morpheus::
|
3
|
+
class Morpheus::SubnetTypesInterface < Morpheus::APIClient
|
4
4
|
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
|
5
5
|
@access_token = access_token
|
6
6
|
@refresh_token = refresh_token
|
@@ -10,14 +10,14 @@ class Morpheus::NetworkSubnetTypesInterface < Morpheus::APIClient
|
|
10
10
|
|
11
11
|
def get(id, params={})
|
12
12
|
raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
|
13
|
-
url = "#{@base_url}/api/
|
13
|
+
url = "#{@base_url}/api/subnet-types/#{id}"
|
14
14
|
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
15
15
|
opts = {method: :get, url: url, headers: headers}
|
16
16
|
execute(opts)
|
17
17
|
end
|
18
18
|
|
19
19
|
def list(params={})
|
20
|
-
url = "#{@base_url}/api/
|
20
|
+
url = "#{@base_url}/api/subnet-types"
|
21
21
|
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
22
22
|
opts = {method: :get, url: url, headers: headers}
|
23
23
|
execute(opts)
|
@@ -24,7 +24,7 @@ class Morpheus::SubnetsInterface < Morpheus::APIClient
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def create(network_id, payload)
|
27
|
-
url = "#{@base_url}/api/subnets"
|
27
|
+
url = "#{@base_url}/api/networks/#{network_id}/subnets"
|
28
28
|
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
29
29
|
opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
|
30
30
|
execute(opts)
|
@@ -3,15 +3,13 @@ require 'morpheus/cli/cli_command'
|
|
3
3
|
class Morpheus::Cli::ApplianceSettingsCommand
|
4
4
|
include Morpheus::Cli::CliCommand
|
5
5
|
include Morpheus::Cli::AccountsHelper
|
6
|
-
|
6
|
+
set_command_hidden # hide until 4.2.0
|
7
7
|
set_command_name :'appliance-settings'
|
8
8
|
|
9
9
|
register_subcommands :get, :update
|
10
10
|
|
11
11
|
set_default_subcommand :get
|
12
12
|
|
13
|
-
set_command_hidden # hiding until 4.2 release
|
14
|
-
|
15
13
|
def connect(opts)
|
16
14
|
@api_client = establish_remote_appliance_connection(opts)
|
17
15
|
@appliance_settings_interface = @api_client.appliance_settings
|
@@ -966,6 +966,10 @@ module Morpheus
|
|
966
966
|
else
|
967
967
|
output = records_as_csv([row], options)
|
968
968
|
end
|
969
|
+
elsif options[:quiet]
|
970
|
+
# note: returning non nil means the calling function knows to return rght away.. kinda weird..
|
971
|
+
# but means we need less if options[:quiet] blocks in every action.
|
972
|
+
output = ""
|
969
973
|
end
|
970
974
|
if output
|
971
975
|
if options[:outfile]
|
@@ -354,7 +354,7 @@ module Morpheus
|
|
354
354
|
@@appliance_credentials_map = load_credentials_file || {}
|
355
355
|
@@appliance_credentials_map.delete(appliance_name.to_s)
|
356
356
|
@@appliance_credentials_map.delete(appliance_name.to_sym)
|
357
|
-
Morpheus::Logging::DarkPrinter.puts "clearing credentials for #{appliance_name} from file #{credentials_file_path}" if Morpheus::Logging.debug?
|
357
|
+
#Morpheus::Logging::DarkPrinter.puts "clearing credentials for #{appliance_name} from file #{credentials_file_path}" if Morpheus::Logging.debug?
|
358
358
|
File.open(credentials_file_path, 'w') {|f| f.write @@appliance_credentials_map.to_yaml } #Store
|
359
359
|
::Morpheus::Cli::Remote.recalculate_variable_map()
|
360
360
|
true
|
@@ -376,7 +376,7 @@ module Morpheus
|
|
376
376
|
def load_credentials_file
|
377
377
|
fn = credentials_file_path
|
378
378
|
if File.exist? fn
|
379
|
-
Morpheus::Logging::DarkPrinter.puts "loading credentials file #{fn}" if Morpheus::Logging.debug?
|
379
|
+
#Morpheus::Logging::DarkPrinter.puts "loading credentials file #{fn}" if Morpheus::Logging.debug?
|
380
380
|
return YAML.load_file(fn)
|
381
381
|
else
|
382
382
|
return nil
|
@@ -405,7 +405,7 @@ module Morpheus
|
|
405
405
|
if !Dir.exists?(File.dirname(fn))
|
406
406
|
FileUtils.mkdir_p(File.dirname(fn))
|
407
407
|
end
|
408
|
-
Morpheus::Logging::DarkPrinter.puts "adding credentials for #{appliance_name} to #{fn}" if Morpheus::Logging.debug?
|
408
|
+
#Morpheus::Logging::DarkPrinter.puts "adding credentials for #{appliance_name} to #{fn}" if Morpheus::Logging.debug?
|
409
409
|
File.open(fn, 'w') {|f| f.write credential_map.to_yaml } #Store
|
410
410
|
FileUtils.chmod(0600, fn)
|
411
411
|
@@appliance_credentials_map = credential_map
|
@@ -442,8 +442,7 @@ module Morpheus
|
|
442
442
|
if !Dir.exists?(File.dirname(fn))
|
443
443
|
FileUtils.mkdir_p(File.dirname(fn))
|
444
444
|
end
|
445
|
-
#Morpheus::Logging::DarkPrinter.puts "renaming credentials
|
446
|
-
Morpheus::Logging::DarkPrinter.puts "renaming credentials from #{appliance_name} to #{appliance_name}" if Morpheus::Logging.debug?
|
445
|
+
#Morpheus::Logging::DarkPrinter.puts "renaming credentials from #{appliance_name} to #{new_appliance_name}" if Morpheus::Logging.debug?
|
447
446
|
File.open(fn, 'w') {|f| f.write credential_map.to_yaml } #Store
|
448
447
|
FileUtils.chmod(0600, fn)
|
449
448
|
@@appliance_credentials_map = credential_map
|
@@ -17,11 +17,13 @@ class Morpheus::Cli::ErrorHandler
|
|
17
17
|
def handle_error(err, options={})
|
18
18
|
exit_code = 1
|
19
19
|
options = (options || {}).clone
|
20
|
-
|
21
|
-
if Morpheus::Logging.debug? && options[:debug].nil?
|
20
|
+
if Morpheus::Logging.debug?
|
22
21
|
options[:debug] = true
|
23
22
|
end
|
24
23
|
do_print_stacktrace = true
|
24
|
+
|
25
|
+
#@stderr.puts "#{dark}Handling error #{err.class} - #{err}#{reset}"
|
26
|
+
|
25
27
|
case (err)
|
26
28
|
when ::OptionParser::InvalidOption, ::OptionParser::AmbiguousOption,
|
27
29
|
::OptionParser::MissingArgument, ::OptionParser::InvalidArgument,
|
@@ -61,10 +63,7 @@ class Morpheus::Cli::ErrorHandler
|
|
61
63
|
when RestClient::Exception
|
62
64
|
print_rest_exception(err, options)
|
63
65
|
# no stacktrace for now...
|
64
|
-
return exit_code
|
65
|
-
# if !options[:debug]
|
66
|
-
# return exit_code
|
67
|
-
# end
|
66
|
+
return exit_code, err
|
68
67
|
when ArgumentError
|
69
68
|
@stderr.puts "#{red}Argument Error: #{err.message}#{reset}"
|
70
69
|
else
|
@@ -83,7 +82,7 @@ class Morpheus::Cli::ErrorHandler
|
|
83
82
|
end
|
84
83
|
end
|
85
84
|
|
86
|
-
return exit_code
|
85
|
+
return exit_code, err
|
87
86
|
|
88
87
|
end
|
89
88
|
|
@@ -149,7 +148,8 @@ class Morpheus::Cli::ErrorHandler
|
|
149
148
|
@stderr.print red, "Error Communicating with the Appliance. #{e}", reset, "\n"
|
150
149
|
end
|
151
150
|
# uh, having this print method return exit_code, err to standardize return values of methods that are still calling it, at the end just by chance..
|
152
|
-
return exit_code, err
|
151
|
+
# return exit_code, err
|
152
|
+
return 1, err
|
153
153
|
end
|
154
154
|
|
155
155
|
def print_rest_errors(response, options={})
|
data/lib/morpheus/cli/groups.rb
CHANGED
@@ -773,7 +773,7 @@ public
|
|
773
773
|
def load_group_file
|
774
774
|
fn = groups_file_path
|
775
775
|
if File.exist? fn
|
776
|
-
Morpheus::Logging::DarkPrinter.puts "loading groups file #{fn}" if Morpheus::Logging.debug?
|
776
|
+
#Morpheus::Logging::DarkPrinter.puts "loading groups file #{fn}" if Morpheus::Logging.debug?
|
777
777
|
return YAML.load_file(fn)
|
778
778
|
else
|
779
779
|
{}
|
data/lib/morpheus/cli/license.rb
CHANGED
@@ -68,10 +68,10 @@ class Morpheus::Cli::License
|
|
68
68
|
return exit_code, err
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
if exit_code != 0
|
72
|
+
print_error red, err.to_s, reset, "\n"
|
73
|
+
return exit_code, err
|
74
|
+
end
|
75
75
|
|
76
76
|
# render output
|
77
77
|
|
@@ -143,8 +143,8 @@ class Morpheus::Cli::License
|
|
143
143
|
if options[:json]
|
144
144
|
puts JSON.pretty_generate(json_response)
|
145
145
|
else
|
146
|
-
print_green_success "License
|
147
|
-
|
146
|
+
print_green_success "License installed!"
|
147
|
+
get([] + (options[:remote] ? ["-r",options[:remote]] : []))
|
148
148
|
end
|
149
149
|
return 0
|
150
150
|
rescue RestClient::Exception => e
|
@@ -265,12 +265,6 @@ class Morpheus::Cli::License
|
|
265
265
|
end
|
266
266
|
|
267
267
|
json_response = @license_interface.uninstall(params)
|
268
|
-
|
269
|
-
@apps_interface.setopts(options)
|
270
|
-
if options[:dry_run]
|
271
|
-
print_dry_run @apps_interface.dry.wiki(app["id"], params)
|
272
|
-
return
|
273
|
-
end
|
274
268
|
render_result = render_with_format(json_response, options)
|
275
269
|
return 0 if render_result
|
276
270
|
return 0 if options[:quiet]
|
@@ -21,6 +21,36 @@ module Morpheus::Cli::InfrastructureHelper
|
|
21
21
|
@clouds_interface
|
22
22
|
end
|
23
23
|
|
24
|
+
def networks_interface
|
25
|
+
# @api_client.networks
|
26
|
+
raise "#{self.class} has not defined @networks_interface" if @networks_interface.nil?
|
27
|
+
@networks_interface
|
28
|
+
end
|
29
|
+
|
30
|
+
def subnets_interface
|
31
|
+
# @api_client.subnets
|
32
|
+
raise "#{self.class} has not defined @subnets_interface" if @subnets_interface.nil?
|
33
|
+
@subnets_interface
|
34
|
+
end
|
35
|
+
|
36
|
+
def network_groups_interface
|
37
|
+
# @api_client.network_groups
|
38
|
+
raise "#{self.class} has not defined @network_groups_interface" if @network_groups_interface.nil?
|
39
|
+
@network_groups_interface
|
40
|
+
end
|
41
|
+
|
42
|
+
def network_types_interface
|
43
|
+
# @api_client.network_types
|
44
|
+
raise "#{self.class} has not defined @network_types_interface" if @network_types_interface.nil?
|
45
|
+
@network_types_interface
|
46
|
+
end
|
47
|
+
|
48
|
+
def subnet_types_interface
|
49
|
+
# @api_client.subnet_types
|
50
|
+
raise "#{self.class} has not defined @subnet_types_interface" if @subnet_types_interface.nil?
|
51
|
+
@subnet_types_interface
|
52
|
+
end
|
53
|
+
|
24
54
|
def find_group_by_name_or_id(val)
|
25
55
|
if val.to_s =~ /\A\d{1,}\Z/
|
26
56
|
return find_group_by_id(val)
|
@@ -103,4 +133,349 @@ module Morpheus::Cli::InfrastructureHelper
|
|
103
133
|
return get_available_cloud_types().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
|
104
134
|
end
|
105
135
|
|
136
|
+
|
137
|
+
# Networks
|
138
|
+
|
139
|
+
def find_network_by_name_or_id(val)
|
140
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
141
|
+
return find_network_by_id(val)
|
142
|
+
else
|
143
|
+
return find_network_by_name(val)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def find_network_by_id(id)
|
148
|
+
begin
|
149
|
+
json_response = networks_interface.get(id.to_i)
|
150
|
+
return json_response['network']
|
151
|
+
rescue RestClient::Exception => e
|
152
|
+
if e.response && e.response.code == 404
|
153
|
+
print_red_alert "Network not found by id #{id}"
|
154
|
+
return nil
|
155
|
+
else
|
156
|
+
raise e
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def find_network_by_name(name)
|
162
|
+
json_response = networks_interface.list({name: name.to_s})
|
163
|
+
networks = json_response['networks']
|
164
|
+
if networks.empty?
|
165
|
+
print_red_alert "Network not found by name #{name}"
|
166
|
+
return nil
|
167
|
+
elsif networks.size > 1
|
168
|
+
print_red_alert "#{networks.size} networks found by name #{name}"
|
169
|
+
rows = networks.collect do |it|
|
170
|
+
{id: it['id'], name: it['name']}
|
171
|
+
end
|
172
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
173
|
+
return nil
|
174
|
+
else
|
175
|
+
network = networks[0]
|
176
|
+
# merge in tenants map
|
177
|
+
if json_response['tenants'] && json_response['tenants'][network['id']]
|
178
|
+
network['tenants'] = json_response['tenants'][network['id']]
|
179
|
+
end
|
180
|
+
return network
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def find_network_type_by_name_or_id(val)
|
185
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
186
|
+
return find_network_type_by_id(val)
|
187
|
+
else
|
188
|
+
return find_network_type_by_name(val)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def find_network_type_by_id(id)
|
193
|
+
begin
|
194
|
+
json_response = network_types_interface.get(id.to_i)
|
195
|
+
return json_response['networkType']
|
196
|
+
rescue RestClient::Exception => e
|
197
|
+
if e.response && e.response.code == 404
|
198
|
+
print_red_alert "Network Type not found by id #{id}"
|
199
|
+
return nil
|
200
|
+
else
|
201
|
+
raise e
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def find_network_type_by_name(name)
|
207
|
+
json_response = network_types_interface.list({name: name.to_s})
|
208
|
+
network_types = json_response['networkTypes']
|
209
|
+
if network_types.empty?
|
210
|
+
print_red_alert "Network Type not found by name #{name}"
|
211
|
+
return network_types
|
212
|
+
elsif network_types.size > 1
|
213
|
+
print_red_alert "#{network_types.size} network types found by name #{name}"
|
214
|
+
rows = network_types.collect do |it|
|
215
|
+
{id: it['id'], name: it['name']}
|
216
|
+
end
|
217
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
218
|
+
return nil
|
219
|
+
else
|
220
|
+
return network_types[0]
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def find_subnet_by_name_or_id(val)
|
225
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
226
|
+
return find_subnet_by_id(val)
|
227
|
+
else
|
228
|
+
return find_subnet_by_name(val)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def find_subnet_by_id(id)
|
233
|
+
begin
|
234
|
+
json_response = subnets_interface.get(id.to_i)
|
235
|
+
return json_response['subnet']
|
236
|
+
rescue RestClient::Exception => e
|
237
|
+
if e.response && e.response.code == 404
|
238
|
+
print_red_alert "Subnet not found by id #{id}"
|
239
|
+
return nil
|
240
|
+
else
|
241
|
+
raise e
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def find_subnet_by_name(name)
|
247
|
+
json_response = subnets_interface.list({name: name.to_s})
|
248
|
+
subnets = json_response['subnets']
|
249
|
+
if subnets.empty?
|
250
|
+
print_red_alert "Subnet not found by name #{name}"
|
251
|
+
return nil
|
252
|
+
elsif subnets.size > 1
|
253
|
+
print_red_alert "#{subnets.size} subnets found by name #{name}"
|
254
|
+
rows = subnets.collect do |it|
|
255
|
+
{id: it['id'], name: it['name']}
|
256
|
+
end
|
257
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
258
|
+
return nil
|
259
|
+
else
|
260
|
+
return subnets[0]
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
def find_subnet_type_by_name_or_id(val)
|
265
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
266
|
+
return find_subnet_type_by_id(val)
|
267
|
+
else
|
268
|
+
return find_subnet_type_by_name(val)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def find_subnet_type_by_id(id)
|
273
|
+
begin
|
274
|
+
json_response = subnet_types_interface.get(id.to_i)
|
275
|
+
return json_response['subnetType']
|
276
|
+
rescue RestClient::Exception => e
|
277
|
+
if e.response && e.response.code == 404
|
278
|
+
print_red_alert "Subnet Type not found by id #{id}"
|
279
|
+
return nil
|
280
|
+
else
|
281
|
+
raise e
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
def find_subnet_type_by_name(name)
|
287
|
+
json_response = subnet_types_interface.list({name: name.to_s})
|
288
|
+
subnet_types = json_response['subnetTypes']
|
289
|
+
if subnet_types.empty?
|
290
|
+
print_red_alert "Subnet Type not found by name #{name}"
|
291
|
+
return subnet_types
|
292
|
+
elsif subnet_types.size > 1
|
293
|
+
print_red_alert "#{subnet_types.size} subnet types found by name #{name}"
|
294
|
+
rows = subnet_types.collect do |it|
|
295
|
+
{id: it['id'], name: it['name']}
|
296
|
+
end
|
297
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
298
|
+
return nil
|
299
|
+
else
|
300
|
+
return subnet_types[0]
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
def find_network_group_by_name_or_id(val)
|
305
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
306
|
+
return find_network_group_by_id(val)
|
307
|
+
else
|
308
|
+
return find_network_group_by_name(val)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def find_network_group_by_id(id)
|
313
|
+
begin
|
314
|
+
json_response = network_groups_interface.get(id.to_i)
|
315
|
+
return json_response['networkGroup']
|
316
|
+
rescue RestClient::Exception => e
|
317
|
+
if e.response && e.response.code == 404
|
318
|
+
print_red_alert "Network Group not found by id #{id}"
|
319
|
+
return nil
|
320
|
+
else
|
321
|
+
raise e
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
def find_network_group_by_name(name)
|
327
|
+
json_response = network_groups_interface.list({name: name.to_s})
|
328
|
+
network_groups = json_response['networkGroups']
|
329
|
+
if network_groups.empty?
|
330
|
+
print_red_alert "Network Group not found by name #{name}"
|
331
|
+
return nil
|
332
|
+
elsif network_groups.size > 1
|
333
|
+
print_red_alert "#{network_groups.size} network groups found by name #{name}"
|
334
|
+
# print_networks_table(networks, {color: red})
|
335
|
+
rows = network_groups.collect do |it|
|
336
|
+
{id: it['id'], name: it['name']}
|
337
|
+
end
|
338
|
+
puts as_pretty_table(rows, [:id, :name], {color:red})
|
339
|
+
return nil
|
340
|
+
else
|
341
|
+
return network_groups[0]
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
def prompt_for_network(network_id, options={}, required=true, field_name='network', field_label='Network')
|
346
|
+
# Prompt for a Network, text input that searches by name or id
|
347
|
+
network = nil
|
348
|
+
still_prompting = true
|
349
|
+
while still_prompting do
|
350
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => field_name, 'type' => 'text', 'fieldLabel' => field_label, 'required' => required, 'description' => 'Network name or ID.'}], network_id ? {(field_name) => network_id} : {})
|
351
|
+
network_id = v_prompt['network']
|
352
|
+
begin
|
353
|
+
network = find_network_by_name_or_id(network_id)
|
354
|
+
rescue SystemExit => cmdexit
|
355
|
+
end
|
356
|
+
if options[:no_prompt]
|
357
|
+
still_prompting = false
|
358
|
+
else
|
359
|
+
still_prompting = network ? false : true
|
360
|
+
end
|
361
|
+
if still_prompting
|
362
|
+
network_id = nil
|
363
|
+
end
|
364
|
+
end
|
365
|
+
return {success:!!network, network: network}
|
366
|
+
end
|
367
|
+
|
368
|
+
def prompt_for_networks(params, options={}, api_client=nil, api_params={})
|
369
|
+
# Networks
|
370
|
+
network_list = nil
|
371
|
+
network_ids = nil
|
372
|
+
still_prompting = true
|
373
|
+
if params['networks'].nil?
|
374
|
+
still_prompting = true
|
375
|
+
while still_prompting do
|
376
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'networks', 'type' => 'text', 'fieldLabel' => 'Networks', 'required' => false, 'description' => 'Networks to include, comma separated list of names or IDs.'}], options[:options])
|
377
|
+
unless v_prompt['networks'].to_s.empty?
|
378
|
+
network_list = v_prompt['networks'].split(",").collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
379
|
+
end
|
380
|
+
network_ids = []
|
381
|
+
bad_ids = []
|
382
|
+
if network_list && network_list.size > 0
|
383
|
+
network_list.each do |it|
|
384
|
+
found_network = nil
|
385
|
+
begin
|
386
|
+
found_network = find_network_by_name_or_id(it)
|
387
|
+
rescue SystemExit => cmdexit
|
388
|
+
end
|
389
|
+
if found_network
|
390
|
+
network_ids << found_network['id']
|
391
|
+
else
|
392
|
+
bad_ids << it
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
still_prompting = bad_ids.empty? ? false : true
|
397
|
+
end
|
398
|
+
else
|
399
|
+
network_list = params['networks']
|
400
|
+
still_prompting = false
|
401
|
+
network_ids = []
|
402
|
+
bad_ids = []
|
403
|
+
if network_list && network_list.size > 0
|
404
|
+
network_list.each do |it|
|
405
|
+
found_network = nil
|
406
|
+
begin
|
407
|
+
found_network = find_network_by_name_or_id(it)
|
408
|
+
rescue SystemExit => cmdexit
|
409
|
+
end
|
410
|
+
if found_network
|
411
|
+
network_ids << found_network['id']
|
412
|
+
else
|
413
|
+
bad_ids << it
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
if !bad_ids.empty?
|
418
|
+
return {success:false, msg:"Networks not found: #{bad_ids}"}
|
419
|
+
end
|
420
|
+
end
|
421
|
+
return {success:true, data: network_ids}
|
422
|
+
end
|
423
|
+
|
424
|
+
def prompt_for_subnets(params, options={}, api_client=nil, api_params={})
|
425
|
+
# todo: make this a generic method now please.
|
426
|
+
# Subnets
|
427
|
+
record_list = nil
|
428
|
+
record_ids = nil
|
429
|
+
still_prompting = true
|
430
|
+
if params['subnets'].nil?
|
431
|
+
still_prompting = true
|
432
|
+
while still_prompting do
|
433
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'subnets', 'type' => 'text', 'fieldLabel' => 'Subnets', 'required' => false, 'description' => 'Subnets to include, comma separated list of names or IDs.'}], options[:options])
|
434
|
+
unless v_prompt['subnets'].to_s.empty?
|
435
|
+
record_list = v_prompt['subnets'].split(",").collect {|it| it.to_s.strip.empty? ? nil : it.to_s.strip }.compact.uniq
|
436
|
+
end
|
437
|
+
record_ids = []
|
438
|
+
bad_ids = []
|
439
|
+
if record_list && record_list.size > 0
|
440
|
+
record_list.each do |it|
|
441
|
+
found_record = nil
|
442
|
+
begin
|
443
|
+
found_record = find_subnet_by_name_or_id(it)
|
444
|
+
rescue SystemExit => cmdexit
|
445
|
+
end
|
446
|
+
if found_record
|
447
|
+
record_ids << found_record['id']
|
448
|
+
else
|
449
|
+
bad_ids << it
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
still_prompting = bad_ids.empty? ? false : true
|
454
|
+
end
|
455
|
+
else
|
456
|
+
record_list = params['subnets']
|
457
|
+
still_prompting = false
|
458
|
+
record_ids = []
|
459
|
+
bad_ids = []
|
460
|
+
if record_list && record_list.size > 0
|
461
|
+
record_list.each do |it|
|
462
|
+
found_network = nil
|
463
|
+
begin
|
464
|
+
found_network = find_record_by_name_or_id(it)
|
465
|
+
rescue SystemExit => cmdexit
|
466
|
+
end
|
467
|
+
if found_network
|
468
|
+
record_ids << found_network['id']
|
469
|
+
else
|
470
|
+
bad_ids << it
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|
474
|
+
if !bad_ids.empty?
|
475
|
+
return {success:false, msg:"Subnets not found: #{bad_ids}"}
|
476
|
+
end
|
477
|
+
end
|
478
|
+
return {success:true, data: record_ids}
|
479
|
+
end
|
480
|
+
|
106
481
|
end
|
@@ -15,8 +15,6 @@ class Morpheus::Cli::MonitoringAlertsCommand
|
|
15
15
|
|
16
16
|
register_subcommands :list, :get, :add, :update, :remove
|
17
17
|
|
18
|
-
set_command_hidden # hiding until 4.1.1 release
|
19
|
-
|
20
18
|
def initialize()
|
21
19
|
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
22
20
|
end
|