Hello,

Attached please find two patches enhancing the integration with SUSE Studio.
They introduced a new image format last year that we are supporting now
(native KVM, i.e. qcow2). See here:

http://blog.susestudio.com/2012/10/kvm-build-format-suse-cloud-support.html

Best Regards,
Johannes

-- 
SUSE LINUX Products GmbH, HRB 16746 (AG Nürnberg)
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer
>From 652f1fdac22834021235829434f53c48759dba3e Mon Sep 17 00:00:00 2001
From: Michael Calmer <m...@suse.de>
Date: Tue, 29 Jan 2013 15:21:22 +0100
Subject: [PATCH] support studio KVM image type

---
 client/tools/rhn-virtualization/actions/image.py   |   35 +++++++++++++-------
 .../scripts/studio-kvm-template.xml                |    2 +-
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/client/tools/rhn-virtualization/actions/image.py b/client/tools/rhn-virtualization/actions/image.py
index e5527e3..407144b 100644
--- a/client/tools/rhn-virtualization/actions/image.py
+++ b/client/tools/rhn-virtualization/actions/image.py
@@ -7,10 +7,12 @@ import os
 import pycurl
 import re
 import sys
+import shutil
 
 sys.path.append("/usr/share/rhn/")
 import virtualization.support as virt_support
 from virtualization.util import generate_uuid
+from virtualization.errors import VirtualizationException
 from up2date_client import up2dateLog
 
 log = up2dateLog.initLog()
@@ -69,14 +71,14 @@ def _connect_to_hypervisor():
     try:
         import libvirt
     except ImportError, ie:
-        raise VirtLibNotFoundException, \
+        raise VirtualizationException, \
               "Unable to locate libvirt: %s" % str(ie)
 
     # Attempt to connect to the hypervisor.
     try:
         connection = libvirt.open(None)
     except Exception, e:
-        raise VirtualizationKickstartException, \
+        raise VirtualizationException, \
               "Could not connect to hypervisor: %s" % str(e)
 
     return connection
@@ -85,7 +87,7 @@ def _connect_to_hypervisor():
 # this is not nice but tarfile.py does not support
 # sparse file writing :(
 #
-def _extractImage( source, dest ):
+def _extractImage( source, dest, imageType ):
     param = "xf"
     if not os.path.exists( source ):
         log.log_debug("source file not found: %s" % source)
@@ -100,12 +102,16 @@ def _extractImage( source, dest ):
     elif( source.endswith("bz2") ):
         param = param + "j"
 
-    # skip the root directory in the tar - extract only the image files
-    cmd = "tar %s %s -C %s --strip-components=1" % ( param, source, dest )
-    log.log_debug(cmd)
-    if os.system( cmd ) != 0:
-        log.log_debug( "%s failed" % cmd )
-        raise Exception("%s failed" % cmd)
+    if imageType == 'qcow2':
+        log.log_debug(2, "copy %s to %s" %(source, dest))
+        shutil.copy2(source, dest)
+    else:
+        # skip the root directory in the tar - extract only the image files
+        cmd = "tar %s %s -C %s --strip-components=1" % ( param, source, dest )
+        log.log_debug(cmd)
+        if os.system( cmd ) != 0:
+            log.log_debug( "%s failed" % cmd )
+            raise Exception("%s failed" % cmd)
 
     return 0
 
@@ -185,7 +191,7 @@ def deploy(params, extraParams="",cache_only=None):
 
     # studioArchiveFileName = workshop_test_sles11sp1.i686-0.0.1.vmx.tar.gz
     # studioArchiveFileName = Just_enough_OS_openSUSE_12.1.x86_64-0.0.1.xen.tar.gz
-    m = re.search( '(.*)\.(x86_64|i\d86)-(\d+\.\d+\.\d+)\.(xen|vmx)', studioArchiveFileName )
+    m = re.search( '(.*)\.(x86_64|i\d86)-(\d+\.\d+\.\d+)\.(xen|vmx|qcow2)', studioArchiveFileName )
 
     imageName    = m.group(1)
     imageArch    = m.group(2)
@@ -193,7 +199,10 @@ def deploy(params, extraParams="",cache_only=None):
     imageType    = m.group(4)
     studioImageDiskFileName = imageName+"."+imageArch+"-"+imageVersion
 
-    connection = _connect_to_hypervisor()
+    try:
+        connection = _connect_to_hypervisor()
+    except Exception, e:
+        return (1, "%s" % e, {})
 
     # if we got an explicit name, we'll use it
     if params.has_key("domainName") and params["domainName"] != "":
@@ -225,7 +234,7 @@ def deploy(params, extraParams="",cache_only=None):
         return (0, "image fetched and cached for later deployment", {})
     try:
         targetDir = _createTargetDir( "%s/%s" % (IMAGE_BASE_PATH, imageName) )
-        _extractImage( "%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), targetDir )
+        _extractImage( "%s/%s" % (IMAGE_BASE_PATH,studioArchiveFileName), targetDir, imageType )
     except Exception, e:
         return (1, "extracting the image tarball failed with: %s" % e, {})
 
@@ -236,6 +245,8 @@ def deploy(params, extraParams="",cache_only=None):
     studioFileExtension = "vmdk"
     if imageType == "xen":
         studioFileExtension = "raw"
+    elif imageType == "qcow2":
+        studioFileExtension = "qcow2"
     extractedImagePath = "%s/%s.%s" % (targetDir,studioImageDiskFileName,studioFileExtension)
     log.log_debug("working on image in %s" % extractedImagePath)
     if not os.path.exists( extractedImagePath ):
diff --git a/client/tools/rhn-virtualization/scripts/studio-kvm-template.xml b/client/tools/rhn-virtualization/scripts/studio-kvm-template.xml
index 42ac7dd..73d7797 100644
--- a/client/tools/rhn-virtualization/scripts/studio-kvm-template.xml
+++ b/client/tools/rhn-virtualization/scripts/studio-kvm-template.xml
@@ -14,7 +14,7 @@
   <devices>
     <emulator>/usr/bin/qemu-kvm</emulator>
     <disk type='file' device='disk'>
-      <driver name='qemu' type='vmdk'/>
+      <driver name='qemu' type='%(imageType)s'/>
       <source file='%(disk)s'/>
       <target dev='hda' bus='ide'/>
       <address type='drive' controller='0' bus='0' unit='0'/>
-- 
1.7.10.4

>From df03b174f5b3f4c55d1868ee9f9c44686cdee66c Mon Sep 17 00:00:00 2001
From: Johannes Renner <jren...@suse.de>
Date: Mon, 7 Jan 2013 16:58:34 +0100
Subject: [PATCH] Make images of type 'kvm' show up on the UI

---
 .../src/com/redhat/rhn/frontend/action/renderers/ImagesRenderer.java |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/java/code/src/com/redhat/rhn/frontend/action/renderers/ImagesRenderer.java b/java/code/src/com/redhat/rhn/frontend/action/renderers/ImagesRenderer.java
index 45eb4e8..dea77e7 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/renderers/ImagesRenderer.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/renderers/ImagesRenderer.java
@@ -49,7 +49,7 @@ public class ImagesRenderer extends BaseFragmentRenderer {
     public static final String ATTRIB_ERROR_MSG = "errorMsg";
 
     // List of all valid image types
-    private static List<String> validImageTypes = Arrays.asList("vmx", "xen");
+    private static List<String> validImageTypes = Arrays.asList("kvm", "vmx", "xen");
 
     // The URL of the page to render
     private static final String PAGE_URL =
-- 
1.7.10.4

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to