diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java index 7ce5e212a8a..8ea82e1d3a0 100755 --- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java +++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java @@ -177,7 +177,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S try { String parent = getRootDir(secondaryStorageUrl); String lPath = parent + "/template/tmpl/" + accountId.toString() + "/" + templateId.toString(); - String result = swiftDownload(swift, "T-" + templateId.toString(), "", lPath); + String result = swiftDownloadContainer(swift, "T-" + templateId.toString(), lPath); if (result != null) { String errMsg = "failed to download template from Swift to secondary storage " + lPath + " , err=" + result; s_logger.warn(errMsg); @@ -268,6 +268,32 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S } + String swiftDownloadContainer(SwiftTO swift, String container, String ldir) { + Script command = new Script("/bin/bash", s_logger); + command.add("-c"); + command.add("cd " + ldir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K " + + swift.getKey() + " download " + container); + OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser(); + String result = command.execute(parser); + if (result != null) { + String errMsg = "swiftDownloadContainer failed err=" + result; + s_logger.warn(errMsg); + return errMsg; + } + if (parser.getLines() != null) { + String[] lines = parser.getLines().split("\\n"); + for (String line : lines) { + if (line.contains("Errno") || line.contains("failed")) { + String errMsg = "swiftDownloadContainer failed , err=" + lines.toString(); + s_logger.warn(errMsg); + return errMsg; + } + } + } + return null; + + } + String swiftUpload(SwiftTO swift, String container, String lDir, String lFilename) { long SWIFT_MAX_SIZE = 5L * 1024L * 1024L * 1024L; List files = new ArrayList();