[PATCH] virtinst use .treeinfo for OS type detection files path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Daniel P. Berrange wrote:
> It does look very promising - its definitely something we should try to
> make use of in virt-install as it ought to make us more robust wrt to
> future changes. If anyone's interested in supplying patches to make use of
> the .treeinfo files, please send them to the list, otherwise we'll consider 
> this a TODO item for our development roadmap.
> 
Here's a completely UNTESTED patch.
The .treeinfo file is available in Fedora and will be available for RHEL 5.2 and
later and probably CentOS 5.2 as well.
Fall backs to old code are still in place.

Greetings,
Alexander.

diff -r 71ebde48210c virtinst/OSDistro.py
--- a/virtinst/OSDistro.py	Wed Feb 06 09:41:07 2008 -0500
+++ b/virtinst/OSDistro.py	Thu Feb 14 11:18:59 2008 +0100
@@ -24,6 +24,7 @@ import gzip
 import gzip
 import re
 import tempfile
+import ConfigParser
 
 from virtinst import _virtinst as _
 
@@ -49,14 +50,41 @@ class Distro:
 # Base image store for any Red Hat related distros which have
 # a common layout
 class RedHatDistro(Distro):
+    def __init__(self, uri, type=None, scratchdir=None):
+        Distro.__init__(self, uri, type, scratchdir)
+        self.treeinfo = None
+
+    def hasTreeinfo(self, fetcher, progresscb):
+	# all Red Hat based distros should have .treeinfo / execute only once
+	if (self.treeinfo is None):
+	    if fetcher.hasFile(".treeinfo"):
+        	logging.debug("Detected .treeinfo file")
+		tmptreeinfo = fetcher.acquireFile(".treeinfo", progresscb)
+		self.treeinfo = ConfigParser.SafeConfigParser()
+		self.treeinfo.read(tmptreeinfo)
+        	return True
+	    else:
+		return False
+	else:
+	    return True
 
     def acquireKernel(self, fetcher, progresscb):
-        if self.type is None:
-            kernelpath = "images/pxeboot/vmlinuz"
-            initrdpath = "images/pxeboot/initrd.img"
-        else:
-            kernelpath = "images/%s/vmlinuz" % (self.type)
-            initrdpath = "images/%s/initrd.img" % (self.type)
+	if self.hasTreeinfo(fetcher, progresscb):
+            if self.type is None:
+		arch = self.treeinfo.get("general", "arch")
+            else:
+		arch = self.type
+
+    	    kernelpath = self.treeinfo.get("images-%s" % arch, "kernel")
+    	    initrdpath = self.treeinfo.get("images-%s" % arch, "initrd")
+	else:
+	    # fall back to old code
+            if self.type is None:
+	        kernelpath = "images/pxeboot/vmlinuz"
+    		initrdpath = "images/pxeboot/initrd.img"
+            else:
+        	kernelpath = "images/%s/vmlinuz" % (self.type)
+        	initrdpath = "images/%s/initrd.img" % (self.type)
 
         kernel = fetcher.acquireFile(kernelpath, progresscb)
         try:
@@ -70,40 +98,59 @@ class RedHatDistro(Distro):
             os.unlink(kernel)
 
     def acquireBootDisk(self, fetcher, progresscb):
-        return fetcher.acquireFile("images/boot.iso", progresscb)
+        if self.hasTreeinfo(fetcher, progresscb):
+	    arch = self.treeinfo.get("general", "arch")
+	    return fetcher.acquireFile(self.treeinfo.get("images-%s" % arch, "boot.iso"), progresscb)
+        else:
+    	    return fetcher.acquireFile("images/boot.iso", progresscb)
 
 # Fedora distro check
 class FedoraDistro(RedHatDistro):
     def isValidStore(self, fetcher, progresscb):
-        if fetcher.hasFile("fedora.css"):
-            logging.debug("Detected a Fedora distro")
-            return True
-        if fetcher.hasFile("Fedora"):
-            logging.debug("Detected a Fedora distro")
-            return True
-        return False
-
-# Fedora distro check
+	if self.hasTreeinfo(fetcher, progresscb):
+	    m = re.match(".*Fedora.*", self.treeinfo.get("general", "family"))
+	    return (m != None)
+	else:
+	    # fall back to old code
+    	    if fetcher.hasFile("fedora.css"):
+        	logging.debug("Detected a Fedora distro")
+        	return True
+    	    if fetcher.hasFile("Fedora"):
+        	logging.debug("Detected a Fedora distro")
+        	return True
+    	    return False
+
+# Red Hat Enterprise Linux distro check
 class RHELDistro(RedHatDistro):
     def isValidStore(self, fetcher, progresscb):
-        if fetcher.hasFile("Server"):
-            logging.debug("Detected a RHEL 5 Server distro")
-            return True
-        if fetcher.hasFile("Client"):
-            logging.debug("Detected a RHEL 5 Client distro")
-            return True
-        if fetcher.hasFile("RedHat"):
-            logging.debug("Detected a RHEL 4 distro")
-            return True
-        return False
+	if self.hasTreeinfo(fetcher, progresscb):
+	    m = re.match(".*Red Hat Enterprise Linux.*", self.treeinfo.get("general", "family"))
+	    return (m != None)
+	else:
+	    # fall back to old code
+    	    if fetcher.hasFile("Server"):
+        	logging.debug("Detected a RHEL 5 Server distro")
+        	return True
+    	    if fetcher.hasFile("Client"):
+        	logging.debug("Detected a RHEL 5 Client distro")
+        	return True
+    	    if fetcher.hasFile("RedHat"):
+        	logging.debug("Detected a RHEL 4 distro")
+        	return True
+    	    return False
 
 # CentOS distro check
 class CentOSDistro(RedHatDistro):
     def isValidStore(self, fetcher, progresscb):
-        if fetcher.hasFile("CentOS"):
-            logging.debug("Detected a CentOS distro")
-            return True
-        return False
+	if self.hasTreeinfo(fetcher, progresscb):
+	    m = re.match(".*CentOS.*", self.treeinfo.get("general", "family"))
+	    return (m != None)
+	else:
+	    # fall back to old code
+    	    if fetcher.hasFile("CentOS"):
+        	logging.debug("Detected a CentOS distro")
+        	return True
+    	    return False
 
 
 

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux