Puppet Function: libvirt_generate_mac

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

Overview

libvirt_generate_mac()Any

compute sha1 hash of all keys concatenated, only the first 6 hex digits will be used

Returns:

  • (Any)

    a mac address



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/puppet/parser/functions/libvirt_generate_mac.rb', line 3

newfunction(:libvirt_generate_mac, type: :rvalue, doc: <<-'ENDHEREDOC') do |args|


  sha1 = Digest::SHA1.hexdigest(args.join(''))
 
  compute sha1 hash of all keys concatenated, only the first 6
  hex digits will be used

  @return a mac address

  ENDHEREDOC

  # generate address in the QEMU/KVM MAC OID
  '52:54:00:' + "#{sha1[0..1]}:#{sha1[2..3]}:#{sha1[4..5]}"
end