http_call
This task plugin is to interact with devices over HTTP and is capable
of calling any method of Python built-in requests
library.
http_call sample usage
Sample code to run http_call
task:
from nornir_salt.plugins.tasks import http_call
from nornir import InitNornir
nr = InitNornir(config_file="nornir_config.yaml")
res = nr.run(
task=http_call,
method="get",
url="https://google.com",
)
http_call returns
Returns requests result string in XML or JSON format.
http_call reference
- nornir_salt.plugins.tasks.http_call.http_call(task: nornir.core.task.Task, method: str, url: str = None, **kwargs) nornir.core.task.Result
Task function to call one of the supported
requests
library methods.- Parameters
method – (str) requests method to call
url – (str) relative to base_url or absolute URL to send request to
kwargs – (dict) any
**kwargs
to use with requests method call
- Returns
(str) attempt to return JSON formatted string if
json
string pattern found in response’sContent-type
header, returns response text otherwise
http_call
follows these rules to form URL to send request to:Use
url
attribute if provided and it absolute - starts withhttp://
orhttps://
If
url
attribute provided but is relative - does not starts withhttp://
orhttps://
- it is merged with inventorybase_url
using formatter{base_url}/{url}
ifbase_url
is absolute - starts withhttp://
orhttps://
If
url
attribute provided andbase_url
listed in inventory and they are both relative - does not startswithhttp://
orhttps://
- target URL formed using formatter:{transport}://{hostname}:{port}/{base_url}/{url}
If
url
attribute provided and is relative and nobase_url
defined in inventoryextras
sections, http_call uses this formatter{transport}://{hostname}:{port}/{url}
to form final URL iftransport
parameter defined in inventoryextras
sectionsIf no
url
attribute provided usebase_url
to send the request ifbase_url
defined in inventoryextras
sections and is absolute - starts withhttp://
orhttps://
- If no
url
attribute provided and nobase_url
defined in inventory extras
sections use this formatter{transport}://{hostname}:{port}/
iftransport
parameter defined in inventoryextras
sections
- If no
Raise error, unable to form URL
Default headers added to HTTP request:
'Content-Type': 'application/yang-data+json', 'Accept': 'application/yang-data+json'
If no
auth
attribute provided in taskkwargs
, host’s username and password inventory parameters used to formauth
tuple.