When attaching a network interface to a virtual machine, Kimchi lets
libvirt choose the network model. However, there is an existing lookup
table which can determine the best network model for each type of guest
operating system, and Kimchi should use that information here as well.
Use the osinfo lookup table to determine the best possible network
interface model when attaching a NIC to a VM.
Signed-off-by: CrÃstian Deives <cristiandeives(a)gmail.com>
---
src/kimchi/xmlutils/interface.py | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/src/kimchi/xmlutils/interface.py b/src/kimchi/xmlutils/interface.py
index 7b79584..2325eb9 100644
--- a/src/kimchi/xmlutils/interface.py
+++ b/src/kimchi/xmlutils/interface.py
@@ -22,6 +22,8 @@ import lxml.etree as ET
from distutils.version import LooseVersion
from lxml.builder import E
+from kimchi import osinfo
+
def get_iface_xml(params, arch=None, os_distro=None, os_version=None):
"""
@@ -33,8 +35,17 @@ def get_iface_xml(params, arch=None, os_distro=None, os_version=None):
interface = E.interface(type=params['type'])
interface.append(E.source(network=params['network']))
- if 'model' in params.keys():
- interface.append(E.model(type=params['model']))
+ model = params.get('model')
+
+ # no model specified; let's try querying osinfo
+ if model is None:
+ # if os_distro and os_version are invalid, nic_model will also be None
+ model = osinfo.lookup(os_distro, os_version).get('nic_model')
+
+ # only append 'model' to the XML if it's been specified as a parameter
or
+ # returned by osinfo.lookup; otherwise let libvirt use its default value
+ if model is not None:
+ interface.append(E.model(type=model))
mac = params.get('mac', None)
if mac is not None:
--
2.1.0