Change in vdsm[master]: kvmstream: tool for streaming images from libvirt

shavivi at redhat.com shavivi at redhat.com
Thu Apr 7 09:33:05 UTC 2016


Shahar Havivi has uploaded a new change for review.

Change subject: kvmstream: tool for streaming images from libvirt
......................................................................

kvmstream: tool for streaming images from libvirt

v2v is needed to a streaming/download tool for importing kvm based
images from Libvirt to vdsm.
for other such as xen and vmware virt-v2v provide the solution.
this tool mimic virt-v2v output in order to use it smoothly in v2v.py
module.

Change-Id: I9d95c3bf4b2605e71f899171259d4721204eb8e2
Signed-off-by: Shahar Havivi <shaharh at redhat.com>
---
A kvmstream.py
1 file changed, 96 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/97/55797/1

diff --git a/kvmstream.py b/kvmstream.py
new file mode 100755
index 0000000..4c793b8
--- /dev/null
+++ b/kvmstream.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+# Copyright 2016 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import argparse
+from itertools import izip
+import libvirt
+import sys
+
+
+elapsed_time = 0
+
+
+def parse_arguments():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('args')
+    parser.add_argument('-u', dest='uri',
+                        help='Libvirt URI')
+    parser.add_argument('-s', dest='source', nargs='+',
+                        help='Source remote volumes path')
+    parser.add_argument('-d', dest='dest', nargs='+',
+                        help='Destination local volumes path')
+    return parser.parse_args(sys.argv)
+
+
+def write_output(msg):
+    sys.stdout.write(msg)
+    sys.stdout.flush()
+
+
+def init_progres():
+    global elapsed_time
+    write_output('[   %d.0] Opening the source -i libvirt\n' % elapsed_time)
+    elapsed_time = elapsed_time + 1
+    write_output('[   %d.0] Creating an overlay to protect\n' % elapsed_time)
+    elapsed_time = elapsed_time + 1
+
+
+def finish_progress():
+    global elapsed_time
+    write_output('[ %d.0] Creating output metadata\n' % elapsed_time)
+    write_output('[ %d.0] Finishing off\n' % elapsed_time)
+
+
+def download_volume(stream, vol, dest, diskno, disks):
+    global elapsed_time
+    write_output('[  %d.0] Copying disk %d/%d to %s\n' %
+                 (elapsed_time, diskno, disks, dest))
+    size = vol.info()[2]
+    pos = 0
+    jump = size / 1024 / 99
+    f = open(dest, 'w')
+    vol.download(stream, 0, 0, 0)
+    write_output('    (0/100%%)\r')
+    counter = 0
+    while pos < size:
+        buf = s.recv(1024)
+        f.write(buf)
+        f.flush()
+        if not pos % jump:
+            counter = counter + 1
+            elapsed_time = elapsed_time + 1
+            write_output('    (%s/100%%)\r' % str(counter))
+        pos = pos + 1024
+    f.close()
+    write_output('    (100/100%%)\r')
+
+
+options = parse_arguments()
+con = libvirt.open(options.uri)
+
+diskno = 1
+disksitems = len(options.source)
+init_progres()
+for item in izip(options.source, options.dest):
+    vol = con.storageVolLookupByPath(item[0])
+    s = con.newStream()
+    download_volume(s, vol, item[1], diskno, disksitems)
+    diskno = diskno + 1
+finish_progress()


-- 
To view, visit https://gerrit.ovirt.org/55797
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d95c3bf4b2605e71f899171259d4721204eb8e2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Shahar Havivi <shavivi at redhat.com>


More information about the vdsm-patches mailing list