cfoundry 0.3.27 → 0.3.28

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.
@@ -111,6 +111,13 @@ module CFoundry::V1
111
111
  end
112
112
  end
113
113
 
114
+ # Retrieve crashed instances
115
+ def crashes
116
+ @client.base.crashes(@name).collect do |i|
117
+ CrashedInstance.new(@name, i[:instance], @client, i)
118
+ end
119
+ end
120
+
114
121
  # Retrieve application statistics, e.g. CPU load and memory usage.
115
122
  def stats
116
123
  @client.base.stats(@name)
@@ -551,5 +558,56 @@ module CFoundry::V1
551
558
  @client.base.files(@app, @index, *path)
552
559
  end
553
560
  end
561
+
562
+ # Class represnting a crashed instance of an application.
563
+ class CrashedInstance
564
+ # The application this instance belonged to.
565
+ attr_reader :app
566
+
567
+ # Crashed instance (pseudo-)unique identifier.
568
+ attr_reader :id
569
+
570
+ # Create a CrashedInstance object.
571
+ #
572
+ # You'll usually call App#crashes instead
573
+ def initialize(appname, id, client, manifest = {})
574
+ @app = appname
575
+ @id = id
576
+ @client = client
577
+ @manifest = manifest
578
+ end
579
+
580
+ # Show string representing the application instance.
581
+ def inspect
582
+ "#<App::CrashedInstance '#@app' \##@id>"
583
+ end
584
+
585
+ # Instance crashed time.
586
+ def since
587
+ @manifest[:since] && Time.at(@manifest[:since])
588
+ end
589
+
590
+ # Retrieve file listing under path for this instance.
591
+ #
592
+ # [path]
593
+ # A sequence of strings representing path segments.
594
+ #
595
+ # For example, <code>files("foo", "bar")</code> for +foo/bar+.
596
+ def files(*path)
597
+ @client.base.files(@app, @id, *path).split("\n").collect do |entry|
598
+ path + [entry.split(/\s+/, 2)[0]]
599
+ end
600
+ end
601
+
602
+ # Retrieve file contents for this instance.
603
+ #
604
+ # [path]
605
+ # A sequence of strings representing path segments.
606
+ #
607
+ # For example, <code>file("foo", "bar")</code> for +foo/bar+.
608
+ def file(*path)
609
+ @client.base.files(@app, @id, *path)
610
+ end
611
+ end
554
612
  end
555
613
  end
@@ -95,6 +95,10 @@ module CFoundry::V1
95
95
  get("apps", name, "instances", nil => :json)[:instances]
96
96
  end
97
97
 
98
+ def crashes(name)
99
+ get("apps", name, "crashes", nil => :json)[:crashes]
100
+ end
101
+
98
102
  def files(name, instance, *path)
99
103
  get("apps", name, "instances", instance, "files", *path)
100
104
  end
@@ -195,6 +195,73 @@ module CFoundry::V2
195
195
  FileUtils.rm_rf(tmpdir) if tmpdir
196
196
  end
197
197
 
198
+ def files(*path)
199
+ Instance.new(self, 0, @client).files(*path)
200
+ end
201
+
202
+ def file(*path)
203
+ Instance.new(self, 0, @client).file(*path)
204
+ end
205
+
206
+ class Instance
207
+ attr_reader :app, :id
208
+
209
+ def initialize(app, id, client, manifest = {})
210
+ @app = app
211
+ @id = id
212
+ @client = client
213
+ @manifest = manifest
214
+ end
215
+
216
+ def inspect
217
+ "#<App::Instance '#{@app.name}' \##@id>"
218
+ end
219
+
220
+ def state
221
+ @manifest[:state]
222
+ end
223
+ alias_method :status, :state
224
+
225
+ def since
226
+ Time.at(@manifest[:since])
227
+ end
228
+
229
+ def debugger
230
+ return unless @manifest[:debug_ip] and @manifest[:debug_port]
231
+
232
+ { :ip => @manifest[:debug_ip],
233
+ :port => @manifest[:debug_port]
234
+ }
235
+ end
236
+
237
+ def console
238
+ return unless @manifest[:console_ip] and @manifest[:console_port]
239
+
240
+ { :ip => @manifest[:console_ip],
241
+ :port => @manifest[:console_port]
242
+ }
243
+ end
244
+
245
+ def healthy?
246
+ case state
247
+ when "STARTING", "RUNNING"
248
+ true
249
+ when "DOWN", "FLAPPING"
250
+ false
251
+ end
252
+ end
253
+
254
+ def files(*path)
255
+ @client.base.files(@app.guid, @id, *path).split("\n").collect do |entry|
256
+ path + [entry.split(/\s+/, 2)[0]]
257
+ end
258
+ end
259
+
260
+ def file(*path)
261
+ @client.base.files(@app.guid, @id, *path)
262
+ end
263
+ end
264
+
198
265
  private
199
266
 
200
267
  # Minimum size for an application payload to bother checking resources.
@@ -100,6 +100,11 @@ module CFoundry::V2
100
100
  retry
101
101
  end
102
102
 
103
+ def files(guid, instance, *path)
104
+ get("v2", "apps", guid, "instances", instance, "files", *path)
105
+ end
106
+ alias :file :files
107
+
103
108
 
104
109
  def params_from(args)
105
110
  depth, query = args
@@ -1,4 +1,4 @@
1
1
  module CFoundry # :nodoc:
2
2
  # CFoundry library version number.
3
- VERSION = "0.3.27"
3
+ VERSION = "0.3.28"
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 43
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 27
10
- version: 0.3.27
9
+ - 28
10
+ version: 0.3.28
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Suraci
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-31 00:00:00 Z
18
+ date: 2012-09-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rest-client