VirshListAll - command virsh --readonly list --all

This module provides VM status using output of command virsh --readonly list --all.

class insights.parsers.virsh_list_all.VirshListAll(context, extra_bad_lines=[])[source]

Bases: insights.core.CommandParser

Parsing output of virsh --readonly list --all.

Typical output of virsh --readonly list --all command is:

Id    Name                           State
----------------------------------------------------
2     rhel7.4                        running
4     rhel7.0                        paused
-     centos6.8-router               shut off
-     cfme-5.7.13                    shut off
-     cfme-rhos-5.9.0.15             shut off
-     fedora-24-kernel               shut off
-     fedora-saio_fedoraSaio         shut off
-     fedora24-misc                  shut off
-     freebsd11.0                    shut off
-     guixSD                         shut off
-     miq-gap-1                      shut off
-     rhel7.2                        shut off
-     RHOSP10                        shut off

Examples

>>> len(output.search(state='shut off')) == 11
True
>>> len(output.search(id=None)) == 11
True
>>> len(output.search(id=2)) == 1
True
>>> output.search(name='rhel7.4') == [{'state': 'running', 'id': 2, 'name': 'rhel7.4'}]
True
>>> output.get_vm_state('rhel7.0') == 'paused'
True
>>> output.get_vm_state('rhel9.0') is None
True
>>> 'cfme' in output
False
>>> 'cfme-5.7.13' in output
True
fields

List of KeyValue namedtupules for each line in the command.

Type

list

cols

List id key value pair derived from the command.

Type

list

keywords

keywords present in the command, each keyword is converted to lowercase.

Type

list

get_vm_state(vmname)[source]

Get VM state associated with vmname

Typical output is virsh --readonly list --all command:

 Id    Name                           State
----------------------------------------------------
 2     rhel7.4                        running
 4     rhel7.0                        paused

Example

>>> output.get_vm_state('rhel7.0')
'paused'
Parameters

vmname (str) -- A key. For ex. rhel7.0.

Returns

State of VM. Returns None if, vmname does not exist.

Return type

str

keyvalue

namedtuple: Represent name value pair as a namedtuple with case.

alias of KeyValue

parse_content(content)[source]

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

search(**kw)[source]

Search item based on key value pair.

Example

>>> len(output.search(state='shut off')) == 11
True
>>> len(output.search(id=None)) == 11
True
>>> len(output.search(id=2)) == 1
True