discovery.restfulGet
discovery.restfulGet(target, protocol, path[, headers, port, use_http])
Performs a GET request on the target using the RESTful protocol specified and returns a node containing information on the discovered system.The function takes the following parameters:
target
– the device or data source against which the request is performed. See also, discovery.dataSource.protocol
– distinguishes the RESTful protocol for distinguishing credentials and handling any device specific behavior. The following protocols are supported:""
— Generic protocol, no authentication"VPLEX"
— VPLEX protocol"basic_auth"
— Generic protocol, HTTP basic authentication"digest_auth"
— Generic protocol, HTTP Digest authentication"oauth2"
— Generic protocol, OAuth2 authentication. The OAuth2 authentication method used is a client credentials grant as described on the IETF Tools website."nimble_auth"
— Generic protocol for Nimble web API with token authentication. Intended for use discovering Nimble storage devices.
path
— a string specifying the URL path on the target, for example/api/about
. The IP address and access method are automatically added according to the credential and endpoint being discovered.headers
— an optional dictionary of HTTP headers to be sent with the request. You can use this to implement custom protocols that require certain HTTP headers to be present. For requests using the VPLEX protocol, the username and password fields are automatically added. It is not possible to override automatically added values.port
— an optional integer. Port on which HTTP server listens. Default value is80
ifuse_http
isTrue
, otherwise443
is used.use_http
— boolean, optional. Whether to use HTTP instead of HTTPS. Default value isFalse
(HTTPS).
and returns a DiscoveryAPIResult node containing the following:
– the response status.response_
status
– the response reason.response_
reasonresponse_headers
– a table of header entries. Sensitive fields are removed.response_body
– the body of the response. When data is successfully retrieved and theresponse_body
is a JSON encoded string, it can be decoded using the json.decode function.
For example:
// GET request, no authentication, HTTP on default port. Response is JSON encoded result := discovery.restfulGet(process, '', '/api/about', use_http:=true); if result then if result.response_status = 200 then if result.response_body then decoded := json.decode(result.response_body); if decoded then product_version := decoded["version"]; log.debug("Found product version from REST API: %product_version%"); else log.debug("Failed to json decode /api/about response. Raw response: %result.response_body%"); end if; else log.debug("/api/about returned no response body"); end if; else log.debug("/api/about returned %result.response_status%"); end if; else log.debug("Failed to query /api/about"); end if; // GET request, Basic Authentication, HTTP on a custom port result := discovery.restfulGet(process, "basic_auth", "/basic/foo", port:=8800, use_http:=true); // GET request, Digest Authentication, HTTPS on a custom port result := discovery.restfulGet(process, "digest_auth", "/digest/xml", port:=8443); // GET request, OAuth2 Authentication, HTTPS on default port result := discovery.restfulGet(process, 'oauth2', '/api/v1.1/admin/baseline'); // GET request, OAuth2 Authentication, headers, HTTPS on default port headers := table(); headers['header_param'] :="header_value"; result := discovery.restfulGet(process, "oauth2", "/api/v1.1/vault/credentials", headers); // GET request, Nimble Authentication, HTTPS on a custom port result := discovery.restfulGet(storage_device, 'nimble_auth', '/v1/arrays', port:=5392);
If the request fails the function returns none.
Was this page helpful? Yes No
Submitting...
Thank you
Comments
Log in or register to comment.