Class: OpsWorker::App
- Inherits:
-
Object
- Object
- OpsWorker::App
- Defined in:
- lib/ops_worker/app.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#revision ⇒ Object
readonly
Returns the value of attribute revision.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Instance Method Summary collapse
- #deploy(revision = nil) ⇒ Object
- #execute_recipes(recipe_names) ⇒ Object
-
#initialize(id, name, revision, stack, opsworks_client) ⇒ App
constructor
A new instance of App.
- #instances ⇒ Object
- #reload ⇒ Object
- #restart ⇒ Object
- #rollback ⇒ Object
- #to_s ⇒ Object
- #update_cookbooks ⇒ Object
-
#update_revision(revision) ⇒ Object
Updates the revision in this app such that all future deploys pull from this revision.
Constructor Details
#initialize(id, name, revision, stack, opsworks_client) ⇒ App
Returns a new instance of App.
5 6 7 8 9 10 11 |
# File 'lib/ops_worker/app.rb', line 5 def initialize(id, name, revision, stack, opsworks_client) @id = id @name = name @stack = stack @revision = revision @opsworks_client = opsworks_client end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/ops_worker/app.rb', line 3 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/ops_worker/app.rb', line 3 def name @name end |
#revision ⇒ Object (readonly)
Returns the value of attribute revision.
3 4 5 |
# File 'lib/ops_worker/app.rb', line 3 def revision @revision end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
3 4 5 |
# File 'lib/ops_worker/app.rb', line 3 def stack @stack end |
Instance Method Details
#deploy(revision = nil) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ops_worker/app.rb', line 43 def deploy(revision = nil) OpsWorker.logger.info {"Deploying app #{@name} from #{revision || @revision}"} if raise StandardError.new("#{@name} is already deploying") end existing_revision = @revision.dup() changing_revisions = revision && revision != existing_revision if changing_revisions update_revision(revision) end deployment_status = create_deployment(:deploy) if changing_revisions update_revision(existing_revision) end deployment_status end |
#execute_recipes(recipe_names) ⇒ Object
82 83 84 85 |
# File 'lib/ops_worker/app.rb', line 82 def execute_recipes(recipe_names) OpsWorker.logger.info {"Executing recipes #{recipe_names} on #{@name}"} create_deployment(:execute_recipes, {"recipes" => recipe_names}, :all) end |
#instances ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ops_worker/app.rb', line 13 def instances if @instances return @instances end instances_result = @opsworks_client.describe_instances(:stack_id => @stack.id, :app_id => @id)[:instances] @instances = instances_result.map do |instance_hash| layers = @stack.layers.select {|l| instance_hash[:layer_ids].include?(l.id)} Instance.new(instance_hash[:instance_id], instance_hash[:hostname], instance_hash[:status], instance_hash[:instance_type], instance_hash[:elastic_ip], instance_hash[:availability_zone], self, layers) end end |
#reload ⇒ Object
91 92 93 |
# File 'lib/ops_worker/app.rb', line 91 def reload @instances = nil end |
#restart ⇒ Object
71 72 73 74 |
# File 'lib/ops_worker/app.rb', line 71 def restart OpsWorker.logger.info {"Restarting #{@name}"} create_deployment(:restart) end |
#rollback ⇒ Object
66 67 68 69 |
# File 'lib/ops_worker/app.rb', line 66 def rollback OpsWorker.logger.info {"Rolling back #{@name}"} create_deployment(:rollback) end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/ops_worker/app.rb', line 87 def to_s "#<OpsWorker::App #{@id}, #{@name}, stack: #{@stack.name}>" end |
#update_cookbooks ⇒ Object
76 77 78 79 |
# File 'lib/ops_worker/app.rb', line 76 def update_cookbooks OpsWorker.logger.info {"Updating cookbooks for #{@name}"} create_deployment(:update_custom_cookbooks, {}, :all) end |
#update_revision(revision) ⇒ Object
Updates the revision in this app such that all future deploys pull from this revision
34 35 36 37 38 39 40 |
# File 'lib/ops_worker/app.rb', line 34 def update_revision(revision) OpsWorker.logger.info {"Changing revision from #{@revision} to #{revision} for app #{@name}"} @opsworks_client.update_app(:app_id => @id, :app_source => {:revision => revision}) @revision = revision reload() end |