2

I'd like to make calls to vagrant's API through a ruby program,like so:

puts Vagrant.constants  

How can i include vagrant at this level ? Am somewhat new to ruby, but I see there are a lot of libraries in vagrant, and am not sure what the common way to call such libraries or to include them recursively would be - maybe there is a dynamic way to include vagrant libraries into an application using the gem api ?

UPDATE : Vagrant doesnt support Gems ?

Some of the comments below have implied that maybe declaring vagrant as a Gem is a solution to this. however, when attempting to setup vagrant as a gemfile dependency, I noticed this error message:

enter image description here

Thus, I think there must be a better way to add vagrant as a ruby dependency, without resorting to a gem file.

Community
  • 1
  • 1
jayunit100
  • 16,490
  • 20
  • 83
  • 152
  • Did you install vagrant gem? – Oleksandr Verhun Oct 06 '14 at 17:09
  • gem installing vagrant leads to overwriting of some files, so i avoided doing this. after all, vagrant exists already on my system, can't i reference it from my ruby program using its existing paths? – jayunit100 Oct 06 '14 at 17:36
  • Ok, but I don't how it will overwrite them, in api you mean some server endpoints or you want to access vagrant from your machine? – Oleksandr Verhun Oct 06 '14 at 17:56
  • running "gem install vagrant " prompted "are you sure you want to overwrite /usr/bin/vagrant ?"... So I answered no . Thus "gem install" isn't the best way i think to add ruby based tests of vagrant related utilities - because it can perturb your existing vagrant installation. – jayunit100 2 hours ago – jayunit100 Oct 06 '14 at 21:11
  • Try to add vagrant gem to gemfile and then run bundle.See if that's gonna overwrite files. – Oleksandr Verhun Oct 07 '14 at 05:04
  • Thanks for the idea @OleksandrVerhun but vagrant doesnt support gem installation . Any other thoughts ? See above screenshot. – jayunit100 Oct 07 '14 at 17:01
  • Well I just don't understand, what kind of api vagrant has.But if you want to connect to some endpoints the idea is to make http requests to the following endpoints and then receive them as JSON or XML or something like that.For http request you can use - http://stackoverflow.com/questions/4581075/how-make-a-http-get-request-using-ruby-on-rails, for parsing JSON into hash there're many rails function json support, f.e. JSON.parse, for xml you can use nokogiri -> http://www.nokogiri.org/tutorials/. If you can provide some endpoints(api), I'll suggest a more accurate answer. – Oleksandr Verhun Oct 07 '14 at 18:08
  • I don't think rest apis are at all relevant here ... – jayunit100 Oct 08 '14 at 14:27
  • That's why I told to give me some directions(docs) to this API, so I can help you. – Oleksandr Verhun Oct 08 '14 at 15:09
  • @OleksandrVerhun thanks..! The vagrant tool is described at vagrantup.com. By API I simply meant accessing it's code programmatically - I'm not trying to use a particular end facing API – jayunit100 Oct 14 '14 at 17:59

0 Answers0