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.
- checksums.yaml +4 -4
- data/bin/morpheus +27 -32
- data/lib/morpheus/api/accounts_interface.rb +36 -47
- data/lib/morpheus/api/api_client.rb +141 -110
- data/lib/morpheus/api/app_templates_interface.rb +56 -72
- data/lib/morpheus/api/apps_interface.rb +111 -132
- data/lib/morpheus/api/auth_interface.rb +30 -0
- data/lib/morpheus/api/clouds_interface.rb +71 -76
- data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
- data/lib/morpheus/api/dashboard_interface.rb +10 -17
- data/lib/morpheus/api/deploy_interface.rb +60 -72
- data/lib/morpheus/api/deployments_interface.rb +53 -71
- data/lib/morpheus/api/groups_interface.rb +55 -45
- data/lib/morpheus/api/instance_types_interface.rb +19 -23
- data/lib/morpheus/api/instances_interface.rb +179 -177
- data/lib/morpheus/api/key_pairs_interface.rb +11 -17
- data/lib/morpheus/api/license_interface.rb +18 -23
- data/lib/morpheus/api/load_balancers_interface.rb +54 -69
- data/lib/morpheus/api/logs_interface.rb +25 -29
- data/lib/morpheus/api/options_interface.rb +13 -17
- data/lib/morpheus/api/provision_types_interface.rb +19 -22
- data/lib/morpheus/api/roles_interface.rb +75 -94
- data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
- data/lib/morpheus/api/security_groups_interface.rb +39 -51
- data/lib/morpheus/api/servers_interface.rb +113 -115
- data/lib/morpheus/api/setup_interface.rb +31 -0
- data/lib/morpheus/api/task_sets_interface.rb +36 -38
- data/lib/morpheus/api/tasks_interface.rb +56 -69
- data/lib/morpheus/api/users_interface.rb +67 -76
- data/lib/morpheus/api/virtual_images_interface.rb +61 -61
- data/lib/morpheus/api/whoami_interface.rb +12 -15
- data/lib/morpheus/cli.rb +71 -60
- data/lib/morpheus/cli/accounts.rb +254 -315
- data/lib/morpheus/cli/alias_command.rb +219 -0
- data/lib/morpheus/cli/app_templates.rb +264 -272
- data/lib/morpheus/cli/apps.rb +608 -671
- data/lib/morpheus/cli/cli_command.rb +259 -21
- data/lib/morpheus/cli/cli_registry.rb +99 -14
- data/lib/morpheus/cli/clouds.rb +599 -372
- data/lib/morpheus/cli/config_file.rb +126 -0
- data/lib/morpheus/cli/credentials.rb +141 -117
- data/lib/morpheus/cli/dashboard_command.rb +48 -56
- data/lib/morpheus/cli/deployments.rb +254 -268
- data/lib/morpheus/cli/deploys.rb +150 -142
- data/lib/morpheus/cli/error_handler.rb +38 -0
- data/lib/morpheus/cli/groups.rb +551 -179
- data/lib/morpheus/cli/hosts.rb +862 -617
- data/lib/morpheus/cli/instance_types.rb +103 -95
- data/lib/morpheus/cli/instances.rb +1335 -1009
- data/lib/morpheus/cli/key_pairs.rb +82 -90
- data/lib/morpheus/cli/library.rb +498 -499
- data/lib/morpheus/cli/license.rb +83 -101
- data/lib/morpheus/cli/load_balancers.rb +314 -300
- data/lib/morpheus/cli/login.rb +66 -44
- data/lib/morpheus/cli/logout.rb +47 -46
- data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
- data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
- data/lib/morpheus/cli/option_parser.rb +35 -0
- data/lib/morpheus/cli/option_types.rb +232 -192
- data/lib/morpheus/cli/recent_activity_command.rb +61 -65
- data/lib/morpheus/cli/remote.rb +446 -199
- data/lib/morpheus/cli/roles.rb +884 -906
- data/lib/morpheus/cli/security_group_rules.rb +213 -203
- data/lib/morpheus/cli/security_groups.rb +237 -192
- data/lib/morpheus/cli/shell.rb +338 -231
- data/lib/morpheus/cli/tasks.rb +326 -308
- data/lib/morpheus/cli/users.rb +457 -462
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/version_command.rb +16 -18
- data/lib/morpheus/cli/virtual_images.rb +526 -345
- data/lib/morpheus/cli/whoami.rb +125 -111
- data/lib/morpheus/cli/workflows.rb +338 -185
- data/lib/morpheus/formatters.rb +8 -1
- data/lib/morpheus/logging.rb +1 -1
- data/lib/morpheus/rest_client.rb +17 -8
- metadata +9 -3
- data/lib/morpheus/api/custom_instance_types.rb +0 -55
data/lib/morpheus/cli/apps.rb
CHANGED
@@ -11,157 +11,113 @@ class Morpheus::Cli::Apps
|
|
11
11
|
include Morpheus::Cli::CliCommand
|
12
12
|
include Morpheus::Cli::ProvisioningHelper
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@instances_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instances
|
14
|
+
register_subcommands :list, :get, :add, :update, :remove, :add_instance, :remove_instance, :logs, :firewall_disable, :firewall_enable, :security_groups, :apply_security_groups
|
15
|
+
alias_subcommand :details, :get
|
16
|
+
set_default_subcommand :list
|
17
|
+
|
18
|
+
def initialize()
|
19
|
+
# @appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
20
|
+
end
|
21
|
+
|
22
|
+
def connect(opts)
|
23
|
+
@api_client = establish_remote_appliance_connection(opts)
|
24
|
+
@apps_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).apps
|
25
|
+
@instance_types_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instance_types
|
26
|
+
@instances_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).instances
|
28
27
|
@options_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).options
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
when 'add-instance'
|
48
|
-
add_instance(args[1..-1])
|
49
|
-
when 'remove-instance'
|
50
|
-
remove_instance(args[1..-1])
|
51
|
-
when 'stop'
|
52
|
-
stop(args[1..-1])
|
53
|
-
when 'start'
|
54
|
-
start(args[1..-1])
|
55
|
-
when 'restart'
|
56
|
-
restart(args[1..-1])
|
57
|
-
when 'logs'
|
58
|
-
logs(args[1..-1])
|
59
|
-
# when 'stats'
|
60
|
-
# stats(args[1..-1])
|
61
|
-
# when 'envs'
|
62
|
-
# envs(args[1..-1])
|
63
|
-
# when 'setenv'
|
64
|
-
# setenv(args[1..-1])
|
65
|
-
# when 'delenv'
|
66
|
-
# delenv(args[1..-1])
|
67
|
-
when 'firewall_disable'
|
68
|
-
firewall_disable(args[1..-1])
|
69
|
-
when 'firewall_enable'
|
70
|
-
firewall_enable(args[1..-1])
|
71
|
-
when 'security_groups'
|
72
|
-
security_groups(args[1..-1])
|
73
|
-
when 'apply_security_groups'
|
74
|
-
apply_security_groups(args[1..-1])
|
75
|
-
else
|
76
|
-
puts "\n#{usage}\n\n"
|
77
|
-
exit 127
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def list(args)
|
82
|
-
options = {}
|
83
|
-
optparse = OptionParser.new do|opts|
|
84
|
-
opts.banner = "Usage: morpheus apps list"
|
85
|
-
build_common_options(opts, options, [:list, :json])
|
86
|
-
end
|
87
|
-
optparse.parse(args)
|
88
|
-
connect(options)
|
89
|
-
begin
|
28
|
+
@groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).groups
|
29
|
+
@logs_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).logs
|
30
|
+
@active_group_id = Morpheus::Cli::Groups.active_groups[@appliance_name]
|
31
|
+
end
|
32
|
+
|
33
|
+
def handle(args)
|
34
|
+
handle_subcommand(args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def list(args)
|
38
|
+
options = {}
|
39
|
+
optparse = OptionParser.new do|opts|
|
40
|
+
opts.banner = subcommand_usage()
|
41
|
+
build_common_options(opts, options, [:list, :json, :dry_run])
|
42
|
+
end
|
43
|
+
optparse.parse!(args)
|
44
|
+
connect(options)
|
45
|
+
begin
|
90
46
|
params = {}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
47
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
48
|
+
params[k] = options[k] unless options[k].nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
if options[:dry_run]
|
52
|
+
print_dry_run @apps_interface.dry.get(params)
|
53
|
+
return
|
54
|
+
end
|
55
|
+
|
56
|
+
json_response = @apps_interface.get(params)
|
57
|
+
if options[:json]
|
58
|
+
print JSON.pretty_generate(json_response)
|
59
|
+
print "\n"
|
60
|
+
return
|
61
|
+
end
|
62
|
+
apps = json_response['apps']
|
63
|
+
print "\n" ,cyan, bold, "Morpheus Apps\n","==================", reset, "\n\n"
|
64
|
+
if apps.empty?
|
65
|
+
puts yellow,"No apps currently configured.",reset
|
66
|
+
else
|
67
|
+
print_apps_table(apps)
|
68
|
+
end
|
69
|
+
print reset,"\n"
|
70
|
+
rescue RestClient::Exception => e
|
71
|
+
print_rest_exception(e, options)
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def add(args)
|
118
77
|
options = {}
|
119
78
|
optparse = OptionParser.new do|opts|
|
120
|
-
opts.banner =
|
121
|
-
opts.on( '-g', '--group GROUP', "Group Name" ) do |val|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
options[:group_id] = val
|
126
|
-
end
|
127
|
-
build_common_options(opts, options, [:options, :json, :dry_run])
|
79
|
+
opts.banner = subcommand_usage("[name]")
|
80
|
+
opts.on( '-g', '--group GROUP', "Group Name or ID" ) do |val|
|
81
|
+
options[:group] = val
|
82
|
+
end
|
83
|
+
build_common_options(opts, options, [:options, :json, :dry_run, :quiet])
|
128
84
|
end
|
129
|
-
optparse.parse(args)
|
85
|
+
optparse.parse!(args)
|
130
86
|
connect(options)
|
131
87
|
begin
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
88
|
+
# use active group by default
|
89
|
+
options[:group] ||= @active_group_id
|
90
|
+
group = options[:group] ? find_group_by_name_or_id_for_provisioning(options[:group]) : nil
|
91
|
+
|
92
|
+
payload = {
|
93
|
+
'app' => {}
|
94
|
+
}
|
95
|
+
if args[0]
|
96
|
+
payload['app']['name'] = args[0]
|
97
|
+
else
|
98
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Enter a name for this app'}], options[:options])
|
99
|
+
payload['app']['name'] = v_prompt['name']
|
100
|
+
end
|
101
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false}], options[:options])
|
102
|
+
payload['app']['description'] = v_prompt['description']
|
103
|
+
if group
|
104
|
+
payload['app']['site'] = {id: group["id"]}
|
105
|
+
else
|
106
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'group', 'fieldLabel' => 'Group', 'type' => 'select', 'selectOptions' => get_available_groups(), 'required' => true}], options[:options])
|
107
|
+
payload['app']['site'] = {id: v_prompt["group"]}
|
108
|
+
end
|
109
|
+
|
110
|
+
# todo: allow adding instances with creation..
|
155
111
|
|
156
112
|
if options[:dry_run]
|
157
|
-
print_dry_run
|
113
|
+
print_dry_run @apps_interface.dry.create(payload)
|
158
114
|
return
|
159
115
|
end
|
160
116
|
json_response = @apps_interface.create(payload)
|
161
117
|
if options[:json]
|
162
118
|
print JSON.pretty_generate(json_response)
|
163
119
|
print "\n"
|
164
|
-
|
120
|
+
elsif !options[:quiet]
|
165
121
|
print_green_success "Added app #{payload['app']['name']}"
|
166
122
|
list([])
|
167
123
|
# details_options = [payload['app']['name']]
|
@@ -172,114 +128,120 @@ class Morpheus::Cli::Apps
|
|
172
128
|
print_rest_exception(e, options)
|
173
129
|
exit 1
|
174
130
|
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
131
|
+
end
|
132
|
+
|
133
|
+
def get(args)
|
134
|
+
options = {}
|
135
|
+
optparse = OptionParser.new do|opts|
|
136
|
+
opts.banner = subcommand_usage("[name]")
|
137
|
+
build_common_options(opts, options, [:json, :dry_run])
|
138
|
+
end
|
139
|
+
optparse.parse!(args)
|
140
|
+
if args.count < 1
|
141
|
+
puts optparse
|
142
|
+
exit 1
|
143
|
+
end
|
144
|
+
connect(options)
|
145
|
+
begin
|
146
|
+
app = find_app_by_name_or_id(args[0])
|
147
|
+
if options[:dry_run]
|
148
|
+
print_dry_run @apps_interface.dry.get(app['id'])
|
149
|
+
return
|
150
|
+
end
|
151
|
+
json_response = @apps_interface.get(app['id'])
|
152
|
+
app = json_response['app']
|
153
|
+
if options[:json]
|
154
|
+
print JSON.pretty_generate(json_response)
|
155
|
+
return
|
156
|
+
end
|
157
|
+
print "\n" ,cyan, bold, "App Details\n","==================", reset, "\n\n"
|
158
|
+
print cyan
|
159
|
+
puts "ID: #{app['id']}"
|
160
|
+
puts "Name: #{app['name']}"
|
161
|
+
puts "Description: #{app['description']}"
|
162
|
+
puts "Account: #{app['account'] ? app['account']['name'] : ''}"
|
163
|
+
# puts "Group: #{app['siteId']}"
|
164
|
+
stats = app['stats']
|
165
|
+
if ((stats['maxMemory'].to_i != 0) || (stats['maxStorage'].to_i != 0))
|
166
|
+
print "\n"
|
167
|
+
# print cyan, "Memory: \t#{Filesize.from("#{stats['usedMemory']} B").pretty} / #{Filesize.from("#{stats['maxMemory']} B").pretty}\n"
|
168
|
+
# print cyan, "Storage: \t#{Filesize.from("#{stats['usedStorage']} B").pretty} / #{Filesize.from("#{stats['maxStorage']} B").pretty}\n\n",reset
|
169
|
+
print_stats_usage(stats, {include: [:memory, :storage]})
|
170
|
+
else
|
171
|
+
#print yellow, "No stat data.", reset
|
172
|
+
end
|
173
|
+
|
174
|
+
app_tiers = app['appTiers']
|
175
|
+
if app_tiers.empty?
|
176
|
+
puts yellow, "This app is empty", reset
|
177
|
+
else
|
178
|
+
app_tiers.each do |app_tier|
|
179
|
+
print "\n" ,cyan, bold, "Tier: #{app_tier['tier']['name']}\n","==================", reset, "\n\n"
|
180
|
+
print cyan
|
181
|
+
instances = (app_tier['appInstances'] || []).collect {|it| it['instance']}
|
182
|
+
if instances.empty?
|
183
|
+
puts yellow, "This tier is empty", reset
|
184
|
+
else
|
185
|
+
instance_table = instances.collect do |instance|
|
186
|
+
status_string = instance['status'].to_s
|
187
|
+
if status_string == 'running'
|
188
|
+
status_string = "#{green}#{status_string.upcase}#{cyan}"
|
189
|
+
elsif status_string == 'stopped' or status_string == 'failed'
|
190
|
+
status_string = "#{red}#{status_string.upcase}#{cyan}"
|
191
|
+
elsif status_string == 'unknown'
|
192
|
+
status_string = "#{white}#{status_string.upcase}#{cyan}"
|
193
|
+
else
|
194
|
+
status_string = "#{yellow}#{status_string.upcase}#{cyan}"
|
195
|
+
end
|
196
|
+
connection_string = ''
|
197
|
+
if !instance['connectionInfo'].nil? && instance['connectionInfo'].empty? == false
|
198
|
+
connection_string = "#{instance['connectionInfo'][0]['ip']}:#{instance['connectionInfo'][0]['port']}"
|
199
|
+
end
|
200
|
+
{id: instance['id'], name: instance['name'], connection: connection_string, environment: instance['instanceContext'], nodes: instance['containers'].count, status: status_string, type: instance['instanceType']['name'], group: !instance['group'].nil? ? instance['group']['name'] : nil, cloud: !instance['cloud'].nil? ? instance['cloud']['name'] : nil}
|
201
|
+
end
|
202
|
+
tp instance_table, :id, :name, :cloud, :type, :environment, :nodes, :connection, :status
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
print cyan
|
207
|
+
|
208
|
+
print reset,"\n"
|
209
|
+
|
210
|
+
rescue RestClient::Exception => e
|
211
|
+
print_rest_exception(e, options)
|
212
|
+
exit 1
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def update(args)
|
252
217
|
options = {}
|
253
218
|
optparse = OptionParser.new do|opts|
|
254
|
-
opts.banner =
|
219
|
+
opts.banner = subcommand_usage("[name]")
|
255
220
|
build_common_options(opts, options, [:options, :json, :dry_run])
|
256
221
|
end
|
257
|
-
optparse.parse(args)
|
222
|
+
optparse.parse!(args)
|
258
223
|
if args.count < 1
|
259
|
-
|
260
|
-
|
261
|
-
|
224
|
+
puts optparse
|
225
|
+
exit 1
|
226
|
+
end
|
262
227
|
connect(options)
|
263
228
|
|
264
229
|
begin
|
265
|
-
|
266
|
-
app = find_app_by_name_or_id(args[0])
|
267
|
-
|
268
|
-
# group = find_group_from_options(options)
|
230
|
+
app = find_app_by_name_or_id(args[0])
|
269
231
|
|
270
|
-
|
271
|
-
|
272
|
-
|
232
|
+
payload = {
|
233
|
+
'app' => {id: app["id"]}
|
234
|
+
}
|
273
235
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
236
|
+
update_app_option_types = [
|
237
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'description' => 'Enter a name for this app'},
|
238
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false}
|
239
|
+
]
|
278
240
|
|
279
|
-
|
241
|
+
params = options[:options] || {}
|
280
242
|
|
281
243
|
if params.empty?
|
282
|
-
puts
|
244
|
+
puts opts
|
283
245
|
option_lines = update_app_option_types.collect {|it| "\t-O #{it['fieldName']}=\"value\"" }.join("\n")
|
284
246
|
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
285
247
|
exit 1
|
@@ -291,9 +253,10 @@ class Morpheus::Cli::Apps
|
|
291
253
|
payload['app'].merge!(params)
|
292
254
|
|
293
255
|
if options[:dry_run]
|
294
|
-
print_dry_run
|
256
|
+
print_dry_run @apps_interface.dry.update(app["id"], payload)
|
295
257
|
return
|
296
258
|
end
|
259
|
+
|
297
260
|
json_response = @apps_interface.update(app["id"], payload)
|
298
261
|
if options[:json]
|
299
262
|
print JSON.pretty_generate(json_response)
|
@@ -309,54 +272,52 @@ class Morpheus::Cli::Apps
|
|
309
272
|
print_rest_exception(e, options)
|
310
273
|
exit 1
|
311
274
|
end
|
312
|
-
|
275
|
+
end
|
313
276
|
|
314
277
|
|
315
|
-
|
316
|
-
usage = "Usage: morpheus apps add-instance [name] [instance] [tier]"
|
278
|
+
def add_instance(args)
|
317
279
|
options = {}
|
318
280
|
optparse = OptionParser.new do|opts|
|
319
|
-
opts.banner =
|
281
|
+
opts.banner = subcommand_usage("[name] [instance] [tier]")
|
320
282
|
build_common_options(opts, options, [:options, :json, :dry_run])
|
321
283
|
end
|
322
|
-
optparse.parse(args)
|
284
|
+
optparse.parse!(args)
|
323
285
|
if args.count < 1
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
286
|
+
puts optparse
|
287
|
+
exit 1
|
288
|
+
end
|
289
|
+
# optional [tier] and [instance] arguments
|
290
|
+
if args[1] && args[1] !~ /\A\-/
|
291
|
+
options[:instance_name] = args[1]
|
292
|
+
if args[2] && args[2] !~ /\A\-/
|
293
|
+
options[:tier_name] = args[2]
|
294
|
+
end
|
295
|
+
end
|
334
296
|
connect(options)
|
335
297
|
begin
|
336
|
-
|
337
|
-
app = find_app_by_name_or_id(args[0])
|
298
|
+
app = find_app_by_name_or_id(args[0])
|
338
299
|
|
339
|
-
|
300
|
+
# Only supports adding an existing instance right now..
|
340
301
|
|
341
|
-
|
302
|
+
payload = {}
|
342
303
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
304
|
+
if options[:instance_name]
|
305
|
+
instance = find_instance_by_name_or_id(options[:instance_name])
|
306
|
+
else
|
307
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instance', 'fieldLabel' => 'Instance', 'type' => 'text', 'required' => true, 'description' => 'Enter the instance name or id'}], options[:options])
|
308
|
+
instance = find_instance_by_name_or_id(v_prompt['instance'])
|
309
|
+
end
|
310
|
+
payload[:instanceId] = instance['id']
|
350
311
|
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
312
|
+
if options[:tier_name]
|
313
|
+
payload[:tierName] = options[:tier_name]
|
314
|
+
else
|
315
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'tier', 'fieldLabel' => 'Tier', 'type' => 'text', 'required' => true, 'description' => 'Enter the name of the tier'}], options[:options])
|
316
|
+
payload[:tierName] = v_prompt['tier']
|
317
|
+
end
|
357
318
|
|
358
319
|
if options[:dry_run]
|
359
|
-
print_dry_run
|
320
|
+
print_dry_run @apps_interface.dry.add_instance(app['id'], payload)
|
360
321
|
return
|
361
322
|
end
|
362
323
|
json_response = @apps_interface.add_instance(app['id'], payload)
|
@@ -374,67 +335,75 @@ class Morpheus::Cli::Apps
|
|
374
335
|
print_rest_exception(e, options)
|
375
336
|
exit 1
|
376
337
|
end
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
338
|
+
end
|
339
|
+
|
340
|
+
def remove(args)
|
341
|
+
options = {}
|
342
|
+
optparse = OptionParser.new do|opts|
|
343
|
+
opts.banner = subcommand_usage("[name]")
|
344
|
+
build_common_options(opts, options, [:json, :dry_run, :quiet])
|
345
|
+
end
|
346
|
+
optparse.parse!(args)
|
347
|
+
if args.count < 1
|
348
|
+
puts optparse
|
349
|
+
exit 1
|
350
|
+
end
|
351
|
+
connect(options)
|
352
|
+
|
353
|
+
begin
|
354
|
+
app = find_app_by_name_or_id(args[0])
|
355
|
+
unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to remove the app '#{app['name']}'?", options)
|
356
|
+
exit 1
|
357
|
+
end
|
358
|
+
if options[:dry_run]
|
359
|
+
print_dry_run @apps_interface.dry.destroy(app['id'])
|
360
|
+
return
|
361
|
+
end
|
362
|
+
json_response = @apps_interface.destroy(app['id'])
|
363
|
+
if options[:json]
|
364
|
+
print JSON.pretty_generate(json_response)
|
365
|
+
print "\n"
|
366
|
+
elsif !options[:quiet]
|
367
|
+
print_green_success "Removed app #{app['name']}"
|
368
|
+
list([])
|
369
|
+
end
|
370
|
+
rescue RestClient::Exception => e
|
371
|
+
print_rest_exception(e, options)
|
372
|
+
exit 1
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
def remove_instance(args)
|
407
377
|
options = {}
|
408
378
|
optparse = OptionParser.new do|opts|
|
409
|
-
opts.banner =
|
379
|
+
opts.banner = subcommand_usage("[name] [instance]")
|
410
380
|
build_common_options(opts, options, [:options, :json, :dry_run])
|
411
381
|
end
|
412
|
-
optparse.parse(args)
|
382
|
+
optparse.parse!(args)
|
413
383
|
if args.count < 1
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
384
|
+
puts optparse
|
385
|
+
exit 1
|
386
|
+
end
|
387
|
+
# optional [tier] and [instance] arguments
|
388
|
+
if args[1] && args[1] !~ /\A\-/
|
389
|
+
options[:instance_name] = args[1]
|
390
|
+
end
|
421
391
|
connect(options)
|
422
392
|
begin
|
423
|
-
|
424
|
-
app = find_app_by_name_or_id(args[0])
|
393
|
+
app = find_app_by_name_or_id(args[0])
|
425
394
|
|
426
|
-
|
395
|
+
payload = {}
|
427
396
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
397
|
+
if options[:instance_name]
|
398
|
+
instance = find_instance_by_name_or_id(options[:instance_name])
|
399
|
+
else
|
400
|
+
v_prompt = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'instance', 'fieldLabel' => 'Instance', 'type' => 'text', 'required' => true, 'description' => 'Enter the instance name or id'}], options[:options])
|
401
|
+
instance = find_instance_by_name_or_id(v_prompt['instance'])
|
402
|
+
end
|
403
|
+
payload[:instanceId] = instance['id']
|
435
404
|
|
436
405
|
if options[:dry_run]
|
437
|
-
print_dry_run
|
406
|
+
print_dry_run @apps_interface.dry.remove_instance(app['id'], payload)
|
438
407
|
return
|
439
408
|
end
|
440
409
|
|
@@ -454,377 +423,345 @@ class Morpheus::Cli::Apps
|
|
454
423
|
print_rest_exception(e, options)
|
455
424
|
exit 1
|
456
425
|
end
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
426
|
+
end
|
427
|
+
|
428
|
+
def logs(args)
|
429
|
+
options = {}
|
430
|
+
optparse = OptionParser.new do|opts|
|
431
|
+
opts.banner = subcommand_usage("[name]")
|
432
|
+
build_common_options(opts, options, [:list, :json, :dry_run])
|
433
|
+
end
|
434
|
+
optparse.parse!(args)
|
435
|
+
if args.count < 1
|
436
|
+
puts optparse
|
437
|
+
exit 1
|
438
|
+
end
|
439
|
+
connect(options)
|
440
|
+
begin
|
441
|
+
app = find_app_by_name_or_id(args[0])
|
442
|
+
containers = []
|
443
|
+
app['appTiers'].each do |app_tier|
|
444
|
+
app_tier['appInstances'].each do |app_instance|
|
445
|
+
containers += app_instance['instance']['containers']
|
446
|
+
end
|
447
|
+
end
|
448
|
+
params = {}
|
449
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
450
|
+
params[k] = options[k] unless options[k].nil?
|
451
|
+
end
|
452
|
+
if options[:dry_run]
|
453
|
+
print_dry_run @logs_interface.dry.container_logs(containers, params)
|
454
|
+
return
|
455
|
+
end
|
456
|
+
logs = @logs_interface.container_logs(containers, params)
|
457
|
+
if options[:json]
|
458
|
+
print JSON.pretty_generate(logs)
|
459
|
+
print "\n"
|
460
|
+
else
|
461
|
+
logs['data'].reverse.each do |log_entry|
|
462
|
+
log_level = ''
|
463
|
+
case log_entry['level']
|
464
|
+
when 'INFO'
|
465
|
+
log_level = "#{blue}#{bold}INFO#{reset}"
|
466
|
+
when 'DEBUG'
|
467
|
+
log_level = "#{white}#{bold}DEBUG#{reset}"
|
468
|
+
when 'WARN'
|
469
|
+
log_level = "#{yellow}#{bold}WARN#{reset}"
|
470
|
+
when 'ERROR'
|
471
|
+
log_level = "#{red}#{bold}ERROR#{reset}"
|
472
|
+
when 'FATAL'
|
473
|
+
log_level = "#{red}#{bold}FATAL#{reset}"
|
474
|
+
end
|
475
|
+
puts "[#{log_entry['ts']}] #{log_level} - #{log_entry['message']}"
|
476
|
+
end
|
477
|
+
print reset,"\n"
|
478
|
+
end
|
479
|
+
rescue RestClient::Exception => e
|
480
|
+
print_rest_exception(e, options)
|
481
|
+
exit 1
|
482
|
+
end
|
483
|
+
end
|
511
484
|
|
512
485
|
=begin
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
486
|
+
def stop(args)
|
487
|
+
options = {}
|
488
|
+
optparse = OptionParser.new do|opts|
|
489
|
+
opts.banner = subcommand_usage("[name]")
|
490
|
+
build_common_options(opts, options, [:json, :dry_run])
|
491
|
+
end
|
492
|
+
optparse.parse!(args)
|
493
|
+
if args.count < 1
|
494
|
+
puts optparse
|
495
|
+
exit 1
|
496
|
+
end
|
497
|
+
connect(options)
|
498
|
+
begin
|
499
|
+
app = find_app_by_name_or_id(args[0])
|
500
|
+
if options[:dry_run]
|
501
|
+
print_dry_run @apps_interface.dry.stop(app['id'])
|
502
|
+
return
|
503
|
+
end
|
504
|
+
@apps_interface.stop(app['id'])
|
505
|
+
list([])
|
506
|
+
rescue RestClient::Exception => e
|
507
|
+
print_rest_exception(e, options)
|
508
|
+
exit 1
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
def start(args)
|
513
|
+
options = {}
|
514
|
+
optparse = OptionParser.new do|opts|
|
515
|
+
opts.banner = subcommand_usage("[name]")
|
516
|
+
build_common_options(opts, options, [:json, :dry_run])
|
517
|
+
end
|
518
|
+
optparse.parse!(args)
|
519
|
+
if args.count < 1
|
520
|
+
puts optparse
|
521
|
+
exit 1
|
522
|
+
end
|
523
|
+
connect(options)
|
524
|
+
begin
|
525
|
+
app = find_app_by_name_or_id(args[0])
|
526
|
+
if options[:dry_run]
|
527
|
+
print_dry_run @apps_interface.dry.start(app['id'])
|
528
|
+
return
|
529
|
+
end
|
530
|
+
@apps_interface.start(app['id'])
|
531
|
+
list([])
|
532
|
+
rescue RestClient::Exception => e
|
533
|
+
print_rest_exception(e, options)
|
534
|
+
exit 1
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
def restart(args)
|
539
|
+
options = {}
|
540
|
+
optparse = OptionParser.new do|opts|
|
541
|
+
opts.banner = subcommand_usage("[name]")
|
542
|
+
build_common_options(opts, options, [:json, :dry_run])
|
543
|
+
end
|
544
|
+
optparse.parse!(args)
|
545
|
+
if args.count < 1
|
546
|
+
puts optparse
|
547
|
+
exit 1
|
548
|
+
end
|
549
|
+
connect(options)
|
550
|
+
begin
|
551
|
+
app = find_app_by_name_or_id(args[0])
|
552
|
+
if options[:dry_run]
|
553
|
+
print_dry_run @apps_interface.dry.restart(app['id'])
|
554
|
+
return
|
555
|
+
end
|
556
|
+
@apps_interface.restart(app['id'])
|
557
|
+
list([])
|
558
|
+
rescue RestClient::Exception => e
|
559
|
+
print_rest_exception(e, options)
|
560
|
+
exit 1
|
561
|
+
end
|
562
|
+
end
|
590
563
|
=end
|
591
564
|
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
if val.to_s =~ /\A\d{1,}\Z/
|
759
|
-
return find_app_by_id(val)
|
760
|
-
else
|
761
|
-
return find_app_by_name(val)
|
762
|
-
end
|
763
|
-
end
|
764
|
-
|
765
|
-
def find_instance_by_id(id)
|
766
|
-
instance_results = @instances_interface.get(id.to_i)
|
767
|
-
if instance_results['instance'].empty?
|
768
|
-
print_red_alert "Instance not found by id #{id}"
|
769
|
-
exit 1
|
770
|
-
end
|
771
|
-
return instance_results['instance']
|
772
|
-
end
|
773
|
-
|
774
|
-
def find_instance_by_name(name)
|
775
|
-
instance_results = @instances_interface.get({name: name})
|
776
|
-
if instance_results['instances'].empty?
|
777
|
-
print_red_alert "Instance not found by name #{name}"
|
778
|
-
exit 1
|
779
|
-
end
|
780
|
-
return instance_results['instances'][0]
|
781
|
-
end
|
782
|
-
|
783
|
-
def find_instance_by_name_or_id(val)
|
784
|
-
if val.to_s =~ /\A\d{1,}\Z/
|
785
|
-
return find_instance_by_id(val)
|
786
|
-
else
|
787
|
-
return find_instance_by_name(val)
|
788
|
-
end
|
789
|
-
end
|
790
|
-
|
791
|
-
def print_apps_table(apps, opts={})
|
565
|
+
def firewall_disable(args)
|
566
|
+
options = {}
|
567
|
+
optparse = OptionParser.new do|opts|
|
568
|
+
opts.banner = subcommand_usage("[name]")
|
569
|
+
build_common_options(opts, options, [:json, :dry_run])
|
570
|
+
end
|
571
|
+
optparse.parse!(args)
|
572
|
+
if args.count < 1
|
573
|
+
puts optparse
|
574
|
+
exit 1
|
575
|
+
end
|
576
|
+
connect(options)
|
577
|
+
|
578
|
+
begin
|
579
|
+
app = find_app_by_name_or_id(args[0])
|
580
|
+
if options[:dry_run]
|
581
|
+
print_dry_run @apps_interface.dry.firewall_disable(app['id'])
|
582
|
+
return
|
583
|
+
end
|
584
|
+
@apps_interface.firewall_disable(app['id'])
|
585
|
+
security_groups([args[0]])
|
586
|
+
rescue RestClient::Exception => e
|
587
|
+
print_rest_exception(e, options)
|
588
|
+
exit 1
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
def firewall_enable(args)
|
593
|
+
options = {}
|
594
|
+
optparse = OptionParser.new do|opts|
|
595
|
+
opts.banner = subcommand_usage("[name]")
|
596
|
+
build_common_options(opts, options, [:json, :dry_run])
|
597
|
+
end
|
598
|
+
optparse.parse!(args)
|
599
|
+
if args.count < 1
|
600
|
+
puts optparse
|
601
|
+
exit 1
|
602
|
+
end
|
603
|
+
connect(options)
|
604
|
+
|
605
|
+
begin
|
606
|
+
app = find_app_by_name_or_id(args[0])
|
607
|
+
if options[:dry_run]
|
608
|
+
print_dry_run @apps_interface.dry.firewall_enable(app['id'])
|
609
|
+
return
|
610
|
+
end
|
611
|
+
@apps_interface.firewall_enable(app['id'])
|
612
|
+
security_groups([args[0]])
|
613
|
+
rescue RestClient::Exception => e
|
614
|
+
print_rest_exception(e, options)
|
615
|
+
exit 1
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
def security_groups(args)
|
620
|
+
options = {}
|
621
|
+
optparse = OptionParser.new do|opts|
|
622
|
+
opts.banner = subcommand_usage("[name]")
|
623
|
+
build_common_options(opts, options, [:json, :dry_run])
|
624
|
+
end
|
625
|
+
optparse.parse!(args)
|
626
|
+
if args.count < 1
|
627
|
+
puts optparse
|
628
|
+
exit 1
|
629
|
+
end
|
630
|
+
connect(options)
|
631
|
+
|
632
|
+
begin
|
633
|
+
app = find_app_by_name_or_id(args[0])
|
634
|
+
if options[:dry_run]
|
635
|
+
print_dry_run @apps_interface.dry.security_groups(app['id'])
|
636
|
+
return
|
637
|
+
end
|
638
|
+
json_response = @apps_interface.security_groups(app['id'])
|
639
|
+
securityGroups = json_response['securityGroups']
|
640
|
+
print "\n" ,cyan, bold, "Morpheus Security Groups for App: #{app['name']}\n","==================", reset, "\n\n"
|
641
|
+
print cyan, "Firewall Enabled=#{json_response['firewallEnabled']}\n\n"
|
642
|
+
if securityGroups.empty?
|
643
|
+
puts yellow,"No security groups currently applied.",reset
|
644
|
+
else
|
645
|
+
securityGroups.each do |securityGroup|
|
646
|
+
print cyan, "= #{securityGroup['id']} (#{securityGroup['name']}) - (#{securityGroup['description']})\n"
|
647
|
+
end
|
648
|
+
end
|
649
|
+
print reset,"\n"
|
650
|
+
|
651
|
+
rescue RestClient::Exception => e
|
652
|
+
print_rest_exception(e, options)
|
653
|
+
exit 1
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
def apply_security_groups(args)
|
658
|
+
options = {}
|
659
|
+
clear_or_secgroups_specified = false
|
660
|
+
optparse = OptionParser.new do|opts|
|
661
|
+
opts.banner = subcommand_usage("[name] [--clear] [-s]")
|
662
|
+
opts.on( '-c', '--clear', "Clear all security groups" ) do
|
663
|
+
options[:securityGroupIds] = []
|
664
|
+
clear_or_secgroups_specified = true
|
665
|
+
end
|
666
|
+
opts.on( '-s', '--secgroups SECGROUPS', "Apply the specified comma separated security group ids" ) do |secgroups|
|
667
|
+
options[:securityGroupIds] = secgroups.split(",")
|
668
|
+
clear_or_secgroups_specified = true
|
669
|
+
end
|
670
|
+
opts.on( '-h', '--help', "Prints this help" ) do
|
671
|
+
puts opts
|
672
|
+
exit
|
673
|
+
end
|
674
|
+
build_common_options(opts, options, [:json, :dry_run])
|
675
|
+
end
|
676
|
+
optparse.parse!(args)
|
677
|
+
if args.count < 1
|
678
|
+
puts optparse
|
679
|
+
exit 1
|
680
|
+
end
|
681
|
+
if !clear_or_secgroups_specified
|
682
|
+
puts optparse
|
683
|
+
exit 1
|
684
|
+
end
|
685
|
+
|
686
|
+
connect(options)
|
687
|
+
|
688
|
+
begin
|
689
|
+
app = find_app_by_name_or_id(args[0])
|
690
|
+
if options[:dry_run]
|
691
|
+
print_dry_run @apps_interface.dry.apply_security_groups(app['id'], options)
|
692
|
+
return
|
693
|
+
end
|
694
|
+
@apps_interface.apply_security_groups(app['id'], options)
|
695
|
+
security_groups([args[0]])
|
696
|
+
rescue RestClient::Exception => e
|
697
|
+
print_rest_exception(e, options)
|
698
|
+
exit 1
|
699
|
+
end
|
700
|
+
end
|
701
|
+
|
702
|
+
private
|
703
|
+
|
704
|
+
def find_app_by_id(id)
|
705
|
+
app_results = @apps_interface.get(id.to_i)
|
706
|
+
if app_results['app'].empty?
|
707
|
+
print_red_alert "App not found by id #{id}"
|
708
|
+
exit 1
|
709
|
+
end
|
710
|
+
return app_results['app']
|
711
|
+
end
|
712
|
+
|
713
|
+
def find_app_by_name(name)
|
714
|
+
app_results = @apps_interface.get({name: name})
|
715
|
+
if app_results['apps'].empty?
|
716
|
+
print_red_alert "App not found by name #{name}"
|
717
|
+
exit 1
|
718
|
+
end
|
719
|
+
return app_results['apps'][0]
|
720
|
+
end
|
721
|
+
|
722
|
+
def find_app_by_name_or_id(val)
|
723
|
+
if val.to_s =~ /\A\d{1,}\Z/
|
724
|
+
return find_app_by_id(val)
|
725
|
+
else
|
726
|
+
return find_app_by_name(val)
|
727
|
+
end
|
728
|
+
end
|
729
|
+
|
730
|
+
def print_apps_table(apps, opts={})
|
792
731
|
table_color = opts[:color] || cyan
|
793
732
|
rows = apps.collect do |app|
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
733
|
+
instances_str = (app['instanceCount'].to_i == 1) ? "1 Instance" : "#{app['instanceCount']} Instances"
|
734
|
+
containers_str = (app['containerCount'].to_i == 1) ? "1 Container" : "#{app['containerCount']} Containers"
|
735
|
+
status_string = app['status']
|
736
|
+
if app['instanceCount'].to_i == 0
|
737
|
+
# show this instead of WARNING
|
738
|
+
status_string = "#{white}EMPTY#{table_color}"
|
739
|
+
elsif status_string == 'running'
|
740
|
+
status_string = "#{green}#{status_string.upcase}#{table_color}"
|
741
|
+
elsif status_string == 'stopped' or status_string == 'failed'
|
742
|
+
status_string = "#{red}#{status_string.upcase}#{table_color}"
|
743
|
+
elsif status_string == 'unknown'
|
744
|
+
status_string = "#{white}#{status_string.upcase}#{table_color}"
|
745
|
+
else
|
746
|
+
status_string = "#{yellow}#{status_string.upcase}#{table_color}"
|
747
|
+
end
|
810
748
|
{
|
811
|
-
id: app['id'],
|
812
|
-
name: app['name'],
|
749
|
+
id: app['id'],
|
750
|
+
name: app['name'],
|
813
751
|
instances: instances_str,
|
814
752
|
containers: containers_str,
|
815
|
-
account: app['account'] ? app['account']['name'] : nil,
|
816
|
-
status: status_string,
|
817
|
-
#dateCreated: format_local_dt(app['dateCreated'])
|
753
|
+
account: app['account'] ? app['account']['name'] : nil,
|
754
|
+
status: status_string,
|
755
|
+
#dateCreated: format_local_dt(app['dateCreated'])
|
818
756
|
}
|
819
757
|
end
|
820
|
-
|
821
758
|
print table_color
|
822
759
|
tp rows, [
|
823
|
-
:id,
|
824
|
-
:name,
|
760
|
+
:id,
|
761
|
+
:name,
|
825
762
|
:instances,
|
826
763
|
:containers,
|
827
|
-
#:account,
|
764
|
+
#:account,
|
828
765
|
:status,
|
829
766
|
#{:dateCreated => {:display_name => "Date Created"} }
|
830
767
|
]
|