File virtman-default-guest-from-host-os.patch of Package virt-manager
Enhancement to default to the host os version when creating a VM
and media detection of the install source is turned off.
Index: virt-manager-2.1.0/virtManager/create.py
===================================================================
--- virt-manager-2.1.0.orig/virtManager/create.py
+++ virt-manager-2.1.0/virtManager/create.py
@@ -10,6 +10,9 @@ import pkgutil
import os
import threading
import time
+import sys
+import os
+import re
from gi.repository import Gdk
from gi.repository import Gtk
@@ -1184,6 +1187,63 @@ class vmmCreate(vmmGObjectUI):
def _iso_activated_cb(self, mediacombo, entry):
self._detectable_media_widget_changed(entry, checkfocus=False)
+ def _lookup_host_os(self):
+ def _lookup_sp(line):
+ sp = ""
+ m = re.search(' SP[12345] ', line)
+ if m:
+ sp = m.group(0).strip().lower()
+ return sp
+ if sys.platform.startswith('linux'):
+ if os.path.exists('/etc/issue'):
+ f = open('/etc/issue')
+ lines = f.readlines()
+ f.close()
+ for line in lines:
+ if "openSUSE " in line:
+ parts = line.split(' ')
+ if len(parts) > 2 and len(parts[3]) <= 4:
+ os_ver = "opensuse" + parts[3]
+ return 'linux', os_ver
+ return 'linux', 'opensuse42.2'
+ if "SUSE Linux Enterprise Server 15" in line:
+ return 'linux', ('sle15' + _lookup_sp(line))
+ if "SUSE Linux Enterprise Server 12" in line:
+ return 'linux', ('sles12' + _lookup_sp(line))
+ if "SUSE Linux Enterprise Server 11" in line:
+ return 'linux', ('sles11' + _lookup_sp(line))
+ if "SUSE Linux Enterprise Desktop 15" in line:
+ return 'linux', ('sled15' + _lookup_sp(line))
+ if "SUSE Linux Enterprise Desktop 12" in line:
+ return 'linux', ('sled12' + _lookup_sp(line))
+ if "SUSE Linux Enterprise Desktop 11" in line:
+ return 'linux', ('sled11' + _lookup_sp(line))
+ return None, None
+
+ def detect_host_os(self):
+ box = self.widget('install-os-type')
+ if box.get_active() <= 0:
+ os_type, os_variant = self._lookup_host_os()
+ if os_type is None:
+ return
+ model = box.get_model()
+ index = 0
+ for row in model:
+ if row[0] == 'linux':
+ box.set_active(index)
+ break
+ index += 1
+ if os_variant is None:
+ return
+ box = self.widget('install-os-version')
+ model = box.get_model()
+ index = 0
+ for row in model:
+ if row[0] == os_variant:
+ box.set_active(index)
+ break
+ index += 1
+
def _detect_os_toggled_cb(self, src):
if not src.is_visible():
return
@@ -1194,6 +1254,8 @@ class vmmCreate(vmmGObjectUI):
if dodetect:
self._os_already_detected_for_media = False
self._start_detect_os_if_needed()
+ else:
+ self.detect_host_os()
def _browse_oscontainer(self, ignore):
self._browse_file("install-oscontainer-fs", is_dir=True)