You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by wi...@apache.org on 2013/02/22 15:01:10 UTC
[58/58] [abbrv] git commit: refs/heads/qemu-img - Implement resizing
with a test
Updated Branches:
refs/heads/qemu-img 593b367b8 -> c08e1bd09
Implement resizing with a test
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/c08e1bd0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/c08e1bd0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/c08e1bd0
Branch: refs/heads/qemu-img
Commit: c08e1bd0966805b4d1906db1cb12711da7e0b703
Parents: 2fb400d
Author: Wido den Hollander <wi...@widodh.nl>
Authored: Fri Feb 22 15:00:38 2013 +0100
Committer: Wido den Hollander <wi...@widodh.nl>
Committed: Fri Feb 22 15:00:38 2013 +0100
----------------------------------------------------------------------
.../org/apache/cloudstack/utils/qemu/QemuImg.java | 40 +++++++++++++--
.../apache/cloudstack/utils/qemu/QemuImgTest.java | 25 +++++++++
2 files changed, 60 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c08e1bd0/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
----------------------------------------------------------------------
diff --git a/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java b/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
index 1d7f6d5..b838522 100644
--- a/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
+++ b/utils/src/org/apache/cloudstack/utils/qemu/QemuImg.java
@@ -290,15 +290,45 @@ public class QemuImg {
*
* @param file
* The file to resize
- * @param
+ * @param size
* The new size
+ * @param delta
+ * Flag if the new size is a delta
*/
- public void resize(String filename, long size) {
+ public void resize(QemuImgFile file, long size, boolean delta) {
String newSize = null;
- if (size > 0) {
- newSize = "+" + size;
+
+ if (delta) {
+ if (size > 0) {
+ newSize = "+" + Long.toString(size);
+ } else {
+ newSize = "-" + Long.toString(size);
+ }
} else {
- newSize = "-" + size;
+ newSize = Long.toString(size);
}
+
+ Script s = new Script(_qemuImgPath);
+ s.add("resize");
+ s.add(file.getFileName());
+ s.add(newSize);
+ s.execute();
+ }
+
+ /**
+ * Resize an image
+ *
+ * This method simple calls 'qemu-img resize'.
+ * A negative size value will get prefixed with - and a positive with +
+ *
+ * Sizes are in bytes and will be passed on that way
+ *
+ * @param file
+ * The file to resize
+ * @param size
+ * The new size
+ */
+ public void resize(QemuImgFile file, long size) {
+ this.resize(file, size, false);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c08e1bd0/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
----------------------------------------------------------------------
diff --git a/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java b/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
index 4bc43d4..2f0ca68 100644
--- a/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
+++ b/utils/test/org/apache/cloudstack/utils/qemu/QemuImgTest.java
@@ -84,6 +84,31 @@ public class QemuImgTest {
}
@Test
+ public void testCreateAndResize() {
+ String filename = "/tmp/test-resize-image.qcow2";
+
+ long startSize = 20480;
+ long endSize = 40960;
+ QemuImgFile file = new QemuImgFile(filename, startSize, PhysicalDiskFormat.QCOW2);
+
+ QemuImg qemu = new QemuImg();
+ qemu.create(file);
+ qemu.resize(file, endSize);
+ Map<String, String> info = qemu.info(file);
+
+ if (info == null) {
+ fail("We didn't get any information back from qemu-img");
+ }
+
+ Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
+ assertEquals(Long.valueOf(endSize), Long.valueOf(infoSize));
+
+ File f = new File(filename);
+ f.delete();
+
+ }
+
+ @Test
public void testConvertBasic() {
long srcSize = 20480;
String srcFileName = "/tmp/test-src-image.qcow2";