VMware Cloud Community
BillStreet00
Enthusiast
Enthusiast

Reading a CSV file into an array

Trying to read a CSV file that is stored on a local file W2K12 server.  The share and file has read access for everyone but I still get a read permission error.  Below is the code I started to use and the error.  Has anyone had success with this in the past?

[2017-11-09 12:56:20.085] [E] Permission denied on file '/xxxxx/scripts$/vminfo.csv' , read not allowed

[2017-11-09 12:56:20.090] [E] Workflow execution stack:

***

item: 'Read in a CSV and convert to objects/item1', state: 'failed', business state: 'null', exception: 'Permission denied on file '/xxxxxx/scripts$/vminfo.csv' , read not allowed'

workflow: 'Read in a CSV and convert to objects' (13735c32-bdad-42bf-b577-09e2cfd104e9)

|  'no inputs'

|  'no outputs'

|  'no attributes'

*** End of execution stack.

Code

var fileReader = new FileReader("//xxxxxx/scripts$/vminfo.csv") ;

fileReader.open() ;

var fileContentAsString = fileReader.readAll();

fileReader.close() ;

0 Kudos
6 Replies
filosmith
Enthusiast
Enthusiast

This post seems to imply that it can't be done directly, but you can mount it manually on your vco appliance and then access it as a local file. https://www.vcoteam.info/articles/learn-vco/278-how-to-allow-the-vco-appliance-to-write-files-to-a-w...

0 Kudos
BillStreet00
Enthusiast
Enthusiast

I found that as well.  I was hoping to avoid that method but I may not be able.

0 Kudos
BillStreet00
Enthusiast
Enthusiast

Can't even mount the share per the link.  I keep getting "not a directory" when running the export logs workflow.

0 Kudos
iiliev
VMware Employee
VMware Employee

You mean the workflow "Export logs and configuration settings"?

It is deprecated and removed in the latest vRO builds. It uses relative paths that are not valid anymore, so the workflow should not be used. Instead, you can export the logs using vRO Control Center.

0 Kudos
BillStreet00
Enthusiast
Enthusiast

Not actually trying to export logs.  I am trying to mount a windows share on the vRO appliance to allow our Ops team the ability to quickly update CSV files and run WorkFlows against them.

0 Kudos
jasnyder
Hot Shot
Hot Shot

A plausible alternative might be to post the CSV to a web server (IIS) and grab it using HTTP GET from vRO?

Sample script for doing that (takes one input - url of type string; sorry for the super simple CSV Parsing implementation that I threw together in 5 minutes - assumes the happy path):

var urlObject = new URL(url);

var csvFile = urlObject.getContent();

System.log(csvFile);

var lines = csvFile.replace("\r","").split("\n") //strip out carriage returns in case this is Windows

var headerLine = lines[0];

var headerFields = headerLine.split(",");

var objects = new Array();

for(var l in lines)

{

    if(l > 0)

    {

        var line = lines[l];

        var columns = line.split(",");

       

        objects[l - 1] = {};

       

        for(var h in headerFields)

        {

            var curHeader = headerFields[h];

            objects[l - 1][curHeader] = columns[h];

        }

    }

}

System.log(JSON.stringify(objects));

Sample output from a GET to http://[webserver]/csvfile.csv:

[2017-11-15 17:55:04.523] [I] firstname,lastname,middleinitial,age

John,Doe,B,30

Jane,Doe,H,32

Jimmy,Dean,L,29

[2017-11-15 17:55:04.530] [I] [{"firstname":"John","lastname":"Doe","middleinitial":"B","age":"30"},{"firstname":"Jane","lastname":"Doe","middleinitial":"H","age":"32"},{"firstname":"Jimmy","lastname":"Dean","middleinitial":"L","age":"29"}]

Understanding that HTTP Get is unsecured and maybe you want some security... you could password protect the web site and pass basic authentication over HTTPS.

Or you could install NFS on windows and expose the file share using NFS services, then mount it to the vRO server.  Instructions for installing NFS on Windows 2012 - Deploy Network File System

0 Kudos