morpheus-cli 8.0.6 → 8.0.8
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/Dockerfile +1 -1
- data/lib/morpheus/api/clouds_interface.rb +35 -0
- data/lib/morpheus/api/clusters_interface.rb +30 -0
- data/lib/morpheus/api/servers_interface.rb +7 -0
- data/lib/morpheus/cli/commands/clouds.rb +348 -0
- data/lib/morpheus/cli/commands/clusters.rb +361 -1
- data/lib/morpheus/cli/commands/hosts.rb +189 -42
- data/lib/morpheus/cli/commands/instances.rb +76 -21
- data/lib/morpheus/cli/commands/license.rb +7 -1
- data/lib/morpheus/cli/commands/service_plans_command.rb +1 -0
- data/lib/morpheus/cli/commands/snapshots.rb +4 -0
- data/lib/morpheus/cli/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df49518b39388f8a75824156a31bff7fb8abcf4545a9f5af29bf6eab4eab6a79
|
4
|
+
data.tar.gz: c82269904d1de5f01a487ebad5bd6ac2dd110a0c2e2b183142dfb42828c5edec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b64913eef407dd0180526e67095182b89517fa2863ee8bce319ba77fb1c1ca25d0898299ebebd6072dc9fcbd19a77f8d3f4fef3298563e24bd37121fb8ae6c75
|
7
|
+
data.tar.gz: 6569d731faabe620597d94d20f78ffde2b5599934cd2b5bdb7153e86ce6cbd8359b83e0ff97a61d1d8ff6b8c4c8c6fc809a82e72ef39da5514859800e8388e2a
|
data/Dockerfile
CHANGED
@@ -2,6 +2,10 @@ require 'morpheus/api/api_client'
|
|
2
2
|
|
3
3
|
class Morpheus::CloudsInterface < Morpheus::APIClient
|
4
4
|
|
5
|
+
def base_path
|
6
|
+
"/api/zones"
|
7
|
+
end
|
8
|
+
|
5
9
|
def cloud_types(params={})
|
6
10
|
url = "#{@base_url}/api/zone-types"
|
7
11
|
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
@@ -137,4 +141,35 @@ class Morpheus::CloudsInterface < Morpheus::APIClient
|
|
137
141
|
end
|
138
142
|
execute(method: :post, url: url, headers: headers, payload: payload)
|
139
143
|
end
|
144
|
+
|
145
|
+
def list_affinity_groups(id, params={})
|
146
|
+
url = "#{base_path}/#{id}/affinity-groups"
|
147
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
148
|
+
execute(method: :get, url: url, headers: headers)
|
149
|
+
end
|
150
|
+
|
151
|
+
def get_affinity_group(id, affinity_group_id, params={})
|
152
|
+
url = "#{base_path}/#{id}/affinity-groups/#{affinity_group_id}"
|
153
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
154
|
+
execute(method: :get, url: url, headers: headers)
|
155
|
+
end
|
156
|
+
|
157
|
+
def create_affinity_group(id, payload)
|
158
|
+
url = "#{base_path}/#{id}/affinity-groups"
|
159
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
160
|
+
execute(method: :post, url: url, headers: headers, payload: payload.to_json)
|
161
|
+
end
|
162
|
+
|
163
|
+
def update_affinity_group(id, affinity_group_id, payload)
|
164
|
+
url = "#{base_path}/#{id}/affinity-groups/#{affinity_group_id}"
|
165
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
166
|
+
execute(method: :put, url: url, headers: headers, payload: payload.to_json)
|
167
|
+
end
|
168
|
+
|
169
|
+
def destroy_affinity_group(id, affinity_group_id, params={})
|
170
|
+
url = "#{base_path}/#{id}/affinity-groups/#{affinity_group_id}"
|
171
|
+
headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
172
|
+
execute(method: :delete, url: url, headers: headers)
|
173
|
+
end
|
174
|
+
|
140
175
|
end
|
@@ -353,4 +353,34 @@ class Morpheus::ClustersInterface < Morpheus::APIClient
|
|
353
353
|
execute(method: :get, url: url, headers: headers)
|
354
354
|
end
|
355
355
|
|
356
|
+
def list_affinity_groups(id, params={})
|
357
|
+
url = "#{base_path}/#{id}/affinity-groups"
|
358
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
359
|
+
execute(method: :get, url: url, headers: headers)
|
360
|
+
end
|
361
|
+
|
362
|
+
def get_affinity_group(id, affinity_group_id, params={})
|
363
|
+
url = "#{base_path}/#{id}/affinity-groups/#{affinity_group_id}"
|
364
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
365
|
+
execute(method: :get, url: url, headers: headers)
|
366
|
+
end
|
367
|
+
|
368
|
+
def create_affinity_group(id, payload)
|
369
|
+
url = "#{base_path}/#{id}/affinity-groups"
|
370
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
371
|
+
execute(method: :post, url: url, headers: headers, payload: payload.to_json)
|
372
|
+
end
|
373
|
+
|
374
|
+
def update_affinity_group(id, affinity_group_id, payload)
|
375
|
+
url = "#{base_path}/#{id}/affinity-groups/#{affinity_group_id}"
|
376
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
377
|
+
execute(method: :put, url: url, headers: headers, payload: payload.to_json)
|
378
|
+
end
|
379
|
+
|
380
|
+
def destroy_affinity_group(id, affinity_group_id, params={})
|
381
|
+
url = "#{base_path}/#{id}/affinity-groups/#{affinity_group_id}"
|
382
|
+
headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
383
|
+
execute(method: :delete, url: url, headers: headers)
|
384
|
+
end
|
385
|
+
|
356
386
|
end
|
@@ -212,5 +212,12 @@ class Morpheus::ServersInterface < Morpheus::APIClient
|
|
212
212
|
execute(opts)
|
213
213
|
end
|
214
214
|
|
215
|
+
def snapshot(serverId, payload = {}, params = {})
|
216
|
+
url = "#{@base_url}/api/servers/#{serverId}/snapshot"
|
217
|
+
headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
218
|
+
opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
|
219
|
+
execute(opts)
|
220
|
+
end
|
221
|
+
|
215
222
|
|
216
223
|
end
|
@@ -11,6 +11,7 @@ class Morpheus::Cli::Clouds
|
|
11
11
|
alias_subcommand :'get-type', :type
|
12
12
|
register_subcommands :wiki, :update_wiki
|
13
13
|
register_subcommands({:'update-logo' => :update_logo,:'update-dark-logo' => :update_dark_logo})
|
14
|
+
register_subcommands :list_affinity_groups, :get_affinity_group, :update_affinity_group, :add_affinity_group, :remove_affinity_group
|
14
15
|
#register_subcommands :firewall_disable, :firewall_enable
|
15
16
|
alias_subcommand :details, :get
|
16
17
|
set_default_subcommand :list
|
@@ -1149,6 +1150,331 @@ EOT
|
|
1149
1150
|
end
|
1150
1151
|
end
|
1151
1152
|
|
1153
|
+
def list_affinity_groups(args)
|
1154
|
+
options = {}
|
1155
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
1156
|
+
opts.banner = subcommand_usage( "[cloud]")
|
1157
|
+
build_standard_list_options(opts, options)
|
1158
|
+
opts.footer = "List affinity groups for a cloud.\n" +
|
1159
|
+
"[cloud] is required. This is the name or id of an existing cloud."
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
optparse.parse!(args)
|
1163
|
+
verify_args!(args:args, optparse:optparse, count:1)
|
1164
|
+
connect(options)
|
1165
|
+
|
1166
|
+
cloud = find_cloud_by_name_or_id(args[0])
|
1167
|
+
return 1 if cloud.nil?
|
1168
|
+
params = {}
|
1169
|
+
params.merge!(parse_list_options(options))
|
1170
|
+
json_response = @clouds_interface.list_affinity_groups(cloud['id'], params)
|
1171
|
+
render_response(json_response, options, 'affinityGroups') do
|
1172
|
+
affinity_groups = json_response['affinityGroups']
|
1173
|
+
print_h1 "Morpheus Cloud Affinity Groups: #{cloud['name']}", parse_list_subtitles(options)
|
1174
|
+
if affinity_groups.empty?
|
1175
|
+
print cyan,"No affinity groups found.",reset,"\n"
|
1176
|
+
else
|
1177
|
+
columns = {
|
1178
|
+
"ID" => 'id',
|
1179
|
+
"Name" => 'name',
|
1180
|
+
"Type" => lambda {|it| format_affinity_type(it['affinityType']) },
|
1181
|
+
"Resource Pool" => lambda {|it| it['pool'] ? (it['pool']['name'] || it['pool']['id']) : '' },
|
1182
|
+
"Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
|
1183
|
+
# "Servers" => lambda {|it| it['serverCount'] },
|
1184
|
+
# "Source" => lambda {|it| it['source'] },
|
1185
|
+
}.upcase_keys!
|
1186
|
+
print as_pretty_table(affinity_groups, columns, options)
|
1187
|
+
print_results_pagination(json_response)
|
1188
|
+
end
|
1189
|
+
print reset,"\n"
|
1190
|
+
end
|
1191
|
+
return 0, nil
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
def get_affinity_group(args)
|
1195
|
+
options = {}
|
1196
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
1197
|
+
opts.banner = subcommand_usage( "[cloud] [affinity group]")
|
1198
|
+
build_standard_get_options(opts, options)
|
1199
|
+
opts.footer = "Get details about a cloud affinity group.\n" +
|
1200
|
+
"[cloud] is required. This is the name or id of an existing cloud.\n" +
|
1201
|
+
"[affinity group] is required. This is the name or id of an existing affinity group."
|
1202
|
+
end
|
1203
|
+
optparse.parse!(args)
|
1204
|
+
verify_args!(args:args, optparse:optparse, count:2)
|
1205
|
+
connect(options)
|
1206
|
+
|
1207
|
+
cloud = find_cloud_by_name_or_id(args[0])
|
1208
|
+
return 1 if cloud.nil?
|
1209
|
+
# this finds the affinity group in the cloud api response, then fetches it by ID
|
1210
|
+
affinity_group = find_cloud_affinity_group_by_name_or_id(cloud['id'], args[1])
|
1211
|
+
if affinity_group.nil?
|
1212
|
+
print_red_alert "Affinity Group not found for '#{args[1]}'"
|
1213
|
+
exit 1
|
1214
|
+
end
|
1215
|
+
|
1216
|
+
params = {}
|
1217
|
+
params.merge!(parse_query_options(options))
|
1218
|
+
@clouds_interface.setopts(options)
|
1219
|
+
if options[:dry_run]
|
1220
|
+
print_dry_run @clouds_interface.dry.get_affinity_group(cloud['id'], affinity_group['id'], params)
|
1221
|
+
return
|
1222
|
+
end
|
1223
|
+
json_response = @clouds_interface.get_affinity_group(cloud['id'], affinity_group['id'], params)
|
1224
|
+
render_response(json_response, options, 'affinityGroup') do
|
1225
|
+
affinity_group = json_response['affinityGroup']
|
1226
|
+
print_h1 "Affinity Group Details", [], options
|
1227
|
+
columns = {
|
1228
|
+
"ID" => 'id',
|
1229
|
+
"Name" => 'name',
|
1230
|
+
"Type" => lambda {|it| format_affinity_type(it['affinityType']) },
|
1231
|
+
"Resource Pool" => lambda {|it| it['pool'] ? (it['pool']['name'] || it['pool']['id']) : '' },
|
1232
|
+
"Visibility" => lambda {|it| it['visibility'].to_s.capitalize },
|
1233
|
+
"Servers" => lambda {|it| it['servers'].size() },
|
1234
|
+
"Source" => lambda {|it| it['source'] },
|
1235
|
+
"Active" => lambda {|it| format_boolean(it['active']) },
|
1236
|
+
}
|
1237
|
+
print_description_list(columns, affinity_group)
|
1238
|
+
if affinity_group['servers'].size > 0
|
1239
|
+
print_h2 "Servers", options
|
1240
|
+
print as_pretty_table(affinity_group['servers'], [:id, :name], options)
|
1241
|
+
end
|
1242
|
+
print reset,"\n"
|
1243
|
+
end
|
1244
|
+
return 0, nil
|
1245
|
+
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
def add_affinity_group(args)
|
1249
|
+
options = {}
|
1250
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
1251
|
+
opts.banner = subcommand_usage( "[cloud] [name] [options]")
|
1252
|
+
build_option_type_options(opts, options, add_cloud_affinity_group_option_types)
|
1253
|
+
# opts.on('--refresh [SECONDS]', String, "Refresh until execution is complete. Default interval is #{default_refresh_interval} seconds.") do |val|
|
1254
|
+
# options[:refresh_interval] = val.to_s.empty? ? default_refresh_interval : val.to_f
|
1255
|
+
# end
|
1256
|
+
# opts.on(nil, '--no-refresh', "Do not refresh" ) do
|
1257
|
+
# options[:no_refresh] = true
|
1258
|
+
# end
|
1259
|
+
build_standard_add_options(opts, options)
|
1260
|
+
opts.footer = "Add affinity group to a cloud.\n" +
|
1261
|
+
"[cloud] is required. This is the name or id of an existing cloud.\n" +
|
1262
|
+
"[name] is required. This is the name of the new affinity group."
|
1263
|
+
end
|
1264
|
+
|
1265
|
+
optparse.parse!(args)
|
1266
|
+
verify_args!(args:args, optparse:optparse, min:1, max:2)
|
1267
|
+
connect(options)
|
1268
|
+
|
1269
|
+
begin
|
1270
|
+
cloud = find_cloud_by_name_or_id(args[0])
|
1271
|
+
return 1 if cloud.nil?
|
1272
|
+
if args[1]
|
1273
|
+
options[:options]['name'] = args[1]
|
1274
|
+
end
|
1275
|
+
if options[:payload]
|
1276
|
+
payload = options[:payload]
|
1277
|
+
# support -O OPTION switch on top of --payload
|
1278
|
+
if options[:options]
|
1279
|
+
payload ||= {}
|
1280
|
+
payload.deep_merge!(options[:options].reject {|k,v| k.is_a?(Symbol) })
|
1281
|
+
end
|
1282
|
+
else
|
1283
|
+
options[:params] ||= {}
|
1284
|
+
options[:params].merge!({:cloudId => cloud['id'],:zoneId => cloud['id']})
|
1285
|
+
option_types = add_cloud_affinity_group_option_types
|
1286
|
+
affinity_group = Morpheus::Cli::OptionTypes.prompt(option_types, options[:options], @api_client, options[:params])
|
1287
|
+
|
1288
|
+
# affinity_group_type = find_affinity_group_type_by_code(affinity_group['affinityGroupType'])
|
1289
|
+
# affinity_group['affinityGroupType'] = {id:affinity_group_type['id']}
|
1290
|
+
|
1291
|
+
# # affinity_group type options
|
1292
|
+
# unless affinity_group_type['optionTypes'].empty?
|
1293
|
+
# affinity_group.merge!(Morpheus::Cli::OptionTypes.prompt(affinity_group_type['optionTypes'], options[:options].deep_merge({:context_map => {'domain' => ''}, :checkbox_as_boolean => true}), @api_client, options[:params]))
|
1294
|
+
# end
|
1295
|
+
|
1296
|
+
# perms
|
1297
|
+
perms = prompt_permissions(options.merge({:for_affinity_group => true}), ['plans', 'groupDefaults'])
|
1298
|
+
|
1299
|
+
affinity_group['resourcePermissions'] = perms['resourcePermissions'] unless perms['resourcePermissions'].nil?
|
1300
|
+
affinity_group['tenants'] = perms['tenantPermissions'] unless perms['tenantPermissions'].nil?
|
1301
|
+
affinity_group['visibility'] = perms['resourcePool']['visibility'] if !perms['resourcePool'].nil? && !perms['resourcePool']['visibility'].nil?
|
1302
|
+
|
1303
|
+
payload = {'affinityGroup' => affinity_group}
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
@clouds_interface.setopts(options)
|
1307
|
+
if options[:dry_run]
|
1308
|
+
print_dry_run @clouds_interface.dry.create_affinity_group(cloud['id'], payload)
|
1309
|
+
return
|
1310
|
+
end
|
1311
|
+
json_response = @clouds_interface.create_affinity_group(cloud['id'], payload)
|
1312
|
+
if options[:json]
|
1313
|
+
puts as_json(json_response)
|
1314
|
+
else
|
1315
|
+
if json_response['success']
|
1316
|
+
if json_response['msg'] == nil
|
1317
|
+
print_green_success "Adding affinity group to cloud #{cloud['name']}"
|
1318
|
+
else
|
1319
|
+
print_green_success json_response['msg']
|
1320
|
+
end
|
1321
|
+
execution_id = json_response['executionId']
|
1322
|
+
if !options[:no_refresh] && execution_id
|
1323
|
+
wait_for_execution_request(json_response['executionId'], options.merge({waiting_status:['new', 'pending', 'executing']}))
|
1324
|
+
end
|
1325
|
+
else
|
1326
|
+
print_red_alert "Failed to create cloud affinity group #{json_response['msg']}"
|
1327
|
+
end
|
1328
|
+
end
|
1329
|
+
return 0
|
1330
|
+
rescue RestClient::Exception => e
|
1331
|
+
print_rest_exception(e, options)
|
1332
|
+
exit 1
|
1333
|
+
end
|
1334
|
+
end
|
1335
|
+
|
1336
|
+
def update_affinity_group(args)
|
1337
|
+
options = {}
|
1338
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
1339
|
+
opts.banner = subcommand_usage( "[cloud] [affinity group] [options]")
|
1340
|
+
opts.on('--active [on|off]', String, "Enable affinity group") do |val|
|
1341
|
+
options[:active] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == ''
|
1342
|
+
end
|
1343
|
+
add_perms_options(opts, options, ['groupDefaults'])
|
1344
|
+
build_standard_update_options(opts, options)
|
1345
|
+
opts.footer = "Update a cloud affinity group.\n" +
|
1346
|
+
"[cloud] is required. This is the name or id of an existing cloud.\n" +
|
1347
|
+
"[affinity group] is required. This is the name or id of an existing affinity group."
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
optparse.parse!(args)
|
1351
|
+
if args.count != 2
|
1352
|
+
raise_command_error "wrong number of arguments, expected 2 and got (#{args.count}) #{args}\n#{optparse}"
|
1353
|
+
end
|
1354
|
+
connect(options)
|
1355
|
+
|
1356
|
+
begin
|
1357
|
+
cloud = find_cloud_by_name_or_id(args[0])
|
1358
|
+
return 1 if cloud.nil?
|
1359
|
+
affinity_group = find_cloud_affinity_group_by_name_or_id(cloud['id'], args[1])
|
1360
|
+
if affinity_group.nil?
|
1361
|
+
print_red_alert "Affinity Group not found by '#{args[1]}'"
|
1362
|
+
exit 1
|
1363
|
+
end
|
1364
|
+
payload = nil
|
1365
|
+
if options[:payload]
|
1366
|
+
payload = options[:payload]
|
1367
|
+
# support -O OPTION switch on top of everything
|
1368
|
+
if options[:options]
|
1369
|
+
payload.deep_merge!({'affinityGroup' => options[:options].reject {|k,v| k.is_a?(Symbol) }})
|
1370
|
+
end
|
1371
|
+
else
|
1372
|
+
payload = {'affinityGroup' => {}}
|
1373
|
+
payload['affinityGroup']['active'] = options[:active].nil? ? (Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'active', 'fieldLabel' => 'Active', 'type' => 'checkbox', 'description' => 'Active', 'defaultValue' => true}], options[:options], @api_client))['active'] == 'on' : options[:active]
|
1374
|
+
|
1375
|
+
perms = prompt_permissions(options.merge({:available_plans => namespace_service_plans}), affinity_group['owner']['id'] == current_user['accountId'] ? ['plans', 'groupDefaults'] : ['plans', 'groupDefaults', 'visibility', 'tenants'])
|
1376
|
+
perms_payload = {}
|
1377
|
+
perms_payload['resourcePermissions'] = perms['resourcePermissions'] if !perms['resourcePermissions'].nil?
|
1378
|
+
perms_payload['tenantPermissions'] = perms['tenantPermissions'] if !perms['tenantPermissions'].nil?
|
1379
|
+
|
1380
|
+
payload['affinityGroup']['permissions'] = perms_payload
|
1381
|
+
payload['affinityGroup']['visibility'] = perms['resourcePool']['visibility'] if !perms['resourcePool'].nil? && !perms['resourcePool']['visibility'].nil?
|
1382
|
+
|
1383
|
+
# support -O OPTION switch on top of everything
|
1384
|
+
if options[:options]
|
1385
|
+
payload.deep_merge!({'affinityGroup' => options[:options].reject {|k,v| k.is_a?(Symbol) }})
|
1386
|
+
end
|
1387
|
+
|
1388
|
+
if payload['affinityGroup'].nil? || payload['affinityGroup'].empty?
|
1389
|
+
raise_command_error "Specify at least one option to update.\n#{optparse}"
|
1390
|
+
end
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
@clouds_interface.setopts(options)
|
1394
|
+
if options[:dry_run]
|
1395
|
+
print_dry_run @clouds_interface.dry.update_affinity_group(cloud['id'], affinity_group['id'], payload)
|
1396
|
+
return
|
1397
|
+
end
|
1398
|
+
json_response = @clouds_interface.update_affinity_group(cloud['id'], affinity_group['id'], payload)
|
1399
|
+
if options[:json]
|
1400
|
+
puts as_json(json_response)
|
1401
|
+
elsif !options[:quiet]
|
1402
|
+
affinity_group = json_response['affinityGroup']
|
1403
|
+
print_green_success "Updated affinity group #{affinity_group['name']}"
|
1404
|
+
#get_args = [cloud["id"], affinity_group["id"]] + (options[:remote] ? ["-r",options[:remote]] : [])
|
1405
|
+
#get_namespace(get_args)
|
1406
|
+
end
|
1407
|
+
return 0
|
1408
|
+
rescue RestClient::Exception => e
|
1409
|
+
print_rest_exception(e, options)
|
1410
|
+
exit 1
|
1411
|
+
end
|
1412
|
+
end
|
1413
|
+
|
1414
|
+
def remove_affinity_group(args)
|
1415
|
+
default_refresh_interval = 5
|
1416
|
+
params = {}
|
1417
|
+
options = {}
|
1418
|
+
optparse = Morpheus::Cli::OptionParser.new do |opts|
|
1419
|
+
opts.banner = subcommand_usage("[cloud] [affinity group]")
|
1420
|
+
# opts.on( '-f', '--force', "Force Delete" ) do
|
1421
|
+
# params[:force] = 'on'
|
1422
|
+
# end
|
1423
|
+
# opts.on('--refresh [SECONDS]', String, "Refresh until execution is complete. Default interval is #{default_refresh_interval} seconds.") do |val|
|
1424
|
+
# options[:refresh_interval] = val.to_s.empty? ? default_refresh_interval : val.to_f
|
1425
|
+
# end
|
1426
|
+
# opts.on(nil, '--no-refresh', "Do not refresh" ) do
|
1427
|
+
# options[:no_refresh] = true
|
1428
|
+
# end
|
1429
|
+
build_standard_remove_options(opts, options)
|
1430
|
+
opts.footer = "Delete an affinity group from a cloud.\n" +
|
1431
|
+
"[cloud] is required. This is the name or id of an existing cloud.\n" +
|
1432
|
+
"[affinity group] is required. This is the name or id of an existing affinity group."
|
1433
|
+
end
|
1434
|
+
optparse.parse!(args)
|
1435
|
+
verify_args!(args:args, optparse:optparse, count:2)
|
1436
|
+
connect(options)
|
1437
|
+
params.merge!(parse_query_options(options))
|
1438
|
+
|
1439
|
+
cloud = find_cloud_by_name_or_id(args[0])
|
1440
|
+
return 1 if cloud.nil?
|
1441
|
+
|
1442
|
+
affinity_group_id = args[1]
|
1443
|
+
if affinity_group_id.empty?
|
1444
|
+
raise_command_error "missing required worker parameter"
|
1445
|
+
end
|
1446
|
+
|
1447
|
+
affinity_group = find_cloud_affinity_group_by_name_or_id(cloud['id'], affinity_group_id)
|
1448
|
+
if affinity_group.nil?
|
1449
|
+
print_red_alert "Affinity Group not found for '#{affinity_group_id}'"
|
1450
|
+
return 1
|
1451
|
+
end
|
1452
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove the cloud affinity group '#{affinity_group['name'] || affinity_group['id']}'?", options)
|
1453
|
+
return 9, "aborted command"
|
1454
|
+
end
|
1455
|
+
|
1456
|
+
@clouds_interface.setopts(options)
|
1457
|
+
if options[:dry_run]
|
1458
|
+
print_dry_run @clouds_interface.dry.destroy_affinity_group(cloud['id'], affinity_group['id'], params)
|
1459
|
+
return
|
1460
|
+
end
|
1461
|
+
json_response = @clouds_interface.destroy_affinity_group(cloud['id'], affinity_group['id'], params)
|
1462
|
+
if options[:json]
|
1463
|
+
puts as_json(json_response)
|
1464
|
+
else
|
1465
|
+
if json_response['success']
|
1466
|
+
print_green_success "Removed affinity group #{affinity_group['name']}"
|
1467
|
+
execution_id = json_response['executionId']
|
1468
|
+
if !options[:no_refresh] && execution_id
|
1469
|
+
wait_for_execution_request(execution_id, options.merge({waiting_status:['new', 'pending', 'executing']}))
|
1470
|
+
end
|
1471
|
+
else
|
1472
|
+
print_red_alert "Failed to remove cloud affinity group #{json_response['msg']}"
|
1473
|
+
end
|
1474
|
+
end
|
1475
|
+
return 0, nil
|
1476
|
+
end
|
1477
|
+
|
1152
1478
|
private
|
1153
1479
|
|
1154
1480
|
def cloud_list_column_definitions(options)
|
@@ -1259,4 +1585,26 @@ EOT
|
|
1259
1585
|
end
|
1260
1586
|
end
|
1261
1587
|
|
1588
|
+
def find_cloud_affinity_group_by_name_or_id(cloud_id, val)
|
1589
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
1590
|
+
@clouds_interface.get_affinity_group(cloud_id, val)['affinityGroup'] rescue nil
|
1591
|
+
else
|
1592
|
+
@clouds_interface.list_affinity_groups(cloud_id, {name: val})['affinityGroups'][0]
|
1593
|
+
end
|
1594
|
+
end
|
1595
|
+
|
1596
|
+
def add_cloud_affinity_group_option_types
|
1597
|
+
[
|
1598
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true},
|
1599
|
+
{'fieldName' => 'affinityType', 'fieldLabel' => 'Type', 'type' => 'select', 'selectOptions' => [{'name' => 'Keep Separate', 'value' => 'KEEP_SEPARATE'}, {'name' => 'Keep Together', 'value' => 'KEEP_TOGETHER'}], 'description' => 'Choose affinity type.', 'required' => true, 'defaultValue' => 'KEEP_SEPARATE'},
|
1600
|
+
{'fieldName' => 'active', 'fieldLabel' => 'Active', 'type' => 'checkbox', 'defaultValue' => true},
|
1601
|
+
{'fieldName' => 'pool.id', 'fieldLabel' => 'Cluster', 'type' => 'select', 'optionSourceType' => 'vmware', 'optionSource' => 'vmwareZonePoolClusters', 'description' => 'Select cluster for the affinity group.', 'required' => true},
|
1602
|
+
{'fieldName' => 'servers', 'fieldLabel' => 'Server', 'type' => 'multiSelect', 'optionSource' => 'searchServers', 'description' => 'Select servers to be in the affinity group.'},
|
1603
|
+
]
|
1604
|
+
end
|
1605
|
+
|
1606
|
+
def format_affinity_type(affinity_type)
|
1607
|
+
affinity_type == "KEEP_SEPARATE" ? "Keep Separate" : "Keep Together"
|
1608
|
+
end
|
1609
|
+
|
1262
1610
|
end
|