client/tools/rhn-virtualization/actions/image.py | 35
++++++----
client/tools/rhn-virtualization/scripts/studio-kvm-template.xml | 2
java/code/src/com/redhat/rhn/frontend/action/renderers/ImagesRenderer.java | 2
3 files changed, 25 insertions(+), 14 deletions(-)
New commits:
commit 03f3464b9949baf8702b629fc2fc9fcc09f523af
Author: Johannes Renner <jrenner(a)suse.de>
Date: Mon Jan 7 16:58:34 2013 +0100
Make images of type 'kvm' show up on the UI
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 =
commit d176ad856a85a39c834c47147c3c5f3206cb33eb
Author: Michael Calmer <mc(a)suse.de>
Date: Tue Jan 29 15:21:22 2013 +0100
support studio KVM image type
diff --git a/client/tools/rhn-virtualization/actions/image.py
b/client/tools/rhn-virtualization/actions/image.py
index 4a81707..499acfc 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'/>