mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
Cleanup readme, add example projects
This commit is contained in:
parent
1d0fc42c80
commit
86e1792775
1 changed files with 6 additions and 66 deletions
72
README.md
72
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue