diff --git a/core/src/com/cloud/agent/api/SecStorageSetupCommand.java b/core/src/com/cloud/agent/api/SecStorageSetupCommand.java index 2c29cdeeda2..28e55c2f4ef 100644 --- a/core/src/com/cloud/agent/api/SecStorageSetupCommand.java +++ b/core/src/com/cloud/agent/api/SecStorageSetupCommand.java @@ -27,6 +27,7 @@ public class SecStorageSetupCommand extends Command { private DataStoreTO store; private String secUrl; private KeystoreManager.Certificates certs; + private String postUploadKey; public SecStorageSetupCommand() { @@ -66,4 +67,11 @@ public class SecStorageSetupCommand extends Command { this.store = store; } + public String getPostUploadKey() { + return postUploadKey; + } + + public void setPostUploadKey(String postUploadKey) { + this.postUploadKey = postUploadKey; + } } diff --git a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java index 3ba4242e0d3..79a14864b7f 100755 --- a/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java +++ b/services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java @@ -310,6 +310,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar setupCmd = new SecStorageSetupCommand(ssStore.getTO(), secUrl, certs); } + //template/volume file upload key + String postUploadKey = _configDao.getValue(Config.SSVMPSK.key()); + setupCmd.setPostUploadKey(postUploadKey); + Answer answer = _agentMgr.easySend(ssHostId, setupCmd); if (answer != null && answer.getResult()) { SecStorageSetupAnswer an = (SecStorageSetupAnswer)answer; diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java index 55f80e16c75..54c36303342 100755 --- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java +++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java @@ -47,6 +47,7 @@ import java.util.UUID; import javax.naming.ConfigurationException; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -1264,6 +1265,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S if (!_inSystemVM) { return new Answer(cmd, true, null); } + Answer answer = null; DataStoreTO dStore = cmd.getDataStore(); if (dStore instanceof NfsTO) { String secUrl = cmd.getSecUrl(); @@ -1277,17 +1279,28 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S configCerts(cmd.getCerts()); nfsIps.add(nfsHostIp); - return new SecStorageSetupAnswer(dir); + answer = new SecStorageSetupAnswer(dir); } catch (Exception e) { String msg = "GetRootDir for " + secUrl + " failed due to " + e.toString(); s_logger.error(msg); - return new Answer(cmd, false, msg); + answer = new Answer(cmd, false, msg); } } else { // TODO: what do we need to setup for S3/Swift, maybe need to mount // to some cache storage - return new Answer(cmd, true, null); + answer = new Answer(cmd, true, null); + } + + savePostUploadPSK(cmd.getPostUploadKey()); + return answer; + } + + private void savePostUploadPSK(String psk) { + try { + FileUtils.writeStringToFile(new File("/etc/cloudstack/agent/ms-psk"),psk, "utf-8"); + } catch (IOException ex) { + s_logger.debug("Failed to copy PSK to the file.", ex); } }