Skip to content

Commit

Permalink
kvm: simplify creating an sriov enabled vm
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Jun 28, 2024
1 parent d627944 commit d5b8d08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions kvirt/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@
# Create 3 vm to emulate baremetal
$ kcli create vm -P start=false -P memory=20480 -P numcpus=16 -P disks=[200] -P uefi=true -P nets=[default] -c 3 myclu
# Create an sriov enabled vm (on KVM only)
$ kcli create vm -i centos9stream -P nets=['{"name": "default"}','{"name": "default", "sriov": "true"}']
"""

vmconsole = """# Open a graphical console for vm ( only shows the command if using container)
Expand Down
9 changes: 7 additions & 2 deletions kvirt/providers/kvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,9 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
else:
_id = cell['id']
matchingnics = [nic for nic in nets if isinstance(nic, dict) and 'numa' in nic and nic['numa'] == _id]
if 'machine' not in overrides and [nic for nic in matchingnics if 'vfio' in nic and nic['vfio']]:
vfio = [nic for nic in matchingnics if 'vfio' in nic and nic['vfio']]
sriov = [nic for nic in matchingnics if 'sriov' in nic and nic['sriov']]
if 'machine' not in overrides and (vfio or sriov):
machine = 'q35'
warning(f"Forcing machine type to {machine}")
newindex = 1
Expand Down Expand Up @@ -631,6 +633,10 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
nets[index] = {'name': netname}
elif isinstance(net, dict):
netname = net.get('name', 'default')
if net.get('sriov', False):
nets[index]['type'] = 'igb'
nets[index]['vfio'] = True
nets[index]['noconf'] = True
if 'mac' in nets[index]:
mac = nets[index]['mac']
macxml = f"<mac address='{mac}'/>"
Expand All @@ -654,7 +660,6 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
mtuxml = f"<mtu size='{nets[index]['mtu']}'/>"
if 'vfio' in nets[index] and nets[index]['vfio']:
iommuxml = "<iommu model='intel'/>"
# ioapicxml = "<ioapic driver='qemu'/>"
if 'multiqueues' in nets[index]:
multiqueues = nets[index]['multiqueues']
if not isinstance(multiqueues, int):
Expand Down

0 comments on commit d5b8d08

Please sign in to comment.