mirror of https://github.com/apache/cloudstack.git
Remove "--output" option from qemu-img info command call
since the option is not supported by qemu-img in CentOS 6.3
This commit is contained in:
parent
388210c8f9
commit
e7392cdac6
|
|
@ -674,8 +674,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
|||
PhysicalDiskFormat format, Storage.ProvisioningType provisioningType, long size) {
|
||||
String volPath = pool.getLocalPath() + "/" + name;
|
||||
String volName = name;
|
||||
long volAllocation = 0;
|
||||
long volCapacity = 0;
|
||||
long virtualSize = 0;
|
||||
long actualSize = 0;
|
||||
|
||||
final int timeout = 0;
|
||||
|
||||
|
|
@ -691,8 +691,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
|||
try{
|
||||
qemu.create(destFile, options);
|
||||
Map<String, String> info = qemu.info(destFile);
|
||||
volAllocation = Long.parseLong(info.get(new String("virtual-size")));
|
||||
volCapacity = Long.parseLong(info.get(new String("actual-size")));
|
||||
virtualSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
actualSize = new File(destFile.getFileName()).length();
|
||||
} catch (QemuImgException e) {
|
||||
s_logger.error("Failed to create " + volPath +
|
||||
" due to a failed executing of qemu-img: " + e.getMessage());
|
||||
|
|
@ -700,8 +700,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
|||
|
||||
KVMPhysicalDisk disk = new KVMPhysicalDisk(volPath, volName, pool);
|
||||
disk.setFormat(format);
|
||||
disk.setSize(volAllocation);
|
||||
disk.setVirtualSize(volCapacity);
|
||||
disk.setSize(actualSize);
|
||||
disk.setVirtualSize(virtualSize);
|
||||
return disk;
|
||||
}
|
||||
|
||||
|
|
@ -1189,7 +1189,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
|||
srcFile = new QemuImgFile(sourcePath, sourceFormat);
|
||||
try {
|
||||
Map<String, String> info = qemu.info(srcFile);
|
||||
String backingFile = info.get(new String("backing-file"));
|
||||
String backingFile = info.get(new String("backing_file"));
|
||||
// qcow2 templates can just be copied into place
|
||||
if (sourceFormat.equals(destFormat) && backingFile == null && sourcePath.endsWith(".qcow2")) {
|
||||
String result = Script.runSimpleBashScript("cp -f " + sourcePath + " " + destPath, timeout);
|
||||
|
|
|
|||
|
|
@ -16,16 +16,13 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.utils.qemu;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.cloud.storage.Storage;
|
||||
|
||||
import com.cloud.utils.script.Script;
|
||||
import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
public class QemuImg {
|
||||
|
||||
|
|
@ -285,9 +282,9 @@ public class QemuImg {
|
|||
* Qemu-img returns human readable output, but this method does it's best
|
||||
* to turn that into machine readeable data.
|
||||
*
|
||||
* Spaces in keys are replaced by hyphen-minus (-).
|
||||
* Sizes (virtual-size and disk-size) are returned in bytes
|
||||
* Paths (image and backing-file) are the absolute path to the file
|
||||
* Spaces in keys are replaced by underscores (_).
|
||||
* Sizes (virtual_size and disk_size) are returned in bytes
|
||||
* Paths (image and backing_file) are the absolute path to the file
|
||||
*
|
||||
* @param file
|
||||
* A QemuImgFile object containing the file to get the information from
|
||||
|
|
@ -296,8 +293,6 @@ public class QemuImg {
|
|||
public Map<String, String> info(QemuImgFile file) throws QemuImgException {
|
||||
Script s = new Script(_qemuImgPath);
|
||||
s.add("info");
|
||||
s.add("--output");
|
||||
s.add("json");
|
||||
s.add(file.getFileName());
|
||||
OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
|
||||
String result = s.execute(parser);
|
||||
|
|
@ -305,9 +300,24 @@ public class QemuImg {
|
|||
throw new QemuImgException(result);
|
||||
}
|
||||
|
||||
Type stringStringMap = new TypeToken<Map<String, String>>(){}.getType();
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(parser.getLines(), stringStringMap);
|
||||
HashMap<String, String> info = new HashMap<String, String>();
|
||||
String[] outputBuffer = parser.getLines().trim().split("\n");
|
||||
for (int i = 0; i < outputBuffer.length; i++) {
|
||||
String[] lineBuffer = outputBuffer[i].split(":", 2);
|
||||
if (lineBuffer.length == 2) {
|
||||
String key = lineBuffer[0].trim().replace(" ", "_");
|
||||
String value = null;
|
||||
|
||||
if (key.equals("virtual_size")) {
|
||||
value = lineBuffer[1].trim().replaceAll("^.*\\(([0-9]+).*$", "$1");
|
||||
} else {
|
||||
value = lineBuffer[1].trim();
|
||||
}
|
||||
|
||||
info.put(key, value);
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
/* List, apply, create or delete snapshots in image */
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class QemuImgTest {
|
|||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
assertEquals(Long.valueOf(size), Long.valueOf(infoSize));
|
||||
|
||||
String infoPath = info.get(new String("image"));
|
||||
|
|
@ -78,13 +78,13 @@ public class QemuImgTest {
|
|||
qemu.create(file, options);
|
||||
Map<String, String> info = qemu.info(file);
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
assertEquals(Long.valueOf(size), Long.valueOf(infoSize));
|
||||
|
||||
String infoPath = info.get(new String("image"));
|
||||
assertEquals(filename, infoPath);
|
||||
|
||||
String infoClusterSize = info.get(new String("cluster-size"));
|
||||
String infoClusterSize = info.get(new String("cluster_size"));
|
||||
assertEquals(clusterSize, infoClusterSize);
|
||||
|
||||
File f = new File(filename);
|
||||
|
|
@ -135,7 +135,7 @@ public class QemuImgTest {
|
|||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
assertEquals(Long.valueOf(endSize), Long.valueOf(infoSize));
|
||||
} catch (QemuImgException e) {
|
||||
fail(e.getMessage());
|
||||
|
|
@ -164,7 +164,7 @@ public class QemuImgTest {
|
|||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
|
||||
} catch (QemuImgException e) {
|
||||
fail(e.getMessage());
|
||||
|
|
@ -192,7 +192,7 @@ public class QemuImgTest {
|
|||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
|
||||
} catch (QemuImgException e) {
|
||||
fail(e.getMessage());
|
||||
|
|
@ -255,7 +255,7 @@ public class QemuImgTest {
|
|||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
String backingFile = info.get(new String("backing-file"));
|
||||
String backingFile = info.get(new String("backing_file"));
|
||||
if (backingFile == null) {
|
||||
fail("The second file does not have a property backing_file! Create failed?");
|
||||
}
|
||||
|
|
@ -306,7 +306,7 @@ public class QemuImgTest {
|
|||
PhysicalDiskFormat infoFormat = PhysicalDiskFormat.valueOf(info.get(new String("format")).toUpperCase());
|
||||
assertEquals(destFormat, infoFormat);
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual-size")));
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
assertEquals(Long.valueOf(srcSize), Long.valueOf(infoSize));
|
||||
|
||||
File sf = new File(srcFileName);
|
||||
|
|
|
|||
Loading…
Reference in New Issue