Method: Fog::Orchestration::Util::RecursiveHotFileLoader#get_file_contents

Defined in:
lib/fog/orchestration/util/recursive_hot_file_loader.rb

#get_file_contents(from_data, base_url) ⇒ Object

Traverse the template tree looking for get_file and type

and populating the @files attribute with their content.
Resource referenced by get_file and type are eventually
replaced with their absolute URI as done in heatclient
and shade.


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fog/orchestration/util/recursive_hot_file_loader.rb', line 95

def get_file_contents(from_data, base_url)
  Fog::Logger.debug("Processing #{from_data} with base_url #{base_url}")

  # Recursively traverse the tree
  #   if recurse_data is Array or Hash
  recurse_data = from_data.kind_of?(Hash) ? from_data.values : from_data
  recurse_data.each { |value| get_file_contents(value, base_url) } if recurse_data.kind_of?(Array)

  # I'm on a Hash, process it.
  return unless from_data.kind_of?(Hash)
  from_data.each do |key, value|
    next if ignore_if(key, value)

    # Resolve relative paths.
    str_url = url_join(base_url, value)

    next if @files.key?(str_url)

    file_content = read_uri(str_url)

    # get_file should not recurse hot templates.
    if key == "type" && template_is_raw?(file_content) && !@visited.include?(str_url)
      template = get_template_contents(str_url)
      file_content = YAML.dump(template)
    end

    @files[str_url] = file_content
    # replace the data value with the normalised absolute URL as required
    #  by https://docs.openstack.org/heat/pike/template_guide/hot_spec.html#get-file
    from_data[key] = str_url
  end
end