The oslo_reports.report Module

The oslo_reports.report Module

Provides Report classes

This module defines various classes representing reports and report sections. All reports take the form of a report class containing various report sections.

class oslo_reports.report.BasicReport

Bases: object

A Basic Report

A Basic Report consists of a collection of ReportSection objects, each of which contains a top-level model and generator. It collects these sections into a cohesive report which may then be serialized by calling run().

add_section(view, generator, index=None)

Add a section to the report

This method adds a section with the given view and generator to the report. An index may be specified to insert the section at a given location in the list; If no index is specified, the section is appended to the list. The view is called on the model which results from the generator when the report is run. A generator is simply a method or callable object which takes no arguments and returns a oslo_reports.models.base.ReportModel or similar object.

Parameters:
  • view – the top-level view for the section
  • generator – the method or class which generates the model
  • index (int or None) – the index at which to insert the section (or None to append it)
run()

Run the report

This method runs the report, having each section generate its data and serialize itself before joining the sections together. The BasicReport accomplishes the joining by joining the serialized sections together with newlines.

Return type:str
Returns:the serialized report
class oslo_reports.report.ReportOfType(tp)

Bases: oslo_reports.report.BasicReport

A Report of a Certain Type

A ReportOfType has a predefined type associated with it. This type is automatically propagated down to the each of the sections upon serialization by wrapping the generator for each section.

See also

Class oslo_reports.models.with_default_view.ModelWithDefaultView # noqa
(the entire class)
Class oslo_reports.models.base.ReportModel
oslo_reports.models.base.ReportModel.set_current_view_type() # noqa
Parameters:tp (str) – the type of the report
add_section(view, generator, index=None)
class oslo_reports.report.ReportSection(view, generator)

Bases: object

A Report Section

A report section contains a generator and a top-level view. When something attempts to serialize the section by calling str() or unicode() on it, the section runs the generator and calls the view on the resulting model.

Parameters:
  • view – the top-level view for this section
  • generator – the generator for this section (any callable object which takes no parameters and returns a data model)
class oslo_reports.report.TextReport(name)

Bases: oslo_reports.report.ReportOfType

A Human-Readable Text Report

This class defines a report that is designed to be read by a human being. It has nice section headers, and a formatted title.

Parameters:name (str) – the title of the report
add_section(heading, generator, index=None)

Add a section to the report

This method adds a section with the given title, and generator to the report. An index may be specified to insert the section at a given location in the list; If no index is specified, the section is appended to the list. The view is called on the model which results from the generator when the report is run. A generator is simply a method or callable object which takes no arguments and returns a oslo_reports.models.base.ReportModel or similar object.

The model is told to serialize as text (if possible) at serialization time by wrapping the generator. The view model’s attached view (if any) is wrapped in a oslo_reports.views.text.header.TitledView

Parameters:
  • heading (str) – the title for the section
  • generator – the method or class which generates the model
  • index (int or None) – the index at which to insert the section (or None to append)
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.