foreman_reserve

Gem Version

This gem will added a route to the API to return the name of available host(s)

Installation:

You have to make sure that the gem is available to foreman, to do that the recommended way is to add a new file to $FOREMAN_DIR/bundler.d named foreman_reserve.rb with the next content:

gem 'foreman_reserve', :git => "https://github.com/david-caro/foreman_reserve.git"
gem 'foreman_reserve'

After that you'll need to create the bundle for foreman, as foreman user run from the $FOREMAN_DIR:

>$ bunde --deploy

Foreman 1.1

In order to work, the foreman application must be the following two lines commented out.

config/routes.rb

# match '*a', :to => 'errors#routing'

config/routes/v1.rb

# match '*other', :to => 'home#route_error'

Usage

To make a host 'reservable', you need to make sure it has a parameter named RESERVED, that parameter will be used to store the current reservation status, you can safely add the parameter to a hostgroup for the hsot to inherit from.

To return 1 host:

>$ curl -u admin:secret -H 'accept:application/json' http://0.0.0.0:3000/api/hosts_reserve

To return multiple hosts, pass a parameter called 'amount'

>$ curl -u admin:secret -H 'accept:application/json' http://0.0.0.0:3000/api/hosts_reserve?amount=3

Filter using a specific query: (name ~ virt%)

>$ curl -u admin:secret -H 'accept:application/json' 'http://0.0.0.0:3000/api/hosts_reserve?query=name%20~%20virt%25'

Release a specific host:

>$ curl -u admin:secret -H 'accept:application/json' 'http://0.0.0.0:3000/api/hosts_release?host_name=myreservedhost'

Release a group of hosts using a query: (name ~ virt%)

>$ curl -u admin:secret -H 'accept:application/json' 'http://0.0.0.0:3000/api/hosts_reserve?query=name%20~%20virt%25'

foreman-python

In order to use from python, there's a python module that already includes this plugin calls, you can find it on pypi or on github:

Contributing to foreman_reserve

Copyright © 2013 Joseph Mitchell Magen and David Caro. See LICENSE.txt for further details.