Skip to content

Commit 3eb9631

Browse files
committed
Support xz format for template registration
1 parent b09f3e8 commit 3eb9631

File tree

7 files changed

+19
-6
lines changed

7 files changed

+19
-6
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ public KVMPhysicalDisk createDiskFromTemplateBacking(KVMPhysicalDisk template, S
178178
*/
179179
public static boolean isTemplateExtractable(String templatePath) {
180180
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
181-
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
181+
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
182+
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
182183
}
183184

184185
/**
@@ -193,6 +194,8 @@ public static String getExtractCommandForDownloadedFile(String downloadedTemplat
193194
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateUuid;
194195
} else if (downloadedTemplateFile.endsWith(".gz")) {
195196
return "gunzip -c " + downloadedTemplateFile + " > " + templateUuid;
197+
} else if (downloadedTemplateFile.endsWith(".xz")) {
198+
return "xz -d -c " + downloadedTemplateFile + " > " + templateUuid;
196199
} else {
197200
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
198201
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/MultipathSCSIAdapterBase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
426426
boolean isTemplateExtractable(String templatePath) {
427427
ScriptResult result = runScript("file", 5000L, templatePath, "| awk -F' ' '{print $2}'");
428428
String type = result.getResult();
429-
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
429+
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
430+
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
430431
}
431432

432433
String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {
@@ -436,6 +437,8 @@ String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String
436437
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;
437438
} else if (downloadedTemplateFile.endsWith(".gz")) {
438439
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;
440+
} else if (downloadedTemplateFile.endsWith(".xz")) {
441+
return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
439442
} else {
440443
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
441444
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP
613613

614614
private boolean isTemplateExtractable(String templatePath) {
615615
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
616-
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
616+
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
617+
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
617618
}
618619

619620
private String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {
@@ -623,6 +624,8 @@ private String getExtractCommandForDownloadedFile(String downloadedTemplateFile,
623624
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;
624625
} else if (downloadedTemplateFile.endsWith(".gz")) {
625626
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;
627+
} else if (downloadedTemplateFile.endsWith(".xz")) {
628+
return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
626629
} else {
627630
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
628631
}

plugins/storage/volume/storpool/src/main/java/com/cloud/hypervisor/kvm/storage/StorPoolStorageAdaptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,8 @@ private String extractTemplate(String templateFilePath, File sourceFile, String
539539

540540
private boolean isTemplateExtractable(String templatePath) {
541541
String type = Script.runSimpleBashScript("file " + templatePath + " | awk -F' ' '{print $2}'");
542-
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip") || type.equalsIgnoreCase("zip");
542+
return type.equalsIgnoreCase("bzip2") || type.equalsIgnoreCase("gzip")
543+
|| type.equalsIgnoreCase("zip") || type.equalsIgnoreCase("xz");
543544
}
544545

545546
private String getExtractCommandForDownloadedFile(String downloadedTemplateFile, String templateFile) {
@@ -549,6 +550,8 @@ private String getExtractCommandForDownloadedFile(String downloadedTemplateFile,
549550
return "bunzip2 -c " + downloadedTemplateFile + " > " + templateFile;
550551
} else if (downloadedTemplateFile.endsWith(".gz")) {
551552
return "gunzip -c " + downloadedTemplateFile + " > " + templateFile;
553+
} else if (downloadedTemplateFile.endsWith(".xz")) {
554+
return "xz -d -c " + downloadedTemplateFile + " > " + templateFile;
552555
} else {
553556
throw new CloudRuntimeException("Unable to extract template " + downloadedTemplateFile);
554557
}

utils/src/main/java/com/cloud/utils/UriUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public static List<String> getMetalinkUrls(String metalinkUrl) {
431431
return urls;
432432
}
433433

434-
public static final Set<String> COMPRESSION_FORMATS = ImmutableSet.of("zip", "bz2", "gz");
434+
public static final Set<String> COMPRESSION_FORMATS = ImmutableSet.of("zip", "bz2", "gz", "xz");
435435

436436
public static final Set<String> buildExtensionSet(boolean metalink, String... baseExtensions) {
437437
final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

utils/src/test/java/com/cloud/utils/UriUtilsParametrizedTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface ThrowingBlock<E extends Exception> {
4444
}
4545

4646
private static final Set<String> COMMPRESSION_FORMATS = ImmutableSet.of("",".zip", ".bz2", ".gz");
47-
private static final Set<String> ILLEGAL_COMMPRESSION_FORMATS = ImmutableSet.of(".7z", ".xz");
47+
private static final Set<String> ILLEGAL_COMMPRESSION_FORMATS = ImmutableSet.of(".7z");
4848
private final static Set<String> FORMATS = ImmutableSet.of(
4949
"vhd",
5050
"vhdx",

utils/src/test/java/com/cloud/utils/UriUtilsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public void testIsUrlForCompressedFile() {
271271
Assert.assertTrue(UriUtils.isUrlForCompressedFile("https://abc.com/xyz.bz2"));
272272
Assert.assertTrue(UriUtils.isUrlForCompressedFile("http://abc.com/xyz.zip"));
273273
Assert.assertTrue(UriUtils.isUrlForCompressedFile("https://abc.com/xyz.gz"));
274+
Assert.assertTrue(UriUtils.isUrlForCompressedFile("http://abc.com/xyz.xz"));
274275
Assert.assertFalse(UriUtils.isUrlForCompressedFile("http://abc.com/xyz.qcow2"));
275276
}
276277

0 commit comments

Comments
 (0)