Satellite PostgreSQL database queries

This module contains the following parsers:

SatelliteAdminSettings - command psql -d foreman -c 'select name, value, "default" from settings where name in ('destroy_vm_on_host_delete', 'unregister_delete_host') --csv'

SatelliteComputeResources - command psql -d foreman -c 'select name, type from compute_resources'

class insights.parsers.satellite_postgresql_query.SatelliteAdminSettings(context, extra_bad_lines=None)[source]

Bases: insights.parsers.satellite_postgresql_query.SatellitePostgreSQLQuery

Parse the output of the command psql -d foreman -c '"select name, value, "default" from settings where name in ('destroy_vm_on_host_delete', 'unregister_delete_host') --csv".

Sample output:

name,value,default
unregister_delete_host,"--- true
...","--- false
..."
destroy_vm_on_host_delete,,"--- true
..."

Examples

>>> type(table)
<class 'insights.parsers.satellite_postgresql_query.SatelliteAdminSettings'>
>>> table.get_setting('unregister_delete_host')
True
>>> table.get_setting('destroy_vm_on_host_delete')
True
get_setting(setting_name)[source]

Get the actual value of setting_name. If the value column isn’t empty, the value of the setting_name is the value column, or else it’s the default column.

Parameters

setting_name (str) -- the value of name column which is searched in the table.

Returns

It depends on the setting, maybe boolean, string, int or a list. None if the setting_name doesn’t exist in the table.

parse_content(content)[source]

The “default” and “value” columns must be selected, or else the settings value can’t be determined. The “default” and “value” column are in yaml format, it is transfer to python object.

Raises
  • SkipException -- when value or default column isn’t found in the table.

  • ParseException -- when the value or default in bad yaml format.

class insights.parsers.satellite_postgresql_query.SatelliteComputeResources(context, extra_bad_lines=None)[source]

Bases: insights.parsers.satellite_postgresql_query.SatellitePostgreSQLQuery

Parse the output of the command psql -d foreman -c 'select name, type from compute_resources' --csv.

Note

Please refer to its super-class insights.parsers.satellite_postgresql_query.SatellitePostgreSQLQuery for more details.

Sample output:

name,type
test_compute_resource1,Foreman::Model::Libvirt
test_compute_resource2,Foreman::Model::RHV

Examples

>>> type(resources_table)
<class 'insights.parsers.satellite_postgresql_query.SatelliteComputeResources'>
>>> rows=resources_table.search(type='Foreman::Model::Libvirt')
>>> len(rows)
1
>>> rows[0]['name']
'test_compute_resource1'
class insights.parsers.satellite_postgresql_query.SatellitePostgreSQLQuery(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser, list

Parent class of satellite postgresql table queries. It saves the rows data into a list. Each row is saved into a dict. The key is the column name, the value is the value of the column.

Resultant data structure:

[
    {
        'name': 'abc',
        'url': '',
        'value': 'test'
    },
    {
        'name': 'def',
        'url': 'http://xx.com',
        'value': ''
    }
]

Sample Output:

name,url,value
abc,,test
def,http://xx.com,

Examples

>>> type(query)
<class 'insights.parsers.satellite_postgresql_query.SatellitePostgreSQLQuery'>
>>> rows = query.search(name='abc')
>>> len(rows)
1
>>> rows[0]['value']
'test'
>>> columns=query.get_columns()
>>> 'url' in columns
True
>>> 'name' in columns
True
Raises
parse_content(content)[source]

This method must be implemented by classes based on this class.

search(**kwargs)[source]

Get the rows by searching the table with kwargs. This uses the insights.parsers.keyword_search() function for searching; see its documentation for usage details. If no search parameters are given, no rows are returned.

It simplify the value of the column according to actual usage.

Returns

A list of dictionaries of rows that match the given search criteria.

Return type

list

Examples

>>> query.search(name__startswith='abc') == [
... {'name': 'abc', 'url': '', 'value': 'test'},
... {'name': 'abcdef', 'url': '', 'value': 'test2'}
... ]
True
>>> query.search(name__startswith='abc', value='test') == [
... {'name': 'abc', 'url': '', 'value': 'test'}
... ]
True