Alternatives - command /usr/bin/alternatives output

class insights.parsers.alternatives.AlternativesOutput(context, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Read the output of /usr/sbin/alternatives --display *program* and convert into information about the given program’s alternatives.

Typical input is:

java - status is auto.
 link currently points to /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre/bin/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/jre/bin/java - priority 1700111
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre/bin/java - priority 1800111
/usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/java - priority 16091
 slave ControlPanel: /usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/ControlPanel
 slave keytool: /usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/keytool
 slave policytool: /usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/policytool
 slave rmid: /usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/rmid
Current `best' version is /usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/java.

Lines are interpreted this way:

  • Program lines are of the form ‘name - status is status’, and start the information for a program. Lines before this are ignored.

  • The current link to this program is found on lines starting with ‘link currently points to’.

  • Lines starting with ‘/’ and with ‘ - priority ‘ in them record an alternative path and its priority.

  • Lines starting with ‘slave program: path’ are recorded against the alternative path.

  • Lines starting with ‘Current `best’ version is’ indicate the default choice of an ‘auto’ status alternative.

The output of alternatives --display *program* can only ever list one program, so as long as one ‘status is’ line is found (as described above), the content of the object displays that program.

program

The name of the program found in the ‘status is’ line. This attribute is set to None if a status line is not found.

Type

str

status

The status of the program, or None if not found.

Type

str

The link to this program, or None if the ‘link currently points to`` line is not found.

Type

str

best

The ‘best choice’ path that alternatives would use, or None if the ‘best choice’ line is not found.

Type

str

paths

The alternative paths for this program. Each path is a dictionary containing the following keys:

  • path: the actual path of this alternative for the program

  • priority: the priority, as an integer (e.g. 1700111)

  • slave: a dictionary of programs dependent on this alternative - the key is the program name (e.g. ‘ControlPanel’) and the value is the path to that program for this alternative path.

Type

dict

Examples

>>> java = AlternativesOutput(context_wrap(JAVA_ALTERNATIVES))
>>> java.program
'java'
>>> java.link
'/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre/bin/java'
>>> len(java.paths)
3
>>> java.paths[0]['path']
'/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/jre/bin/java'
>>> java.paths[0]['priority']
1700111
>>> java.paths[2]['slave']['ControlPanel']
'/usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/ControlPanel'
parse_content(content)[source]

Parse the output of the alternatives command.

class insights.parsers.alternatives.JavaAlternatives(context, extra_bad_lines=None)[source]

Bases: insights.parsers.alternatives.AlternativesOutput

Class to read the /usr/sbin/alternatives --display java output.

Uses the AlternativesOutput base class to get information about the alternatives for java available and which one is currently in use.

Examples

>>> java = shared[JavaAlternatives]
>>> java.program
'java'
>>> java.link
'/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b15.el7_2.x86_64/jre/bin/java'
>>> len(java.paths)
3
>>> java.paths[0]['path']
'/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.2.el7_2.x86_64/jre/bin/java'
>>> java.paths[0]['priority']
1700111
>>> java.paths[2]['slave']['ControlPanel']
'/usr/lib/jvm/jre-1.6.0-ibm.x86_64/bin/ControlPanel'