Chapter 42. Calling Automation Using the RESTful API
Our first look at the integration capabilities of CloudForms examines how external systems can make inbound calls to CloudForms to run Automate instances using the RESTful API.1
Being able to call automation in this way enables our workflows to be utilized by other enterprise tools in a number of ways. For example, organizations may wish to use a help-desk ticketing system as their starting point for new virtual machine provisioning requests. The ticketing system can make a RESTful call to CloudForms Automate to initiate the workflow.
API Entry Point
We can call any Automate instance from the RESTful API, by issuing a POST
call to /api/automation_requests and enclosing a JSON-encoded parameter hash such as the following:
post_params
=
{
:version
=>
'1.1'
,
:uri_parts
=>
{
:namespace
=>
'ACME/General'
,
:class
=>
'Methods'
,
:instance
=>
'HelloWorld'
},
:requester
=>
{
:auto_approve
=>
true
}
}
.
to_json
We can call the RESTful API from an external Ruby script by using the rest-client
gem:
url
=
'https://cloudforms_server'
query
=
'/api/automation_requests'
rest_return
=
RestClient
:
:Request
.
execute
(
method
:
:post
,
url
:
url
+
query
,
:user
=>
username
,
:password
=>
password
,
:headers
=>
{
:accept
=>
:json
},
:payload
=>
post_params
,
verify_ssl
:
false
)
result
=
JSON
.
parse
(
rest_return
)
The request ID is returned to us in the result from the initial call:
request_id
=
result
[
'results'
][
0
][
'id'
]
We call poll this to check on status:
query ...
Get Mastering CloudForms Automation now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.