Skip to content

module layout

Yoram Hekma edited this page Jun 14, 2016 · 1 revision

Every module is put into katlibs/modules and is expected to have a main function and a add_to_subparsers function that defines the options/parameters and adds it to the given subparser. For example the add_to_subparsers in cleanout_view.py:

def add_to_subparsers(subparsers):
    parser_cleanout_view = subparsers.add_parser('cleanout_view', help='Cleanup of content view versions')
    parser_cleanout_view.add_argument('view_name', nargs='?')
    parser_cleanout_view.add_argument('-k', '--keep', help='Keep this many of the newest unused versions', default=0)
    parser_cleanout_view.set_defaults(funcname='cleanout_view')

In addition to this, the module's main function function gets executed with at least the following arguments:

  • connection (the KatelloConnection instance as defined in katlibs/main/katello_helpers.py)
  • conf_file (A string containing the passed configuration file)
  • config_obj (A ConfigParser.ConfigParser object of the conf_file)
  • func_name (string of the function/module that gets called)
  • verbose (Boolean)

Note that any extra arguments you specify in the add_to_subparsers function gets passed along to the main function as well. In order to not break when extra arguments are added to the main ballista program, we recommend to always accept **kwargs in addition to any arguments you may want to handle yourself.

Clone this wiki locally