Puppet Function: get_dimensions

Defined in:
lib/puppet/parser/functions/get_dimensions.rb
Function type:
Ruby 3.x API

Overview

get_dimensions()Any

Returns:

  • (Any)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet/parser/functions/get_dimensions.rb', line 1

Puppet::Parser::Functions.newfunction(:get_dimensions, :type => :rvalue) do |args|
dimension_list = args[0]
aws_integration = args[1]
dimensions = "?"
if aws_integration
        puts "Getting AWS metadata..."
        uri = URI.parse("http://169.254.169.254/2014-11-05/dynamic/instance-identity/document")
        http = Net::HTTP.new(uri.host, uri.port)
        http.open_timeout = 4
        http.read_timeout = 4
        begin
                http.start
                begin
                        response = http.request(Net::HTTP::Get.new(uri.request_uri))
                rescue Timeout::Error
                       puts "ERROR: Unable to get AWS metadata, Timeout due to reading"
                rescue Exception
                       puts "ERROR: Unable to get AWS metadata, exception occurred!"
                end
        rescue Timeout::Error
                puts "ERROR: Unable to get AWS metadata, Timeout due to connecting"
        rescue Exception
                puts "ERROR: Unable to get AWS metadata, exception occurred!"
        end
        unless response.nil? || response == 0
                result = JSON.parse(response.body)
                dimensions << "sfxdim_AWSUniqueId=#{result["instanceId"]}_#{result["region"]}_#{result["accountId"]}&"
        end
end
unless dimension_list.empty?
        dimension_list.each {|key, value| dimensions << "sfxdim_#{key}=#{value}&"}
end
dimensions[0...-1]
end