Class: Dumbwaiter::Layer

Inherits:
Object
  • Object
show all
Defined in:
lib/dumbwaiter/layer.rb

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack, opsworks_layer, opsworks = Aws::OpsWorks::Client.new(region: "us-east-1")) ⇒ Layer

Returns a new instance of Layer.



18
19
20
21
22
# File 'lib/dumbwaiter/layer.rb', line 18

def initialize(stack, opsworks_layer, opsworks = Aws::OpsWorks::Client.new(region: "us-east-1"))
  @stack = stack
  @opsworks_layer = opsworks_layer
  @opsworks = opsworks
end

Instance Attribute Details

#opsworksObject (readonly)

Returns the value of attribute opsworks.



4
5
6
# File 'lib/dumbwaiter/layer.rb', line 4

def opsworks
  @opsworks
end

#opsworks_layerObject (readonly)

Returns the value of attribute opsworks_layer.



4
5
6
# File 'lib/dumbwaiter/layer.rb', line 4

def opsworks_layer
  @opsworks_layer
end

#stackObject (readonly)

Returns the value of attribute stack.



4
5
6
# File 'lib/dumbwaiter/layer.rb', line 4

def stack
  @stack
end

Class Method Details

.all(stack, opsworks = Aws::OpsWorks::Client.new(region: "us-east-1")) ⇒ Object



8
9
10
# File 'lib/dumbwaiter/layer.rb', line 8

def self.all(stack, opsworks = Aws::OpsWorks::Client.new(region: "us-east-1"))
  opsworks.describe_layers(stack_id: stack.id).layers.map { |layer| new(stack, layer, opsworks) }
end

.find(stack, layer_name, opsworks = Aws::OpsWorks::Client.new(region: "us-east-1")) ⇒ Object

Raises:



12
13
14
15
16
# File 'lib/dumbwaiter/layer.rb', line 12

def self.find(stack, layer_name, opsworks = Aws::OpsWorks::Client.new(region: "us-east-1"))
  layer = all(stack, opsworks).detect { |layer| layer.shortname == layer_name }
  raise NotFound.new("No layer found with name #{layer_name}") if layer.nil?
  layer
end

Instance Method Details

#custom_recipesObject



43
44
45
# File 'lib/dumbwaiter/layer.rb', line 43

def custom_recipes
  opsworks_layer.custom_recipes.to_hash
end

#idObject



24
25
26
# File 'lib/dumbwaiter/layer.rb', line 24

def id
  opsworks_layer.layer_id
end

#instancesObject



54
55
56
# File 'lib/dumbwaiter/layer.rb', line 54

def instances
  @instances ||= Dumbwaiter::Instance.all(self, opsworks)
end

#run_recipe(*recipes) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/dumbwaiter/layer.rb', line 32

def run_recipe(*recipes)
  opsworks.create_deployment(
    stack_id: stack.id,
    instance_ids: instances.map(&:id),
    command: {
      name: "execute_recipes",
      args: {recipes: recipes}
    }
  )
end

#shortnameObject



28
29
30
# File 'lib/dumbwaiter/layer.rb', line 28

def shortname
  opsworks_layer.shortname
end

#update_custom_recipes(event_name, runlist) ⇒ Object



47
48
49
50
51
52
# File 'lib/dumbwaiter/layer.rb', line 47

def update_custom_recipes(event_name, runlist)
  opsworks.update_layer(
    layer_id: id,
    custom_recipes: custom_recipes.merge(event_name => runlist)
  )
end