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
requestslibrary methods.- Parameters
method – (str) requests method to call
url – (str) relative to base_url or absolute URL to send request to
kwargs – (dict) any
**kwargsto use with requests method call
- Returns
(str) attempt to return JSON formatted string if
jsonstring pattern found in response’sContent-typeheader, returns response text otherwise
http_callfollows these rules to form URL to send request to:Use
urlattribute if provided and it absolute - starts withhttp://orhttps://If
urlattribute provided but is relative - does not starts withhttp://orhttps://- it is merged with inventorybase_urlusing formatter{base_url}/{url}ifbase_urlis absolute - starts withhttp://orhttps://If
urlattribute provided andbase_urllisted in inventory and they are both relative - does not startswithhttp://orhttps://- target URL formed using formatter:{transport}://{hostname}:{port}/{base_url}/{url}If
urlattribute provided and is relative and nobase_urldefined in inventoryextrassections, http_call uses this formatter{transport}://{hostname}:{port}/{url}to form final URL iftransportparameter defined in inventoryextrassectionsIf no
urlattribute provided usebase_urlto send the request ifbase_urldefined in inventoryextrassections and is absolute - starts withhttp://orhttps://- If no
urlattribute provided and nobase_urldefined in inventory extrassections use this formatter{transport}://{hostname}:{port}/iftransportparameter defined in inventoryextrassections
- 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
authattribute provided in taskkwargs, host’s username and password inventory parameters used to formauthtuple.