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(appname, index, client, manifest = {}) ⇒ Instance

Create an Instance object.

You’ll usually call App#instances instead



508
509
510
511
512
513
# File 'lib/cfoundry/v1/app.rb', line 508

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

Instance Attribute Details

#appObject (readonly)

The application this instance belongs to.



500
501
502
# File 'lib/cfoundry/v1/app.rb', line 500

def app
  @app
end

#indexObject (readonly)

Application instance number.



503
504
505
# File 'lib/cfoundry/v1/app.rb', line 503

def index
  @index
end

Instance Method Details

#consoleObject

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



543
544
545
546
547
548
549
# File 'lib/cfoundry/v1/app.rb', line 543

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.



533
534
535
536
537
538
539
# File 'lib/cfoundry/v1/app.rb', line 533

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

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

#file(*path) ⇒ Object

Retrieve file contents for this instance.

path

A sequence of strings representing path segments.

For example, files("foo", "bar") for foo/bar.



580
581
582
# File 'lib/cfoundry/v1/app.rb', line 580

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

#files(*path) ⇒ Object

Retrieve file listing under path for this instance.

path

A sequence of strings representing path segments.

For example, files("foo", "bar") for foo/bar.



568
569
570
571
572
# File 'lib/cfoundry/v1/app.rb', line 568

def files(*path)
  @client.base.files(@app, @index, *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)


553
554
555
556
557
558
559
560
# File 'lib/cfoundry/v1/app.rb', line 553

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

#inspectObject

Show string representing the application instance.



516
517
518
# File 'lib/cfoundry/v1/app.rb', line 516

def inspect
  "#<App::Instance '#@app' \##@index>"
end

#sinceObject

Instance start time.



527
528
529
# File 'lib/cfoundry/v1/app.rb', line 527

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

#stateObject Also known as: status

Instance state.



521
522
523
# File 'lib/cfoundry/v1/app.rb', line 521

def state
  @manifest[:state]
end