WWW::Foreman::API - Perl client to the Foreman API
use WWW::Foreman::API; use Data::Dumper; my $api = WWW::Foreman::API->new( user => $user, password => $password, url => $foreman_api_url, verify_ssl => 1 ); print Dumper $api->get('hosts');
This module is a generic client to the Foreman API. To use this module, you should use the post(), get(), put() and delete() methods.
post()
get()
put()
delete()
new()
Create a Foreman API object.
my $api = WWW::Foreman::API->new( user => $user, password => $password, url => $foreman_api_url, verify_ssl => 1 );
The user who will be used for the API requests.
The password of the user.
The url of the Foreman API. For example, https://foreman/api.
If this parameter is set to 0, this disables certificate chain checking, as well as host name checking.
The get() method sends a GET request to the Foreman API, using the API end point supplied as an argument. For example, this code:
$api->get('hosts/2');
will send a GET request to https://foreman_url/api/hosts/2
The post() method sends a POST request to the Foreman API, using the API end point and the parameters supplied as arguments. For example, this code:
$api->post('architectures', \%params);
will send a POST request to https://foreman_url/api/architecures. \%params is a hash ref which contains the parameters being send within the request.
\%params
The put() method sends a PUT request to the Foreman API, using the API end point and the parameters supplied as arguments. For example, this code:
$api->put('architectures/2', \%params);
will send a PUT request to https://foreman_url/api/architecures/2. \%params is a hash ref which contains the parameters being send within the request.
The delete() method sends a DELETE request to the Foreman API, using the API end point supplied as argument. For example, this code:
$api->delete('hosts/2');
will send a DELETE request to https://<url_foreman/api/hosts/2
For more information about the api endpoints and the parameters for each request, please refer to the official documentation: https://theforeman.org/api/1.12/index.html.
The return value is an hash reference which is the deserialised json returned by the API. For example:
$VAR1 = { 'page' => 1, 'per_page' => 20, 'results' => [ { 'created_at' => '2015-04-03T13:59:04.398Z', 'id' => 1, 'updated_at' => '2015-05-14T13:59:04.398Z', 'name' => 'x86_64' } ], 'total' => 1, 'subtotal' => 1, 'search' => undef, 'sort' => { 'by' => undef, 'order' => undef } };
Vincent Lequertier <vi.le@autistici.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WWW::Foreman::API, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Foreman::API
CPAN shell
perl -MCPAN -e shell install WWW::Foreman::API
For more information on module installation, please visit the detailed CPAN module installation guide.