qubes.tools – Command line utilities

Those are Python modules that house actual functionality of CLI tools – the files installed in /usr/bin only import these modules and run main() function.

The modules should make available for import theirs command line parsers (instances of argparse.ArgumentParser) as either .parser attribute or function get_parser(), which returns parser. Manual page will be automatically checked during generation if its “Options” section contains all options from this parser (and only those).

Module contents

Qubes’ command line tools

class qubes.tools.AliasedSubParsersAction(option_strings, prog, parser_class, dest='==SUPPRESS==', required=False, help=None, metavar=None)[source]

Bases: _SubParsersAction

class qubes.tools.HelpPropertiesAction(option_strings, klass=None, dest='==SUPPRESS==', default='==SUPPRESS==', help='list all available properties with short descriptions and exit')[source]

Bases: Action

Action for argument parser that displays all properties and exits.

class qubes.tools.PoolsAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: QubesAction

Action for argument parser to gather multiple pools

parse_qubes_app(parser, namespace)[source]

This method is called by qubes.tools.QubesArgumentParser after the namespace.app is instantiated. Oerwrite this method when extending qubes.tools.QubesAction to initialized values based on the namespace.app

class qubes.tools.PropertyAction(option_strings, dest, metavar='NAME=VALUE', required=False, help='set property to a value')[source]

Bases: Action

Action for argument parser that stores a property.

class qubes.tools.QubesAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: Action

Interface providing a convinience method to be called, after namespace.app is instantiated.

parse_qubes_app(parser, namespace)[source]

This method is called by qubes.tools.QubesArgumentParser after the namespace.app is instantiated. Oerwrite this method when extending qubes.tools.QubesAction to initialized values based on the namespace.app

class qubes.tools.QubesArgumentParser(want_app=True, want_app_no_instance=False, want_force_root=False, vmname_nargs=None, **kwargs)[source]

Bases: ArgumentParser

Parser preconfigured for use in most of the Qubes command-line tools.

Parameters:
  • want_app (bool) – instantiate qubes.Qubes object

  • want_app_no_instance (bool) – don’t actually instantiate qubes.Qubes object, just add argument for custom xml file

  • want_force_root (bool) – add --force-root option

  • vmname_nargs (mixed) –

    The number of VMNAME arguments that should be consumed. Values include:

    • N (an integer) consumes N arguments (and produces a list)

    • ’?’ consumes zero or one arguments

    • ’*’ consumes zero or more arguments (and produces a list)

    • ’+’ consumes one or more arguments (and produces a list)

kwargs are passed to argparser.ArgumentParser.

Currenty supported options:

--force-root (optional) --qubesxml location of qubes.xml (help is suppressed) --offline-mode do not talk to hypervisor (help is suppressed) --verbose and --quiet

dont_run_as_root(namespace)[source]

Prevent running as root.

Parameters:

args (argparse.Namespace) – if there is .force_root attribute set to true, run anyway

error_runtime(message)[source]

Runtime error, without showing usage.

Parameters:

message (str) – message to show

print_error(*args, **kwargs)[source]

Print to sys.stderr

static set_qubes_verbosity(namespace)[source]

Apply a verbosity setting.

This is done by configuring global logging. :param argparse.Namespace args: args as parsed by parser

class qubes.tools.RunningVmNameAction(option_strings, nargs=1, dest='vmnames', help=None, **kwargs)[source]

Bases: VmNameAction

Action for argument parser that gets a running domain from VMNAME

parse_qubes_app(parser, namespace)[source]

This method is called by qubes.tools.QubesArgumentParser after the namespace.app is instantiated. Oerwrite this method when extending qubes.tools.QubesAction to initialized values based on the namespace.app

class qubes.tools.SinglePropertyAction(option_strings, dest, metavar='VALUE', const=None, nargs=None, required=False, help=None)[source]

Bases: Action

Action for argument parser that stores a property.

class qubes.tools.VmNameAction(option_strings, nargs=1, dest='vmnames', help=None, **kwargs)[source]

Bases: QubesAction

Action for parsing one ore multiple domains from provided VMNAMEs

parse_qubes_app(parser, namespace)[source]

This method is called by qubes.tools.QubesArgumentParser after the namespace.app is instantiated. Oerwrite this method when extending qubes.tools.QubesAction to initialized values based on the namespace.app

class qubes.tools.VmNameGroup(container, required, vm_action=<class 'qubes.tools.VmNameAction'>, help=None)[source]

Bases: _MutuallyExclusiveGroup

Adds an a VMNAME, –all & –exclude parameters to a :py:class:argparse.ArgumentParser`.

class qubes.tools.VolumeAction(help='A pool & volume id combination', required=True, **kwargs)[source]

Bases: QubesAction

Action for argument parser that gets the :py:class:qubes.storage.Volume from a POOL_NAME:VOLUME_ID string.

parse_qubes_app(parser, namespace)[source]

Acquire the :py:class:qubes.storage.Volume object from namespace.app.

qubes.tools.get_parser_for_command(command)[source]

Get parser for given qvm-tool.

Parameters:

command (str) – command name

Return type:

argparse.ArgumentParser

Raises:
qubes.tools.print_table(table)[source]

Uses the unix column command to print pretty table.

Parameters:

text (str) – list of lists/sets

qubes.tools.VM_ALL = <object object>

constant returned when some action should be performed on all qubes

All CLI tools