Skip to content

Commit

Permalink
Add VF Manager Jinja
Browse files Browse the repository at this point in the history
  • Loading branch information
James Denton committed Aug 21, 2019
1 parent fb9a2af commit 37e3082
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
15 changes: 15 additions & 0 deletions roles/neutron-sriov/templates/pf9-sriov-vf-manager.service.j2
@@ -0,0 +1,15 @@
[Unit]
Description=Platform9 SR-IOV Virtual Function Manager
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/opt/pf9/pf9-virtual-functions.sh start
ExecStop=/opt/pf9/pf9-virtual-functions.sh stop
ExecReload=/opt/pf9/pf9-virtual-functions.sh reload
StandardOutput=journal

[Install]
WantedBy=multi-user.target
61 changes: 61 additions & 0 deletions roles/neutron-sriov/templates/pf9-virtual-functions.sh.j2
@@ -0,0 +1,61 @@
#!/bin/bash
# Copyright 2019 Platform9 Systems Inc.
# All Rights Reserved.

##
# This script implements SR-IOV virtual functions based on variables defined
# within Platform9 Express.
#
# DO NOT EDIT THIS FILE MANUALLY!
##

# VF Array
declare -A vfs

{% for vf in sriov_numvfs %}
vfs[{{ vf.split(':')[0] }}]={{ vf.split(':')[1] }}
{% endfor %}

function get_vf_count {
vf_count=$(</sys/class/net/$1/device/sriov_numvfs)
}

function unset_vf {
echo 0 > /sys/class/net/$1/device/sriov_numvfs
}

function set_vf {
echo $2 > /sys/class/net/$1/device/sriov_numvfs
}

function start {
for vf in "${!vfs[@]}"
do
echo "Enabling ${vfs[$vf]} virtual functions on $vf."
set_vf $vf ${vfs[$vf]}
done
}

function stop {
for vf in "${!vfs[@]}"
do
echo "Removing virtual functions from $vf."
unset_vf $vf
done
}

function reload {
for vf in "${!vfs[@]}"
do
get_vf_count $vf
if [ "$vf_count" -ne "${vfs[$vf]}" ]; then
echo "Virtual function count has changed. Resetting virtual functions on $vf. Affected VMs must be power cycled to restore connectivity!"
unset_vf $vf
set_vf $vf ${vfs[$vf]}
else
echo "Virtual function count on $vf has not changed. Ignoring service reload."
fi
done
}

"$@"

0 comments on commit 37e3082

Please sign in to comment.