Class: EY::Model::Environment
- Defined in:
- lib/engineyard/model/environment.rb
Instance Attribute Summary collapse
-
#ignore_bad_master ⇒ Object
Returns the value of attribute ignore_bad_master.
Class Method Summary collapse
Instance Method Summary collapse
- #app_master! ⇒ Object
- #configuration ⇒ Object (also: #config)
- #default_branch ⇒ Object
- #deploy(app, ref, deploy_options = {}) ⇒ Object
- #download_recipes ⇒ Object
- #ensure_eydeploy_present(&blk) ⇒ Object
- #logs ⇒ Object
- #put_up_maintenance_page(app, verbose = false) ⇒ Object
- #rebuild ⇒ Object
- #recipe_file ⇒ Object
- #resolve_branch(branch, allow_non_default_branch = false) ⇒ Object
- #rollback(app, verbose = false) ⇒ Object
- #run_custom_recipes ⇒ Object
- #shorten_name_for(app) ⇒ Object
- #take_down_maintenance_page(app, verbose = false) ⇒ Object
- #upload_recipes(file_to_upload = recipe_file) ⇒ Object
Instance Attribute Details
#ignore_bad_master ⇒ Object
Returns the value of attribute ignore_bad_master.
5 6 7 |
# File 'lib/engineyard/model/environment.rb', line 5 def ignore_bad_master @ignore_bad_master end |
Class Method Details
.from_array ⇒ Object
16 17 18 |
# File 'lib/engineyard/model/environment.rb', line 16 def self.from_array(*) Collection::Environments[*super] end |
.from_hash(hash) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/engineyard/model/environment.rb', line 7 def self.from_hash(hash) super.tap do |env| env.username = hash['ssh_username'] env.apps = App.from_array(env.apps, :api => env.api) env.instances = Instance.from_array(hash['instances'], :environment => env) env.app_master = Instance.from_hash(env.app_master.merge(:environment => env)) if env.app_master end end |
Instance Method Details
#app_master! ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/engineyard/model/environment.rb', line 24 def app_master! master = app_master if master.nil? raise NoAppMasterError.new(name) elsif !ignore_bad_master && master.status != "running" raise BadAppMasterStatusError.new(master.status) end master end |
#configuration ⇒ Object Also known as: config
142 143 144 |
# File 'lib/engineyard/model/environment.rb', line 142 def configuration EY.config.environments[self.name] || {} end |
#default_branch ⇒ Object
147 148 149 |
# File 'lib/engineyard/model/environment.rb', line 147 def default_branch EY.config.default_branch(name) end |
#deploy(app, ref, deploy_options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/engineyard/model/environment.rb', line 38 def deploy(app, ref, ={}) # regarding deploy_options['migrate']: # # missing means migrate how the yaml file says to # nil means don't migrate # true means migrate w/custom command (if present) or default # a string means migrate with this specific command default_migration_command = config['migration_command'] || 'rake db:migrate' migration_from_config = if config.has_key?('migrate') if config['migrate'] default_migration_command else nil end else default_migration_command end migration_from_command_line = if ['migrate'].nil? nil elsif ['migrate'].respond_to?(:to_str) ['migrate'].to_str else default_migration_command end cmd = if .has_key?('migrate') migration_from_command_line else migration_from_config end app_master!.deploy(app, ref, cmd, config, ['verbose']) end |
#download_recipes ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/engineyard/model/environment.rb', line 95 def download_recipes if File.exist?('cookbooks') raise EY::Error, "Could not download, cookbooks already exists" end require 'tempfile' tmp = Tempfile.new("recipes") tmp.write(api.request("/environments/#{id}/recipes")) tmp.flush cmd = "tar xzf '#{tmp.path}' cookbooks" unless system(cmd) raise EY::Error, "Could not unarchive recipes.\nCommand `#{cmd}` exited with an error." end end |
#ensure_eydeploy_present(&blk) ⇒ Object
34 35 36 |
# File 'lib/engineyard/model/environment.rb', line 34 def ensure_eydeploy_present(&blk) app_master!.ensure_eydeploy_present(&blk) end |
#logs ⇒ Object
20 21 22 |
# File 'lib/engineyard/model/environment.rb', line 20 def logs Log.from_array(api_get("/environments/#{id}/logs")["logs"]) end |
#put_up_maintenance_page(app, verbose = false) ⇒ Object
83 84 85 |
# File 'lib/engineyard/model/environment.rb', line 83 def put_up_maintenance_page(app, verbose=false) app_master!.put_up_maintenance_page(app, verbose) end |
#rebuild ⇒ Object
87 88 89 |
# File 'lib/engineyard/model/environment.rb', line 87 def rebuild api.request("/environments/#{id}/rebuild", :method => :put) end |
#recipe_file ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/engineyard/model/environment.rb', line 119 def recipe_file require 'tempfile' unless File.exist?("cookbooks") raise EY::Error, "Could not find chef recipes. Please run from the root of your recipes repo." end tmp = Tempfile.new("recipes") cmd = "tar czf '#{tmp.path}' cookbooks/" unless system(cmd) raise EY::Error, "Could not archive recipes.\nCommand `#{cmd}` exited with an error." end tmp end |
#resolve_branch(branch, allow_non_default_branch = false) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/engineyard/model/environment.rb', line 135 def resolve_branch(branch, allow_non_default_branch=false) if !allow_non_default_branch && branch && default_branch && (branch != default_branch) raise BranchMismatchError.new(default_branch, branch) end branch || default_branch end |
#rollback(app, verbose = false) ⇒ Object
75 76 77 |
# File 'lib/engineyard/model/environment.rb', line 75 def rollback(app, verbose=false) app_master!.rollback(app, config, verbose) end |
#run_custom_recipes ⇒ Object
91 92 93 |
# File 'lib/engineyard/model/environment.rb', line 91 def run_custom_recipes api.request("/environments/#{id}/run_custom_recipes", :method => :put) end |
#shorten_name_for(app) ⇒ Object
151 152 153 |
# File 'lib/engineyard/model/environment.rb', line 151 def shorten_name_for(app) name.gsub(/^#{Regexp.quote(app.name)}_/, '') end |
#take_down_maintenance_page(app, verbose = false) ⇒ Object
79 80 81 |
# File 'lib/engineyard/model/environment.rb', line 79 def take_down_maintenance_page(app, verbose=false) app_master!.take_down_maintenance_page(app, verbose) end |
#upload_recipes(file_to_upload = recipe_file) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/engineyard/model/environment.rb', line 112 def upload_recipes(file_to_upload = recipe_file) api.request("/environments/#{id}/recipes", :method => :post, :params => {:file => file_to_upload} ) end |