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/login.rb
CHANGED
@@ -9,49 +9,71 @@ class Morpheus::Cli::Login
|
|
9
9
|
include Morpheus::Cli::CliCommand
|
10
10
|
# include Morpheus::Cli::WhoamiHelper
|
11
11
|
# include Morpheus::Cli::AccountsHelper
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
12
|
+
def initialize()
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect(opts)
|
17
|
+
#@api_client = establish_remote_appliance_connection(opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def usage
|
21
|
+
"Usage: morpheus login"
|
22
|
+
end
|
23
|
+
|
24
|
+
def handle(args)
|
25
|
+
login(args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def login(args)
|
29
|
+
options = {}
|
30
|
+
username, password = nil, nil
|
31
|
+
optparse = OptionParser.new do|opts|
|
32
|
+
opts.banner = usage
|
33
|
+
opts.on( '-u', '--username USERNAME', "Username" ) do |val|
|
34
|
+
username = val
|
35
|
+
end
|
36
|
+
opts.on( '-p', '--password PASSWORD', "Password" ) do |val|
|
37
|
+
password = val
|
38
|
+
end
|
39
|
+
build_common_options(opts, options, [:json, :remote, :quiet])
|
40
|
+
end
|
41
|
+
optparse.parse!(args)
|
42
|
+
|
43
|
+
# connect(options)
|
44
|
+
if options[:remote]
|
45
|
+
appliance = Morpheus::Cli::Remote.appliances[options[:remote].to_sym]
|
46
|
+
if appliance
|
47
|
+
@appliance_name, @appliance_url = options[:remote].to_sym, appliance[:host]
|
48
|
+
else
|
49
|
+
@appliance_name, @appliance_url = nil, nil
|
50
|
+
end
|
51
|
+
else
|
52
|
+
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
if !@appliance_name
|
57
|
+
print yellow,"Please specify a remote appliance with -r or see the command `remote use`#{reset}\n"
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
if options[:quiet]
|
61
|
+
if username.empty? || password.empty?
|
62
|
+
print yellow,"You have not specified username and password\n"
|
63
|
+
return false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
options[:remote_username] = username if username
|
67
|
+
options[:remote_password] = password if password
|
68
|
+
#options[:remote_url] = true # will skip credentials save
|
69
|
+
Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).login(options)
|
70
|
+
|
71
|
+
rescue RestClient::Exception => e
|
72
|
+
print_rest_exception(e, options)
|
73
|
+
exit 1
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
56
78
|
|
57
79
|
end
|
data/lib/morpheus/cli/logout.rb
CHANGED
@@ -11,51 +11,52 @@ class Morpheus::Cli::Logout
|
|
11
11
|
include Morpheus::Cli::CliCommand
|
12
12
|
# include Morpheus::Cli::WhoamiHelper
|
13
13
|
# include Morpheus::Cli::AccountsHelper
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
14
|
+
def initialize()
|
15
|
+
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect(opts)
|
19
|
+
#@api_client = establish_remote_appliance_connection(opts)
|
20
|
+
#@access_token = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def usage
|
24
|
+
"Usage: morpheus logout"
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle(args)
|
28
|
+
logout(args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def logout(args)
|
32
|
+
options = {}
|
33
|
+
optparse = OptionParser.new do|opts|
|
34
|
+
opts.banner = usage
|
35
|
+
build_common_options(opts, options, [:remote]) # todo: support :remote too perhaps
|
36
|
+
end
|
37
|
+
optparse.parse!(args)
|
38
|
+
connect(options)
|
39
|
+
|
40
|
+
begin
|
41
|
+
if !@appliance_name
|
42
|
+
print yellow,"Please specify a Morpheus Appliance to logout of with -r or see the command `remote use`#{reset}\n"
|
43
|
+
return
|
44
|
+
end
|
45
|
+
creds = Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).load_saved_credentials()
|
46
|
+
if !creds
|
47
|
+
print yellow,"You are not currently logged in to #{display_appliance(@appliance_name, @appliance_url)}\n",reset
|
48
|
+
return 0
|
49
|
+
else
|
50
|
+
Morpheus::Cli::Credentials.new(@appliance_name, @appliance_url).logout()
|
51
|
+
print cyan,"Goodbye\n",reset
|
52
|
+
end
|
53
|
+
|
54
|
+
rescue RestClient::Exception => e
|
55
|
+
print_rest_exception(e, options)
|
56
|
+
return 1
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
60
61
|
|
61
62
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'table_print'
|
2
2
|
require 'morpheus/cli/mixins/print_helper'
|
3
3
|
|
4
|
-
# Mixin for Morpheus::Cli command classes
|
4
|
+
# Mixin for Morpheus::Cli command classes
|
5
5
|
# Provides common methods for fetching and printing accounts, roles, and users.
|
6
6
|
# The including class must establish @accounts_interface, @roles_interface, @users_interface
|
7
7
|
module Morpheus::Cli::AccountsHelper
|
@@ -10,10 +10,35 @@ module Morpheus::Cli::AccountsHelper
|
|
10
10
|
klass.send :include, Morpheus::Cli::PrintHelper
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def accounts_interface
|
14
|
+
# @api_client.accounts
|
14
15
|
raise "#{self.class} has not defined @accounts_interface" if @accounts_interface.nil?
|
16
|
+
@accounts_interface
|
17
|
+
end
|
18
|
+
|
19
|
+
def users_interface
|
20
|
+
# @api_client.users
|
21
|
+
raise "#{self.class} has not defined @users_interface" if @users_interface.nil?
|
22
|
+
@users_interface
|
23
|
+
end
|
24
|
+
|
25
|
+
def roles_interface
|
26
|
+
# @api_client.roles
|
27
|
+
raise "#{self.class} has not defined @roles_interface" if @roles_interface.nil?
|
28
|
+
@roles_interface
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_account_by_name_or_id(val)
|
32
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
33
|
+
return find_account_by_id(val)
|
34
|
+
else
|
35
|
+
return find_account_by_name(val)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_account_by_id(id)
|
15
40
|
begin
|
16
|
-
json_response =
|
41
|
+
json_response = accounts_interface.get(id.to_i)
|
17
42
|
return json_response['account']
|
18
43
|
rescue RestClient::Exception => e
|
19
44
|
if e.response && e.response.code == 404
|
@@ -25,8 +50,7 @@ module Morpheus::Cli::AccountsHelper
|
|
25
50
|
end
|
26
51
|
|
27
52
|
def find_account_by_name(name)
|
28
|
-
|
29
|
-
accounts = @accounts_interface.list({name: name.to_s})['accounts']
|
53
|
+
accounts = accounts_interface.list({name: name.to_s})['accounts']
|
30
54
|
if accounts.empty?
|
31
55
|
print_red_alert "Account not found by name #{name}"
|
32
56
|
return nil
|
@@ -43,7 +67,10 @@ module Morpheus::Cli::AccountsHelper
|
|
43
67
|
|
44
68
|
def find_account_from_options(options)
|
45
69
|
account = nil
|
46
|
-
if options[:
|
70
|
+
if options[:account]
|
71
|
+
account = find_account_by_name_or_id(options[:account])
|
72
|
+
exit 1 if account.nil?
|
73
|
+
elsif options[:account_name]
|
47
74
|
account = find_account_by_name(options[:account_name])
|
48
75
|
exit 1 if account.nil?
|
49
76
|
elsif options[:account_id]
|
@@ -55,10 +82,17 @@ module Morpheus::Cli::AccountsHelper
|
|
55
82
|
return account
|
56
83
|
end
|
57
84
|
|
85
|
+
def find_role_by_name_or_id(account_id, val)
|
86
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
87
|
+
return find_role_by_id(account_id, val)
|
88
|
+
else
|
89
|
+
return find_role_by_name(account_id, val)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
58
93
|
def find_role_by_id(account_id, id)
|
59
|
-
raise "#{self.class} has not defined @roles_interface" if @roles_interface.nil?
|
60
94
|
begin
|
61
|
-
json_response =
|
95
|
+
json_response = roles_interface.get(account_id, id.to_i)
|
62
96
|
return json_response['role']
|
63
97
|
rescue RestClient::Exception => e
|
64
98
|
if e.response && e.response.code == 404
|
@@ -70,8 +104,7 @@ module Morpheus::Cli::AccountsHelper
|
|
70
104
|
end
|
71
105
|
|
72
106
|
def find_role_by_name(account_id, name)
|
73
|
-
|
74
|
-
roles = @roles_interface.list(account_id, {authority: name.to_s})['roles']
|
107
|
+
roles = roles_interface.list(account_id, {authority: name.to_s})['roles']
|
75
108
|
if roles.empty?
|
76
109
|
print_red_alert "Role not found by name #{name}"
|
77
110
|
return nil
|
@@ -87,10 +120,17 @@ module Morpheus::Cli::AccountsHelper
|
|
87
120
|
|
88
121
|
alias_method :find_role_by_authority, :find_role_by_name
|
89
122
|
|
123
|
+
def find_user_by_username_or_id(account_id, val)
|
124
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
125
|
+
return find_user_by_id(account_id, val)
|
126
|
+
else
|
127
|
+
return find_user_by_username(account_id, val)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
90
131
|
def find_user_by_id(account_id, id)
|
91
|
-
raise "#{self.class} has not defined @users_interface" if @users_interface.nil?
|
92
132
|
begin
|
93
|
-
json_response =
|
133
|
+
json_response = users_interface.get(account_id, id.to_i)
|
94
134
|
return json_response['user']
|
95
135
|
rescue RestClient::Exception => e
|
96
136
|
if e.response && e.response.code == 404
|
@@ -102,8 +142,7 @@ module Morpheus::Cli::AccountsHelper
|
|
102
142
|
end
|
103
143
|
|
104
144
|
def find_user_by_username(account_id, username)
|
105
|
-
|
106
|
-
users = @users_interface.list(account_id, {username: username.to_s})['users']
|
145
|
+
users = users_interface.list(account_id, {username: username.to_s})['users']
|
107
146
|
if users.empty?
|
108
147
|
print_red_alert "User not found by username #{username}"
|
109
148
|
return nil
|
@@ -127,21 +166,20 @@ module Morpheus::Cli::AccountsHelper
|
|
127
166
|
status_state = "#{red}INACTIVE#{table_color}"
|
128
167
|
end
|
129
168
|
{
|
130
|
-
id: account['id'],
|
131
|
-
name: account['name'],
|
132
|
-
description: account['description'],
|
133
|
-
role: account['role'] ? account['role']['authority'] : nil,
|
169
|
+
id: account['id'],
|
170
|
+
name: account['name'],
|
171
|
+
description: account['description'],
|
172
|
+
role: account['role'] ? account['role']['authority'] : nil,
|
134
173
|
status: status_state,
|
135
|
-
dateCreated: format_local_dt(account['dateCreated'])
|
174
|
+
dateCreated: format_local_dt(account['dateCreated'])
|
136
175
|
}
|
137
176
|
end
|
138
|
-
|
139
177
|
print table_color
|
140
178
|
tp rows, [
|
141
|
-
:id,
|
142
|
-
:name,
|
143
|
-
:description,
|
144
|
-
:role,
|
179
|
+
:id,
|
180
|
+
:name,
|
181
|
+
:description,
|
182
|
+
:role,
|
145
183
|
{:dateCreated => {:display_name => "Date Created"} },
|
146
184
|
:status
|
147
185
|
]
|
@@ -178,21 +216,21 @@ module Morpheus::Cli::AccountsHelper
|
|
178
216
|
# ]
|
179
217
|
rows = roles.collect do |role|
|
180
218
|
{
|
181
|
-
id: role['id'],
|
182
|
-
name: role['authority'],
|
183
|
-
description: role['description'],
|
219
|
+
id: role['id'],
|
220
|
+
name: role['authority'],
|
221
|
+
description: role['description'],
|
184
222
|
scope: role['scope'],
|
185
223
|
multitenant: role['multitenant'] ? 'Yes' : 'No',
|
186
224
|
type: format_role_type(role),
|
187
225
|
owner: role['owner'] ? role['owner']['name'] : "System",
|
188
|
-
dateCreated: format_local_dt(role['dateCreated'])
|
226
|
+
dateCreated: format_local_dt(role['dateCreated'])
|
189
227
|
}
|
190
228
|
end
|
191
229
|
print table_color
|
192
230
|
tp rows, [
|
193
|
-
:id,
|
194
|
-
:name,
|
195
|
-
:description,
|
231
|
+
:id,
|
232
|
+
:name,
|
233
|
+
:description,
|
196
234
|
# opts[:is_master_account] ? :scope : nil,
|
197
235
|
opts[:is_master_account] ? :type : nil,
|
198
236
|
opts[:is_master_account] ? :multitenant : nil,
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'morpheus/cli/mixins/print_helper'
|
2
|
+
require 'morpheus/cli/option_types'
|
3
|
+
require 'morpheus/rest_client'
|
4
|
+
# Mixin for Morpheus::Cli command classes
|
5
|
+
# Provides common methods for infrastructure management
|
6
|
+
module Morpheus::Cli::InfrastructureHelper
|
7
|
+
|
8
|
+
def self.included(klass)
|
9
|
+
klass.send :include, Morpheus::Cli::PrintHelper
|
10
|
+
end
|
11
|
+
|
12
|
+
def groups_interface
|
13
|
+
# @api_client.groups
|
14
|
+
raise "#{self.class} has not defined @groups_interface" if @groups_interface.nil?
|
15
|
+
@groups_interface
|
16
|
+
end
|
17
|
+
|
18
|
+
def clouds_interface
|
19
|
+
# @api_client.clouds
|
20
|
+
raise "#{self.class} has not defined @clouds_interface" if @clouds_interface.nil?
|
21
|
+
@clouds_interface
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_group_by_name_or_id(val)
|
25
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
26
|
+
return find_group_by_id(val)
|
27
|
+
else
|
28
|
+
return find_group_by_name(val)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_group_by_id(id)
|
33
|
+
begin
|
34
|
+
json_response = groups_interface.get(id.to_i)
|
35
|
+
return json_response['group']
|
36
|
+
rescue RestClient::Exception => e
|
37
|
+
if e.response && e.response.code == 404
|
38
|
+
print_red_alert "Group not found by id #{id}"
|
39
|
+
exit 1
|
40
|
+
else
|
41
|
+
raise e
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_group_by_name(name)
|
47
|
+
json_results = groups_interface.get({name: name})
|
48
|
+
if json_results['groups'].empty?
|
49
|
+
print_red_alert "Group not found by name #{name}"
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
group = json_results['groups'][0]
|
53
|
+
return group
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_cloud_by_name_or_id(val)
|
57
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
58
|
+
return find_cloud_by_id(val)
|
59
|
+
else
|
60
|
+
return find_cloud_by_name(val)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_cloud_by_id(id)
|
65
|
+
json_results = clouds_interface.get(id.to_i)
|
66
|
+
if json_results['zone'].empty?
|
67
|
+
print_red_alert "Cloud not found by id #{id}"
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
cloud = json_results['zone']
|
71
|
+
return cloud
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_cloud_by_name(name)
|
75
|
+
json_results = clouds_interface.get({name: name})
|
76
|
+
if json_results['zones'].empty?
|
77
|
+
print_red_alert "Cloud not found by name #{name}"
|
78
|
+
exit 1
|
79
|
+
end
|
80
|
+
cloud = json_results['zones'][0]
|
81
|
+
return cloud
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_available_cloud_types(refresh=false)
|
85
|
+
if !@available_cloud_types || refresh
|
86
|
+
@available_cloud_types = clouds_interface.cloud_types['zoneTypes']
|
87
|
+
end
|
88
|
+
return @available_cloud_types
|
89
|
+
end
|
90
|
+
|
91
|
+
def cloud_type_for_name_or_id(val)
|
92
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
93
|
+
return cloud_type_for_id(val)
|
94
|
+
else
|
95
|
+
return cloud_type_for_name(val)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
def cloud_type_for_id(id)
|
99
|
+
return get_available_cloud_types().find { |z| z['id'].to_i == id.to_i}
|
100
|
+
end
|
101
|
+
|
102
|
+
def cloud_type_for_name(name)
|
103
|
+
return get_available_cloud_types().find { |z| z['name'].downcase == name.downcase || z['code'].downcase == name.downcase}
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|