Best way to call Powershell from Sinatra

I am wanting to use Sinatra to create a REST web service that will
execute Powershell (PowerCLI for VMware) on the back end. The Rest API
will accept JSON which will then be used to make connections to
specified vsphere servers and do things like clone VMs, add memory, CPU,
disk, NIC.

The PowerCLI code is already written, I just need the web service to
call the code and pass the paramters (JSON). I am not sure if it’s best
to put the PowerCLI code in the web service and call it as exec
(interpolation hell) or to have Sinatra just call the powershell scripts
and pass the JSON that way.

Anything else I’m missing? (Yes I’m aware of rbvmomi)

May be you can just shell out? Remember that if your Powershell script
will fall apart and you use something that directly use that code, your
web service will fall apart. By shelling out you add a layer of
isolation.

I would use some sort of delayed jobs to make the call asynchronous.
When you have something running in the background you should not make a
sync call, the web page or API call response should be quick. Ths
GitHub - brandonhilkert/sucker_punch: Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday. could be an option if you
do not want to use a DB for the background jobs.

Concluding that’s how I would do it:

sinatra → sucker_punch → external script → collect STDOUT in
sucker_punch → get result in sinatra