morpheus-cli 2.10.0 → 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/morpheus +27 -32
  3. data/lib/morpheus/api/accounts_interface.rb +36 -47
  4. data/lib/morpheus/api/api_client.rb +141 -110
  5. data/lib/morpheus/api/app_templates_interface.rb +56 -72
  6. data/lib/morpheus/api/apps_interface.rb +111 -132
  7. data/lib/morpheus/api/auth_interface.rb +30 -0
  8. data/lib/morpheus/api/clouds_interface.rb +71 -76
  9. data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
  10. data/lib/morpheus/api/dashboard_interface.rb +10 -17
  11. data/lib/morpheus/api/deploy_interface.rb +60 -72
  12. data/lib/morpheus/api/deployments_interface.rb +53 -71
  13. data/lib/morpheus/api/groups_interface.rb +55 -45
  14. data/lib/morpheus/api/instance_types_interface.rb +19 -23
  15. data/lib/morpheus/api/instances_interface.rb +179 -177
  16. data/lib/morpheus/api/key_pairs_interface.rb +11 -17
  17. data/lib/morpheus/api/license_interface.rb +18 -23
  18. data/lib/morpheus/api/load_balancers_interface.rb +54 -69
  19. data/lib/morpheus/api/logs_interface.rb +25 -29
  20. data/lib/morpheus/api/options_interface.rb +13 -17
  21. data/lib/morpheus/api/provision_types_interface.rb +19 -22
  22. data/lib/morpheus/api/roles_interface.rb +75 -94
  23. data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
  24. data/lib/morpheus/api/security_groups_interface.rb +39 -51
  25. data/lib/morpheus/api/servers_interface.rb +113 -115
  26. data/lib/morpheus/api/setup_interface.rb +31 -0
  27. data/lib/morpheus/api/task_sets_interface.rb +36 -38
  28. data/lib/morpheus/api/tasks_interface.rb +56 -69
  29. data/lib/morpheus/api/users_interface.rb +67 -76
  30. data/lib/morpheus/api/virtual_images_interface.rb +61 -61
  31. data/lib/morpheus/api/whoami_interface.rb +12 -15
  32. data/lib/morpheus/cli.rb +71 -60
  33. data/lib/morpheus/cli/accounts.rb +254 -315
  34. data/lib/morpheus/cli/alias_command.rb +219 -0
  35. data/lib/morpheus/cli/app_templates.rb +264 -272
  36. data/lib/morpheus/cli/apps.rb +608 -671
  37. data/lib/morpheus/cli/cli_command.rb +259 -21
  38. data/lib/morpheus/cli/cli_registry.rb +99 -14
  39. data/lib/morpheus/cli/clouds.rb +599 -372
  40. data/lib/morpheus/cli/config_file.rb +126 -0
  41. data/lib/morpheus/cli/credentials.rb +141 -117
  42. data/lib/morpheus/cli/dashboard_command.rb +48 -56
  43. data/lib/morpheus/cli/deployments.rb +254 -268
  44. data/lib/morpheus/cli/deploys.rb +150 -142
  45. data/lib/morpheus/cli/error_handler.rb +38 -0
  46. data/lib/morpheus/cli/groups.rb +551 -179
  47. data/lib/morpheus/cli/hosts.rb +862 -617
  48. data/lib/morpheus/cli/instance_types.rb +103 -95
  49. data/lib/morpheus/cli/instances.rb +1335 -1009
  50. data/lib/morpheus/cli/key_pairs.rb +82 -90
  51. data/lib/morpheus/cli/library.rb +498 -499
  52. data/lib/morpheus/cli/license.rb +83 -101
  53. data/lib/morpheus/cli/load_balancers.rb +314 -300
  54. data/lib/morpheus/cli/login.rb +66 -44
  55. data/lib/morpheus/cli/logout.rb +47 -46
  56. data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
  57. data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
  58. data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
  59. data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
  60. data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
  61. data/lib/morpheus/cli/option_parser.rb +35 -0
  62. data/lib/morpheus/cli/option_types.rb +232 -192
  63. data/lib/morpheus/cli/recent_activity_command.rb +61 -65
  64. data/lib/morpheus/cli/remote.rb +446 -199
  65. data/lib/morpheus/cli/roles.rb +884 -906
  66. data/lib/morpheus/cli/security_group_rules.rb +213 -203
  67. data/lib/morpheus/cli/security_groups.rb +237 -192
  68. data/lib/morpheus/cli/shell.rb +338 -231
  69. data/lib/morpheus/cli/tasks.rb +326 -308
  70. data/lib/morpheus/cli/users.rb +457 -462
  71. data/lib/morpheus/cli/version.rb +1 -1
  72. data/lib/morpheus/cli/version_command.rb +16 -18
  73. data/lib/morpheus/cli/virtual_images.rb +526 -345
  74. data/lib/morpheus/cli/whoami.rb +125 -111
  75. data/lib/morpheus/cli/workflows.rb +338 -185
  76. data/lib/morpheus/formatters.rb +8 -1
  77. data/lib/morpheus/logging.rb +1 -1
  78. data/lib/morpheus/rest_client.rb +17 -8
  79. metadata +9 -3
  80. data/lib/morpheus/api/custom_instance_types.rb +0 -55
@@ -0,0 +1,219 @@
1
+ require 'optparse'
2
+ require 'morpheus/cli/cli_command'
3
+ require 'morpheus/cli/shell'
4
+ require 'json'
5
+
6
+ # This command allows the creation of an alias
7
+ # these aliases are stored in the $MORPHEUS_CLI_HOME/.morpheusrc
8
+ # See Morpheus::Cli::ConfigFile
9
+ #
10
+ class Morpheus::Cli::AliasCommand
11
+ include Morpheus::Cli::CliCommand
12
+ set_command_name :alias
13
+ register_subcommands :add, :remove, :list
14
+ #set_default_subcommand :add
15
+
16
+ def initialize()
17
+ end
18
+
19
+ def usage
20
+ out = "Usage: morpheus #{command_name} [name]='[command]'"
21
+ out
22
+ end
23
+
24
+ def handle(args)
25
+ if args.empty?
26
+ puts usage
27
+ exit 127
28
+ elsif self.class.has_subcommand?(args[0])
29
+ handle_subcommand(args)
30
+ elsif args.count == 1
31
+ add(args)
32
+ else
33
+ handle_subcommand(args)
34
+ #list([])
35
+ end
36
+ end
37
+
38
+ def add(args)
39
+ options = {}
40
+ do_remove = false
41
+ optparse = Morpheus::Cli::OptionParser.new do|opts|
42
+ opts.banner = usage
43
+ #build_common_options(opts, options, [])
44
+ opts.on('-h', '--help', "Prints this help" ) do
45
+ puts opts.banner
46
+ puts "Commands:"
47
+ subcommands.sort.each {|cmd, method|
48
+ puts "\t#{cmd.to_s}"
49
+ }
50
+ puts "" +
51
+ "This defines an alias of a command.\n" +
52
+ "The [name] should be a one word .\n" +
53
+ "The [command] must be quoted if it is more than one word.\n" +
54
+ "The [command] may include multiple commands, semicolon delimited.\n" +
55
+ #"Example: alias cloud='clouds' .\n" +
56
+ "Aliases are preserved for future use in your config.\n" +
57
+ "You can use just `alias` instead of `alias add`.\n" +
58
+ "For more information, see https://github.com/gomorpheus/morpheus-cli/wiki/Alias"
59
+ exit
60
+ end
61
+ end
62
+ optparse.parse!(args)
63
+ if args.count != 1
64
+ puts optparse
65
+ exit 1
66
+ end
67
+ alias_definition = args[0]
68
+ alias_name, command_string = Morpheus::Cli::CliRegistry.parse_alias_definition(alias_definition)
69
+
70
+ if alias_name.empty? || command_string.empty?
71
+ print_red_alert "invalid alias syntax: #{alias_definition}"
72
+ return false
73
+ else
74
+ # config[:aliases] ||= []
75
+ # config[:aliases] << {name: alias_name, command: command_string}
76
+ begin
77
+ Morpheus::Cli::CliRegistry.instance.add_alias(alias_name, command_string)
78
+ #print "registered alias #{alias_name}", "\n"
79
+ rescue => err
80
+ print_red_alert "#{err.message}"
81
+ return false
82
+ end
83
+ Morpheus::Cli::ConfigFile.instance.save_file()
84
+ end
85
+
86
+ Morpheus::Cli::Shell.instance.recalculate_auto_complete_commands()
87
+
88
+ end
89
+
90
+ def remove(args)
91
+ options = {}
92
+ do_remove = false
93
+ optparse = Morpheus::Cli::OptionParser.new do|opts|
94
+ opts.banner = subcommand_usage("[alias1] [alias2]")
95
+ build_common_options(opts, options, [])
96
+ opts.footer = "This is how you remove alias definitions from your config."
97
+ end
98
+ optparse.parse!(args)
99
+ if args.count < 1
100
+ puts optparse
101
+ exit 1
102
+ end
103
+ alias_names = args
104
+ alias_names.each do |arg|
105
+ if !Morpheus::Cli::CliRegistry.has_alias?(arg)
106
+ print_red_alert "alias not found by name '#{arg}'"
107
+ exit 1
108
+ end
109
+ end
110
+
111
+ alias_names.each do |arg|
112
+ Morpheus::Cli::CliRegistry.instance.remove_alias(arg)
113
+ end
114
+
115
+ Morpheus::Cli::ConfigFile.instance.save_file()
116
+ if args.count == 1
117
+ puts "removed alias '#{alias_names[0]}'"
118
+ else
119
+ puts "removed aliases '#{alias_names.join(', ')}'"
120
+ end
121
+ end
122
+
123
+ def list(args)
124
+ options = {format:'friendly', sort:'name'}
125
+ do_remove = false
126
+ optparse = Morpheus::Cli::OptionParser.new do|opts|
127
+ opts.banner = subcommand_usage()
128
+ opts.on( '-E', '--export', "Generate output that can be used verbatim in a .morpheusrc config file." ) do
129
+ options[:format] = 'export'
130
+ end
131
+ build_common_options(opts, options, [:list, :json])
132
+ opts.footer = "This outputs a list of your defined aliases."
133
+ end
134
+ optparse.parse!(args)
135
+
136
+ #my_aliases = Morpheus::Cli::CliRegistry.all_aliases
137
+ my_aliases = Morpheus::Cli::CliRegistry.all_aliases.collect {|k,v|
138
+ {name: k, command_string: v}
139
+ }
140
+
141
+ # todo: generic support :list options on a local Array
142
+ if options[:phrase]
143
+ # my_aliases = my_aliases.grep(/^#{Regexp.escape(options[:phrase])}/)
144
+ match_regex = /#{Regexp.escape(options[:phrase])}/
145
+ my_aliases = my_aliases.select {|it|
146
+ it[:name].to_s =~ match_regex || it[:command_string].to_s =~ match_regex
147
+ }
148
+ end
149
+
150
+ options[:sort] ||= 'name'
151
+ options[:direction] ||= 'asc'
152
+
153
+ if options[:sort]
154
+ if options[:sort].to_s == 'name'
155
+ my_aliases = my_aliases.sort {|x,y| x[:name].to_s.downcase <=> y[:name].to_s.downcase }
156
+ elsif options[:sort].to_s == 'ts'
157
+ # just relies on the order they were registered in, heh...
158
+ my_aliases = my_aliases.sort {|x,y| x[:command_string].to_s.downcase <=> y[:command_string].to_s.downcase }
159
+ else
160
+ # a-z is the default, and the best
161
+ end
162
+ end
163
+
164
+ if options[:direction] == 'desc'
165
+ my_aliases = my_aliases.reverse
166
+ end
167
+ if options[:offset]
168
+ my_aliases = my_aliases.slice(options[:offset].to_i, my_aliases.size)
169
+ end
170
+ if options[:max]
171
+ my_aliases = my_aliases.first(options[:max].to_i)
172
+ end
173
+ num_aliases = my_aliases.size
174
+ out = ""
175
+ if options[:json]
176
+ options[:format] = 'json'
177
+ end
178
+ if options[:format] == 'json' || options[:json]
179
+ alias_json = {}
180
+ my_aliases.each do |it|
181
+ alias_json[it[:name]] = it[:command_string]
182
+ end
183
+ out << JSON.pretty_generate({aliases: alias_json})
184
+ out << "\n"
185
+ elsif options[:format] == 'export' || options[:format] == 'config'
186
+ # out << "# morpheus aliases for #{`whoami`}\n" # windows!
187
+ out << "# morpheus aliases\n"
188
+ my_aliases.each do |it|
189
+ out << "#{it[:name]}='#{it[:command_string]}'"
190
+ out << "\n"
191
+ end
192
+ else
193
+ # friendly
194
+ #out << cyan
195
+ if num_aliases == 0
196
+ #print "You have #{num_aliases} aliases defined."
197
+ out << "Found #{num_aliases} aliases"
198
+ elsif num_aliases == 1
199
+ #print "You have just one alias defined."
200
+ out << "Found #{num_aliases} alias"
201
+ else
202
+ #print "You have #{num_aliases} aliases defined."
203
+ out << "Found #{num_aliases} aliases"
204
+ end
205
+ if options[:phrase]
206
+ out << " matching '#{options[:phrase]}'"
207
+ end
208
+ out << "\n"
209
+ out << reset
210
+ my_aliases.each do |it|
211
+ out << "\t#{cyan}#{it[:name]}#{reset}='#{it[:command_string]}'"
212
+ out << "\n"
213
+ end
214
+ out << reset
215
+ end
216
+ print out
217
+ end
218
+
219
+ end
@@ -7,128 +7,108 @@ require 'json'
7
7
 
8
8
  class Morpheus::Cli::AppTemplates
9
9
  include Morpheus::Cli::CliCommand
10
+ include Morpheus::Cli::ProvisioningHelper
11
+
12
+ register_subcommands :list, :get, :add, :update, :remove, :'add-instance', :'remove-instance', :'connect-tiers', :'available-tiers', :'available-types'
13
+ alias_subcommand :details, :get
14
+ set_default_subcommand :list
10
15
 
11
- def initialize()
12
- @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
13
- end
14
-
15
- def connect(opts)
16
- @access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials()
17
- if @access_token.empty?
18
- print_red_alert "Invalid Credentials. Unable to acquire access token. Please verify your credentials and try again."
19
- exit 1
20
- end
21
- @active_groups = ::Morpheus::Cli::Groups.load_group_file
22
- @api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
23
- @app_templates_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).app_templates
16
+ def initialize()
17
+ # @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
18
+ end
19
+
20
+ def connect(opts)
21
+ @api_client = establish_remote_appliance_connection(opts)
22
+ @app_templates_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).app_templates
24
23
  @groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
25
24
  @instances_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instances
26
25
  @instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
27
26
  @options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).options
28
- end
29
-
30
- def handle(args)
31
- usage = "Usage: morpheus app-templates [list,details,add,update,remove,add-instance,remove-instance,connect-tiers,available-tiers] [name]"
32
- if args.empty?
33
- puts "\n#{usage}\n\n"
34
- exit 1
35
- end
36
-
37
- case args[0]
38
- when 'list'
39
- list(args[1..-1])
40
- when 'details'
41
- details(args[1..-1])
42
- when 'add'
43
- add(args[1..-1])
44
- when 'update'
45
- update(args[1..-1])
46
- when 'add-instance'
47
- add_instance(args[1..-1])
48
- when 'remove-instance'
49
- remove_instance(args[1..-1])
50
- when 'connect-tiers'
51
- connect_tiers(args[1..-1])
52
- when 'remove'
53
- remove(args[1..-1])
54
- when 'available-tiers'
55
- available_tiers(args[1..-1])
56
- when 'available-types'
57
- available_types(args[1..-1])
58
- else
59
- puts "\n#{usage}\n\n"
60
- exit 127
61
- end
62
- end
63
-
64
- def list(args)
65
- options = {}
66
- optparse = OptionParser.new do|opts|
67
- build_common_options(opts, options, [:list, :json])
68
- end
69
- optparse.parse(args)
70
- connect(options)
71
- begin
27
+ @active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
28
+ end
29
+
30
+ def handle(args)
31
+ handle_subcommand(args)
32
+ end
33
+
34
+ def list(args)
35
+ options = {}
36
+ optparse = OptionParser.new do|opts|
37
+ opts.banner = subcommand_usage()
38
+ build_common_options(opts, options, [:list, :json, :dry_run])
39
+ end
40
+ optparse.parse!(args)
41
+ connect(options)
42
+ begin
72
43
  params = {}
73
- [:phrase, :offset, :max, :sort, :direction].each do |k|
74
- params[k] = options[k] unless options[k].nil?
75
- end
76
-
77
- json_response = @app_templates_interface.list(params)
78
- app_templates = json_response['appTemplates']
79
- if options[:json]
80
- print JSON.pretty_generate(json_response)
81
- print "\n"
82
- else
83
- print "\n" ,cyan, bold, "Morpheus App Templates\n","==================", reset, "\n\n"
84
- if app_templates.empty?
85
- puts yellow,"No app templates found.",reset
86
- else
87
- print_app_templates_table(app_templates)
88
- end
89
- print reset,"\n\n"
90
- end
91
- rescue RestClient::Exception => e
92
- print_rest_exception(e, options)
93
- exit 1
94
- end
95
- end
96
-
97
- def details(args)
98
- usage = "Usage: morpheus app-templates details [name]"
99
- options = {}
100
- optparse = OptionParser.new do|opts|
101
- opts.banner = usage
44
+ [:phrase, :offset, :max, :sort, :direction].each do |k|
45
+ params[k] = options[k] unless options[k].nil?
46
+ end
47
+ if options[:dry_run]
48
+ print_dry_run @app_templates_interface.dry.list(params)
49
+ return
50
+ end
51
+ json_response = @app_templates_interface.list(params)
52
+ app_templates = json_response['appTemplates']
53
+ if options[:json]
54
+ print JSON.pretty_generate(json_response)
55
+ print "\n"
56
+ else
57
+ print "\n" ,cyan, bold, "Morpheus App Templates\n","==================", reset, "\n\n"
58
+ if app_templates.empty?
59
+ puts yellow,"No app templates found.",reset
60
+ else
61
+ print_app_templates_table(app_templates)
62
+ print_results_pagination(json_response)
63
+ end
64
+ print reset,"\n"
65
+ end
66
+ rescue RestClient::Exception => e
67
+ print_rest_exception(e, options)
68
+ exit 1
69
+ end
70
+ end
71
+
72
+ def get(args)
73
+ options = {}
74
+ optparse = OptionParser.new do|opts|
75
+ opts.banner = subcommand_usage("[name]")
102
76
  opts.on( '-c', '--config', "Display Config Data" ) do |val|
103
77
  options[:config] = true
104
78
  end
105
- build_common_options(opts, options, [:json])
106
- end
107
- optparse.parse(args)
79
+ build_common_options(opts, options, [:json, :dry_run])
80
+ end
81
+ optparse.parse!(args)
108
82
  if args.count < 1
109
- puts "\n#{usage}\n\n"
83
+ puts optparse
110
84
  exit 1
111
85
  end
112
- name = args[0]
113
- connect(options)
114
- begin
115
-
116
- app_template = find_app_template_by_name(name)
117
- exit 1 if app_template.nil?
118
-
119
- json_response = @app_templates_interface.get(app_template['id'])
120
- app_template = json_response['appTemplate']
121
-
122
- if options[:json]
123
- print JSON.pretty_generate(json_response)
124
- print "\n"
125
- else
126
- print "\n" ,cyan, bold, "App Template Details\n","==================", reset, "\n\n"
127
- print cyan
128
- puts "ID: #{app_template['id']}"
129
- puts "Name: #{app_template['name']}"
130
- #puts "Category: #{app_template['category']}"
131
- puts "Account: #{app_template['account'] ? app_template['account']['name'] : ''}"
86
+ connect(options)
87
+ begin
88
+ if options[:dry_run]
89
+ if args[0].to_s =~ /\A\d{1,}\Z/
90
+ print_dry_run @instances_interface.dry.get(args[0].to_i)
91
+ else
92
+ print_dry_run @instances_interface.dry.list({name:args[0]})
93
+ end
94
+ return
95
+ end
96
+ app_template = find_app_template_by_name_or_id(args[0])
97
+ exit 1 if app_template.nil?
98
+
99
+ json_response = @app_templates_interface.get(app_template['id'])
100
+ app_template = json_response['appTemplate']
101
+
102
+ if options[:json]
103
+ print JSON.pretty_generate(json_response)
104
+ print "\n"
105
+ else
106
+ print "\n" ,cyan, bold, "App Template Details\n","==================", reset, "\n\n"
107
+ print cyan
108
+ puts "ID: #{app_template['id']}"
109
+ puts "Name: #{app_template['name']}"
110
+ #puts "Category: #{app_template['category']}"
111
+ puts "Account: #{app_template['account'] ? app_template['account']['name'] : ''}"
132
112
  instance_type_names = (app_template['instanceTypes'] || []).collect {|it| it['name'] }
133
113
  #puts "Instance Types: #{instance_type_names.join(', ')}"
134
114
  config = app_template['config']['tierView']
@@ -141,8 +121,9 @@ class Morpheus::Cli::AppTemplates
141
121
  print "\n"
142
122
  print cyan, "= #{tier['data']['name']}\n"
143
123
  instances.each do |instance|
144
- instance_id = instance['data']['id'].sub('newinstance-', '')
145
- print green, " - #{instance['data']['typeName']} (#{instance_id})\n",reset
124
+ instance_id = instance['data']['id'].to_s.sub('newinstance-', '')
125
+ instance_name = instance['data']['instance.name'] || ''
126
+ print green, " #{instance_name} - #{instance['data']['typeName']} (#{instance_id})\n",reset
146
127
  end
147
128
 
148
129
  end
@@ -154,35 +135,34 @@ class Morpheus::Cli::AppTemplates
154
135
  puts JSON.pretty_generate(config)
155
136
  end
156
137
 
157
- print reset,"\n\n"
158
- end
159
- rescue RestClient::Exception => e
160
- print_rest_exception(e, options)
161
- exit 1
162
- end
163
- end
138
+ print reset,"\n"
139
+ end
140
+ rescue RestClient::Exception => e
141
+ print_rest_exception(e, options)
142
+ exit 1
143
+ end
144
+ end
164
145
 
165
- def add(args)
166
- usage = "Usage: morpheus app-templates add"
146
+ def add(args)
167
147
  options = {}
168
148
  optparse = OptionParser.new do|opts|
169
- opts.banner = usage
149
+ opts.banner = subcommand_usage()
170
150
  # opts.on( '-g', '--group GROUP', "Group Name" ) do |group|
171
151
  # options[:options] ||= {}
172
152
  # options[:options]['group'] = group
173
153
  # end
174
- build_common_options(opts, options, [:options, :json])
154
+ build_common_options(opts, options, [:options, :json, :dry_run])
175
155
  end
176
- optparse.parse(args)
156
+ optparse.parse!(args)
177
157
  connect(options)
178
158
  begin
179
-
159
+
180
160
  params = Morpheus::Cli::OptionTypes.prompt(add_app_template_option_types, options[:options], @api_client, options[:params])
181
161
 
182
162
  #puts "parsed params is : #{params.inspect}"
183
163
  app_template_keys = ['name']
184
164
  app_template_payload = params.select {|k,v| app_template_keys.include?(k) }
185
-
165
+
186
166
  group = nil
187
167
  if params['group'].to_s != ''
188
168
  group = find_group_by_name(params['group'])
@@ -195,6 +175,12 @@ class Morpheus::Cli::AppTemplates
195
175
  request_payload = {appTemplate: app_template_payload}
196
176
  request_payload['siteId'] = group['id'] if group
197
177
  request_payload['config'] = config
178
+
179
+ if options[:dry_run]
180
+ print_dry_run @app_templates_interface.dry.create(request_payload)
181
+ return
182
+ end
183
+
198
184
  json_response = @app_templates_interface.create(request_payload)
199
185
 
200
186
  if options[:json]
@@ -203,42 +189,40 @@ class Morpheus::Cli::AppTemplates
203
189
  else
204
190
  print_green_success "Added app template #{app_template_payload['name']}"
205
191
  details_options = [app_template_payload["name"]]
206
- details(details_options)
192
+ get(details_options)
207
193
  end
208
194
 
209
195
  rescue RestClient::Exception => e
210
196
  print_rest_exception(e, options)
211
197
  exit 1
212
198
  end
213
- end
199
+ end
214
200
 
215
- def update(args)
216
- usage = "Usage: morpheus app-templates update [name] [options]"
201
+ def update(args)
217
202
  options = {}
218
203
  optparse = OptionParser.new do|opts|
219
- opts.banner = usage
220
- build_common_options(opts, options, [:options, :json])
204
+ opts.banner = subcommand_usage("[name] [options]")
205
+ build_common_options(opts, options, [:options, :json, :dry_run])
221
206
  end
222
- optparse.parse(args)
207
+ optparse.parse!(args)
223
208
 
224
209
  if args.count < 1
225
- puts "\n#{usage}\n\n"
210
+ puts optparse
226
211
  exit 1
227
212
  end
228
- name = args[0]
229
213
 
230
214
  connect(options)
231
-
215
+
232
216
  begin
233
217
 
234
- app_template = find_app_template_by_name(name)
218
+ app_template = find_app_template_by_name_or_id(args[0])
235
219
  exit 1 if app_template.nil?
236
220
 
237
221
  #params = Morpheus::Cli::OptionTypes.prompt(update_app_template_option_types, options[:options], @api_client, options[:params])
238
222
  params = options[:options] || {}
239
223
 
240
224
  if params.empty?
241
- puts "\n#{usage}\n\n"
225
+ puts optparse
242
226
  option_lines = update_app_template_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
243
227
  puts "\nAvailable Options:\n#{option_lines}\n\n"
244
228
  exit 1
@@ -247,7 +231,7 @@ class Morpheus::Cli::AppTemplates
247
231
  #puts "parsed params is : #{params.inspect}"
248
232
  app_template_keys = ['name']
249
233
  app_template_payload = params.select {|k,v| app_template_keys.include?(k) }
250
-
234
+
251
235
  group = nil
252
236
  if params['group'].to_s != ''
253
237
  group = find_group_by_name(params['group'])
@@ -263,49 +247,56 @@ class Morpheus::Cli::AppTemplates
263
247
  end
264
248
  # request_payload['config'] = config['tierView']
265
249
  request_payload['config'] = config
250
+
251
+ if options[:dry_run]
252
+ print_dry_run @app_templates_interface.dry.update(app_template['id'], request_payload)
253
+ return
254
+ end
255
+
266
256
  json_response = @app_templates_interface.update(app_template['id'], request_payload)
267
257
 
268
-
258
+
269
259
  if options[:json]
270
260
  print JSON.pretty_generate(json_response)
271
261
  print "\n"
272
262
  else
273
263
  print_green_success "Updated app template #{app_template_payload['name']}"
274
264
  details_options = [app_template_payload["name"] || app_template['name']]
275
- details(details_options)
265
+ get(details_options)
276
266
  end
277
267
 
278
268
  rescue RestClient::Exception => e
279
269
  print_rest_exception(e, options)
280
270
  exit 1
281
271
  end
282
- end
272
+ end
283
273
 
284
274
  def remove(args)
285
- usage = "Usage: morpheus app-templates remove [name]"
286
275
  options = {}
287
276
  optparse = OptionParser.new do|opts|
288
- opts.banner = usage
289
- build_common_options(opts, options, [:auto_confirm, :json])
277
+ opts.banner = subcommand_usage("[name]")
278
+ build_common_options(opts, options, [:auto_confirm, :json, :dry_run])
290
279
  end
291
- optparse.parse(args)
280
+ optparse.parse!(args)
292
281
 
293
282
  if args.count < 1
294
- puts "\n#{usage}\n\n"
283
+ puts optparse
295
284
  exit 1
296
285
  end
297
- name = args[0]
298
286
 
299
287
  connect(options)
300
288
  begin
301
- # allow finding by ID since name is not unique!
302
- app_template = ((name.to_s =~ /\A\d{1,}\Z/) ? find_app_template_by_id(name) : find_app_template_by_name(name) )
289
+ app_template = find_app_template_by_name_or_id(args[0])
303
290
  exit 1 if app_template.nil?
304
291
  unless options[:yes] || Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the app template #{app_template['name']}?")
305
292
  exit
306
293
  end
294
+ if options[:dry_run]
295
+ print_dry_run @app_templates_interface.dry.destroy(app_template['id'])
296
+ return
297
+ end
307
298
  json_response = @app_templates_interface.destroy(app_template['id'])
308
-
299
+
309
300
  if options[:json]
310
301
  print JSON.pretty_generate(json_response)
311
302
  print "\n"
@@ -320,10 +311,9 @@ class Morpheus::Cli::AppTemplates
320
311
  end
321
312
 
322
313
  def add_instance(args)
323
- usage = "Usage: morpheus app-templates add-instance [name] [tier] [instance-type]"
324
314
  options = {}
325
315
  optparse = OptionParser.new do|opts|
326
- opts.banner = usage
316
+ opts.banner = subcommand_usage("[name] [tier] [instance-type]")
327
317
  # opts.on( '-g', '--group GROUP', "Group" ) do |val|
328
318
  # options[:group] = val
329
319
  # end
@@ -332,7 +322,7 @@ class Morpheus::Cli::AppTemplates
332
322
  # end
333
323
  build_common_options(opts, options, [:json])
334
324
  end
335
- optparse.parse(args)
325
+ optparse.parse!(args)
336
326
 
337
327
  if args.count < 3
338
328
  puts "\n#{optparse}\n\n"
@@ -341,11 +331,11 @@ class Morpheus::Cli::AppTemplates
341
331
 
342
332
  connect(options)
343
333
 
344
- name = args[0]
334
+ app_template_name = args[0]
345
335
  tier_name = args[1]
346
336
  instance_type_code = args[2]
347
337
 
348
- app_template = find_app_template_by_name(name)
338
+ app_template = find_app_template_by_name_or_id(app_template_name)
349
339
  exit 1 if app_template.nil?
350
340
 
351
341
  instance_type = find_instance_type_by_code(instance_type_code)
@@ -398,7 +388,7 @@ class Morpheus::Cli::AppTemplates
398
388
  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])
399
389
  service_plan = service_plans.find {|sp| sp["id"] == plan_prompt['servicePlan'].to_i }
400
390
  payload[:servicePlan] = service_plan["id"]
401
-
391
+
402
392
 
403
393
  type_payload = {}
404
394
  if !layout['optionTypes'].nil? && !layout['optionTypes'].empty?
@@ -428,43 +418,43 @@ class Morpheus::Cli::AppTemplates
428
418
 
429
419
  config['nodes'] ||= []
430
420
 
431
- tier = config['nodes'].find {|node|
421
+ tier = config['nodes'].find {|node|
432
422
  node["data"] && node["data"]["type"] == "tier" && node["data"]["id"] == "newtier-#{tier_name}"
433
423
  }
434
424
  if !tier
435
425
  tier = {
436
- "classes"=>"tier newtier-#{tier_name}",
437
- "data"=>{"id"=>"newtier-#{tier_name}", "name"=> tier_name, "type"=>"tier"},
438
- "grabbable"=>true, "group"=>"nodes","locked"=>false,
439
- #"position"=>{"x"=>-2.5, "y"=>-45},
426
+ "classes"=>"tier newtier-#{tier_name}",
427
+ "data"=>{"id"=>"newtier-#{tier_name}", "name"=> tier_name, "type"=>"tier"},
428
+ "grabbable"=>true, "group"=>"nodes","locked"=>false,
429
+ #"position"=>{"x"=>-2.5, "y"=>-45},
440
430
  "removed"=>false, "selectable"=>true, "selected"=>false
441
431
  }
442
432
  config['nodes'] << tier
443
433
  end
444
-
434
+
445
435
  instance_id = generate_id()
446
436
 
447
437
  instance_type_node = {
448
- "classes"=>"instance newinstance-#{instance_id} #{instance_type['code']}",
438
+ "classes"=>"instance newinstance-#{instance_id} #{instance_type['code']}",
449
439
  "data"=>{
450
440
  "controlName" => "instance.layout.id",
451
- "id"=>"newinstance-#{instance_id}",
441
+ "id"=>"newinstance-#{instance_id}",
452
442
  "nodeId"=>["newinstance-#{instance_id}"], # not sure what this is for..
453
- "index"=>nil,
443
+ "index"=>nil,
454
444
  "instance.layout.id"=>layout_id.to_s,
455
- "instance.name"=>instance_name,
456
- "instanceType"=>instance_type['code'],
457
- "isPlaced"=>true,
458
- "name"=> instance_name,
459
- "parent"=>tier['data']['id'],
460
- "type"=>"instance",
445
+ "instance.name"=>instance_name,
446
+ "instanceType"=>instance_type['code'],
447
+ "isPlaced"=>true,
448
+ "name"=> instance_name,
449
+ "parent"=>tier['data']['id'],
450
+ "type"=>"instance",
461
451
  "typeName"=>instance_type['name'],
462
452
  "servicePlan"=>plan_prompt['servicePlan'].to_s,
463
453
  # "servicePlanOptions.maxCpu": "",
464
454
  # "servicePlanOptions.maxCpuId": nil,
465
455
  # "servicePlanOptions.maxMemory": "",
466
456
  # "servicePlanOptions.maxMemoryId": nil,
467
-
457
+
468
458
  # "volumes.datastoreId": nil,
469
459
  # "volumes.name": "root",
470
460
  # "volumes.rootVolume": "true",
@@ -475,9 +465,9 @@ class Morpheus::Cli::AppTemplates
475
465
  "version"=>version_prompt['version'],
476
466
  "siteId"=>group_id.to_s,
477
467
  "zoneId"=>cloud_id.to_s
478
- },
479
- "grabbable"=>true, "group"=>"nodes", "locked"=>false,
480
- #"position"=>{"x"=>-79.83254449505226, "y"=>458.33806818181824},
468
+ },
469
+ "grabbable"=>true, "group"=>"nodes", "locked"=>false,
470
+ #"position"=>{"x"=>-79.83254449505226, "y"=>458.33806818181824},
481
471
  "removed"=>false, "selectable"=>true, "selected"=>false
482
472
  }
483
473
 
@@ -493,7 +483,7 @@ class Morpheus::Cli::AppTemplates
493
483
 
494
484
  # re-index nodes for this tier
495
485
  tier_instances = config['nodes'].select {|node| node['data']['parent'] == tier['data']['id'] }
496
- tier_instances.each_with_index do |node, idx|
486
+ tier_instances.each_with_index do |node, idx|
497
487
  node['data']['index'] = idx
498
488
  end
499
489
 
@@ -503,6 +493,10 @@ class Morpheus::Cli::AppTemplates
503
493
  request_payload['config'] = config
504
494
 
505
495
  begin
496
+ if options[:dry_run]
497
+ print_dry_run @app_templates_interface.dry.update(app_template['id'], request_payload)
498
+ return
499
+ end
506
500
  json_response = @app_templates_interface.update(app_template['id'], request_payload)
507
501
 
508
502
  if options[:json]
@@ -510,48 +504,46 @@ class Morpheus::Cli::AppTemplates
510
504
  print "\n"
511
505
  else
512
506
  print_green_success "Added instance type to app template #{app_template['name']}"
513
- details_options = [app_template['name']]
514
- details(details_options)
507
+ get([app_template['name']])
515
508
  end
516
509
 
517
510
  rescue RestClient::Exception => e
518
511
  print_rest_exception(e, options)
519
512
  exit 1
520
513
  end
521
-
514
+
522
515
  end
523
516
 
524
517
  def remove_instance(args)
525
- usage = "Usage: morpheus app-templates remove-instance [name] [instance-id]"
526
518
  options = {}
527
519
  optparse = OptionParser.new do|opts|
528
- opts.banner = usage
520
+ opts.banner = subcommand_usage("[name] [instance-id]")
529
521
  build_common_options(opts, options, [:auto_confirm, :json])
530
522
  end
531
- optparse.parse(args)
523
+ optparse.parse!(args)
532
524
 
533
525
  if args.count < 2
534
- puts "\n#{usage}\n\n"
526
+ puts optparse
535
527
  exit 1
536
528
  end
537
- name = args[0]
529
+ app_template_name = args[0]
538
530
  instance_id = args[1]
539
531
 
540
532
  connect(options)
541
-
533
+
542
534
  begin
543
535
 
544
- app_template = find_app_template_by_name(name)
536
+ app_template = find_app_template_by_name_or_id(app_template_name)
545
537
  exit 1 if app_template.nil?
546
538
 
547
- config = app_template['config']['tierView']
539
+ config = app_template['config']['tierView']
548
540
 
549
541
  config['nodes'] ||= []
550
542
 
551
- instance_node = config['nodes'].find { |node|
543
+ instance_node = config['nodes'].find { |node|
552
544
  node["data"] && node["data"]["type"] == "instance" && node["data"]["id"] == "newinstance-#{instance_id}"
553
545
  }
554
-
546
+
555
547
  if instance_node.nil?
556
548
  print_red_alert "Instance not found by id #{instance_id}"
557
549
  exit 1
@@ -561,7 +553,7 @@ class Morpheus::Cli::AppTemplates
561
553
  exit
562
554
  end
563
555
 
564
- tier = config['nodes'].find {|node|
556
+ tier = config['nodes'].find {|node|
565
557
  node["data"] && node["data"]["type"] == "tier" && node["data"]["id"] == instance_node['data']['parent']
566
558
  }
567
559
 
@@ -574,11 +566,11 @@ class Morpheus::Cli::AppTemplates
574
566
  config['nodes'] = config['nodes'].reject {|node|
575
567
  node["data"] && node["data"]["type"] == "instance" && node["data"]["id"] == "newinstance-#{instance_id}"
576
568
  }
577
-
569
+
578
570
 
579
571
  # re-index nodes for this tier
580
572
  tier_instances = config['nodes'].select {|node| node['data']['parent'] == tier['data']['id'] }
581
- tier_instances.each_with_index do |node, idx|
573
+ tier_instances.each_with_index do |node, idx|
582
574
  node['data']['index'] = idx
583
575
  end
584
576
 
@@ -588,14 +580,13 @@ class Morpheus::Cli::AppTemplates
588
580
  request_payload['config'] = config
589
581
  json_response = @app_templates_interface.update(app_template['id'], request_payload)
590
582
 
591
-
583
+
592
584
  if options[:json]
593
585
  print JSON.pretty_generate(json_response)
594
586
  print "\n"
595
587
  else
596
588
  print_green_success "Added instance type to app template #{app_template['name']}"
597
- details_options = [app_template['name']]
598
- details(details_options)
589
+ get([app_template['name']])
599
590
  end
600
591
 
601
592
  rescue RestClient::Exception => e
@@ -605,34 +596,33 @@ class Morpheus::Cli::AppTemplates
605
596
  end
606
597
 
607
598
  def connect_tiers(args)
608
- usage = "Usage: morpheus app-templates connect-tiers [name] [tier1] [tier2]"
609
599
  options = {}
610
600
  optparse = OptionParser.new do|opts|
611
- opts.banner = usage
612
- build_common_options(opts, options, [:json])
601
+ opts.banner = subcommand_usage("[name] [tier1] [tier2]")
602
+ build_common_options(opts, options, [:json, :dry_run])
613
603
  end
614
- optparse.parse(args)
604
+ optparse.parse!(args)
615
605
 
616
606
  if args.count < 3
617
- puts "\n#{usage}\n\n"
607
+ puts optparse
618
608
  exit 1
619
609
  end
620
- name = args[0]
610
+ app_template_name = args[0]
621
611
  tier1_name = args[1]
622
612
  tier2_name = args[2]
623
613
 
624
614
  connect(options)
625
-
615
+
626
616
  begin
627
617
 
628
- app_template = find_app_template_by_name(name)
618
+ app_template = find_app_template_by_name_or_id(app_template_name)
629
619
  exit 1 if app_template.nil?
630
620
 
631
- config = app_template['config']['tierView']
621
+ config = app_template['config']['tierView']
632
622
 
633
623
  config['nodes'] ||= []
634
624
 
635
- tier1 = config['nodes'].find {|node|
625
+ tier1 = config['nodes'].find {|node|
636
626
  node["data"] && node["data"]["type"] == "tier" && node["data"]["id"] == "newtier-#{tier1_name}"
637
627
  }
638
628
  if tier1.nil?
@@ -640,14 +630,14 @@ class Morpheus::Cli::AppTemplates
640
630
  exit 1
641
631
  end
642
632
 
643
- tier2 = config['nodes'].find {|node|
633
+ tier2 = config['nodes'].find {|node|
644
634
  node["data"] && node["data"]["type"] == "tier" && node["data"]["id"] == "newtier-#{tier2_name}"
645
635
  }
646
636
  if tier2.nil?
647
637
  print_red_alert "Tier not found by name #{tier2_name}!"
648
638
  exit 1
649
639
  end
650
-
640
+
651
641
  config['edges'] ||= []
652
642
 
653
643
  found_edge = config['edges'].find {|edge|
@@ -663,12 +653,12 @@ class Morpheus::Cli::AppTemplates
663
653
  # not sure how this id is being generated in the ui exactly
664
654
  new_edge_index = (1..999).find {|i|
665
655
  !config['edges'].find {|edge| edge['data']['id'] == "ele#{i}" }
666
- }
656
+ }
667
657
  new_edge = {
668
- "classes"=>"",
669
- "data"=>{"id"=>"ele#{new_edge_index}", "source"=>tier1['data']['id'], "target"=>tier2['data']['id']},
670
- "grabbable"=>true, "group"=>"edges", "locked"=>false,
671
- #"position"=>{},
658
+ "classes"=>"",
659
+ "data"=>{"id"=>"ele#{new_edge_index}", "source"=>tier1['data']['id'], "target"=>tier2['data']['id']},
660
+ "grabbable"=>true, "group"=>"edges", "locked"=>false,
661
+ #"position"=>{},
672
662
  "removed"=>false, "selectable"=>true, "selected"=>false
673
663
  }
674
664
 
@@ -679,16 +669,20 @@ class Morpheus::Cli::AppTemplates
679
669
  request_payload['siteId'] = app_template['config']['siteId']
680
670
  # request_payload['config'] = config['tierView']
681
671
  request_payload['config'] = config
672
+
673
+ if options[:dry_run]
674
+ print_dry_run @app_templates_interface.dry.update(app_template['id'], request_payload)
675
+ return
676
+ end
682
677
  json_response = @app_templates_interface.update(app_template['id'], request_payload)
683
678
 
684
-
679
+
685
680
  if options[:json]
686
681
  print JSON.pretty_generate(json_response)
687
682
  print "\n"
688
683
  else
689
684
  print_green_success "Connected tiers for app template #{app_template['name']}"
690
- details_options = [app_template['name']]
691
- details(details_options)
685
+ get([app_template['name']])
692
686
  end
693
687
 
694
688
  rescue RestClient::Exception => e
@@ -700,13 +694,17 @@ class Morpheus::Cli::AppTemplates
700
694
  def available_tiers(args)
701
695
  options = {}
702
696
  optparse = OptionParser.new do|opts|
703
- build_common_options(opts, options, [:json])
697
+ build_common_options(opts, options, [:json, :dry_run])
704
698
  end
705
- optparse.parse(args)
699
+ optparse.parse!(args)
706
700
  connect(options)
707
701
  params = {}
708
-
702
+
709
703
  begin
704
+ if options[:dry_run]
705
+ print_dry_run @app_templates_interface.dry.list_tiers(params)
706
+ return
707
+ end
710
708
  json_response = @app_templates_interface.list_tiers(params)
711
709
  tiers = json_response['tiers']
712
710
  if options[:json]
@@ -719,21 +717,21 @@ class Morpheus::Cli::AppTemplates
719
717
  else
720
718
  rows = tiers.collect do |tier|
721
719
  {
722
- id: tier['id'],
723
- name: tier['name'],
720
+ id: tier['id'],
721
+ name: tier['name'],
724
722
  }
725
723
  end
726
724
  print cyan
727
725
  tp rows, [:name]
728
726
  print reset
729
727
  end
730
- print reset,"\n\n"
728
+ print reset,"\n"
731
729
  end
732
730
  rescue RestClient::Exception => e
733
731
  print_rest_exception(e, options)
734
732
  exit 1
735
733
  end
736
-
734
+
737
735
  end
738
736
 
739
737
  def available_types(args)
@@ -741,11 +739,15 @@ class Morpheus::Cli::AppTemplates
741
739
  optparse = OptionParser.new do|opts|
742
740
  build_common_options(opts, options, [:json])
743
741
  end
744
- optparse.parse(args)
742
+ optparse.parse!(args)
745
743
  connect(options)
746
744
  params = {}
747
-
745
+
748
746
  begin
747
+ if options[:dry_run]
748
+ print_dry_run @app_templates_interface.dry.list_types(params)
749
+ return
750
+ end
749
751
  json_response = @app_templates_interface.list_types(params)
750
752
  instance_types = json_response['types']
751
753
  if options[:json]
@@ -758,39 +760,47 @@ class Morpheus::Cli::AppTemplates
758
760
  else
759
761
  rows = instance_types.collect do |instance_type|
760
762
  {
761
- id: instance_type['id'],
762
- code: instance_type['code'],
763
- name: instance_type['name'],
763
+ id: instance_type['id'],
764
+ code: instance_type['code'],
765
+ name: instance_type['name'],
764
766
  }
765
767
  end
766
768
  print cyan
767
769
  tp rows, [:code, :name]
768
770
  print reset
769
771
  end
770
- print reset,"\n\n"
772
+ print reset,"\n"
771
773
  end
772
774
  rescue RestClient::Exception => e
773
775
  print_rest_exception(e, options)
774
776
  exit 1
775
777
  end
776
-
778
+
777
779
  end
778
780
 
779
- private
780
-
781
+ private
782
+
781
783
 
782
- def add_app_template_option_types
783
- [
784
- {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
784
+ def add_app_template_option_types
785
+ [
786
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 1},
785
787
  {'fieldName' => 'group', 'fieldLabel' => 'Group', 'type' => 'text', 'required' => true, 'displayOrder' => 2},
786
- ]
787
- end
788
+ ]
789
+ end
788
790
 
789
- def update_app_template_option_types
790
- add_app_template_option_types
791
- end
791
+ def update_app_template_option_types
792
+ add_app_template_option_types
793
+ end
792
794
 
793
- def find_app_template_by_id(id)
795
+ def find_app_template_by_name_or_id(val)
796
+ if val.to_s =~ /\A\d{1,}\Z/
797
+ return find_app_template_by_id(val)
798
+ else
799
+ return find_app_template_by_name(val)
800
+ end
801
+ end
802
+
803
+ def find_app_template_by_id(id)
794
804
  begin
795
805
  json_response = @app_templates_interface.get(id.to_i)
796
806
  return json_response['appTemplate']
@@ -803,7 +813,7 @@ private
803
813
  end
804
814
  end
805
815
 
806
- def find_app_template_by_name(name)
816
+ def find_app_template_by_name(name)
807
817
  app_templates = @app_templates_interface.list({name: name.to_s})['appTemplates']
808
818
  if app_templates.empty?
809
819
  print_red_alert "App Template not found by name #{name}"
@@ -811,7 +821,7 @@ private
811
821
  elsif app_templates.size > 1
812
822
  print_red_alert "#{app_templates.size} app templates by name #{name}"
813
823
  print_app_templates_table(app_templates, {color: red})
814
- print reset,"\n\n"
824
+ print reset,"\n"
815
825
  return nil
816
826
  else
817
827
  return app_templates[0]
@@ -838,44 +848,26 @@ private
838
848
  end
839
849
  end
840
850
 
841
- def find_instance_type_by_code(code)
842
- results = @instance_types_interface.get({code: code})
843
- if results['instanceTypes'].empty?
844
- print_red_alert "Instance Type not found by code #{code}"
845
- return nil
846
- end
847
- return results['instanceTypes'][0]
848
- end
849
-
850
- def find_instance_type_by_name(name)
851
- results = @instance_types_interface.get({name: name})
852
- if results['instanceTypes'].empty?
853
- print_red_alert "Instance Type not found by name #{name}"
854
- return nil
855
- end
856
- return results['instanceTypes'][0]
857
- end
858
-
859
- def print_app_templates_table(app_templates, opts={})
851
+ def print_app_templates_table(app_templates, opts={})
860
852
  table_color = opts[:color] || cyan
861
853
  rows = app_templates.collect do |app_template|
862
- instance_type_names = (app_template['instanceTypes'] || []).collect {|it| it['name'] }.join(', ')
854
+ instance_type_names = (app_template['instanceTypes'] || []).collect {|it| it['name'] }.join(', ')
863
855
  {
864
- id: app_template['id'],
865
- name: app_template['name'],
866
- #code: app_template['code'],
856
+ id: app_template['id'],
857
+ name: app_template['name'],
858
+ #code: app_template['code'],
867
859
  instance_types: instance_type_names,
868
- account: app_template['account'] ? app_template['account']['name'] : nil,
869
- #dateCreated: format_local_dt(app_template['dateCreated'])
860
+ account: app_template['account'] ? app_template['account']['name'] : nil,
861
+ #dateCreated: format_local_dt(app_template['dateCreated'])
870
862
  }
871
863
  end
872
-
864
+
873
865
  print table_color
874
866
  tp rows, [
875
- :id,
876
- :name,
867
+ :id,
868
+ :name,
877
869
  {:instance_types => {:display_name => "Instance Types"} },
878
- :account,
870
+ :account,
879
871
  #{:dateCreated => {:display_name => "Date Created"} }
880
872
  ]
881
873
  print reset