Class: Enc::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/enc/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(asset) ⇒ Builder

Returns a new instance of Builder.



3
4
5
# File 'lib/enc/builder.rb', line 3

def initialize(asset)
  @asset = asset
end

Instance Method Details

#get_asset_attributesObject



33
34
35
# File 'lib/enc/builder.rb', line 33

def get_asset_attributes
  @asset.get_flattened_attributes
end

#get_asset_extrasObject



27
28
29
30
31
# File 'lib/enc/builder.rb', line 27

def get_asset_extras
  {'TAG'    => @asset.tag,
   'STATE'  => @asset.state.name,
   'STATUS' => @asset.status}
end

#to_yamlObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/enc/builder.rb', line 7

def to_yaml
  return String.new.to_yaml unless @asset.uses_enc?
  output = {'parameters' => {'deployment_environment' => @asset.get_deployment_environment,
                             'datacenter'             => @asset.get_datacenter,
                             'roles'                  => @asset.get_roles_as_string}}

  # Do not require the puppet environment until we upgrade to puppet 3.x.
  # output[:environment] => @asset.get_puppet_environment

  # We do this to satisfy the current requirement to have a roleN for each role, where N is the sorted index of the
  # role list.
  @asset.get_roles_by_index.each do |index, role|
    output['parameters']['role' + (index + 1).to_s] = role
  end

  # It's not strictly necessary, but nice to have the $collins parameter at the end of the output.
  output['parameters']['collins'] = get_asset_extras.merge!(get_asset_attributes)
  output.to_yaml
end