Files
puppet-tripleo/lib/puppet/parser/functions/netmask_to_cidr.rb
Michael Henkel 8b9e2b3c6c Contrail: Fix controlplane/dataplane network asignments & enable optional dpdk
This patch will move the Contrail roles communication towards
OpenStack APIs from the public/external network to the
internal_api network. I will also add the option to enable
dpdk for Contrail.

Change-Id: Ia835df656031cdf28de20f41ec6ab1c028dced23
Closes-Bug: 1698422
2017-07-05 22:52:58 +02:00

15 lines
495 B
Ruby

# Custom function to transform netmask from IP notation to
# CIDR format. Input is an IP address, output a CIDR:
# 255.255.255.0 = 24
# The CIDR formated netmask is needed for some
# Contrail configuration files
require 'ipaddr'
module Puppet::Parser::Functions
newfunction(:netmask_to_cidr, :type => :rvalue) do |args|
if args[0].class != String
raise Puppet::ParseError, "Syntax error: #{args[0]} must be a String"
end
IPAddr.new(args[0]).to_i.to_s(2).count("1")
end
end