How can I write to files?

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.

For full details on the following information, please see page 64 of the vCenter Orchestrator Administration guide, section "Setting Server File System Access from Workflows and JavaScript". In order to read/write to files on your server, you must edit the js-io-rights.conf file and restart your vCO service. Otherwise, you must read/write to the temp folder or a folder that already has rights assigned. You can get the temp folder using the following:

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 :)

 

Search

Book Shelf

 
Experts Exchange

NUC Lab Kit

Below are my thoughts for a vSAN nuc lab. Since I already have cables, not including them here. I ordered (and received by Nov 30, 2016)
3 x nuc, 3 x 32GB Crucial mem, 3 x Toshiba NVMe drive, 3 x Startech USB to GB NIC, and 3 x Crucial 1TB SSD. I've also been very happy with my Cisco SG300-10 so I bought one more since my existing one only has one port available. Each of the items listed here are linked below - all were purchased using the provided links below.
single NIC (See this post for details on using the USB -> GB NIC item listed below

I stayed with the i5 for the power consumption and form factor vs. the i7 Skull Canyon ;)