From 86e1792775578f850e597f0f4c7b85ea7b88cf34 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Sat, 17 Sep 2016 16:20:28 -0700 Subject: [PATCH] Cleanup readme, add example projects --- README.md | 72 +++++-------------------------------------------------- 1 file changed, 6 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 65d4322..4c86ad6 100644 --- a/README.md +++ b/README.md @@ -94,71 +94,11 @@ This cli tool uses the [vmpooler API](https://github.com/puppetlabs/vmpooler/blo ## Using the Pooler class -An example of an application using vmfloaty as a library can be seen in [vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler). +vmfloaty providers a `Pooler` class that gives users the ability to make requests to vmpooler without having to write their own requests. It also provides an `Auth` class for managing vmpooler tokens within your application. -### Scripting +### Example Projects -If you want to write some ruby scripts around the vmpooler api, vmfloaty provides a `Pooler` and `Auth` class to make things easier. The ruby script below shows off an example of a script that gets a token, grabs a vm, runs some commands through ssh, and then destroys the vm. - -```ruby -require 'vmfloaty/pooler' -require 'vmfloaty/auth' -require 'io/console' -require 'net/ssh' - -def aquire_token(verbose, url) - STDOUT.flush - puts "Enter username:" - user = $stdin.gets.chomp - puts "Enter password:" - password = STDIN.noecho(&:gets).chomp - token = Auth.get_token(verbose, url, user, password) - - puts "Your token:\n#{token}" - token -end - -def grab_vms(os_string, token, url, verbose) - response_body = Pooler.retrieve(verbose, os_string, token, url) - - if response_body['ok'] == false - STDERR.puts "There was a problem with your request" - exit 1 - end - - response_body[os_string] -end - -def run_puppet_on_host(hostname) - STDOUT.flush - puts "Enter 'root' password for vm:" - password = STDIN.noecho(&:gets).chomp - user = 'root' - # run puppet - run_puppet = "/opt/puppetlabs/puppet/bin/puppet agent -t" - - begin - ssh = Net::SSH.start(hostname, user, :password => password) - output = ssh.exec!(run_puppet) - puts output - ssh.close - rescue - STDERR.puts "Unable to connect to #{hostname} using #{user}" - exit 1 - end -end - -if __FILE__ == $0 - verbose = true - url = 'https://vmpooler.mycompany.net/api/v1' - token = aquire_token(verbose, url) - os = ARGV[0] - - hostname = grab_vm(os, token, url, verbose) - run_puppet_on_host(hostname) -end -``` - -``` -ruby myscript.rb centos-7-x86_64 -``` +- [John McCabe: vmpooler-bitbar](https://github.com/johnmccabe/vmpooler-bitbar/) + + vmpooler status and management in your menubar with bitbar +- [Brian Cain: vagrant-vmpooler](https://github.com/briancain/vagrant-vmpooler) + + Use Vagrant to manage your vmpooler instances