Class: EngineyardAPI::Environment
- Inherits:
-
Object
- Object
- EngineyardAPI::Environment
- Defined in:
- lib/engineyard-api/environment.rb
Overview
Environment class stores all environment data, and crawls over other parts of the api to grab data for Instance and App classes.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Used for development.
-
#account ⇒ Object
:nodoc:.
-
#add_instance(body) ⇒ Object
Create a new instance.
-
#add_status ⇒ Object
Checks to see how many add instance actions are working on environment.
-
#app_master ⇒ Object
Return EngineyardAPI::Instance of current app_master.
-
#app_server_stack_name ⇒ Object
Returns current stack name.
-
#apps ⇒ Object
Returns array of EngineyardAPI::APP’s.
-
#busy? ⇒ Boolean
Checks if environment is busy.
-
#deploying? ⇒ Boolean
Checks if environment is deploying (works for standard deploy only (i.e. via dashboard or ey_cli utillity).
- #deployment_configurations ⇒ Object
-
#environment_id ⇒ Object
Returns integer containing environment ID.
-
#framework_env ⇒ Object
Returns framework environment (i.e. “production”, or “staging”).
-
#initialize(id, environment = nil) ⇒ Environment
constructor
:nodoc:.
-
#instance_count ⇒ Object
Returns number of instances in environment.
-
#instance_status ⇒ Object
Returns current status.
-
#instances ⇒ Object
Returns array full of EngineyardAPI::Instnaces.
-
#keys(k = nil) ⇒ Object
This was mostly used for testing api.
-
#load_balancer_ip_address ⇒ Object
Return load balancer IP address, if any.
-
#name ⇒ Object
Returns String containing th eenvironment name.
-
#rebuild ⇒ Object
Like pressing ‘apply’ on dashboard.
-
#reload(e = nil) ⇒ Object
Call environment information from API.
-
#remove_instance(remove_instance) ⇒ Object
Remove instance.
-
#remove_status ⇒ Object
Same as add_status, except checks for instances being removed.
-
#ssh_username ⇒ Object
Default user used for deployments (usually ‘deploy’).
-
#stack_name ⇒ Object
Name of current stack associated with environment.
Constructor Details
#initialize(id, environment = nil) ⇒ Environment
:nodoc:
5 6 7 8 9 10 11 |
# File 'lib/engineyard-api/environment.rb', line 5 def initialize(id,environment = nil) # :nodoc: @environment = environment if environment @id = id @path = "/environments/#{id}" #EngineyardAPI::API = EngineyardAPI::API reload(environment) end |
Instance Method Details
#[](key) ⇒ Object
Used for development. same as keys method, but does not return a list of keys if no params.
112 113 114 |
# File 'lib/engineyard-api/environment.rb', line 112 def [](key) @enviornment[key] end |
#account ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/engineyard-api/environment.rb', line 43 def account # :nodoc: @environment['account'] end |
#add_instance(body) ⇒ Object
Create a new instance. first param can take any arguments in hash that API would accept (i.e. :instance_size, :volume_size, etc)
89 90 91 92 |
# File 'lib/engineyard-api/environment.rb', line 89 def add_instance(body) request = {:body => {:request => body}} EngineyardAPI::API.post("#{@path}/add_instances", request) end |
#add_status ⇒ Object
Checks to see how many add instance actions are working on environment. returns array.
95 96 97 |
# File 'lib/engineyard-api/environment.rb', line 95 def add_status EngineyardAPI::API.get("#{@path}/add_instances") end |
#app_master ⇒ Object
Return EngineyardAPI::Instance of current app_master
78 79 80 |
# File 'lib/engineyard-api/environment.rb', line 78 def app_master @app_master end |
#app_server_stack_name ⇒ Object
Returns current stack name
58 59 60 |
# File 'lib/engineyard-api/environment.rb', line 58 def app_server_stack_name @environment['app_server_stack_name'] end |
#apps ⇒ Object
Returns array of EngineyardAPI::APP’s
68 69 70 |
# File 'lib/engineyard-api/environment.rb', line 68 def apps @applications end |
#busy? ⇒ Boolean
Checks if environment is busy. returns true and hash of actions if instances are being added, instances are being removed, or if deploy is ongoing.
117 118 119 120 |
# File 'lib/engineyard-api/environment.rb', line 117 def busy? return true, {:add_status => add_status["requests"] , :remove_status => remove_status["requests"] } if add_status["requests"].count > 0 or remove_status["requests"].count > 0 return false end |
#deploying? ⇒ Boolean
Checks if environment is deploying (works for standard deploy only (i.e. via dashboard or ey_cli utillity)
123 124 125 126 |
# File 'lib/engineyard-api/environment.rb', line 123 def return true if apps.select {|app| app.last_deploy['finished_at'] == nil }.count > 0 return false end |
#deployment_configurations ⇒ Object
73 74 75 |
# File 'lib/engineyard-api/environment.rb', line 73 def deployment_configurations @environment['deployment_configurations'] end |
#environment_id ⇒ Object
Returns integer containing environment ID
14 15 16 |
# File 'lib/engineyard-api/environment.rb', line 14 def environment_id @environment['id'] end |
#framework_env ⇒ Object
Returns framework environment (i.e. “production”, or “staging”)
63 64 65 |
# File 'lib/engineyard-api/environment.rb', line 63 def framework_env @environment['framework_env'] end |
#instance_count ⇒ Object
Returns number of instances in environment
24 25 26 |
# File 'lib/engineyard-api/environment.rb', line 24 def instance_count @environment['instances_count'] end |
#instance_status ⇒ Object
Returns current status
34 35 36 |
# File 'lib/engineyard-api/environment.rb', line 34 def instance_status @environment['instance_status'] end |
#instances ⇒ Object
Returns array full of EngineyardAPI::Instnaces
29 30 31 |
# File 'lib/engineyard-api/environment.rb', line 29 def instances @instances end |
#keys(k = nil) ⇒ Object
This was mostly used for testing api. not used in script. keeping for future development reasons.
83 84 85 86 |
# File 'lib/engineyard-api/environment.rb', line 83 def keys(k=nil) # :nodoc: return @environment.keys unless k return @environment[k] end |
#load_balancer_ip_address ⇒ Object
Return load balancer IP address, if any.
39 40 41 |
# File 'lib/engineyard-api/environment.rb', line 39 def load_balancer_ip_address @environment['load_balancer_ip_address'] end |
#name ⇒ Object
Returns String containing th eenvironment name
19 20 21 |
# File 'lib/engineyard-api/environment.rb', line 19 def name @environment['name'] end |
#rebuild ⇒ Object
Like pressing ‘apply’ on dashboard
129 130 131 |
# File 'lib/engineyard-api/environment.rb', line 129 def rebuild EngineyardAPI::API.put("#{@path}/update_instances",{:body => ""}) end |
#reload(e = nil) ⇒ Object
Call environment information from API. Information is cached in class until reload is called again. Prevents calling API when not needed.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/engineyard-api/environment.rb', line 134 def reload(e=nil) @environment = EngineyardAPI::API.get(@path)['environment'] unless e @instances = Array.new @applications = Array.new # Populate instances @environment['instances'].each {|instance| @instances << EngineyardAPI::Instance.new(instance) } # Populate Apps @environment['apps'].each {|app| @applications << EngineyardAPI::App.new(app) } @app_master=App.new(@environment['app_master']) @applications.each { |app| app.last_deploy=EngineyardAPI::API.get("/apps/#{app.app_id}/environments/#{environment_id}/deployments/last")['deployment'] } return true end |
#remove_instance(remove_instance) ⇒ Object
Remove instance. Provide role (:app, or :util), and :amazon_id if needed.
100 101 102 103 104 |
# File 'lib/engineyard-api/environment.rb', line 100 def remove_instance(remove_instance) request = {:body => { :request => {:role => role } } } if [:app,:util].include? remove_instance request = {:body => { :request => { :provisioned_id => remove_instance.amazon_id } }} unless [:app,:util].include? remove_instance EngineyardAPI::API.post("#{@path}/remove_instances",request) end |
#remove_status ⇒ Object
Same as add_status, except checks for instances being removed. retruns array.
107 108 109 |
# File 'lib/engineyard-api/environment.rb', line 107 def remove_status EngineyardAPI::API.get("#{@path}/remove_instances") end |
#ssh_username ⇒ Object
Default user used for deployments (usually ‘deploy’)
53 54 55 |
# File 'lib/engineyard-api/environment.rb', line 53 def ssh_username @environment['ssh_username'] end |
#stack_name ⇒ Object
Name of current stack associated with environment
48 49 50 |
# File 'lib/engineyard-api/environment.rb', line 48 def stack_name @environment['stack_name'] end |