- Category: Development
- Published: Thursday, 21 October 2010 12:55
- Written by Burke Azbill
- Hits: 12280
When scripting workflows in VMware vCenter Orchestrator (vCO) it is often desirable to read or write to local files on the vCO server whether this is a .conf, .txt, .cmd, .bat, .xml, or any other text file. In order to do so, you must be sure to either work with files in a pre-approved folder or add your custom folder to a configuration file.
var tempFolder = System.getTempDirectory();
The default contents of the js-io-rights.conf file are as follows:
-rwx C:/ +rwx C:/orchestrator +rx ../../configuration/jetty/logs/ +rx ../server/vmo/log/ +rx ../bin/ +rx ./boot.properties +rx ../server/vmo/conf/ +rx ../server/vmo/conf/plugins/ +rx ../server/vmo/deploy/vmo-server/vmo-ds.xml +rx ../../apps/ +r ../../version.txt
So, based on the file contents above, without editing or restarting the service, if you update your script to write your text file to the c:\orchestrator folder (you will need to create this folder on your vCO server, the script should work.
Now, as a quick example, create a new workflow with a single scriptable task in it. Inside the scriptable task, insert the following code (I'm assuming a WINDOWS based vCO server here):
var fw = new FileWriter("c:/orchestrator/test.txt"); fw.open(); fw.write("Hello there, is this working?"); fw.close();
Save and close your worklow after validating.
Now try running it.
Check the C:/orchestrator folder and confirm there is now a test.txt file with the content specified in the script.
Hope this helps :)