morpheus-cli 5.3.1.1 → 5.3.2.3

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/lib/morpheus/api/accounts_interface.rb +4 -30
  4. data/lib/morpheus/api/api_client.rb +12 -0
  5. data/lib/morpheus/api/load_balancer_pools_interface.rb +9 -0
  6. data/lib/morpheus/api/load_balancer_types_interface.rb +9 -0
  7. data/lib/morpheus/api/load_balancer_virtual_servers_interface.rb +9 -0
  8. data/lib/morpheus/api/load_balancers_interface.rb +4 -53
  9. data/lib/morpheus/api/network_routers_interface.rb +56 -0
  10. data/lib/morpheus/api/option_type_lists_interface.rb +19 -7
  11. data/lib/morpheus/api/secondary_read_interface.rb +25 -0
  12. data/lib/morpheus/api/secondary_rest_interface.rb +42 -0
  13. data/lib/morpheus/cli/cli_command.rb +9 -9
  14. data/lib/morpheus/cli/instances.rb +39 -37
  15. data/lib/morpheus/cli/library_cluster_layouts_command.rb +2 -3
  16. data/lib/morpheus/cli/library_container_scripts_command.rb +3 -4
  17. data/lib/morpheus/cli/library_container_templates_command.rb +4 -0
  18. data/lib/morpheus/cli/library_container_types_command.rb +2 -3
  19. data/lib/morpheus/cli/library_instance_types_command.rb +2 -3
  20. data/lib/morpheus/cli/library_layouts_command.rb +4 -0
  21. data/lib/morpheus/cli/library_option_lists_command.rb +68 -16
  22. data/lib/morpheus/cli/library_option_types_command.rb +4 -0
  23. data/lib/morpheus/cli/library_spec_templates_command.rb +3 -4
  24. data/lib/morpheus/cli/load_balancer_types.rb +37 -0
  25. data/lib/morpheus/cli/load_balancers.rb +149 -314
  26. data/lib/morpheus/cli/log_settings_command.rb +7 -3
  27. data/lib/morpheus/cli/mixins/load_balancers_helper.rb +156 -0
  28. data/lib/morpheus/cli/mixins/print_helper.rb +11 -0
  29. data/lib/morpheus/cli/mixins/provisioning_helper.rb +3 -7
  30. data/lib/morpheus/cli/mixins/rest_command.rb +657 -0
  31. data/lib/morpheus/cli/network_routers_command.rb +1183 -185
  32. data/lib/morpheus/cli/networks_command.rb +194 -101
  33. data/lib/morpheus/cli/option_types.rb +29 -39
  34. data/lib/morpheus/cli/tenants_command.rb +18 -20
  35. data/lib/morpheus/cli/version.rb +1 -1
  36. data/lib/morpheus/cli.rb +1 -0
  37. data/lib/morpheus/ext/string.rb +41 -0
  38. data/lib/morpheus/formatters.rb +4 -0
  39. metadata +11 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a64f6250b5cad8827e2d0e11349e21fbb6fedc974503a79fa9a2b1defb7d381a
4
- data.tar.gz: 6ab1fb279210a5b7a5dce73e19061b82dec7872463e38b5848fb7fe49a6891d3
3
+ metadata.gz: fedf8a7443a29dd8ac5097e8f17bec94d481d3d1cadffd16dce033d9cb152f61
4
+ data.tar.gz: f1a306e2a42cebcb474371e589c07b2b31f6ed84faee0d47b640813e672d08ce
5
5
  SHA512:
6
- metadata.gz: 98e1a3b24ad173eb9d8077ae0e0a9a7602beecf42e370e1bc6be5e82a9a52385f2e749c035273c3057f3b3377dbbf4cd9eee1086131fdda55fe46e296d7d7c86
7
- data.tar.gz: 03c1b3f5059084a7c57e68ed6888174aaca554eea319f85d043ed79752470c1487d0ea946b0e9d10244e894e03061e2266036d40a0d3d86692d0ce0c607c6dfb
6
+ metadata.gz: fe7834f3099b3dd5666c9230c8b833ac05a613d58465850d0eaf5e88cdb973a8eec4ac020946d6ba902abb43cd71d705760040e69b243a2e670e2dd8b5295c9b
7
+ data.tar.gz: 3cc4909d59ae2fcf99f319e74a13eb4db2261fe475629723b6a091fbf3dd13aa5f92e939ae9262ec44b9817b97591c21d6ac69046c400c41523ed588c9602087
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 5.3.1.1
3
+ RUN gem install morpheus-cli -v 5.3.2.3
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -1,35 +1,9 @@
1
- require 'morpheus/api/api_client'
1
+ require 'morpheus/api/rest_interface'
2
2
 
3
- class Morpheus::AccountsInterface < Morpheus::APIClient
4
-
5
- def get(id)
6
- raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
7
- url = "#{@base_url}/api/accounts/#{id}"
8
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
9
- execute(method: :get, url: url, headers: headers)
10
- end
11
-
12
- def list(params={})
13
- url = "#{@base_url}/api/accounts"
14
- headers = { params: params, authorization: "Bearer #{@access_token}" }
15
- execute(method: :get, url: url, headers: headers)
16
- end
3
+ class Morpheus::AccountsInterface < Morpheus::RestInterface
17
4
 
18
- def create(payload)
19
- url = "#{@base_url}/api/accounts"
20
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
21
- execute(method: :post, url: url, headers: headers, payload: payload.to_json)
5
+ def base_path
6
+ "/api/accounts"
22
7
  end
23
8
 
24
- def update(id, payload)
25
- url = "#{@base_url}/api/accounts/#{id}"
26
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
27
- execute(method: :put, url: url, headers: headers, payload: payload.to_json)
28
- end
29
-
30
- def destroy(id)
31
- url = "#{@base_url}/api/accounts/#{id}"
32
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
33
- execute(method: :delete, url: url, headers: headers)
34
- end
35
9
  end
@@ -474,6 +474,18 @@ class Morpheus::APIClient
474
474
  Morpheus::LoadBalancersInterface.new(common_interface_options).setopts(@options)
475
475
  end
476
476
 
477
+ def load_balancer_types
478
+ Morpheus::LoadBalancerTypesInterface.new(common_interface_options).setopts(@options)
479
+ end
480
+
481
+ def load_balancer_virtual_servers
482
+ Morpheus::LoadBalancerVirtualServersInterface.new(common_interface_options).setopts(@options)
483
+ end
484
+
485
+ def load_balancer_pools
486
+ Morpheus::LoadBalancerPoolsInterface.new(common_interface_options).setopts(@options)
487
+ end
488
+
477
489
  def tasks
478
490
  Morpheus::TasksInterface.new(common_interface_options).setopts(@options)
479
491
  end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/secondary_rest_interface'
2
+
3
+ class Morpheus::LoadBalancerPoolsInterface < Morpheus::SecondaryRestInterface
4
+
5
+ def base_path(load_balancer_id)
6
+ "/api/load-balancers/#{load_balancer_id}/pools"
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/read_interface'
2
+
3
+ class Morpheus::LoadBalancerTypesInterface < Morpheus::ReadInterface
4
+
5
+ def base_path
6
+ "/api/load-balancer-types"
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/secondary_rest_interface'
2
+
3
+ class Morpheus::LoadBalancerVirtualServersInterface < Morpheus::SecondaryRestInterface
4
+
5
+ def base_path(load_balancer_id)
6
+ "/api/load-balancers/#{load_balancer_id}/virtual-servers"
7
+ end
8
+
9
+ end
@@ -1,58 +1,9 @@
1
- require 'morpheus/api/api_client'
1
+ require 'morpheus/api/rest_interface'
2
2
 
3
- class Morpheus::LoadBalancersInterface < Morpheus::APIClient
3
+ class Morpheus::LoadBalancersInterface < Morpheus::RestInterface
4
4
 
5
- def load_balancer_types(options={})
6
- url = "#{@base_url}/api/load-balancer-types"
7
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
8
- if options.is_a?(Hash)
9
- headers[:params].merge!(options)
10
- elsif options.is_a?(Numeric)
11
- url = "#{@base_url}/api/load-balancer-types/#{options}"
12
- elsif options.is_a?(String)
13
- headers[:params]['name'] = options
14
- end
15
- execute(method: :get, url: url, headers: headers)
5
+ def base_path
6
+ "/api/load-balancers"
16
7
  end
17
8
 
18
- def list(params={})
19
- url = "#{@base_url}/api/load-balancers"
20
- headers = { params: params, authorization: "Bearer #{@access_token}" }
21
- opts = {method: :get, url: url, headers: headers}
22
- execute(opts)
23
- end
24
-
25
- def get(options=nil)
26
- url = "#{@base_url}/api/load-balancers"
27
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
28
- if options.is_a?(Hash)
29
- headers[:params].merge!(options)
30
- elsif options.is_a?(Numeric)
31
- url = "#{@base_url}/api/load-balancers/#{options}"
32
- elsif options.is_a?(String)
33
- headers[:params]['name'] = options
34
- end
35
- execute(method: :get, url: url, headers: headers)
36
- end
37
-
38
- def update(id, options)
39
- url = "#{@base_url}/api/load-balancers/#{id}"
40
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
41
- payload = options
42
- execute(method: :put, url: url, headers: headers, payload: payload.to_json)
43
- end
44
-
45
-
46
- def create(options)
47
- url = "#{@base_url}/api/load-balancers"
48
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
49
- payload = options
50
- execute(method: :post, url: url, headers: headers, payload: payload.to_json)
51
- end
52
-
53
- def destroy(id)
54
- url = "#{@base_url}/api/load-balancers/#{id}"
55
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
56
- execute(method: :delete, url: url, headers: headers)
57
- end
58
9
  end
@@ -59,6 +59,34 @@ class Morpheus::NetworkRoutersInterface < Morpheus::APIClient
59
59
  execute(opts)
60
60
  end
61
61
 
62
+ def list_firewall_rule_groups(router_id, params={})
63
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups"
64
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json', params: params }
65
+ opts = {method: :get, url: url, headers: headers}
66
+ execute(opts)
67
+ end
68
+
69
+ def create_firewall_rule_group(router_id, payload={})
70
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups"
71
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
72
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
73
+ execute(opts)
74
+ end
75
+
76
+ def update_firewall_rule_group(router_id, group_id, payload={})
77
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups/#{group_id}"
78
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
79
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
80
+ execute(opts)
81
+ end
82
+
83
+ def destroy_firewall_rule_group(router_id, group_id, payload={})
84
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups/#{group_id}"
85
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
86
+ opts = {method: :delete, url: url, headers: headers, payload: payload.to_json}
87
+ execute(opts)
88
+ end
89
+
62
90
  def create_firewall_rule(router_id, payload={})
63
91
  url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rules"
64
92
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -66,6 +94,13 @@ class Morpheus::NetworkRoutersInterface < Morpheus::APIClient
66
94
  execute(opts)
67
95
  end
68
96
 
97
+ def update_firewall_rule(router_id, rule_id, payload={})
98
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rules/#{rule_id}"
99
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
100
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
101
+ execute(opts)
102
+ end
103
+
69
104
  def destroy_firewall_rule(router_id, rule_id, payload={})
70
105
  url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rules/#{rule_id}"
71
106
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -87,6 +122,27 @@ class Morpheus::NetworkRoutersInterface < Morpheus::APIClient
87
122
  execute(opts)
88
123
  end
89
124
 
125
+ def create_nat(router_id, payload={})
126
+ url = "#{@base_url}/api/networks/routers/#{router_id}/nats"
127
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
128
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
129
+ execute(opts)
130
+ end
131
+
132
+ def update_nat(router_id, nat_id, payload={})
133
+ url = "#{@base_url}/api/networks/routers/#{router_id}/nats/#{nat_id}"
134
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
135
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
136
+ execute(opts)
137
+ end
138
+
139
+ def destroy_nat(router_id, nat_id, payload={})
140
+ url = "#{@base_url}/api/networks/routers/#{router_id}/nats/#{nat_id}"
141
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
142
+ opts = {method: :delete, url: url, headers: headers, payload: payload.to_json}
143
+ execute(opts)
144
+ end
145
+
90
146
  def update_permissions(router_id, payload)
91
147
  url = "#{@base_url}/api/networks/routers/#{router_id}/permissions"
92
148
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -2,38 +2,50 @@ require 'morpheus/api/api_client'
2
2
 
3
3
  class Morpheus::OptionTypeListsInterface < Morpheus::APIClient
4
4
 
5
- def get(id)
5
+ def base_path
6
+ "/api/library/option-type-lists"
7
+ end
8
+
9
+ def get(id, params={})
6
10
  raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
7
- url = "#{@base_url}/api/library/option-type-lists/#{id}"
8
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
11
+ url = "#{base_path}/#{id}"
12
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
9
13
  opts = {method: :get, url: url, headers: headers}
10
14
  execute(opts)
11
15
  end
12
16
 
13
17
  def list(params={})
14
- url = "#{@base_url}/api/library/option-type-lists"
18
+ url = "#{base_path}"
15
19
  headers = { params: {}, authorization: "Bearer #{@access_token}" }
16
20
  headers[:params].merge!(params)
17
21
  opts = {method: :get, url: url, headers: headers}
18
22
  execute(opts)
19
23
  end
20
24
 
25
+ def list_items(id, params={})
26
+ raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
27
+ url = "#{base_path}/#{id}/items"
28
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
29
+ opts = {method: :get, url: url, headers: headers}
30
+ execute(opts)
31
+ end
32
+
21
33
  def create(payload)
22
- url = "#{@base_url}/api/library/option-type-lists"
34
+ url = "#{base_path}"
23
35
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
24
36
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
25
37
  execute(opts)
26
38
  end
27
39
 
28
40
  def update(id, payload)
29
- url = "#{@base_url}/api/library/option-type-lists/#{id}"
41
+ url = "#{base_path}/#{id}"
30
42
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
31
43
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
32
44
  execute(opts)
33
45
  end
34
46
 
35
47
  def destroy(id)
36
- url = "#{@base_url}/api/library/option-type-lists/#{id}"
48
+ url = "#{base_path}/#{id}"
37
49
  headers = { :params => {}, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
38
50
  opts = {method: :delete, url: url, headers: headers}
39
51
  execute(opts)
@@ -0,0 +1,25 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ # Interface class to be subclassed by interfaces that provide CRUD endpoints
4
+ # for objects underneath another resource
5
+ # Subclasses must override the base_path(resource_id) method
6
+ class Morpheus::SecondaryReadInterface < Morpheus::APIClient
7
+
8
+ # subclasses should override in your interface
9
+ # Example: "/api/things/#{resource_id}/widgets"
10
+ def base_path(resource_id)
11
+ raise "#{self.class} has not defined base_path(resource_id)!"
12
+ end
13
+
14
+ def list(resource_id, params={}, headers={})
15
+ validate_id!(resource_id)
16
+ execute(method: :get, url: "#{base_path(resource_id)}", params: params, headers: headers)
17
+ end
18
+
19
+ def get(resource_id, id, params={}, headers={})
20
+ validate_id!(resource_id)
21
+ validate_id!(id)
22
+ execute(method: :get, url: "#{base_path(resource_id)}/#{id}", params: params, headers: headers)
23
+ end
24
+
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ # Interface class to be subclassed by interfaces that provide CRUD endpoints
4
+ # for objects underneath another resource
5
+ # Subclasses must override the base_path(resource_id) method
6
+ class Morpheus::SecondaryRestInterface < Morpheus::APIClient
7
+
8
+ # subclasses should override in your interface
9
+ # Example: "/api/things/#{resource_id}/widgets"
10
+ def base_path(resource_id)
11
+ raise "#{self.class} has not defined base_path(resource_id)!"
12
+ end
13
+
14
+ def list(resource_id, params={}, headers={})
15
+ validate_id!(resource_id)
16
+ execute(method: :get, url: "#{base_path(resource_id)}", params: params, headers: headers)
17
+ end
18
+
19
+ def get(resource_id, id, params={}, headers={})
20
+ validate_id!(resource_id)
21
+ validate_id!(id)
22
+ execute(method: :get, url: "#{base_path(resource_id)}/#{id}", params: params, headers: headers)
23
+ end
24
+
25
+ def create(resource_id, payload, params={}, headers={})
26
+ validate_id!(resource_id)
27
+ execute(method: :post, url: "#{base_path(resource_id)}", params: params, payload: payload, headers: headers)
28
+ end
29
+
30
+ def update(resource_id, id, payload, params={}, headers={})
31
+ validate_id!(resource_id)
32
+ validate_id!(id)
33
+ execute(method: :put, url: "#{base_path(resource_id)}/#{id}", params: params, payload: payload, headers: headers)
34
+ end
35
+
36
+ def destroy(resource_id, id, params = {}, headers={})
37
+ validate_id!(resource_id)
38
+ validate_id!(id)
39
+ execute(method: :delete, url: "#{base_path(resource_id)}/#{id}", params: params, headers: headers)
40
+ end
41
+
42
+ end
@@ -18,11 +18,11 @@ module Morpheus
18
18
  # todo: use delegate
19
19
  module CliCommand
20
20
 
21
- def self.included(klass)
22
- klass.send :include, Morpheus::Cli::PrintHelper
23
- klass.send :include, Morpheus::Benchmarking::HasBenchmarking
24
- klass.extend ClassMethods
25
- Morpheus::Cli::CliRegistry.add(klass, klass.command_name)
21
+ def self.included(base)
22
+ base.send :include, Morpheus::Cli::PrintHelper
23
+ base.send :include, Morpheus::Benchmarking::HasBenchmarking
24
+ base.extend ClassMethods
25
+ Morpheus::Cli::CliRegistry.add(base, base.command_name)
26
26
  end
27
27
 
28
28
  # the beginning of instance variables from optparse !
@@ -983,10 +983,11 @@ module Morpheus
983
983
  out = ""
984
984
  out << usage.to_s.strip if usage
985
985
  out << "\n"
986
- if !subcommands.empty?
986
+ my_subcommands = visible_subcommands
987
+ if !my_subcommands.empty?
987
988
  out << "Commands:"
988
989
  out << "\n"
989
- subcommands.sort.each {|subcmd, method|
990
+ my_subcommands.sort.each {|subcmd, method|
990
991
  desc = get_subcommand_description(subcmd)
991
992
  out << "\t#{subcmd.to_s}"
992
993
  out << "\t#{desc}" if desc
@@ -1527,8 +1528,7 @@ module Morpheus
1527
1528
  cmds = subcommands.clone
1528
1529
  if @hidden_subcommands && !@hidden_subcommands.empty?
1529
1530
  @hidden_subcommands.each do |hidden_cmd|
1530
- cmds.delete(hidden_cmd.to_s)
1531
- cmds.delete(hidden_cmd.to_sym)
1531
+ cmds.delete(hidden_cmd.to_s.gsub('_', '-'))
1532
1532
  end
1533
1533
  end
1534
1534
  cmds
@@ -2565,46 +2565,50 @@ class Morpheus::Cli::Instances
2565
2565
  options = {}
2566
2566
  optparse = Morpheus::Cli::OptionParser.new do |opts|
2567
2567
  opts.banner = subcommand_usage("[instance]")
2568
- build_common_options(opts, options, [:options, :json, :dry_run, :remote])
2568
+ build_standard_update_options(opts, options)
2569
2569
  end
2570
2570
  optparse.parse!(args)
2571
- if args.count < 1
2572
- puts optparse
2573
- exit 1
2574
- end
2571
+ verify_args!(args:args, optparse:optparse, count:1)
2575
2572
  connect(options)
2576
- begin
2577
- instance = find_instance_by_name_or_id(args[0])
2578
-
2579
- group_id = instance['group']['id']
2580
- cloud_id = instance['cloud']['id']
2581
- layout_id = instance['layout']['id']
2582
-
2583
- plan_id = instance['plan']['id']
2573
+ instance = find_instance_by_name_or_id(args[0])
2574
+ return 1, "instance not found" if instance.nil?
2575
+
2576
+ payload = {}
2577
+ if options[:payload]
2578
+ payload = options[:payload]
2579
+ payload.deep_merge!(parse_passed_options(options))
2580
+ else
2584
2581
  payload = {
2585
- :instance => {:id => instance["id"]}
2582
+ "instance" => {:id => instance["id"]}
2586
2583
  }
2584
+ payload.deep_merge!(parse_passed_options(options))
2587
2585
 
2588
2586
  # avoid 500 error
2589
2587
  # payload[:servicePlanOptions] = {}
2590
2588
 
2591
2589
  puts "\nDue to limitations by most Guest Operating Systems, Disk sizes can only be expanded and not reduced.\nIf a smaller plan is selected, memory and CPU (if relevant) will be reduced but storage will not.\n\n"
2592
2590
 
2591
+ group_id = instance['group']['id']
2592
+ cloud_id = instance['cloud']['id']
2593
+ layout_id = instance['layout']['id']
2594
+ plan_id = instance['plan']['id']
2595
+ current_plan_name = instance['plan']['name']
2593
2596
  # prompt for service plan
2594
2597
  service_plans_json = @instances_interface.service_plans({zoneId: cloud_id, siteId: group_id, layoutId: layout_id})
2595
2598
  service_plans = service_plans_json["plans"]
2596
2599
  service_plans_dropdown = service_plans.collect {|sp| {'name' => sp["name"], 'value' => sp["id"]} } # already sorted
2597
2600
  service_plans_dropdown.each do |plan|
2598
- if plan['value'] && plan['value'].to_i == plan_id.to_i
2599
- plan['name'] = "#{plan['name']} (current)"
2600
- end
2601
+ # if plan['value'] && plan['value'].to_i == plan_id.to_i
2602
+ # plan['name'] = "#{plan['name']} (current)"
2603
+ # current_plan_name = plan['name']
2604
+ # end
2601
2605
  end
2602
- plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'Plan', 'selectOptions' => service_plans_dropdown, 'required' => true, 'description' => 'Choose the appropriately sized plan for this instance'}],options[:options])
2606
+ plan_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'servicePlan', 'type' => 'select', 'fieldLabel' => 'Plan', 'selectOptions' => service_plans_dropdown, 'required' => true, 'defaultValue' => current_plan_name, 'description' => 'Choose the appropriately sized plan for this instance'}],options[:options])
2603
2607
  service_plan = service_plans.find {|sp| sp["id"] == plan_prompt['servicePlan'].to_i }
2604
2608
  new_plan_id = service_plan["id"]
2605
2609
  #payload[:servicePlan] = new_plan_id # ew, this api uses servicePlanId instead
2606
2610
  #payload[:servicePlanId] = new_plan_id
2607
- payload[:instance][:plan] = {id: service_plan["id"]}
2611
+ payload["instance"]["plan"] = {"id" => service_plan["id"]}
2608
2612
 
2609
2613
  volumes_response = @instances_interface.volumes(instance['id'])
2610
2614
  current_volumes = volumes_response['volumes'].sort {|x,y| x['displayOrder'] <=> y['displayOrder'] }
@@ -2612,29 +2616,27 @@ class Morpheus::Cli::Instances
2612
2616
  # prompt for volumes
2613
2617
  volumes = prompt_resize_volumes(current_volumes, service_plan, options)
2614
2618
  if !volumes.empty?
2615
- payload[:volumes] = volumes
2619
+ payload["volumes"] = volumes
2616
2620
  end
2617
2621
 
2618
2622
  # only amazon supports this option
2619
2623
  # for now, always do this
2620
- payload[:deleteOriginalVolumes] = true
2621
- @instances_interface.setopts(options)
2622
- if options[:dry_run]
2623
- print_dry_run @instances_interface.dry.resize(instance['id'], payload)
2624
- return
2625
- end
2626
- json_response = @instances_interface.resize(instance['id'], payload)
2627
- if options[:json]
2628
- puts as_json(json_response, options)
2629
- return 0
2630
- else
2631
- print_green_success "Resizing instance #{instance['name']}"
2632
- #list([])
2633
- end
2634
- rescue RestClient::Exception => e
2635
- print_rest_exception(e, options)
2636
- exit 1
2624
+ payload["deleteOriginalVolumes"] = true
2625
+ end
2626
+ payload.delete("rootVolume")
2627
+ (1..20).each {|i| payload.delete("dataVolume#{i}") }
2628
+ @instances_interface.setopts(options)
2629
+ if options[:dry_run]
2630
+ print_dry_run @instances_interface.dry.resize(instance['id'], payload)
2631
+ return
2632
+ end
2633
+ json_response = @instances_interface.resize(instance['id'], payload)
2634
+ render_response(json_response, options, 'snapshots') do
2635
+ print_green_success "Resizing instance #{instance['name']}"
2637
2636
  end
2637
+ return 0, nil
2638
+
2639
+
2638
2640
  end
2639
2641
 
2640
2642
  def backup(args)