Source code for dnacentersdk.api.v2_2_3_3.reports

# -*- coding: utf-8 -*-
"""Cisco DNA Center Reports API wrapper.

Copyright (c) 2019-2021 Cisco Systems.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""


from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

from builtins import *

from past.builtins import basestring

from ...restsession import RestSession
from ...utils import (
    check_type,
    dict_from_items_with_values,
    apply_path_params,
    dict_of_str,
)


[docs]class Reports(object): """Cisco DNA Center Reports API (version: 2.2.3.3). Wraps the DNA Center Reports API and exposes the API as native Python methods that return native Python objects. """ def __init__(self, session, object_factory, request_validator): """Initialize a new Reports object with the provided RestSession. Args: session(RestSession): The RESTful session object to be used for API calls to the DNA Center service. Raises: TypeError: If the parameter types are incorrect. """ check_type(session, RestSession) super(Reports, self).__init__() self._session = session self._object_factory = object_factory self._request_validator = request_validator
[docs] def create_or_schedule_a_report(self, deliveries=None, name=None, schedule=None, tags=None, view=None, viewGroupId=None, viewGroupVersion=None, headers=None, payload=None, active_validation=True, **request_parameters): """Create/Schedule a report configuration. Use "Get view details for a given view group & view" API to get the metadata required to configure a report. . Args: deliveries(list): Reports's Array of available delivery channels (list of objects). name(string): Reports's report name . schedule(object): Reports's schedule. tags(list): Reports's array of tags for report (list of strings). view(object): Reports's view. viewGroupId(string): Reports's viewGroupId of the viewgroup for the report . viewGroupVersion(string): Reports's version of viewgroup for the report . headers(dict): Dictionary of HTTP Headers to send with the Request . payload(dict): A JSON serializable Python object to send in the body of the Request. active_validation(bool): Enable/Disable payload validation. Defaults to True. **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: MyDict: JSON response. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(payload, dict) if headers is not None: if 'Content-Type' in headers: check_type(headers.get('Content-Type'), basestring, may_be_none=False) if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { } _payload = { 'tags': tags, 'deliveries': deliveries, 'name': name, 'schedule': schedule, 'view': view, 'viewGroupId': viewGroupId, 'viewGroupVersion': viewGroupVersion, } _payload.update(payload or {}) _payload = dict_from_items_with_values(_payload) if active_validation: self._request_validator('jsd_fa310ab095148bdb00d7d3d5e1676_v2_2_3_3')\ .validate(_payload) with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/reports') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.post(endpoint_full_url, params=_params, json=_payload, headers=_headers) else: json_data = self._session.post(endpoint_full_url, params=_params, json=_payload) return self._object_factory('bpm_fa310ab095148bdb00d7d3d5e1676_v2_2_3_3', json_data)
[docs] def get_list_of_scheduled_reports(self, view_group_id=None, view_id=None, headers=None, **request_parameters): """Get list of scheduled report configurations. . Args: view_group_id(basestring): viewGroupId query parameter. viewGroupId of viewgroup for report . view_id(basestring): viewId query parameter. viewId of view for report . headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: list: JSON response. A list of MyDict objects. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(view_group_id, basestring) check_type(view_id, basestring) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { 'viewGroupId': view_group_id, 'viewId': view_id, } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/reports') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.get(endpoint_full_url, params=_params) return self._object_factory('bpm_d89e1c3e150ef9faaff44fa483de5_v2_2_3_3', json_data)
[docs] def get_a_scheduled_report(self, report_id, headers=None, **request_parameters): """Get scheduled report configuration by reportId . Args: report_id(basestring): reportId path parameter. reportId of report . headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: MyDict: JSON response. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(report_id, basestring, may_be_none=False) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { 'reportId': report_id, } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/reports/{reportId}') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.get(endpoint_full_url, params=_params) return self._object_factory('bpm_f9cb7c424b5502b4ad54ccbb1ca4f4_v2_2_3_3', json_data)
[docs] def delete_a_scheduled_report(self, report_id, headers=None, **request_parameters): """Delete a scheduled report configuration. Deletes the report executions also. . Args: report_id(basestring): reportId path parameter. reportId of report . headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: MyDict: JSON response. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(report_id, basestring, may_be_none=False) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { 'reportId': report_id, } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/reports/{reportId}') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.delete(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.delete(endpoint_full_url, params=_params) return self._object_factory('bpm_a6a151b68d450dfaf1e8a92e0f5cc68_v2_2_3_3', json_data)
[docs] def get_all_execution_details_for_a_given_report(self, report_id, headers=None, **request_parameters): """Get details of all executions for a given report . Args: report_id(basestring): reportId path parameter. reportId of report . headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: MyDict: JSON response. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(report_id, basestring, may_be_none=False) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { 'reportId': report_id, } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/reports/{reportId}/executions') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.get(endpoint_full_url, params=_params) return self._object_factory('bpm_a4b1ca0320185570bc12da238f0e88bb_v2_2_3_3', json_data)
[docs] def download_report_content(self, execution_id, report_id, dirpath=None, save_file=None, headers=None, **request_parameters): """Returns report content. Save the response to a file by converting the response data as a blob and setting the file format available from content-disposition response header. . Args: report_id(basestring): reportId path parameter. reportId of report . execution_id(basestring): executionId path parameter. executionId of report execution . dirpath(basestring): Directory absolute path. Defaults to os.getcwd(). save_file(bool): Enable or disable automatic file creation of raw response. headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: urllib3.response.HTTPResponse: HTTP Response container. For more information check the `urlib3 documentation <https://urllib3.readthedocs.io/en/latest/reference/urllib3.response.html>`_ Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. DownloadFailure: If was not able to download the raw response to a file. """ check_type(headers, dict) check_type(report_id, basestring, may_be_none=False) check_type(execution_id, basestring, may_be_none=False) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { 'reportId': report_id, 'executionId': execution_id, } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/reports/{reportId}/executions/{e' + 'xecutionId}') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers, stream=True, dirpath=dirpath, save_file=save_file) else: json_data = self._session.get(endpoint_full_url, params=_params, stream=True, dirpath=dirpath, save_file=save_file) return self._object_factory('bpm_b2790cdb5abf98c8e00011de86a4_v2_2_3_3', json_data)
[docs] def get_all_view_groups(self, headers=None, **request_parameters): """Gives a list of summary of all view groups. . Args: headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: list: JSON response. A list of MyDict objects. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/view-groups') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.get(endpoint_full_url, params=_params) return self._object_factory('bpm_bbff833d5d5756698f4764a9d488cc98_v2_2_3_3', json_data)
[docs] def get_views_for_a_given_view_group(self, view_group_id, headers=None, **request_parameters): """Gives a list of summary of all views in a viewgroup. Use "Get all view groups" API to get the viewGroupIds (required as a query param for this API) for available viewgroups. . Args: view_group_id(basestring): viewGroupId path parameter. viewGroupId of viewgroup. . headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: MyDict: JSON response. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(view_group_id, basestring, may_be_none=False) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { 'viewGroupId': view_group_id, } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/view-groups/{viewGroupId}') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.get(endpoint_full_url, params=_params) return self._object_factory('bpm_c5879612ddc05cd0a0de09d29da4907e_v2_2_3_3', json_data)
[docs] def get_view_details_for_a_given_view_group_and_view(self, view_group_id, view_id, headers=None, **request_parameters): """Gives complete information of the view that is required to configure a report. Use "Get views for a given view group" API to get the viewIds (required as a query param for this API) for available views. . Args: view_group_id(basestring): viewGroupId path parameter. viewGroupId of viewgroup . view_id(basestring): viewId path parameter. view id of view . headers(dict): Dictionary of HTTP Headers to send with the Request . **request_parameters: Additional request parameters (provides support for parameters that may be added in the future). Returns: MyDict: JSON response. Access the object's properties by using the dot notation or the bracket notation. Raises: TypeError: If the parameter types are incorrect. MalformedRequest: If the request body created is invalid. ApiError: If the DNA Center cloud returns an error. """ check_type(headers, dict) check_type(view_group_id, basestring, may_be_none=False) check_type(view_id, basestring, may_be_none=False) if headers is not None: if 'X-Auth-Token' in headers: check_type(headers.get('X-Auth-Token'), basestring, may_be_none=False) _params = { } _params.update(request_parameters) _params = dict_from_items_with_values(_params) path_params = { 'viewGroupId': view_group_id, 'viewId': view_id, } with_custom_headers = False _headers = self._session.headers or {} if headers: _headers.update(dict_of_str(headers)) with_custom_headers = True e_url = ('/dna/intent/api/v1/data/view-' + 'groups/{viewGroupId}/views/{viewId}') endpoint_full_url = apply_path_params(e_url, path_params) if with_custom_headers: json_data = self._session.get(endpoint_full_url, params=_params, headers=_headers) else: json_data = self._session.get(endpoint_full_url, params=_params) return self._object_factory('bpm_d1944177c95598ebd1986582dc8069a_v2_2_3_3', json_data)