From ffa35eb398cf3bb2bb5118992dc031e4c597765f Mon Sep 17 00:00:00 2001 From: elarochelle Date: Mon, 25 Aug 2014 14:50:52 -0400 Subject: [PATCH 1/4] Adding unified module for TM report calls. --- docs/install.rst | 4 +- docs/tm.rst | 1 + docs/tm/reports.rst | 17 ++++++ dyn/__init__.py | 2 +- dyn/tm/reports.py | 134 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 docs/tm/reports.rst create mode 100644 dyn/tm/reports.py diff --git a/docs/install.rst b/docs/install.rst index 8c92e32..77ff712 100644 --- a/docs/install.rst +++ b/docs/install.rst @@ -10,9 +10,7 @@ The first step to using any software package is getting it properly installed. Distribute & Pip ---------------- -Installing dyn is simple via `pip `_. Currently -the dyn module is only available internally within Dyn, because of this it can -only be downloaded while on Dyn's internal VPN:: +Installing dyn is simple via `pip `_. $ pip install dyn diff --git a/docs/tm.rst b/docs/tm.rst index 49caf1b..06bb25b 100644 --- a/docs/tm.rst +++ b/docs/tm.rst @@ -25,5 +25,6 @@ this part of the documentation is for you. tm/accounts tm/records tm/services + tm/reports tm/errors diff --git a/docs/tm/reports.rst b/docs/tm/reports.rst new file mode 100644 index 0000000..6fa483c --- /dev/null +++ b/docs/tm/reports.rst @@ -0,0 +1,17 @@ +.. _tm-reports: + +TM Reports +========== +The :mod:`reports` module contains interfaces for all of the various Report +collection calls offered by the dyn.tm REST API + +List Functions +-------------- + +.. autofunction:: dyn.tm.reports.get_check_permission +.. autofunction:: dyn.tm.reports.get_dnssec_timeline +.. autofunction:: dyn.tm.reports.get_rttm_log +.. autofunction:: dyn.tm.reports.get_rttm_rrset +.. autofunction:: dyn.tm.reports.get_qps +.. autofunction:: dyn.tm.reports.get_zone_notes + diff --git a/dyn/__init__.py b/dyn/__init__.py index d0059f1..7202d74 100644 --- a/dyn/__init__.py +++ b/dyn/__init__.py @@ -5,7 +5,7 @@ Requires Python 2.6 or higher, or the "simplejson" package. """ -version_info = (1, 0, 1) +version_info = (1, 0, 2) __name__ = 'dyn' __doc__ = 'A python wrapper for the DynDNS and DynEmail APIs' __author__ = 'Jonathan Nappi, Cole Tuininga' diff --git a/dyn/tm/reports.py b/dyn/tm/reports.py new file mode 100644 index 0000000..32144ea --- /dev/null +++ b/dyn/tm/reports.py @@ -0,0 +1,134 @@ +# -*- coding: utf-8 -*- +"""This module contains interfaces for all Account management features of the +REST API +""" +from .session import DynectSession + +__author__ = 'elarochelle' +__all__ = ['get_qps'] + + +def get_check_permission(permission, zone_name=None): + """Returns a list of allowed and forbidden permissions for the currently + logged in user based on the provided permissions array. + + :param permission: A list of permissions to check for the current user. + :param zone_name: The zone to check for specific permissions. + :return: A :class:`dict` containing permission information. + """ + api_args = {'permission': permission} + if zone_name is not None: + api_args['zone_name'] = zone_name + response = DynectSession.get_session().execute('/CheckPermissionReport/', + 'POST', api_args) + return response['data'] + + +def get_dnssec_timeline(zone_name, start_ts=None, end_ts=None): + """Generates a report of events for the :class:`DNSSEC` service + attached to the specified zone has performed and has scheduled + to perform. + + :param zone_name: The name of the zone with DNSSEC service + :param start_ts: UNIX timestamp identifying point in time for the + report + :param end_ts: UNIX timestamp indicating the end of the data range for + the report + :return: A :class:`dict` containing log report data + """ + api_args = {'zone': zone_name} + if start_ts is not None: + api_args['start_ts'] = start_ts + if end_ts is not None: + api_args['end_ts'] = end_ts + response = DynectSession.get_session().execute('/DNSSECTimelineReport/', + 'POST', api_args) + return response['data'] + + +def get_rttm_log(zone_name, fqdn, start_ts, end_ts): + """Generates a report with information about changes to an existing + RTTM service. + + :param zone_name: The name of the zone + :param fqdn: The FQDN where RTTM is attached + :param start_ts: UNIX timestamp identifying point in time for the log + report + :param end_ts: UNIX timestamp indicating the end of the data range for + the report + :return: A :class:`dict` containing log report data + """ + api_args = {'zone': zone_name, + 'fqdn': fqdn, + 'start_ts': start_ts, + 'end_ts': end_ts} + response = DynectSession.get_session().execute('/RTTMLogReport/', + 'POST', api_args) + return response['data'] + + +def get_rttm_rrset(zone_name, fqdn, ts): + """Generates a report of regional response sets for this RTTM service + at a given point in time. + + :param zone_name: The name of the zone + :param fqdn: The FQDN where RTTM is attached + :param ts: UNIX timestamp identifying point in time for the report + :return: A :class:`dict` containing rrset report data + """ + api_args = {'zone': zone_name, + 'fqdn': fqdn, + 'ts': ts} + response = DynectSession.get_session().execute('/RTTMRRSetReport/', + 'POST', api_args) + return response['data'] + + +def get_qps(start_ts, end_ts, breakdown=None, hosts=None, rrecs=None, + zones = None): + """Generates a report with information about Queries Per Second (QPS). + + :param start_ts: UNIX timestamp identifying point in time for the QPS + report + :param end_ts: UNIX timestamp indicating the end of the data range for + the report + :param breakdown: By default, most data is aggregated together. + Valid values ('hosts', 'rrecs', 'zones'). + :param hosts: List of hosts to include in the report. + :param rrecs: List of record types to include in report. + :param zones: List of zones to include in report. + :return: A :class:`str` with CSV data + """ + api_args = {'start_ts': start_ts, + 'end_ts': end_ts} + if breakdown is not None: + api_args['breakdown'] = breakdown + if hosts is not None: + api_args['hosts'] = hosts + if rrecs is not None: + api_args['rrecs'] = rrecs + if zones is not None: + api_args['zones'] = zones + print(api_args) + response = DynectSession.get_session().execute('/QPSReport/', + 'POST', api_args) + return response['data'] + + +def get_zone_notes(zone_name, offset=None, limit=None): + """Generates a report containing the Zone Notes for given zone. + + :param zone_name: The name of the zone + :param offset: UNIX timestamp of the starting point at which to + retrieve the notes + :param limit: The maximum number of notes to be retrieved + :return: A :class:`list` of :class:`dict` containing Zone Notes + """ + api_args = {'zone': zone_name} + if offset: + api_args['offset'] = offset + if limit: + api_args['limit'] = limit + response = DynectSession.get_session().execute('/ZoneNoteReport/', + 'POST', api_args) + return response['data'] From 6856d030e7e83a4f74583b453071f72a85d815a5 Mon Sep 17 00:00:00 2001 From: elarochelle Date: Tue, 26 Aug 2014 12:48:45 -0400 Subject: [PATCH 2/4] Fixes from comments for TM Reports --- docs/tm/reports.rst | 2 +- dyn/tm/reports.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/tm/reports.rst b/docs/tm/reports.rst index 6fa483c..ec7bb1d 100644 --- a/docs/tm/reports.rst +++ b/docs/tm/reports.rst @@ -2,7 +2,7 @@ TM Reports ========== -The :mod:`reports` module contains interfaces for all of the various Report +The :mod:`~dyn.tm.reports` module contains interfaces for all of the various Report collection calls offered by the dyn.tm REST API List Functions diff --git a/dyn/tm/reports.py b/dyn/tm/reports.py index 32144ea..3cd4cd0 100644 --- a/dyn/tm/reports.py +++ b/dyn/tm/reports.py @@ -1,20 +1,21 @@ # -*- coding: utf-8 -*- -"""This module contains interfaces for all Account management features of the +"""This module contains interfaces for all Report generation features of the REST API """ from .session import DynectSession __author__ = 'elarochelle' -__all__ = ['get_qps'] +__all__ = ['get_check_permission', 'get_dnssec_timeline', 'get_qps', + 'get_rttm_log', 'get_rttm_rrset', 'get_zone_notes'] def get_check_permission(permission, zone_name=None): """Returns a list of allowed and forbidden permissions for the currently - logged in user based on the provided permissions array. + logged in user based on the provided permissions array. - :param permission: A list of permissions to check for the current user. - :param zone_name: The zone to check for specific permissions. - :return: A :class:`dict` containing permission information. + :param permission: A list of permissions to check for the current user. + :param zone_name: The zone to check for specific permissions. + :return: A :class:`dict` containing permission information. """ api_args = {'permission': permission} if zone_name is not None: From 8d238a3f72668c206fb1c9096db54b8d564b25e0 Mon Sep 17 00:00:00 2001 From: elarochelle Date: Tue, 26 Aug 2014 12:54:06 -0400 Subject: [PATCH 3/4] Updated history --- HISTORY.rst | 6 ++++++ dyn/tm/reports.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index e1f5893..c4bda84 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,5 +1,11 @@ Release History --------------- +1.0.2 (2014-08-26) +++++++++++++++++++ + +* Added reports module +* Updated installation documentation. + 1.0.1 (2014-08-06) ++++++++++++++++++ diff --git a/dyn/tm/reports.py b/dyn/tm/reports.py index 3cd4cd0..d38888d 100644 --- a/dyn/tm/reports.py +++ b/dyn/tm/reports.py @@ -16,7 +16,7 @@ def get_check_permission(permission, zone_name=None): :param permission: A list of permissions to check for the current user. :param zone_name: The zone to check for specific permissions. :return: A :class:`dict` containing permission information. - """ + """ api_args = {'permission': permission} if zone_name is not None: api_args['zone_name'] = zone_name From ebdf8c624a834b1e221c28a62d6e2c76cf827b56 Mon Sep 17 00:00:00 2001 From: elarochelle Date: Wed, 27 Aug 2014 11:05:42 -0400 Subject: [PATCH 4/4] Oops, forgot to remove this print --- dyn/tm/reports.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dyn/tm/reports.py b/dyn/tm/reports.py index d38888d..c1aa903 100644 --- a/dyn/tm/reports.py +++ b/dyn/tm/reports.py @@ -110,7 +110,6 @@ def get_qps(start_ts, end_ts, breakdown=None, hosts=None, rrecs=None, api_args['rrecs'] = rrecs if zones is not None: api_args['zones'] = zones - print(api_args) response = DynectSession.get_session().execute('/QPSReport/', 'POST', api_args) return response['data']