Welcome to Python Foreman’s documentation!

Client module documentation

Tutorial

Definitions files

The Python Foreman can get the methods and it’s definitions from two places the definitions directory or the foreman instance.

This definitions directory contains some apipie json definitions retrieved from different foreman versions and api versions, by default it will try to match the foreman version with the fittest of those files.

It can also get it’s definitions from the live Foreman instance, to do that, you have to make sure that the urls:

  • FOREMAN_URL/apidoc/v2.json
  • FOREMAN_URL/apidoc/v1.json

are available, usually that means that you’ll have to set the config.use_cache parameter for the apipie gem to false (normally found under FOREMAN_HOME/config/initializers/apipie.rb)

Basic Tutorial

Connect

To connect to a foreman server just instantiate a foreman.client.Foreman object with the server’s url and authentication aprameters, like this:

>>> from getpass import getpass
>>> from foreman.client import Foreman
>>> f = Foreman('http://myforeman.server:3000', ('myuser', getpass()))

The available methods are separated in two ways, by resource (apiv2) and by method ($type_$resource_$method).

Take into account that all those methods are autogenerated and they might vary for different versions of Foreman.

index

Those are the main methods to get info for groups of objects, for example, to get a sumary of all the hosts you could do:

>>> f.index_hosts()
>>> f.hosts.index()

Take into account that it accepts some parameters to handle the paging and the ammount of elements to get.

show

This methods give you all the information for a specific object, for example:

>>> f.show_hosts(id=1)
>>> f.hosts.show(id='myuber.host.com')

Will show all the info for the host with id 1.

create

This methods create a new object into foreman. An example:

>>> f.create_hosts(host={'name': 'mynewhost', 'ip': '192.168.1.1', 'mac': '00:00:00:00:00:00'})
>>> f.hosts.create(host={'name': 'mynewhost', 'ip': '192.168.1.1', 'mac': '00:00:00:00:00:00'})

To see the exact parameters look at the `foreman API docs<http://theforeman.org/api.html>`_.

update

This methods update the info for the given object, usually called with an id and a hash representating the object.

destroy

This methods give you a way to destroy any object.

Advanced Tutorial

TODO

Changelog

Here you can find the full changelog for this version

Indices and tables