Class: CFCM::CF::Session
- Inherits:
-
Object
- Object
- CFCM::CF::Session
- Defined in:
- lib/cfcm/cf.rb
Instance Method Summary collapse
- #add_instance(app) ⇒ Object
- #app_exists(app_name) ⇒ Object
- #get_app(app_name) ⇒ Object
-
#initialize(target, username, password) ⇒ Session
constructor
A new instance of Session.
- #is_logged_in ⇒ Object
- #max_instance_growth(app_name) ⇒ Object
- #remaining_memory ⇒ Object
- #remove_instance(app) ⇒ Object
Constructor Details
#initialize(target, username, password) ⇒ Session
Returns a new instance of Session.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cfcm/cf.rb', line 6 def initialize(target, username, password) begin @client = CFoundry::V1::Client.new(target) @client.login({:username => username, :password => password}) rescue #puts "Could not login!" #TODO: Handle error return end end |
Instance Method Details
#add_instance(app) ⇒ Object
63 64 65 66 67 |
# File 'lib/cfcm/cf.rb', line 63 def add_instance(app) app.total_instances += 1 app.update! return self.get_app(app.name) end |
#app_exists(app_name) ⇒ Object
32 33 34 35 |
# File 'lib/cfcm/cf.rb', line 32 def app_exists(app_name) app = self.get_app(app_name) return app != nil end |
#get_app(app_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cfcm/cf.rb', line 21 def get_app(app_name) if !@client puts "Must be loged in" #TODO: Handle error return end return @client.app_by_name(app_name) return nil end |
#is_logged_in ⇒ Object
17 18 19 |
# File 'lib/cfcm/cf.rb', line 17 def is_logged_in return @client.logged_in? end |
#max_instance_growth(app_name) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cfcm/cf.rb', line 48 def max_instance_growth(app_name) if !@client puts "Must be loged in" #TODO: Handle error return end remaining_memory = self.remaining_memory app = self.get_app(app_name) app_memory = app.memory max_new_instances = (remaining_memory / app_memory).floor return max_new_instances end |
#remaining_memory ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cfcm/cf.rb', line 37 def remaining_memory if !@client puts "Must be loged in" #TODO: Handle error return end info = @client.info return info[:limits][:memory] - info[:usage][:memory] end |
#remove_instance(app) ⇒ Object
69 70 71 72 73 |
# File 'lib/cfcm/cf.rb', line 69 def remove_instance(app) app.total_instances -= 1 app.update! return self.get_app(app.name) end |