Added possibility to set driver interface attribute for nic
PROD-36097
Change-Id: I3ed0e5b1679f0904f54e663425628db7bd615a6d
diff --git a/README.rst b/README.rst
index a14d847..97910c9 100644
--- a/README.rst
+++ b/README.rst
@@ -449,6 +449,13 @@
- name: nic04
bridge: br-public
model: virtio
+ driver:
+ name: vhost
+ # Optional value. If not set - equal to quantity CPU of VM
+ queues: '2'
+ # Optional values. Must be a power of 2 between 256 and 1024
+ tx_queue_size: '1024'
+ rx_queue_size: '1024'
- name: nic05
bridge: br-prv
model: virtio
diff --git a/_modules/virtng.py b/_modules/virtng.py
index ae906d5..ea78c19 100644
--- a/_modules/virtng.py
+++ b/_modules/virtng.py
@@ -484,6 +484,7 @@
attributes['type'] = attributes.get('type', None)
attributes['source'] = attributes.get('source', None)
attributes['virtualport'] = attributes.get('virtualport', None)
+ attributes['driver'] = attributes.get('driver', None)
def _apply_default_overlay(attributes):
for key, value in overlays[hypervisor].items():
@@ -786,13 +787,26 @@
# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
for _nic in nicp:
- if _nic['virtualport']:
+ if _nic['virtualport'] or _nic['driver']:
interfaces = xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("devices")[0].getElementsByTagName("interface")
for interface in interfaces:
if interface.getElementsByTagName('mac')[0].getAttribute('address').lower() == _nic['mac'].lower():
- vport_xml = xml_doc.createElement("virtualport")
- vport_xml.setAttribute("type", _nic['virtualport']['type'])
- interface.appendChild(vport_xml)
+ if _nic['virtualport']:
+ vport_xml = xml_doc.createElement("virtualport")
+ vport_xml.setAttribute("type", _nic['virtualport']['type'])
+ interface.appendChild(vport_xml)
+ if _nic['driver']:
+ driver_xml = xml_doc.createElement("driver")
+ driver_xml.setAttribute("name", _nic['driver']['name'])
+ if _nic['driver'].get('queues'):
+ driver_xml.setAttribute("queues", _nic['driver']['queues'])
+ else:
+ driver_xml.setAttribute("queues", str(cpu))
+ if _nic['driver'].get('rx_queue_size'):
+ driver_xml.setAttribute("rx_queue_size", _nic['driver']['rx_queue_size'])
+ if _nic['driver'].get('tx_queue_size'):
+ driver_xml.setAttribute("tx_queue_size", _nic['driver']['tx_queue_size'])
+ interface.appendChild(driver_xml)
# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
if rng: