Class: CF::App
Direct Known Subclasses
CLI
Defined Under Namespace
Classes: Env
Constant Summary
collapse
- MEM_CHOICES =
["64M", "128M", "256M", "512M"]
Constants included
from Dots
Dots::COLOR_CODES, Dots::DOT_COUNT, Dots::DOT_TICK
Instance Method Summary
collapse
Methods inherited from Command
add_callback, after, around, before, callbacks, callbacks_for, ensuring, flag, #invoke_task
#ask, #force?, #handler, #input_state, #list_choices, #prompt
Methods included from Dots
b, c, #color?, #dots!, #stop_dots!, #with_progress
Instance Method Details
#apps ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/cf/cli/app.rb', line 9
def apps
apps =
with_progress("Getting applications") do
client.apps
end
if apps.empty? and !simple_output?
puts ""
puts "No applications."
return
end
apps.each.with_index do |a, num|
display_app(a)
end
end
|
#delete(name) ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/cf/cli/app.rb', line 108
def delete(name)
return unless input(:really, name)
with_progress("Deleting #{c(name, :blue)}") do
client.app(name).delete!
end
ensure
forget(:really)
end
|
#file(name, path = "/") ⇒ Object
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/cf/cli/app.rb', line 150
def file(name, path = "/")
file =
with_progress("Getting file contents") do
client.app(name).file(*path.split("/"))
end
puts "" unless simple_output?
print file
end
|
#files(name, path = "/") ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/cf/cli/app.rb', line 136
def files(name, path = "/")
files =
with_progress("Getting file listing") do
client.app(name).files(*path.split("/"))
end
puts "" unless simple_output?
files.each do |file|
puts file
end
end
|
#health(*names) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/cf/cli/app.rb', line 27
def health(*names)
apps =
with_progress("Getting application health") do
names.collect do |n|
[n, app_status(client.app(n))]
end
end
apps.each do |name, status|
unless simple_output?
puts ""
print "#{c(name, :blue)}: "
end
puts status
end
end
|
#instances(name) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/cf/cli/app.rb', line 119
def instances(name)
instances =
with_progress("Getting instances for #{c(name, :blue)}") do
client.app(name).instances
end
instances.each do |i|
if simple_output?
puts i.index
else
puts ""
display_instance(i)
end
end
end
|
#logs(name) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
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
|
# File 'lib/cf/cli/app.rb', line 163
def logs(name)
app = client.app(name)
unless app.exists?
err "Unknown application."
return
end
instances =
if input(:instance) == "all"
app.instances
else
app.instances.select { |i| i.index == input(:instance) }
end
if instances.empty?
if input(:instance) == "all"
err "No instances found."
else
err "Instance #{name} \##{input(:instance)} not found."
end
return
end
instances.each do |i|
logs =
with_progress(
"Getting logs for " +
c(name, :blue) + " " +
c("\##{i.index}", :yellow)) do
i.files("logs")
end
puts "" unless simple_output?
logs.each do |log|
body =
with_progress("Reading " + b(log.join("/"))) do
i.file(*log)
end
puts body
puts "" unless body.empty?
end
end
end
|
#map(name, url) ⇒ Object
343
344
345
346
347
348
349
350
351
|
# File 'lib/cf/cli/app.rb', line 343
def map(name, url)
simple = url.sub(/^https?:\/\/(.*)\/?/i, '\1')
with_progress("Updating #{c(name, :blue)}") do
app = client.app(name)
app.urls << simple
app.update!
end
end
|
#push(name = nil) ⇒ Object
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/cf/cli/app.rb', line 236
def push(name = nil)
path = File.expand_path(input(:path))
name ||= input(:name)
detector = Detector.new(client, path)
frameworks = detector.all_frameworks
detected, default = detector.frameworks
app = client.app(name)
if app.exists?
upload_app(app, path)
restart(app.name) if input(:restart)
return
end
app.total_instances = input(:instances)
domain = client.target.sub(/^https?:\/\/api\.(.+)\/?/, '\1')
app.urls = [input(:url, name, domain)]
framework = input(:framework, ["other"] + detected.keys, default)
if framework == "other"
forget(:framework)
framework = input(:framework, frameworks.keys)
end
framework_runtimes =
frameworks[framework]["runtimes"].collect do |k|
"#{k["name"]} (#{k["description"]})"
end
runtime = input(:runtime, framework_runtimes).split.first
app.framework = framework
app.runtime = runtime
app.memory = megabytes(input(:memory))
with_progress("Creating #{c(name, :blue)}") do
app.create!
end
begin
upload_app(app, path)
rescue
err "Upload failed. Try again with 'vmc push'."
raise
end
start(name) if input(:start)
end
|
#restart(name) ⇒ Object
99
100
101
102
|
# File 'lib/cf/cli/app.rb', line 99
def restart(name)
stop(name)
start(name)
end
|
#scale(name) ⇒ Object
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
# File 'lib/cf/cli/app.rb', line 324
def scale(name)
app = client.app(name)
instances = passed_value(:instances)
memory = passed_value(:memory)
unless instances || memory
instances = input(:instances, app.total_instances)
memory = input(:memory, app.memory)
end
with_progress("Scaling #{c(name, :blue)}") do
app.total_instances = instances.to_i if instances
app.memory = megabytes(memory) if memory
app.update!
end
end
|
#start(name) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/cf/cli/app.rb', line 68
def start(name)
app = client.app(name)
unless app.exists?
err "Unknown application."
return
end
switch_mode(app, input(:debug_mode))
with_progress("Starting #{c(name, :blue)}") do |s|
if app.running?
s.skip do
err "Already started."
return
end
end
app.start!
end
check_application(app)
if app.debug_mode && !simple_output?
puts ""
instances(name)
end
end
|
#stats(name) ⇒ Object
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
# File 'lib/cf/cli/app.rb', line 297
def stats(name)
stats =
with_progress("Getting stats") do
client.app(name).stats
end
stats.sort_by { |k, _| k }.each do |idx, info|
stats = info["stats"]
usage = stats["usage"]
puts ""
puts "instance #{c("#" + idx, :blue)}:"
print " cpu: #{percentage(usage["cpu"])} of"
puts " #{b(stats["cores"])} cores"
puts " memory: #{usage(usage["mem"] * 1024, stats["mem_quota"])}"
puts " disk: #{usage(usage["disk"], stats["disk_quota"])}"
end
end
|
#stop(name) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/cf/cli/app.rb', line 46
def stop(name)
with_progress("Stopping #{c(name, :blue)}") do |s|
app = client.app(name)
unless app.exists?
s.fail do
err "Unknown application."
end
end
if app.stopped?
s.skip do
err "Application is not running."
end
end
app.stop!
end
end
|
#unmap(name, url) ⇒ Object
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
# File 'lib/cf/cli/app.rb', line 354
def unmap(name, url)
simple = url.sub(/^https?:\/\/(.*)\/?/i, '\1')
with_progress("Updating #{c(name, :blue)}") do |s|
app = client.app(name)
unless app.urls.delete(simple)
s.fail do
err "URL #{url} is not mapped to this application."
return
end
end
app.update!
end
end
|
#update(*args) ⇒ Object
292
293
294
|
# File 'lib/cf/cli/app.rb', line 292
def update(*args)
err "The 'update' command is no longer used; use 'push' instead."
end
|