Class: Opsicle::Layer

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options = {}) ⇒ Layer

Returns a new instance of Layer.



9
10
11
12
13
# File 'lib/opsicle/layer.rb', line 9

def initialize(client, options = {})
  @client = client
  @id = options[:id]
  @name = options[:name]
end

Class Attribute Details

.clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/opsicle/layer.rb', line 6

def client
  @client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.get_layersObject



32
33
34
# File 'lib/opsicle/layer.rb', line 32

def self.get_layers
  client.api_call('describe_layers', stack_id: client.config.opsworks_config[:stack_id])[:layers]
end

.instance_ids(client, layers) ⇒ Object

Public - gets all the layer ids for the given layers

client - a new Client layers - an array of layer shortnames

Return - An array of instance ids belonging to the input layers



41
42
43
44
# File 'lib/opsicle/layer.rb', line 41

def self.instance_ids(client, layers)
  @client = client
  get_info.map{ |layer| layer.get_instance_ids if layers.include?(layer.name) }.flatten.compact.uniq
end

Instance Method Details

#get_instance_idsObject

Public - Gets all the instance ids for a layer

Return - An array of instance ids



18
19
20
# File 'lib/opsicle/layer.rb', line 18

def get_instance_ids
  client.api_call('describe_instances', layer_id: id)[:instances].map{ |s| s[:instance_id] }
end