morpheus-cli 3.3.1.4 → 3.3.2
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 +28 -0
- data/lib/morpheus/api/instance_types_interface.rb +12 -10
- data/lib/morpheus/api/instances_interface.rb +4 -0
- data/lib/morpheus/api/library_container_scripts_interface.rb +49 -0
- data/lib/morpheus/api/library_container_templates_interface.rb +49 -0
- data/lib/morpheus/api/library_container_types_interface.rb +65 -0
- data/lib/morpheus/api/library_container_upgrades_interface.rb +66 -0
- data/lib/morpheus/api/library_instance_types_interface.rb +59 -0
- data/lib/morpheus/api/library_layouts_interface.rb +65 -0
- data/lib/morpheus/api/servers_interface.rb +4 -0
- data/lib/morpheus/api/user_sources_interface.rb +120 -0
- data/lib/morpheus/api/virtual_images_interface.rb +7 -0
- data/lib/morpheus/cli.rb +12 -1
- data/lib/morpheus/cli/accounts.rb +35 -9
- data/lib/morpheus/cli/cli_command.rb +82 -2
- data/lib/morpheus/cli/curl_command.rb +1 -1
- data/lib/morpheus/cli/echo_command.rb +1 -1
- data/lib/morpheus/cli/hosts.rb +40 -14
- data/lib/morpheus/cli/instance_types.rb +106 -64
- data/lib/morpheus/cli/instances.rb +39 -15
- data/lib/morpheus/cli/library.rb +1 -1184
- data/lib/morpheus/cli/library_container_scripts_command.rb +437 -0
- data/lib/morpheus/cli/library_container_templates_command.rb +397 -0
- data/lib/morpheus/cli/library_container_types_command.rb +653 -0
- data/lib/morpheus/cli/library_instance_types_command.rb +491 -0
- data/lib/morpheus/cli/library_layouts_command.rb +650 -0
- data/lib/morpheus/cli/library_option_lists_command.rb +476 -0
- data/lib/morpheus/cli/library_option_types_command.rb +549 -0
- data/lib/morpheus/cli/library_upgrades_command.rb +604 -0
- data/lib/morpheus/cli/mixins/library_helper.rb +123 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +21 -22
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +56 -11
- data/lib/morpheus/cli/network_services_command.rb +1 -1
- data/lib/morpheus/cli/option_types.rb +12 -2
- data/lib/morpheus/cli/power_scheduling_command.rb +1 -1
- data/lib/morpheus/cli/shell.rb +120 -22
- data/lib/morpheus/cli/sleep_command.rb +45 -0
- data/lib/morpheus/cli/user_sources_command.rb +963 -0
- data/lib/morpheus/cli/users.rb +33 -2
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/version_command.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +93 -39
- data/lib/morpheus/formatters.rb +37 -27
- data/lib/morpheus/terminal.rb +1 -1
- metadata +20 -2
@@ -22,6 +22,10 @@ class Morpheus::ServersInterface < Morpheus::APIClient
|
|
22
22
|
execute(opts)
|
23
23
|
end
|
24
24
|
|
25
|
+
def list(options={})
|
26
|
+
get(options)
|
27
|
+
end
|
28
|
+
|
25
29
|
def create(options)
|
26
30
|
url = "#{@base_url}/api/servers"
|
27
31
|
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'morpheus/api/api_client'
|
2
|
+
|
3
|
+
class Morpheus::UserSourcesInterface < Morpheus::APIClient
|
4
|
+
def initialize(access_token, refresh_token, expires_at = nil, base_url=nil)
|
5
|
+
@access_token = access_token
|
6
|
+
@refresh_token = refresh_token
|
7
|
+
@base_url = base_url
|
8
|
+
@expires_at = expires_at
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(account_id, id)
|
12
|
+
raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
|
13
|
+
url = build_url(account_id, id)
|
14
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
15
|
+
opts = {method: :get, url: url, timeout: 10, headers: headers}
|
16
|
+
execute(opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
def list(account_id, options={})
|
20
|
+
url = build_url(account_id)
|
21
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
22
|
+
headers[:params].merge!(options)
|
23
|
+
opts = {method: :get, url: url, timeout: 10, headers: headers}
|
24
|
+
execute(opts)
|
25
|
+
end
|
26
|
+
|
27
|
+
# def feature_permissions(account_id, id)
|
28
|
+
# url = build_url(account_id, id) + "/feature-permissions"
|
29
|
+
# headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
30
|
+
# opts = {method: :get, url: url, timeout: 10, headers: headers}
|
31
|
+
# execute(opts)
|
32
|
+
# end
|
33
|
+
|
34
|
+
# def available_roles(account_id, id=nil, options={})
|
35
|
+
# url = build_url(account_id, id) + "/available-roles"
|
36
|
+
# headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
37
|
+
# headers[:params].merge!(options)
|
38
|
+
# opts = {method: :get, url: url, timeout: 10, headers: headers}
|
39
|
+
# execute(opts)
|
40
|
+
# end
|
41
|
+
|
42
|
+
def create(account_id, options)
|
43
|
+
url = build_url(account_id)
|
44
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
45
|
+
payload = options
|
46
|
+
opts = {method: :post, url: url, timeout: 10, headers: headers, payload: payload.to_json}
|
47
|
+
execute(opts)
|
48
|
+
end
|
49
|
+
|
50
|
+
def update(account_id, id, options)
|
51
|
+
url = build_url(account_id, id)
|
52
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
53
|
+
payload = options
|
54
|
+
opts = {method: :put, url: url, timeout: 10, headers: headers, payload: payload.to_json}
|
55
|
+
execute(opts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def destroy(account_id, id)
|
59
|
+
url = build_url(account_id, id)
|
60
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
61
|
+
opts = {method: :delete, url: url, timeout: 10, headers: headers}
|
62
|
+
execute(opts)
|
63
|
+
end
|
64
|
+
|
65
|
+
def activate(account_id, id, options)
|
66
|
+
url = build_url(account_id, id) + "/activate"
|
67
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
68
|
+
payload = options
|
69
|
+
opts = {method: :put, url: url, timeout: 10, headers: headers, payload: payload.to_json}
|
70
|
+
execute(opts)
|
71
|
+
end
|
72
|
+
|
73
|
+
def deactivate(account_id, id, options)
|
74
|
+
url = build_url(account_id, id) + "/deactivate"
|
75
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
76
|
+
payload = options
|
77
|
+
opts = {method: :put, url: url, timeout: 10, headers: headers, payload: payload.to_json}
|
78
|
+
execute(opts)
|
79
|
+
end
|
80
|
+
|
81
|
+
def update_subdomain(account_id, id, options)
|
82
|
+
url = build_url(account_id, id) + "/subdomain"
|
83
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
84
|
+
payload = options
|
85
|
+
opts = {method: :put, url: url, timeout: 10, headers: headers, payload: payload.to_json}
|
86
|
+
execute(opts)
|
87
|
+
end
|
88
|
+
|
89
|
+
# move me to my own interface class
|
90
|
+
def list_types(params={})
|
91
|
+
url = "#{@base_url}/api/user-source-types"
|
92
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
93
|
+
opts = {method: :get, url: url, timeout: 10, headers: headers}
|
94
|
+
execute(opts)
|
95
|
+
end
|
96
|
+
|
97
|
+
# move me to my own interface class
|
98
|
+
def get_type(id, params={})
|
99
|
+
url = "#{@base_url}/api/user-source-types/#{id}"
|
100
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
101
|
+
opts = {method: :get, url: url, timeout: 10, headers: headers}
|
102
|
+
execute(opts)
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def build_url(account_id=nil, user_id=nil)
|
108
|
+
url = "#{@base_url}/api"
|
109
|
+
if account_id
|
110
|
+
url += "/accounts/#{account_id}/user-sources"
|
111
|
+
else
|
112
|
+
url += "/user-sources"
|
113
|
+
end
|
114
|
+
if user_id
|
115
|
+
url += "/#{user_id}"
|
116
|
+
end
|
117
|
+
url
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -71,6 +71,13 @@ class Morpheus::VirtualImagesInterface < Morpheus::APIClient
|
|
71
71
|
execute(method: :post, url: url, headers: headers, payload: payload)
|
72
72
|
end
|
73
73
|
|
74
|
+
def upload_by_url(id, file_url)
|
75
|
+
url = "#{@base_url}/api/virtual-images/#{id}/upload"
|
76
|
+
headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'}
|
77
|
+
headers[:params][:url] = file_url
|
78
|
+
execute(method: :post, url: url, headers: headers)
|
79
|
+
end
|
80
|
+
|
74
81
|
def destroy_file(id, filename)
|
75
82
|
url = "#{@base_url}/api/virtual-images/#{id}/files"
|
76
83
|
#url = "#{@base_url}/api/virtual-images/#{id}/files/#{filename}"
|
data/lib/morpheus/cli.rb
CHANGED
@@ -49,6 +49,7 @@ module Morpheus
|
|
49
49
|
# shell scripting commands
|
50
50
|
load 'morpheus/cli/source_command.rb'
|
51
51
|
load 'morpheus/cli/echo_command.rb'
|
52
|
+
load 'morpheus/cli/sleep_command.rb'
|
52
53
|
load 'morpheus/cli/coloring_command.rb'
|
53
54
|
load 'morpheus/cli/log_level_command.rb'
|
54
55
|
load 'morpheus/cli/ssl_verification_command.rb'
|
@@ -81,10 +82,20 @@ module Morpheus
|
|
81
82
|
load 'morpheus/cli/accounts.rb'
|
82
83
|
load 'morpheus/cli/users.rb'
|
83
84
|
load 'morpheus/cli/user_groups_command.rb'
|
85
|
+
load 'morpheus/cli/user_sources_command.rb'
|
84
86
|
load 'morpheus/cli/roles.rb'
|
85
87
|
load 'morpheus/cli/key_pairs.rb'
|
86
88
|
load 'morpheus/cli/virtual_images.rb'
|
87
|
-
load 'morpheus/cli/library.rb'
|
89
|
+
# load 'morpheus/cli/library.rb' # gone until we collapse these again
|
90
|
+
load 'morpheus/cli/library_instance_types_command.rb'
|
91
|
+
load 'morpheus/cli/library_layouts_command.rb'
|
92
|
+
load 'morpheus/cli/library_upgrades_command.rb'
|
93
|
+
load 'morpheus/cli/library_container_types_command.rb'
|
94
|
+
load 'morpheus/cli/library_container_scripts_command.rb'
|
95
|
+
load 'morpheus/cli/library_container_templates_command.rb'
|
96
|
+
load 'morpheus/cli/library_option_types_command.rb'
|
97
|
+
load 'morpheus/cli/library_option_lists_command.rb'
|
98
|
+
|
88
99
|
load 'morpheus/cli/version_command.rb'
|
89
100
|
load 'morpheus/cli/alias_command.rb'
|
90
101
|
# todo: combine checks, incidents, apps, and goups under monitoring?
|
@@ -10,7 +10,7 @@ require 'json'
|
|
10
10
|
class Morpheus::Cli::Accounts
|
11
11
|
include Morpheus::Cli::CliCommand
|
12
12
|
include Morpheus::Cli::AccountsHelper
|
13
|
-
register_subcommands :list, :get, :add, :update, :remove
|
13
|
+
register_subcommands :list, :count, :get, :add, :update, :remove
|
14
14
|
alias_subcommand :details, :get
|
15
15
|
set_default_subcommand :list
|
16
16
|
|
@@ -31,17 +31,16 @@ class Morpheus::Cli::Accounts
|
|
31
31
|
|
32
32
|
def list(args)
|
33
33
|
options = {}
|
34
|
-
optparse = OptionParser.new do|opts|
|
34
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
35
35
|
opts.banner = subcommand_usage()
|
36
|
-
build_common_options(opts, options, [:list, :json, :remote, :dry_run])
|
36
|
+
build_common_options(opts, options, [:list, :query, :json, :remote, :dry_run])
|
37
|
+
opts.footer = "List accounts."
|
37
38
|
end
|
38
39
|
optparse.parse!(args)
|
39
40
|
connect(options)
|
40
41
|
begin
|
41
42
|
params = {}
|
42
|
-
|
43
|
-
params[k] = options[k] unless options[k].nil?
|
44
|
-
end
|
43
|
+
params.merge!(parse_list_options(options))
|
45
44
|
if options[:dry_run]
|
46
45
|
print_dry_run @accounts_interface.dry.list(params)
|
47
46
|
return
|
@@ -54,9 +53,7 @@ class Morpheus::Cli::Accounts
|
|
54
53
|
else
|
55
54
|
title = "Morpheus Accounts"
|
56
55
|
subtitles = []
|
57
|
-
|
58
|
-
subtitles << "Search: #{params[:phrase]}".strip
|
59
|
-
end
|
56
|
+
subtitles += parse_list_subtitles(options)
|
60
57
|
print_h1 title, subtitles
|
61
58
|
if accounts.empty?
|
62
59
|
puts yellow,"No accounts found.",reset
|
@@ -72,6 +69,35 @@ class Morpheus::Cli::Accounts
|
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
72
|
+
def count(args)
|
73
|
+
options = {}
|
74
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
75
|
+
opts.banner = subcommand_usage("[options]")
|
76
|
+
build_common_options(opts, options, [:query, :remote, :dry_run])
|
77
|
+
opts.footer = "Get the number of accounts."
|
78
|
+
end
|
79
|
+
optparse.parse!(args)
|
80
|
+
connect(options)
|
81
|
+
begin
|
82
|
+
params = {}
|
83
|
+
params.merge!(parse_list_options(options))
|
84
|
+
if options[:dry_run]
|
85
|
+
print_dry_run @accounts_interface.dry.list(params)
|
86
|
+
return
|
87
|
+
end
|
88
|
+
json_response = @accounts_interface.list(params)
|
89
|
+
# print number only
|
90
|
+
if json_response['meta'] && json_response['meta']['total']
|
91
|
+
print cyan, json_response['meta']['total'], reset, "\n"
|
92
|
+
else
|
93
|
+
print yellow, "unknown", reset, "\n"
|
94
|
+
end
|
95
|
+
rescue RestClient::Exception => e
|
96
|
+
print_rest_exception(e, options)
|
97
|
+
exit 1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
75
101
|
def get(args)
|
76
102
|
options = {}
|
77
103
|
optparse = OptionParser.new do|opts|
|
@@ -286,6 +286,41 @@ module Morpheus
|
|
286
286
|
options[:direction] = "desc"
|
287
287
|
end
|
288
288
|
|
289
|
+
# arbitrary query parameters in the format -Q "category=web&phrase=nginx"
|
290
|
+
# opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'phrase=foobar&category=web'" ) do |val|
|
291
|
+
# options[:query_filters_raw] = val
|
292
|
+
# options[:query_filters] = {}
|
293
|
+
# # todo: smarter parsing
|
294
|
+
# val.split('&').each do |filter|
|
295
|
+
# k, v = filter.split('=')
|
296
|
+
# # allow "woot:true instead of woot=true"
|
297
|
+
# if (k.include?(":") && v == nil)
|
298
|
+
# k, v = k.split(":")
|
299
|
+
# end
|
300
|
+
# if (!k.to_s.empty?)
|
301
|
+
# options[:query_filters][k.to_s.strip] = v.to_s.strip
|
302
|
+
# end
|
303
|
+
# end
|
304
|
+
# end
|
305
|
+
|
306
|
+
when :query, :query_filters
|
307
|
+
# arbitrary query parameters in the format -Q "category=web&phrase=nginx"
|
308
|
+
opts.on( '-Q', '--query PARAMS', "Query parameters. PARAMS format is 'phrase=foobar&category=web'" ) do |val|
|
309
|
+
options[:query_filters_raw] = val
|
310
|
+
options[:query_filters] = {}
|
311
|
+
# todo: smarter parsing
|
312
|
+
val.split('&').each do |filter|
|
313
|
+
k, v = filter.split('=')
|
314
|
+
# allow "woot:true instead of woot=true"
|
315
|
+
if (k.include?(":") && v == nil)
|
316
|
+
k, v = k.split(":")
|
317
|
+
end
|
318
|
+
if (!k.to_s.empty?)
|
319
|
+
options[:query_filters][k.to_s.strip] = v.to_s.strip
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
289
324
|
when :last_updated
|
290
325
|
# opts.on("--last-updated TIME", Time, "Filter by gte last updated") do |time|
|
291
326
|
opts.on("--last-updated TIME", String, "Filter by Last Updated (gte)") do |time|
|
@@ -399,7 +434,7 @@ module Morpheus
|
|
399
434
|
end
|
400
435
|
|
401
436
|
when :fields
|
402
|
-
opts.on('--fields x,y,z', Array, "Filter Output to a limited set of fields. Default is all fields.") do |val|
|
437
|
+
opts.on('-F', '--fields x,y,z', Array, "Filter Output to a limited set of fields. Default is all fields.") do |val|
|
403
438
|
options[:include_fields] = val
|
404
439
|
end
|
405
440
|
|
@@ -425,7 +460,7 @@ module Morpheus
|
|
425
460
|
Term::ANSIColor::coloring = false
|
426
461
|
end
|
427
462
|
|
428
|
-
opts.on('-V','--debug', "Print extra output for debugging.
|
463
|
+
opts.on('-V','--debug', "Print extra output for debugging.") do
|
429
464
|
options[:debug] = true
|
430
465
|
Morpheus::Logging.set_log_level(Morpheus::Logging::Logger::DEBUG)
|
431
466
|
::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
|
@@ -656,6 +691,51 @@ module Morpheus
|
|
656
691
|
true
|
657
692
|
end
|
658
693
|
|
694
|
+
# parse the parameters provided by the common :list options
|
695
|
+
# returns Hash of params the format {"phrase": => "foobar", "max": 100}
|
696
|
+
def parse_list_options(options={})
|
697
|
+
list_params = {}
|
698
|
+
[:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
|
699
|
+
if options.key?(k)
|
700
|
+
list_params[k.to_s] = options[k]
|
701
|
+
elsif options.key?(k.to_s)
|
702
|
+
list_params[k.to_s] = options[k.to_s]
|
703
|
+
end
|
704
|
+
end
|
705
|
+
# arbitrary filters
|
706
|
+
if options[:query_filters]
|
707
|
+
options[:query_filters].each do |k, v|
|
708
|
+
if k
|
709
|
+
list_params[k] = v
|
710
|
+
end
|
711
|
+
end
|
712
|
+
end
|
713
|
+
return list_params
|
714
|
+
end
|
715
|
+
|
716
|
+
# parse the subtitles provided by the common :list options
|
717
|
+
# returns Array of subtitles as strings in the format ["Phrase: blah", "Max: 100"]
|
718
|
+
def parse_list_subtitles(options={})
|
719
|
+
subtitles = []
|
720
|
+
list_params = {}
|
721
|
+
[:phrase, :offset, :max, :sort, :direction, :lastUpdated].each do |k|
|
722
|
+
if options.key?(k)
|
723
|
+
subtitles << "#{k.to_s}: #{options[k]}"
|
724
|
+
elsif options.key?(k.to_s)
|
725
|
+
subtitles << "#{k.to_s}: #{options[k.to_s]}"
|
726
|
+
end
|
727
|
+
end
|
728
|
+
# arbitrary filters
|
729
|
+
if options[:query_filters]
|
730
|
+
formatted_filters = options[:query_filters].collect {|k,v| "#{k.to_s}=#{v}" }.join('&')
|
731
|
+
subtitles << "Query: #{formatted_filters}"
|
732
|
+
# options[:query_filters].each do |k, v|
|
733
|
+
# subtitles << "#{k.to_s}: #{v}"
|
734
|
+
# end
|
735
|
+
end
|
736
|
+
return subtitles
|
737
|
+
end
|
738
|
+
|
659
739
|
module ClassMethods
|
660
740
|
|
661
741
|
def set_command_name(cmd_name)
|
@@ -21,7 +21,7 @@ class Morpheus::Cli::CurlCommand
|
|
21
21
|
This invokes the `curl` command with url "appliance_url/api/$0
|
22
22
|
and includes the authorization header -H "Authorization: Bearer access_token"
|
23
23
|
Arguments for the curl command should be passed after ' -- '
|
24
|
-
Example: morpheus curl "/api/servers/1" -- -XGET -
|
24
|
+
Example: morpheus curl "/api/servers/1" -- -XGET -sv
|
25
25
|
|
26
26
|
EOT
|
27
27
|
end
|
data/lib/morpheus/cli/hosts.rb
CHANGED
@@ -10,7 +10,7 @@ require 'json'
|
|
10
10
|
class Morpheus::Cli::Hosts
|
11
11
|
include Morpheus::Cli::CliCommand
|
12
12
|
include Morpheus::Cli::ProvisioningHelper
|
13
|
-
register_subcommands :list, :get, :stats, :add, :remove, :logs, :start, :stop, :resize, :run_workflow, {:'make-managed' => :install_agent}, :upgrade_agent, :server_types
|
13
|
+
register_subcommands :list, :count, :get, :stats, :add, :remove, :logs, :start, :stop, :resize, :run_workflow, {:'make-managed' => :install_agent}, :upgrade_agent, :server_types
|
14
14
|
alias_subcommand :details, :get
|
15
15
|
set_default_subcommand :list
|
16
16
|
|
@@ -36,7 +36,7 @@ class Morpheus::Cli::Hosts
|
|
36
36
|
def list(args)
|
37
37
|
options = {}
|
38
38
|
params = {}
|
39
|
-
optparse = OptionParser.new do|opts|
|
39
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
40
40
|
opts.banner = subcommand_usage()
|
41
41
|
opts.on( '-g', '--group GROUP', "Group Name or ID" ) do |val|
|
42
42
|
options[:group] = val
|
@@ -81,7 +81,8 @@ class Morpheus::Cli::Hosts
|
|
81
81
|
opts.on( '', '--noagent', "Show only Servers with No agent" ) do |val|
|
82
82
|
params[:agentInstalled] = false
|
83
83
|
end
|
84
|
-
build_common_options(opts, options, [:list, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
84
|
+
build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
|
85
|
+
opts.footer = "List hosts."
|
85
86
|
end
|
86
87
|
optparse.parse!(args)
|
87
88
|
connect(options)
|
@@ -98,15 +99,13 @@ class Morpheus::Cli::Hosts
|
|
98
99
|
params['zoneId'] = cloud['id']
|
99
100
|
end
|
100
101
|
|
101
|
-
|
102
|
-
params[k] = options[k] unless options[k].nil?
|
103
|
-
end
|
102
|
+
params.merge!(parse_list_options(options))
|
104
103
|
|
105
104
|
if options[:dry_run]
|
106
|
-
print_dry_run @servers_interface.dry.
|
105
|
+
print_dry_run @servers_interface.dry.list(params)
|
107
106
|
return
|
108
107
|
end
|
109
|
-
json_response = @servers_interface.
|
108
|
+
json_response = @servers_interface.list(params)
|
110
109
|
|
111
110
|
if options[:json]
|
112
111
|
if options[:include_fields]
|
@@ -140,9 +139,7 @@ class Morpheus::Cli::Hosts
|
|
140
139
|
if cloud
|
141
140
|
subtitles << "Cloud: #{cloud['name']}".strip
|
142
141
|
end
|
143
|
-
|
144
|
-
subtitles << "Search: #{params[:phrase]}".strip
|
145
|
-
end
|
142
|
+
subtitles += parse_list_subtitles(options)
|
146
143
|
print_h1 title, subtitles
|
147
144
|
if servers.empty?
|
148
145
|
print yellow,"No hosts found.",reset,"\n"
|
@@ -206,6 +203,35 @@ class Morpheus::Cli::Hosts
|
|
206
203
|
end
|
207
204
|
end
|
208
205
|
|
206
|
+
def count(args)
|
207
|
+
options = {}
|
208
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
209
|
+
opts.banner = subcommand_usage("[options]")
|
210
|
+
build_common_options(opts, options, [:query, :remote, :dry_run])
|
211
|
+
opts.footer = "Get the number of hosts."
|
212
|
+
end
|
213
|
+
optparse.parse!(args)
|
214
|
+
connect(options)
|
215
|
+
begin
|
216
|
+
params = {}
|
217
|
+
params.merge!(parse_list_options(options))
|
218
|
+
if options[:dry_run]
|
219
|
+
print_dry_run @servers_interface.dry.list(params)
|
220
|
+
return
|
221
|
+
end
|
222
|
+
json_response = @servers_interface.list(params)
|
223
|
+
# print number only
|
224
|
+
if json_response['meta'] && json_response['meta']['total']
|
225
|
+
print cyan, json_response['meta']['total'], reset, "\n"
|
226
|
+
else
|
227
|
+
print yellow, "unknown", reset, "\n"
|
228
|
+
end
|
229
|
+
rescue RestClient::Exception => e
|
230
|
+
print_rest_exception(e, options)
|
231
|
+
exit 1
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
209
235
|
def get(args)
|
210
236
|
options = {}
|
211
237
|
optparse = OptionParser.new do|opts|
|
@@ -230,7 +256,7 @@ class Morpheus::Cli::Hosts
|
|
230
256
|
if arg.to_s =~ /\A\d{1,}\Z/
|
231
257
|
print_dry_run @servers_interface.dry.get(arg.to_i)
|
232
258
|
else
|
233
|
-
print_dry_run @servers_interface.dry.
|
259
|
+
print_dry_run @servers_interface.dry.list({name: arg})
|
234
260
|
end
|
235
261
|
return
|
236
262
|
end
|
@@ -310,7 +336,7 @@ class Morpheus::Cli::Hosts
|
|
310
336
|
if arg.to_s =~ /\A\d{1,}\Z/
|
311
337
|
print_dry_run @servers_interface.dry.get(arg.to_i)
|
312
338
|
else
|
313
|
-
print_dry_run @servers_interface.dry.
|
339
|
+
print_dry_run @servers_interface.dry.list({name: arg})
|
314
340
|
end
|
315
341
|
return
|
316
342
|
end
|
@@ -970,7 +996,7 @@ class Morpheus::Cli::Hosts
|
|
970
996
|
end
|
971
997
|
|
972
998
|
def find_host_by_name(name)
|
973
|
-
results = @servers_interface.
|
999
|
+
results = @servers_interface.list({name: name})
|
974
1000
|
if results['servers'].empty?
|
975
1001
|
print_red_alert "Server not found by name #{name}"
|
976
1002
|
exit 1
|