diff --git a/roles/neutron-sriov/templates/pf9-sriov-vf-manager.service.j2 b/roles/neutron-sriov/templates/pf9-sriov-vf-manager.service.j2 new file mode 100644 index 00000000..4f5e9e71 --- /dev/null +++ b/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 diff --git a/roles/neutron-sriov/templates/pf9-virtual-functions.sh.j2 b/roles/neutron-sriov/templates/pf9-virtual-functions.sh.j2 new file mode 100644 index 00000000..1bafa27f --- /dev/null +++ b/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 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 +} + +"$@"