aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/parser/functions/netmask_to_cidr.rb14
-rw-r--r--lib/puppet/provider/sriov_vf_config/numvfs.rb2
2 files changed, 15 insertions, 1 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
diff --git a/lib/puppet/provider/sriov_vf_config/numvfs.rb b/lib/puppet/provider/sriov_vf_config/numvfs.rb
index cfa663c..22acf21 100644
--- a/lib/puppet/provider/sriov_vf_config/numvfs.rb
+++ b/lib/puppet/provider/sriov_vf_config/numvfs.rb
@@ -12,7 +12,7 @@ Puppet::Type.type(:sriov_vf_config).provide(:numvfs) do
if File.file?(sriov_numvfs_path)
_set_numvfs
else
- fail("#{sriov_numvfs_path} doesn't exist. Check if #{sriov_get_interface} is a valid network interface supporting SR-IOV")
+ warning("#{sriov_numvfs_path} doesn't exist. Check if #{sriov_get_interface} is a valid network interface supporting SR-IOV")
end
end