aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-07-14 23:44:24 +0000
committerGerrit Code Review <review@openstack.org>2017-07-14 23:44:24 +0000
commit152d224c73cdbd3243a560a27f6a18e5ffbb2e3c (patch)
tree7da4c385f51ff15be45890eab1dc8fbdabe33d9c /lib
parente0fa2c122b013a77ea76e6746c9d5d082e5f081b (diff)
parent8b9e2b3c6ca5221249b8aa7dc792e756ee92209a (diff)
Merge "Contrail: Fix controlplane/dataplane network asignments & enable optional dpdk"
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/netmask_to_cidr.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/netmask_to_cidr.rb b/lib/puppet/parser/functions/netmask_to_cidr.rb
new file mode 100644
index 0000000..68ee4cf
--- /dev/null
+++ b/lib/puppet/parser/functions/netmask_to_cidr.rb
@@ -0,0 +1,14 @@
+# 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