SWIFT : download container

This commit is contained in:
anthony 2011-12-23 17:16:50 -08:00
parent b2b653f7d4
commit a9f5e5f88a

View File

@ -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<String> files = new ArrayList<String>();