morpheus-cli 3.6.4 → 3.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebb3ffe2cbabe89c6f9ba8148cf1e2d2a7bfd51893a71f69acf05c406013454d
4
- data.tar.gz: 298427126d4530f189b3ffbc09a9c06baeaf91018412a9b5633dda1ed76e5571
3
+ metadata.gz: e5af54f955b29a018c9dc09a30706f3dff383b42b71f08e92ba63539cf679171
4
+ data.tar.gz: f10233595e661594134eb2605bbe3dd48be90458c36441c5bd7afddbabc7093f
5
5
  SHA512:
6
- metadata.gz: 0bcc8b841e8a23e6c90e81c724dcc5fecd967eee7294c97069708f849db2e98880c2f3832188a5740c4dd3aa81267682b7cd5b8bd84af0d229df8807ad6f9c33
7
- data.tar.gz: 6b94513b1484b9caa2d04ced8c24f143f5e41f4746e3bbeb92c074aa0c2dacaf9166f4b5d409c390d25ec11965fa58678d0d9568e6d4dd9b27c66e33aac3107c
6
+ metadata.gz: 19e02a97f046c115b8080fb6489f07e4973e0dc734dd6986a492816e4abcd805d32ad49008593973acc9fc1346c1416d2cfc93121c96576a8fcb8cdb1b056dc3
7
+ data.tar.gz: 69d7ab3ae77e4fccc8ee42f09fc7c16f4f3383801a39acd57c8d661bcc0ea38633ed97a6c81840f761e84d3038aded3e2bd15667c8d9522f129dc39a265e3339
@@ -94,14 +94,24 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
94
94
  end
95
95
 
96
96
  def suspend(id, params={})
97
- url = "#{@base_url}/api/instances/#{id}/suspend"
97
+ url = "#{@base_url}/api/instances/suspend"
98
+ if id.is_a?(Array)
99
+ params['ids'] = id
100
+ else
101
+ url = "#{@base_url}/api/instances/#{id}/suspend"
102
+ end
98
103
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
99
104
  opts = {method: :put, url: url, headers: headers}
100
105
  execute(opts)
101
106
  end
102
107
 
103
108
  def eject(id, params={})
104
- url = "#{@base_url}/api/instances/#{id}/eject"
109
+ url = "#{@base_url}/api/instances/eject"
110
+ if id.is_a?(Array)
111
+ params['ids'] = id
112
+ else
113
+ url = "#{@base_url}/api/instances/#{id}/eject"
114
+ end
105
115
  headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
106
116
  opts = {method: :put, url: url, headers: headers}
107
117
  execute(opts)
@@ -42,16 +42,26 @@ class Morpheus::ServersInterface < Morpheus::APIClient
42
42
  execute(opts)
43
43
  end
44
44
 
45
- def stop(serverId,payload = {})
46
- url = "#{@base_url}/api/servers/#{serverId}/stop"
47
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
45
+ def stop(serverId,payload = {}, params={})
46
+ url = "#{@base_url}/api/servers/stop"
47
+ if serverId.is_a?(Array)
48
+ params['ids'] = serverId
49
+ else
50
+ url = "#{@base_url}/api/servers/#{serverId}/stop"
51
+ end
52
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
48
53
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
49
54
  execute(opts)
50
55
  end
51
56
 
52
- def start(serverId,payload = {})
53
- url = "#{@base_url}/api/servers/#{serverId}/start"
54
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
57
+ def start(serverId,payload = {}, params = {})
58
+ url = "#{@base_url}/api/servers/start"
59
+ if serverId.is_a?(Array)
60
+ params['ids'] = serverId
61
+ else
62
+ url = "#{@base_url}/api/servers/#{serverId}/start"
63
+ end
64
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
55
65
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
56
66
  execute(opts)
57
67
  end
@@ -1999,13 +1999,17 @@ class Morpheus::Cli::BlueprintsCommand
1999
1999
  group_access_str = ""
2000
2000
  begin
2001
2001
  rows = []
2002
- if blueprint['resourcePermission']['allSites'] || blueprint['resourcePermission']['all']
2003
- rows.push({"name" => 'All'})
2004
- end
2005
- if blueprint['resourcePermission']['sites']
2006
- blueprint['resourcePermission']['sites'].each do |site|
2007
- rows.push(site)
2002
+ if blueprint['resourcePermission']
2003
+ if blueprint['resourcePermission']['allSites'] || blueprint['resourcePermission']['all']
2004
+ rows.push({"name" => 'All'})
2005
+ end
2006
+ if blueprint['resourcePermission']['sites']
2007
+ blueprint['resourcePermission']['sites'].each do |site|
2008
+ rows.push(site)
2009
+ end
2008
2010
  end
2011
+ else
2012
+ # rows.push({"name" => 'All'})
2009
2013
  end
2010
2014
  group_access_str = rows.collect {|it| it['default'] ? "#{it['name']} (default)" : "#{it['name']}"}.join(',')
2011
2015
  rescue => ex
@@ -820,17 +820,27 @@ class Morpheus::Cli::Hosts
820
820
  end
821
821
  connect(options)
822
822
  begin
823
- host = find_host_by_name_or_id(args[0])
823
+ host_ids = parse_id_list(args)
824
+ hosts = []
825
+ host_ids.each do |host_id|
826
+ host = find_host_by_name_or_id(host_id)
827
+ return 1 if host.nil?
828
+ hosts << host
829
+ end
830
+ objects_label = "#{hosts.size == 1 ? 'host' : (hosts.size.to_s + ' hosts')} #{anded_list(hosts.collect {|it| it['name'] })}"
831
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to start #{objects_label}?", options)
832
+ return 9, "aborted command"
833
+ end
824
834
  if options[:dry_run]
825
- print_dry_run @servers_interface.dry.start(host['id'])
835
+ print_dry_run @servers_interface.dry.start(hosts.collect {|it| it['id'] })
826
836
  return
827
837
  end
828
- json_response = @servers_interface.start(host['id'])
838
+ json_response = @servers_interface.start(hosts.collect {|it| it['id'] })
829
839
  if options[:json]
830
840
  print JSON.pretty_generate(json_response)
831
841
  print "\n"
832
842
  elsif !options[:quiet]
833
- print_green_success "Host #{host['name']} started."
843
+ print_green_success "Started #{objects_label}"
834
844
  end
835
845
  return
836
846
  rescue RestClient::Exception => e
@@ -852,17 +862,27 @@ class Morpheus::Cli::Hosts
852
862
  end
853
863
  connect(options)
854
864
  begin
855
- host = find_host_by_name_or_id(args[0])
865
+ host_ids = parse_id_list(args)
866
+ hosts = []
867
+ host_ids.each do |host_id|
868
+ host = find_host_by_name_or_id(host_id)
869
+ return 1 if host.nil?
870
+ hosts << host
871
+ end
872
+ objects_label = "#{hosts.size == 1 ? 'host' : (hosts.size.to_s + ' hosts')} #{anded_list(hosts.collect {|it| it['name'] })}"
873
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop #{objects_label}?", options)
874
+ return 9, "aborted command"
875
+ end
856
876
  if options[:dry_run]
857
- print_dry_run @servers_interface.dry.stop(host['id'])
877
+ print_dry_run @servers_interface.dry.stop(hosts.collect {|it| it['id'] })
858
878
  return
859
879
  end
860
- json_response = @servers_interface.stop(host['id'])
880
+ json_response = @servers_interface.stop(hosts.collect {|it| it['id'] })
861
881
  if options[:json]
862
882
  print JSON.pretty_generate(json_response)
863
883
  print "\n"
864
884
  elsif !options[:quiet]
865
- puts "Host #{host['name']} stopped."
885
+ print_green_success "Stopped #{objects_label}"
866
886
  end
867
887
  return
868
888
  rescue RestClient::Exception => e
@@ -1339,10 +1339,16 @@ class Morpheus::Cli::Instances
1339
1339
  options = {}
1340
1340
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1341
1341
  opts.banner = subcommand_usage("[name]")
1342
+ opts.on('--mute-monitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1343
+ params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1344
+ end
1342
1345
  opts.on('--muteMonitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1343
1346
  params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1344
1347
  end
1348
+ opts.add_hidden_option('muteMonitoring') if opts.is_a?(Morpheus::Cli::OptionParser)
1345
1349
  build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
1350
+ opts.footer = "Stop an instance.\n" +
1351
+ "[name] is required. This is the name or id of an instance. Supports 1-N [instance] arguments."
1346
1352
  end
1347
1353
  optparse.parse!(args)
1348
1354
  if args.count < 1
@@ -1351,21 +1357,44 @@ class Morpheus::Cli::Instances
1351
1357
  end
1352
1358
  connect(options)
1353
1359
  begin
1354
- instance = find_instance_by_name_or_id(args[0])
1355
- unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop this instance?", options)
1356
- exit 1
1360
+ instance_ids = parse_id_list(args)
1361
+ instances = []
1362
+ instance_ids.each do |instance_id|
1363
+ instance = find_instance_by_name_or_id(instance_id)
1364
+ return 1 if instance.nil?
1365
+ instances << instance
1366
+ end
1367
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1368
+ return 9, "aborted command"
1357
1369
  end
1358
1370
  if options[:dry_run]
1359
- print_dry_run @instances_interface.dry.stop(instance['id'], params)
1360
- return
1371
+ print_h1 "DRY RUN"
1372
+ instances.each do |instance|
1373
+ print_dry_run @instances_interface.dry.stop(instance['id'], params), false
1374
+ end
1375
+ return 0
1361
1376
  end
1362
- json_response = @instances_interface.stop(instance['id'], params)
1363
- if options[:json]
1364
- puts as_json(json_response, options)
1365
- elsif !options[:quiet]
1366
- print green, "Stopping instance #{instance['name']}", reset, "\n"
1377
+ bad_responses = []
1378
+ instances.each do |instance|
1379
+ json_response = @instances_interface.stop(instance['id'], params)
1380
+ render_result = render_with_format(json_response, options)
1381
+ if render_result
1382
+ #return 0
1383
+ elsif !options[:quiet]
1384
+ print green, "Stopping instance #{instance['name']}", reset, "\n"
1385
+ end
1386
+ if json_response['success'] == false
1387
+ bad_responses << json_response
1388
+ if !options[:quiet]
1389
+ print_rest_errors(json_response)
1390
+ end
1391
+ end
1392
+ end
1393
+ if !bad_responses.empty?
1394
+ return 1
1367
1395
  end
1368
1396
  return 0
1397
+
1369
1398
  rescue RestClient::Exception => e
1370
1399
  print_rest_exception(e, options)
1371
1400
  exit 1
@@ -1377,7 +1406,9 @@ class Morpheus::Cli::Instances
1377
1406
  options = {}
1378
1407
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1379
1408
  opts.banner = subcommand_usage("[name]")
1380
- build_common_options(opts, options, [:json, :dry_run, :remote])
1409
+ build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
1410
+ opts.footer = "Start an instance.\n" +
1411
+ "[name] is required. This is the name or id of an instance. Supports 1-N [instance] arguments."
1381
1412
  end
1382
1413
  optparse.parse!(args)
1383
1414
  if args.count < 1
@@ -1386,17 +1417,41 @@ class Morpheus::Cli::Instances
1386
1417
  end
1387
1418
  connect(options)
1388
1419
  begin
1389
- instance = find_instance_by_name_or_id(args[0])
1420
+ instance_ids = parse_id_list(args)
1421
+ instances = []
1422
+ instance_ids.each do |instance_id|
1423
+ instance = find_instance_by_name_or_id(instance_id)
1424
+ return 1 if instance.nil?
1425
+ instances << instance
1426
+ end
1427
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to start #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1428
+ return 9, "aborted command"
1429
+ end
1390
1430
  if options[:dry_run]
1391
- print_dry_run @instances_interface.dry.start(instance['id'], params)
1431
+ print_h1 "DRY RUN"
1432
+ instances.each do |instance|
1433
+ print_dry_run @instances_interface.dry.start(instance['id'], params), false
1434
+ end
1392
1435
  return 0
1393
1436
  end
1394
- json_response = @instances_interface.start(instance['id'], params)
1395
- if options[:json]
1396
- puts as_json(json_response, options)
1397
- return 0
1398
- elsif !options[:quiet]
1399
- print green, "Starting instance #{instance['name']}", reset, "\n"
1437
+ bad_responses = []
1438
+ instances.each do |instance|
1439
+ json_response = @instances_interface.start(instance['id'], params)
1440
+ render_result = render_with_format(json_response, options)
1441
+ if render_result
1442
+ #return 0
1443
+ elsif !options[:quiet]
1444
+ print green, "Starting instance #{instance['name']}", reset, "\n"
1445
+ end
1446
+ if json_response['success'] == false
1447
+ bad_responses << json_response
1448
+ if !options[:quiet]
1449
+ print_rest_errors(json_response)
1450
+ end
1451
+ end
1452
+ end
1453
+ if !bad_responses.empty?
1454
+ return 1
1400
1455
  end
1401
1456
  return 0
1402
1457
  rescue RestClient::Exception => e
@@ -1410,10 +1465,16 @@ class Morpheus::Cli::Instances
1410
1465
  options = {}
1411
1466
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1412
1467
  opts.banner = subcommand_usage("[name]")
1413
- opts.on('--muteMonitoring [on|off]', String, "Mute monitoring. Default is on.") do |val|
1468
+ opts.on('--mute-monitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1469
+ params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1470
+ end
1471
+ opts.on('--muteMonitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1414
1472
  params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1415
1473
  end
1474
+ opts.add_hidden_option('muteMonitoring') if opts.is_a?(Morpheus::Cli::OptionParser)
1416
1475
  build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
1476
+ opts.footer = "Start an instance.\n" +
1477
+ "[name] is required. This is the name or id of an instance. Supports 1-N [instance] arguments."
1417
1478
  end
1418
1479
  optparse.parse!(args)
1419
1480
  if args.count < 1
@@ -1422,19 +1483,41 @@ class Morpheus::Cli::Instances
1422
1483
  end
1423
1484
  connect(options)
1424
1485
  begin
1425
- instance = find_instance_by_name_or_id(args[0])
1426
- unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to restart this instance?", options)
1427
- exit 1
1486
+ instance_ids = parse_id_list(args)
1487
+ instances = []
1488
+ instance_ids.each do |instance_id|
1489
+ instance = find_instance_by_name_or_id(instance_id)
1490
+ return 1 if instance.nil?
1491
+ instances << instance
1492
+ end
1493
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to restart #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1494
+ return 9, "aborted command"
1428
1495
  end
1429
1496
  if options[:dry_run]
1430
- print_dry_run @instances_interface.dry.restart(instance['id'], params)
1497
+ print_h1 "DRY RUN"
1498
+ instances.each do |instance|
1499
+ print_dry_run @instances_interface.dry.restart(instance['id'], params), false
1500
+ end
1431
1501
  return 0
1432
1502
  end
1433
- json_response = @instances_interface.restart(instance['id'], params)
1434
- if options[:json]
1435
- puts as_json(json_response, options)
1436
- elsif !options[:quiet]
1437
- print green, "Restarting instance #{instance['name']}", reset, "\n"
1503
+ bad_responses = []
1504
+ instances.each do |instance|
1505
+ json_response = @instances_interface.restart(instance['id'], params)
1506
+ render_result = render_with_format(json_response, options)
1507
+ if render_result
1508
+ #return 0
1509
+ elsif !options[:quiet]
1510
+ print green, "Restarting instance #{instance['name']}", reset, "\n"
1511
+ end
1512
+ if json_response['success'] == false
1513
+ bad_responses << json_response
1514
+ if !options[:quiet]
1515
+ print_rest_errors(json_response)
1516
+ end
1517
+ end
1518
+ end
1519
+ if !bad_responses.empty?
1520
+ return 1
1438
1521
  end
1439
1522
  return 0
1440
1523
  rescue RestClient::Exception => e
@@ -1460,17 +1543,30 @@ class Morpheus::Cli::Instances
1460
1543
  end
1461
1544
  connect(options)
1462
1545
  begin
1463
- instance = find_instance_by_name_or_id(args[0])
1464
- unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to suspend this instance?", options)
1465
- exit 1
1546
+ instance_ids = parse_id_list(args)
1547
+ instances = []
1548
+ instance_ids.each do |instance_id|
1549
+ instance = find_instance_by_name_or_id(instance_id)
1550
+ return 1 if instance.nil?
1551
+ instances << instance
1552
+ end
1553
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to suspend #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1554
+ return 9, "aborted command"
1466
1555
  end
1556
+
1467
1557
  if options[:dry_run]
1468
- print_dry_run @instances_interface.dry.suspend(instance['id'], params)
1558
+ print_dry_run @instances_interface.dry.suspend(instances.collect {|it| it['id'] }, params)
1469
1559
  return
1470
1560
  end
1471
- json_response = @instances_interface.suspend(instance['id'], params)
1561
+ json_response = @instances_interface.suspend(instances.collect {|it| it['id'] }, params)
1472
1562
  if options[:json]
1473
1563
  puts as_json(json_response, options)
1564
+ elsif !options[:quiet]
1565
+ if instances.size == 1
1566
+ print_green_success "Suspended instance #{instances[0]['name']}"
1567
+ else
1568
+ print_green_success "Suspended #{instances.size} instances"
1569
+ end
1474
1570
  end
1475
1571
  return 0
1476
1572
  rescue RestClient::Exception => e
@@ -1493,17 +1589,29 @@ class Morpheus::Cli::Instances
1493
1589
  end
1494
1590
  connect(options)
1495
1591
  begin
1496
- instance = find_instance_by_name_or_id(args[0])
1497
- # unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to eject this instance?", options)
1498
- # exit 1
1499
- # end
1592
+ instance_ids = parse_id_list(args)
1593
+ instances = []
1594
+ instance_ids.each do |instance_id|
1595
+ instance = find_instance_by_name_or_id(instance_id)
1596
+ return 1 if instance.nil?
1597
+ instances << instance
1598
+ end
1599
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to eject #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1600
+ return 9, "aborted command"
1601
+ end
1500
1602
  if options[:dry_run]
1501
- print_dry_run @instances_interface.dry.eject(instance['id'], params)
1603
+ print_dry_run @instances_interface.dry.eject(instances.collect {|it| it['id'] }, params)
1502
1604
  return
1503
1605
  end
1504
- json_response = @instances_interface.eject(instance['id'], params)
1606
+ json_response = @instances_interface.eject(instances.collect {|it| it['id'] }, params)
1505
1607
  if options[:json]
1506
1608
  puts as_json(json_response, options)
1609
+ elsif !options[:quiet]
1610
+ if instances.size == 1
1611
+ print_green_success "Ejected instance #{instances[0]['name']}"
1612
+ else
1613
+ print_green_success "Ejected #{instances.size} instances"
1614
+ end
1507
1615
  end
1508
1616
  return 0
1509
1617
  rescue RestClient::Exception => e
@@ -1517,10 +1625,16 @@ class Morpheus::Cli::Instances
1517
1625
  options = {}
1518
1626
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1519
1627
  opts.banner = subcommand_usage("[name]")
1628
+ opts.on('--mute-monitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1629
+ params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1630
+ end
1520
1631
  opts.on('--muteMonitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1521
1632
  params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1522
1633
  end
1634
+ opts.add_hidden_option('muteMonitoring') if opts.is_a?(Morpheus::Cli::OptionParser)
1523
1635
  build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
1636
+ opts.footer = "Stop service on an instance.\n" +
1637
+ "[name] is required. This is the name or id of an instance. Supports 1-N [instance] arguments."
1524
1638
  end
1525
1639
  optparse.parse!(args)
1526
1640
  if args.count < 1
@@ -1529,21 +1643,44 @@ class Morpheus::Cli::Instances
1529
1643
  end
1530
1644
  connect(options)
1531
1645
  begin
1532
- instance = find_instance_by_name_or_id(args[0])
1533
- unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop service on this instance?", options)
1534
- exit 1
1646
+ instance_ids = parse_id_list(args)
1647
+ instances = []
1648
+ instance_ids.each do |instance_id|
1649
+ instance = find_instance_by_name_or_id(instance_id)
1650
+ return 1 if instance.nil?
1651
+ instances << instance
1652
+ end
1653
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to stop service on #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1654
+ return 9, "aborted command"
1535
1655
  end
1536
1656
  if options[:dry_run]
1537
- print_dry_run @instances_interface.dry.stop(instance['id'], params)
1657
+ print_h1 "DRY RUN"
1658
+ instances.each do |instance|
1659
+ print_dry_run @instances_interface.dry.stop(instance['id'], params), false
1660
+ end
1538
1661
  return 0
1539
1662
  end
1540
- json_response = @instances_interface.stop(instance['id'], params)
1541
- if options[:json]
1542
- puts as_json(json_response, options)
1543
- elsif !options[:quiet]
1544
- print green, "Stopping service on instance #{instance['name']}", reset, "\n"
1663
+ bad_responses = []
1664
+ instances.each do |instance|
1665
+ json_response = @instances_interface.stop(instance['id'], params)
1666
+ render_result = render_with_format(json_response, options)
1667
+ if render_result
1668
+ #return 0
1669
+ elsif !options[:quiet]
1670
+ print green, "Stopping service on instance #{instance['name']}", reset, "\n"
1671
+ end
1672
+ if json_response['success'] == false
1673
+ bad_responses << json_response
1674
+ if !options[:quiet]
1675
+ print_rest_errors(json_response)
1676
+ end
1677
+ end
1678
+ end
1679
+ if !bad_responses.empty?
1680
+ return 1
1545
1681
  end
1546
1682
  return 0
1683
+
1547
1684
  rescue RestClient::Exception => e
1548
1685
  print_rest_exception(e, options)
1549
1686
  exit 1
@@ -1551,11 +1688,13 @@ class Morpheus::Cli::Instances
1551
1688
  end
1552
1689
 
1553
1690
  def start_service(args)
1554
- params = {'server' => true}
1691
+ params = {'server' => true} # server is true eh? so start-service is the same as start
1555
1692
  options = {}
1556
1693
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1557
1694
  opts.banner = subcommand_usage("[name]")
1558
- build_common_options(opts, options, [:quiet, :json, :dry_run, :remote])
1695
+ build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
1696
+ opts.footer = "Start service on an instance.\n" +
1697
+ "[name] is required. This is the name or id of an instance. Supports 1-N [instance] arguments."
1559
1698
  end
1560
1699
  optparse.parse!(args)
1561
1700
  if args.count < 1
@@ -1564,17 +1703,43 @@ class Morpheus::Cli::Instances
1564
1703
  end
1565
1704
  connect(options)
1566
1705
  begin
1567
- instance = find_instance_by_name_or_id(args[0])
1706
+ instance_ids = parse_id_list(args)
1707
+ instances = []
1708
+ instance_ids.each do |instance_id|
1709
+ instance = find_instance_by_name_or_id(instance_id)
1710
+ return 1 if instance.nil?
1711
+ instances << instance
1712
+ end
1713
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to start service on #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1714
+ return 9, "aborted command"
1715
+ end
1568
1716
  if options[:dry_run]
1569
- print_dry_run @instances_interface.dry.start(instance['id'], params)
1717
+ print_h1 "DRY RUN"
1718
+ instances.each do |instance|
1719
+ print_dry_run @instances_interface.dry.start(instance['id'], params), false
1720
+ end
1570
1721
  return 0
1571
1722
  end
1572
- json_response = @instances_interface.start(instance['id'], params)
1573
- if options[:json]
1574
- puts as_json(json_response, options)
1575
- elsif !options[:quiet]
1576
- print green, "Starting service on instance #{instance['name']}", reset, "\n"
1723
+ bad_responses = []
1724
+ instances.each do |instance|
1725
+ json_response = @instances_interface.start(instance['id'], params)
1726
+ render_result = render_with_format(json_response, options)
1727
+ if render_result
1728
+ #return 0
1729
+ elsif !options[:quiet]
1730
+ print green, "Starting service on instance #{instance['name']}", reset, "\n"
1731
+ end
1732
+ if json_response['success'] == false
1733
+ bad_responses << json_response
1734
+ if !options[:quiet]
1735
+ print_rest_errors(json_response)
1736
+ end
1737
+ end
1738
+ end
1739
+ if !bad_responses.empty?
1740
+ return 1
1577
1741
  end
1742
+ return 0
1578
1743
  rescue RestClient::Exception => e
1579
1744
  print_rest_exception(e, options)
1580
1745
  exit 1
@@ -1586,10 +1751,16 @@ class Morpheus::Cli::Instances
1586
1751
  options = {}
1587
1752
  optparse = Morpheus::Cli::OptionParser.new do |opts|
1588
1753
  opts.banner = subcommand_usage("[name]")
1589
- opts.on('--muteMonitoring [on|off]', String, "Mute monitoring. Default is on.") do |val|
1754
+ opts.on('--mute-monitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1590
1755
  params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1591
1756
  end
1757
+ opts.on('--muteMonitoring [on|off]', String, "Mute monitoring. Default is off.") do |val|
1758
+ params['muteMonitoring'] = val.nil? || val.to_s == 'on' || val.to_s == 'true'
1759
+ end
1760
+ opts.add_hidden_option('muteMonitoring') if opts.is_a?(Morpheus::Cli::OptionParser)
1592
1761
  build_common_options(opts, options, [:auto_confirm, :quiet, :json, :dry_run, :remote])
1762
+ opts.footer = "Restart service on an instance.\n" +
1763
+ "[name] is required. This is the name or id of an instance. Supports 1-N [instance] arguments."
1593
1764
  end
1594
1765
  optparse.parse!(args)
1595
1766
  if args.count < 1
@@ -1598,19 +1769,41 @@ class Morpheus::Cli::Instances
1598
1769
  end
1599
1770
  connect(options)
1600
1771
  begin
1601
- instance = find_instance_by_name_or_id(args[0])
1602
- unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to restart service on this instance?", options)
1603
- exit 1
1772
+ instance_ids = parse_id_list(args)
1773
+ instances = []
1774
+ instance_ids.each do |instance_id|
1775
+ instance = find_instance_by_name_or_id(instance_id)
1776
+ return 1 if instance.nil?
1777
+ instances << instance
1778
+ end
1779
+ unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to restart service on #{instances.size == 1 ? 'instance' : (instances.size.to_s + ' instances')} #{anded_list(instances.collect {|it| it['name'] })}?", options)
1780
+ return 9, "aborted command"
1604
1781
  end
1605
1782
  if options[:dry_run]
1606
- print_dry_run @instances_interface.dry.restart(instance['id'], params)
1783
+ print_h1 "DRY RUN"
1784
+ instances.each do |instance|
1785
+ print_dry_run @instances_interface.dry.restart(instance['id'], params), false
1786
+ end
1607
1787
  return 0
1608
1788
  end
1609
- json_response = @instances_interface.restart(instance['id'], params)
1610
- if options[:json]
1611
- puts as_json(json_response, options)
1612
- elsif !options[:quiet]
1613
- print green, "Restarting service on instance #{instance['name']}", reset, "\n"
1789
+ bad_responses = []
1790
+ instances.each do |instance|
1791
+ json_response = @instances_interface.restart(instance['id'], params)
1792
+ render_result = render_with_format(json_response, options)
1793
+ if render_result
1794
+ #return 0
1795
+ elsif !options[:quiet]
1796
+ print green, "Restarting service on instance #{instance['name']}", reset, "\n"
1797
+ end
1798
+ if json_response['success'] == false
1799
+ bad_responses << json_response
1800
+ if !options[:quiet]
1801
+ print_rest_errors(json_response)
1802
+ end
1803
+ end
1804
+ end
1805
+ if !bad_responses.empty?
1806
+ return 1
1614
1807
  end
1615
1808
  return 0
1616
1809
  rescue RestClient::Exception => e
@@ -1684,7 +1877,7 @@ class Morpheus::Cli::Instances
1684
1877
  action_id = val.to_s
1685
1878
  end
1686
1879
  build_common_options(opts, options, [:auto_confirm, :json, :dry_run, :quiet, :remote])
1687
- opts.footer = "Execute an action for a instance or instances"
1880
+ opts.footer = "Execute an action for one or many instances."
1688
1881
  end
1689
1882
  optparse.parse!(args)
1690
1883
  if args.count < 1
@@ -83,9 +83,7 @@ module Morpheus::Cli::PrintHelper
83
83
  print out
84
84
  end
85
85
 
86
- # @deprecated, use ErrorHandler.print_rest_exception()
87
86
  def print_rest_exception(e, options={})
88
- # ugh, time to clean this stuff up
89
87
  if respond_to?(:my_terminal)
90
88
  Morpheus::Cli::ErrorHandler.new(my_terminal.stderr).print_rest_exception(e, options)
91
89
  else
@@ -93,6 +91,14 @@ module Morpheus::Cli::PrintHelper
93
91
  end
94
92
  end
95
93
 
94
+ def print_rest_errors(errors, options={})
95
+ if respond_to?(:my_terminal)
96
+ Morpheus::Cli::ErrorHandler.new(my_terminal.stderr).print_rest_errors(errors, options)
97
+ else
98
+ Morpheus::Cli::ErrorHandler.new.print_rest_errors(errors, options)
99
+ end
100
+ end
101
+
96
102
  def print_dry_run(opts, command_string=nil)
97
103
  http_method = opts[:method]
98
104
  url = opts[:url]
@@ -104,10 +110,12 @@ module Morpheus::Cli::PrintHelper
104
110
  end
105
111
  request_string = "#{http_method.to_s.upcase} #{url}".strip
106
112
  payload = opts[:payload] || opts[:body]
107
- if command_string
108
- print_h1 "DRY RUN > #{command_string}"
109
- else
110
- print_h1 "DRY RUN"
113
+ if command_string != false
114
+ if command_string
115
+ print_h1 "DRY RUN > #{command_string}"
116
+ else
117
+ print_h1 "DRY RUN"
118
+ end
111
119
  end
112
120
  print cyan
113
121
  print "Request: ", "\n"
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "3.6.4"
4
+ VERSION = "3.6.5"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpheus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.4
4
+ version: 3.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Estes