VMware Cloud Community
imtrinity94
Enthusiast
Enthusiast
Jump to solution

Access vRO Filesystem using Polyglot

Hi, I was wondering how to access the vRO getTempDirectory() equivalent while working with Python or NodeJS. Anyone has any idea on that or any workaround?

My end goal is to save a file that I am getting over GET and do a POST later.

NOTE: The marked correct answer is using the filesystem inside ZIP to read data and not write it, As it is read-only. That's the best i could find yet. Please let me know if you have some better ideas.


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
Labels (2)
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
imtrinity94
Enthusiast
Enthusiast
Jump to solution

I guess I was too quick to write that in my last comment and definitely ignorant. In reality, it's half truth. You are right, this is not writable at all. The filesystem inside is read-only.

However, luckily that suited my case. I had to send a package over REST and that package is static. So, i did this and it worked for me.

 

 

 

 

exports.handler = (context, inputs) => {
	const process = require('process');
	const request = require('request');
	const fs = require('fs');
	process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

	var options = {
	  'method': 'POST',
	  'url': 'https://vRO.fqdn/vco/api/packages',
	  'headers': {
		'Accept': 'application/xml',
		'Authorization': 'Basic eDIxMzgxNkB********DpNYXIjMjAyMw=='
	  },
	  formData: {
		'file': {
		  'value': fs.createReadStream('com.mayank.emptyPackage.package'),
		  'options': {
			'filename': 'com.mayank.emptyPackage.package',
			'contentType': null
		  }
		}
	  }
	};
	request(options, function (error, response) {
	  if (error) throw new Error(error);
	  console.log(response.body);
	});
}

 

 

 

inside the ZIP, I have added the package already and I am sending it over POST call.

imtrinity94_0-1677428705476.png

 

 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/

View solution in original post

4 Replies
imtrinity94
Enthusiast
Enthusiast
Jump to solution

I found a workaround. Instead of using Type=Script, use Type=Zip for Polyglot scripts (Python, NodeJS & PowerShell) and use the folder structure in that zip as your playground. 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
0 Kudos
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello Mayank,

very interesting approach, but in my case with Node,js it doesn't work. Can you publish your example please. Below my.

Thanks and best regards
Stefan

exports.handler = (context, inputs, callback) => {
  //console.log('Inputs were ' + JSON.stringify(inputs));
  try {
    var fs = require("fs");

    fs.writeFileSync(__dirname + "/temp/helloWorld.txt", "Hello World");

    var fileContent = fs.readFileSync(__dirname + "/temp/helloWorld.txt", "utf8");
    console.log(fileContent);

  } catch(exception) {
    console.log("An error occurred");
    console.log(exception);
  }

  callback(undefined, {status: "done"});
}

 

StefanSchnell_0-1677343168620.png

StefanSchnell_1-1677343494162.png

 


More interesting information at blog.stschnell.de

0 Kudos
imtrinity94
Enthusiast
Enthusiast
Jump to solution

I guess I was too quick to write that in my last comment and definitely ignorant. In reality, it's half truth. You are right, this is not writable at all. The filesystem inside is read-only.

However, luckily that suited my case. I had to send a package over REST and that package is static. So, i did this and it worked for me.

 

 

 

 

exports.handler = (context, inputs) => {
	const process = require('process');
	const request = require('request');
	const fs = require('fs');
	process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

	var options = {
	  'method': 'POST',
	  'url': 'https://vRO.fqdn/vco/api/packages',
	  'headers': {
		'Accept': 'application/xml',
		'Authorization': 'Basic eDIxMzgxNkB********DpNYXIjMjAyMw=='
	  },
	  formData: {
		'file': {
		  'value': fs.createReadStream('com.mayank.emptyPackage.package'),
		  'options': {
			'filename': 'com.mayank.emptyPackage.package',
			'contentType': null
		  }
		}
	  }
	};
	request(options, function (error, response) {
	  if (error) throw new Error(error);
	  console.log(response.body);
	});
}

 

 

 

inside the ZIP, I have added the package already and I am sending it over POST call.

imtrinity94_0-1677428705476.png

 

 


Mayank Goyal
vRO Engineer
https://www.linkedin.com/in/mayankgoyal1994/
https://cloudblogger.co.in/
StefanSchnell
Enthusiast
Enthusiast
Jump to solution

Hello Mayank,

thank you very much for sharing your source.

Best regards
Stefan


More interesting information at blog.stschnell.de

0 Kudos