Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imtrinity94/2f27e640f3c8f2ee2499622016cc2a91 to your computer and use it in GitHub Desktop.
Save imtrinity94/2f27e640f3c8f2ee2499622016cc2a91 to your computer and use it in GitHub Desktop.
Create a temporary text-based file on the vRO server, which can then be copied elsewhere like a guest vCenter VM
/**
*
* @module actions.mayank.goyal
* @name createTemporaryFileInVro
* @version 1.0.0
* @description Create a temporary text-based file, in a temporary directory, on the vRO server
* @param {string} fileContents
* @param {string} fileName
*
* @outputType string
*
*/
function createTemporaryFileInVro(fileContents, fileName) {
var tempDir = System.getTempDirectory();
vroTempFileFullPath = tempDir + "/" + fileName;
var writer;
try {
writer = new FileWriter(vroTempFileFullPath);
} catch (e) {
throw "Failed to create temp file in vRO server: " + vroTempFileFullPath + " :: " + e;
}
try {
writer.open();
} catch (e) {
throw "Failed to open temp file for editing in vRO server: " + vroTempFileFullPath + " :: " + e;
}
try {
writer.write(fileContents);
} catch (e) {
throw "Failed to write contents to temp file in vRO server: " + vroTempFileFullPath + " :: " + e;
}
try {
writer.close();
System.debug("Contents written to vRO temp file " + vroTempFileFullPath + " successfully.");
} catch (e) {
throw "Failed to close temp file after editing in vRO server: " + vroTempFileFullPath + " :: " + e;
}
return vroTempFileFullPath;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment