virt-manager/virtman-default-guest-from-host-os.patch

74 lines
2.5 KiB
Diff

Index: virt-manager-0.9.5/src/virtManager/create.py
===================================================================
--- virt-manager-0.9.5.orig/src/virtManager/create.py
+++ virt-manager-0.9.5/src/virtManager/create.py
@@ -20,6 +20,8 @@
import threading
import logging
+import sys
+import os
import gtk
@@ -1159,6 +1161,51 @@ class vmmCreate(vmmGObjectUI):
return
self.start_detection(forward=forward)
+ def _lookup_host_os(self):
+ if sys.platform == 'linux2':
+ if os.path.exists('/etc/issue'):
+ f = open('/etc/issue')
+ lines = f.readlines()
+ f.close()
+ for line in lines:
+ if "openSUSE 13" in line:
+ return 'linux', 'opensuse13'
+ if "openSUSE 12" in line:
+ return 'linux', 'opensuse12'
+ if "SUSE Linux Enterprise Server 11" in line:
+ return 'linux', 'sles11'
+ if "SUSE Linux Enterprise Desktop 11" in line:
+ return 'linux', 'sled11'
+ if "Fedora" in line:
+ return 'linux', 'fedora17'
+ if "Red Hat Enterprise Linux Server" in line:
+ return 'linux', 'rhel6'
+ 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 toggle_detect_os(self, src):
dodetect = src.get_active()
@@ -1174,6 +1221,7 @@ class vmmCreate(vmmGObjectUI):
self.widget("install-os-version-label").hide()
self.widget("install-os-type").show()
self.widget("install-os-version").show()
+ self.detect_host_os()
def _selected_os_row(self):
box = self.widget("install-os-type")