The osc_lib.utils.columns Module

The osc_lib.utils.columns Module

osc_lib.utils.columns.get_column_definitions(attr_map, long_listing)

Return table headers and column names for a listing table.

An attribute map (attr_map) is a list of table entry definitions and the format of the map is as follows:

Parameters:
  • attr_map

    a list of table entry definitions. Each entry should be a tuple consisting of (API attribute name, header name, listing mode). For example:

    (('id', 'ID', LIST_BOTH),
     ('name', 'Name', LIST_BOTH),
     ('tenant_id', 'Project', LIST_LONG_ONLY))
    

    The third field of each tuple must be one of LIST_BOTH, LIST_LONG_ONLY (a corresponding column is shown only in a long mode), or LIST_SHORT_ONLY (a corresponding column is shown only in a short mode).

  • long_listing – A boolean value which indicates a long listing or not. In most cases, parsed_args.long is passed to this argument.
Returns:

A tuple of a list of table headers and a list of column names.

osc_lib.utils.columns.get_columns(item, attr_map=None)

Return pair of resource attributes and corresponding display names.

Parameters:
  • item

    a dictionary which represents a resource. Keys of the dictionary are expected to be attributes of the resource. Values are not referred to by this method.

    {'id': 'myid', 'name': 'myname',
     'foo': 'bar', 'tenant_id': 'mytenan'}
    
  • attr_map

    a list of mapping from attribute to display name. The same format is used as for get_column_definitions attr_map.

    (('id', 'ID', LIST_BOTH),
     ('name', 'Name', LIST_BOTH),
     ('tenant_id', 'Project', LIST_LONG_ONLY))
    
Returns:

A pair of tuple of attributes and tuple of display names.

(('id', 'name', 'tenant_id', 'foo'),  # attributes
 ('ID', 'Name', 'Project', 'foo')     # display names

Both tuples of attributes and display names are sorted by display names in the alphabetical order. Attributes not found in a given attr_map are kept as-is.

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.