Class: Stemcell::MetadataSource
- Inherits:
-
Object
- Object
- Stemcell::MetadataSource
- Defined in:
- lib/stemcell/metadata_source.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ 'chef_environment' => 'production', 'git_branch' => 'production', 'count' => 1, 'instance_hostname' => '', 'instance_domain_name' => '', }
- 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
-
#chef_root ⇒ Object
readonly
Returns the value of attribute chef_root.
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
Instance Method Summary collapse
- #expand_role(role, environment, override_options = {}, options = {}) ⇒ Object
-
#initialize(chef_root) ⇒ MetadataSource
constructor
A new instance of MetadataSource.
Constructor Details
#initialize(chef_root) ⇒ MetadataSource
Returns a new instance of MetadataSource.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/stemcell/metadata_source.rb', line 24 def initialize(chef_root) @chef_root = chef_root raise ArgumentError, "You must specify a chef root" unless chef_root = read_template @default_options = DEFAULT_OPTIONS.merge(['defaults']) @all_backing_store_options = ['backing_store'] @all_azs_by_region = ['availability_zones'] end |
Instance Attribute Details
#chef_root ⇒ Object (readonly)
Returns the value of attribute chef_root.
6 7 8 |
# File 'lib/stemcell/metadata_source.rb', line 6 def chef_root @chef_root end |
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
7 8 9 |
# File 'lib/stemcell/metadata_source.rb', line 7 def @default_options end |
Instance Method Details
#expand_role(role, environment, override_options = {}, options = {}) ⇒ Object
36 37 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 |
# File 'lib/stemcell/metadata_source.rb', line 36 def (role, environment, ={}, ={}) raise ArgumentError, "Missing chef role" unless role raise ArgumentError, "Missing chef environment" unless environment allow_empty_roles = .fetch(:allow_empty_roles, false) = (role, environment) role_empty = .nil? || .empty? raise EmptyRoleError if !allow_empty_roles && role_empty = ( , , ) # Merge all the options together in priority order = .dup .deep_merge!() .deep_merge!() if .deep_merge!() # Add the AZ if not specified if (region = ['region']) ['availability_zone'] ||= random_az_in_region(region) end # The chef environment and role used to expand the runlist takes # priority over all other options. ['chef_environment'] = environment ['chef_role'] = role end |