Class: CFoundry::V1::App::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/cfoundry/v1/app.rb

Overview

Class represnting a running instance of an application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, id, client, manifest = {}) ⇒ Instance

Create an Instance object.

You’ll usually call App#instances instead



298
299
300
301
302
303
# File 'lib/cfoundry/v1/app.rb', line 298

def initialize(app, id, client, manifest = {})
  @app = app
  @id = id
  @client = client
  @manifest = manifest
end

Instance Attribute Details

#appObject (readonly)

The application this instance belongs to.



290
291
292
# File 'lib/cfoundry/v1/app.rb', line 290

def app
  @app
end

#idObject (readonly)

Application instance number.



293
294
295
# File 'lib/cfoundry/v1/app.rb', line 293

def id
  @id
end

Instance Method Details

#consoleObject

Instance console data. If instance has a console, returns a hash containing :ip and :port keys.



333
334
335
336
337
338
339
# File 'lib/cfoundry/v1/app.rb', line 333

def console
  return unless @manifest[:console_ip] and @manifest[:console_port]

  { :ip => @manifest[:console_ip],
    :port => @manifest[:console_port]
  }
end

#debuggerObject

Instance debugger data. If instance is in debug mode, returns a hash containing :ip and :port keys.



323
324
325
326
327
328
329
# File 'lib/cfoundry/v1/app.rb', line 323

def debugger
  return unless @manifest[:debug_ip] and @manifest[:debug_port]

  { :ip => @manifest[:debug_ip],
    :port => @manifest[:debug_port]
  }
end

#file(*path) ⇒ Object



358
359
360
# File 'lib/cfoundry/v1/app.rb', line 358

def file(*path)
  @client.base.files(@app.name, @id, *path)
end

#files(*path) ⇒ Object



352
353
354
355
356
# File 'lib/cfoundry/v1/app.rb', line 352

def files(*path)
  @client.base.files(@app.name, @id, *path).split("\n").collect do |entry|
    path + [entry.split(/\s+/, 2)[0]]
  end
end

#healthy?Boolean

True if instance is starting or running, false if it’s down or flapping.

Returns:

  • (Boolean)


343
344
345
346
347
348
349
350
# File 'lib/cfoundry/v1/app.rb', line 343

def healthy?
  case state
  when "STARTING", "RUNNING"
    true
  when "DOWN", "FLAPPING"
    false
  end
end

#inspectObject

Show string representing the application instance.



306
307
308
# File 'lib/cfoundry/v1/app.rb', line 306

def inspect
  "#<App::Instance '#{@app.name}' \##@id>"
end

#sinceObject

Instance start time.



317
318
319
# File 'lib/cfoundry/v1/app.rb', line 317

def since
  Time.at(@manifest[:since])
end

#stateObject Also known as: status

Instance state.



311
312
313
# File 'lib/cfoundry/v1/app.rb', line 311

def state
  @manifest[:state]
end