Class: Stemcell::MetadataSource::ChefRepository

Inherits:
Object
  • Object
show all
Includes:
Chef::Mixin::DeepMerge
Defined in:
lib/stemcell/metadata_source/chef_repository.rb

Constant Summary collapse

METADATA_ATTRIBUTES =

Search for instance metadata in the following role attributes, with priority given to the keys at the head.

[
  :instance_metadata,
  :stemcell
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chef_root) ⇒ ChefRepository

Returns a new instance of ChefRepository.



18
19
20
21
22
23
24
25
# File 'lib/stemcell/metadata_source/chef_repository.rb', line 18

def initialize(chef_root)
  @chef_root = chef_root
  if chef_root.nil?
    raise ArgumentError, "You must specify a chef repository"
  end

  configure_chef
end

Instance Attribute Details

#chef_rootObject (readonly)

Returns the value of attribute chef_root.



9
10
11
# File 'lib/stemcell/metadata_source/chef_repository.rb', line 9

def chef_root
  @chef_root
end

Instance Method Details

#metadata_for_role(chef_role, chef_environment, chef_options = {}) ⇒ Object

This method will return nil if the role has no stemcell metdata.



28
29
30
31
# File 'lib/stemcell/metadata_source/chef_repository.rb', line 28

def (chef_role, chef_environment, chef_options = {})
  attrs = expand_role(chef_role, chef_environment, chef_options)
  METADATA_ATTRIBUTES.inject(nil) { |r, key| r || attrs[key] }
end