Define a function for range to mask conversion

A function shall be defined to convert a range to mask and
the same shall be used for pmd-cpu-mask and dpdk-lcore-mask

Change-Id: If663c5478d79ded8f08aa07f2546128d38dbb64f
Signed-off-by: Karthik S <ksundara@redhat.com>
This commit is contained in:
Karthik S 2017-03-22 10:18:02 -04:00
parent a50b381f9b
commit 4134b9080c
2 changed files with 31 additions and 18 deletions

View File

@ -0,0 +1,29 @@
# Converts the range to a mask
Puppet::Functions.create_function(:'range_to_mask') do
dispatch :empty_param do
param 'Pattern[/^$/]', :range
end
dispatch :range_param do
param 'Pattern[/^[0-9\-\,]/]', :range
end
dispatch :undef_param do
param 'Undef', :range
end
def empty_param(range)
nil
end
def undef_param(range)
nil
end
def range_param (range)
range.to_s.split(",").map{|c| c.include?("-")?(c.split("-").map(&:to_i)[0]..c.split("-").map(&:to_i)[1]).to_a.join(","):c}.join(",").split(",").map{|c| 1<<c.to_i}.inject(0,:|).to_s(16)
end
end

View File

@ -87,22 +87,8 @@ class vswitch::dpdk (
before => Service['openvswitch'],
}
if $pmd_core_list and !empty($pmd_core_list){
$pmd_core_list_updated = inline_template('<%= @pmd_core_list.split(",").map{|c| c.include?("-")?(c.split("-").map(&:to_i)[0]..c.split("-").map(&:to_i)[1]).to_a.join(","):c}.join(",") %>')
$pmd_core_mask = inline_template('<%= @pmd_core_list_updated.split(",").map{|c| 1<<c.to_i}.inject(0,:|).to_s(16) %>')
}
else {
$pmd_core_mask = undef
}
if $host_core_list and !empty($host_core_list) {
$host_core_list_updated = inline_template('<%= @host_core_list.split(",").map{|c| c.include?("-")?(c.split("-").map(&:to_i)[0]..c.split("-").map(&:to_i)[1]).to_a.join(","):c}.join(",") %>')
$dpdk_lcore_mask = inline_template('<%= @host_core_list_updated.split(",").map{|c| 1<<c.to_i}.inject(0,:|).to_s(16) %>')
}
else {
$dpdk_lcore_mask = undef
}
$pmd_core_mask = range_to_mask($pmd_core_list)
$dpdk_lcore_mask = range_to_mask($host_core_list)
if $memory_channels and !empty($memory_channels) {
$memory_channels_conf = "-n ${memory_channels}"
@ -131,6 +117,4 @@ class vswitch::dpdk (
}
create_resources ('vs_config', $dpdk_configs, $dpdk_dependencies)
}