qubesadmin.tools package¶
Submodules¶
qubesadmin.tools.dochelpers module¶
Documentation helpers.
This module contains classes and functions which help to maintain documentation, particularly our custom Sphinx extension.
- class qubesadmin.tools.dochelpers.CommandCheckVisitor(command, sub_commands, document)[source]¶
Bases:
SparseNodeVisitorChecks if the visited sub command section nodes and the specified sub command args are in sync.
- check_undocumented_sub_commands()[source]¶
Call this to check if any undocumented sub_commands are left.
While the documentation talks about a ‘SparseNodeVisitor.depart_document()’ function, this function does not exists. (For details see implementation of
NodeVisitor.dispatch_departure()) So we need to manually call this.
- visit_Text(node)[source]¶
If the visited text node starts with ‘alias: ‘, all the provided comma separted alias in this node, are removed from self.sub_commands
- visit_section(node)[source]¶
Checks if the visited sub-command section nodes exists and it options are in sync.
Uses
OptionsCheckVisitorfor checking sub-commands options
- class qubesadmin.tools.dochelpers.ManpageCheckVisitor(app, command, document)[source]¶
Bases:
SparseNodeVisitorChecks if the sub-commands and options specified in the ‘COMMAND’ and ‘OPTIONS’ (case insensitve) sections in sync the command parser.
- class qubesadmin.tools.dochelpers.OptionsCheckVisitor(command, args, document)[source]¶
Bases:
SparseNodeVisitorChecks if the visited option nodes and the specified args are in sync.
- check_undocumented_arguments(ignored_options=None)[source]¶
Call this to check if any undocumented arguments are left.
While the documentation talks about a ‘SparseNodeVisitor.depart_document()’ function, this function does not exists. (For details see implementation of
NodeVisitor.dispatch_departure()) So we need to manually call this.
qubesadmin.tools.qubes_prefs module¶
Manipulate global properties.
qubesadmin.tools.qvm_backup module¶
qvm-backup tool
qubesadmin.tools.qvm_backup_restore module¶
Console frontend for backup restore code
- qubesadmin.tools.qvm_backup_restore.handle_broken(app, args, restore_info)[source]¶
Display information about problems with VMs selected for resetore
qubesadmin.tools.qvm_check module¶
Exits sucessfull if the provided domain(s) exist, else returns failure
- class qubesadmin.tools.qvm_check.QvmCheckArgumentParser(description)[source]¶
Bases:
QubesArgumentParserExtended argument parser for qvm-check to collect invalid domains
- class qubesadmin.tools.qvm_check.QvmCheckVmNameAction(option_strings, nargs=1, dest='vmnames', help=None, **kwargs)[source]¶
Bases:
VmNameActionAction for parsing one or multiple valid/invalid VMNAMEs
qubesadmin.tools.qvm_clone module¶
Clone a domain
qubesadmin.tools.qvm_create module¶
qvm-create tool
qubesadmin.tools.qvm_device module¶
Qubes volume and block device management
- class qubesadmin.tools.qvm_device.DeviceAction(help='A backend, port & device id combination', required=True, allow_unknown=False, only_port=False, **kwargs)[source]¶
Bases:
QubesActionAction for argument parser that gets the :py:class:
qubesadmin.device_protocol.VirtualDevicefrom a BACKEND:PORT_ID:DEVICE_ID string.
- class qubesadmin.tools.qvm_device.Line(device: DeviceInfo, assignment=False)[source]¶
Bases:
objectHelper class to hold single device info for listing
- property assignments¶
list of frontends the device is assigned to
- qubesadmin.tools.qvm_device.assign_device(args)[source]¶
Called by the parser to execute the qvm-devices assign subcommand.
- qubesadmin.tools.qvm_device.attach_device(args)[source]¶
Called by the parser to execute the qvm-devices attach subcommand.
- qubesadmin.tools.qvm_device.detach_device(args)[source]¶
Called by the parser to execute the qvm-devices detach subcommand.
- qubesadmin.tools.qvm_device.get_parser(device_class=None)[source]¶
Create
argparse.ArgumentParsersuitable for qvm-block.
- qubesadmin.tools.qvm_device.info_device(args)[source]¶
Called by the parser to execute the qvm-devices info subcommand.
- qubesadmin.tools.qvm_device.init_list_parser(sub_parsers)[source]¶
Configures the parser for the qvm-devices list subcommand
- qubesadmin.tools.qvm_device.is_on_deny_list(device, dest_vm)[source]¶
Checks if any interface of the device is on the deny list for dest_vm vm.
- qubesadmin.tools.qvm_device.list_devices(args)[source]¶
Called by the parser to execute the qubes-devices list subcommand.
- qubesadmin.tools.qvm_device.parse_ro_option_as_read_only(options)[source]¶
For backward compatibility.
Read-only option could be represented as –ro, -o read-only=yes or -o ro=True etc.
- qubesadmin.tools.qvm_device.prepare_table(dev_list, with_sbdf=False)[source]¶
Converts a list of
qubes.devices.DeviceInfoobjects to a list of tuples for thequbes.tools.print_table().If qvm-devices is running in a TTY, it will omit duplicate data.
- Parameters:
dev_list (iterable) – List of
qubes.devices.DeviceInfoobjects.with_sbdf (bool) – when True, include SBDF identifier of PCI device
- Returns:
list of tuples
qubesadmin.tools.qvm_features module¶
qvm-features - Manage domain’s features
qubesadmin.tools.qvm_firewall module¶
qvm-firewall tool
- class qubesadmin.tools.qvm_firewall.RuleAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
Action- Parser action for a single firewall rule. It accept syntax:
<action> [<dsthost> [<proto> [<dstports>|<icmptype>]]]
action=<action> [specialtarget=dns] [dsthost=<dsthost>] [proto=<proto>] [dstports=<dstports>] [icmptype=<icmptype>]
Or a mix of them.
- qubesadmin.tools.qvm_firewall.rules_del(vm, args)[source]¶
Delete a rule according to args.rule/args.rule_no
qubesadmin.tools.qvm_kill module¶
Immediately terminate a qube without a graceful shutdown sequence.
qubesadmin.tools.qvm_ls module¶
qvm-ls - List available domains
- class qubesadmin.tools.qvm_ls.Column(head: str, attr: str | Callable[[QubesVM], object], doc: str | None = None)[source]¶
Bases:
objectA column in qvm-ls output.
- Parameters:
head (str) – Column head (usually uppercase).
attr – Attribute path (dotted string) or callable
(vm) -> value.doc (str) – Description of column (will be visible in –help-columns).
- cell(vm, insertion=0)[source]¶
Format one cell, handling tree indentation for the NAME column.
- Parameters:
vm – Domain to get a value from.
insertion – Tree depth; shifts NAME value to the right.
- Returns:
string to display
- columns = {'CLASS': Column(head='CLASS'), 'DISK': Column(head='DISK'), 'FLAGS': Column(head='FLAGS'), 'GATEWAY': Column(head='GATEWAY'), 'MEMORY': Column(head='MEMORY'), 'PRIV-CURR': Column(head='PRIV-CURR'), 'PRIV-MAX': Column(head='PRIV-MAX'), 'PRIV-POOL': Column(head='PRIV-POOL'), 'PRIV-USED': Column(head='PRIV-USED'), 'ROOT-CURR': Column(head='ROOT-CURR'), 'ROOT-MAX': Column(head='ROOT-MAX'), 'ROOT-POOL': Column(head='ROOT-POOL'), 'ROOT-USED': Column(head='ROOT-USED'), 'STATE': Column(head='STATE')}¶
collection of all columns
- class qubesadmin.tools.qvm_ls.PropertyColumn(name)[source]¶
Bases:
ColumnColumn that displays a VM property by name.
- Parameters:
name – Name of VM property.
- class qubesadmin.tools.qvm_ls.Table(domains, colnames, spinner, *, raw_data=False, tree_sorted=False, sort_order='NAME', reverse_sort=False, ignore_case=False)[source]¶
Bases:
objectTable that is displayed to the user.
- Parameters:
domains – Domains to include in the table.
colnames (list) – Names of the columns (need not to be uppercase).
- sort_to_tree(domains)[source]¶
Sort the domains as a network tree. It returns a list of sets. Each tuple stores the insertion of the cell name and the vm object.
- Parameters:
domains (list()) – The domains which will be sorted
- Return list(tuple()) tree:
returns a list of tuple(insertion, vm)
- qubesadmin.tools.qvm_ls.formats = {'disk': ('name', 'state', 'disk', 'priv-curr', 'priv-max', 'priv-used', 'root-curr', 'root-max', 'root-used'), 'full': ('name', 'state', 'class', 'label', 'qid', 'xid', 'uuid'), 'kernel': ('name', 'state', 'class', 'template', 'kernel', 'kernelopts'), 'network': ('name', 'state', 'netvm', 'ip', 'ipback', 'gateway'), 'prefs': ('name', 'label', 'template', 'netvm', 'vcpus', 'initialmem', 'maxmem', 'virt_mode'), 'simple': ('name', 'state', 'class', 'label', 'template', 'netvm')}¶
Available formats. Feel free to plug your own one.
qubesadmin.tools.qvm_pause module¶
qvm-pause - Pause a domain
qubesadmin.tools.qvm_pool module¶
Manages Qubes pools and their options
- qubesadmin.tools.qvm_pool.get_parser()[source]¶
Creates
argparse.ArgumentParsersuitable for qvm-pool.
qubesadmin.tools.qvm_prefs module¶
Manipulate VM properties.
qubesadmin.tools.qvm_remove module¶
Remove domains from the system
qubesadmin.tools.qvm_run module¶
qvm-run tool
qubesadmin.tools.qvm_service module¶
qvm-service - Manage domain’s services
qubesadmin.tools.qvm_shutdown module¶
Shutdown a qube
qubesadmin.tools.qvm_start module¶
qvm-start - start a domain
- class qubesadmin.tools.qvm_start.DriveAction(option_strings, dest='drive', *, prefix='cdrom:', metavar='IMAGE', required=False, help='Attach drive')[source]¶
Bases:
ActionAction for argument parser that stores drive image path.
- qubesadmin.tools.qvm_start.get_drive_assignment(app, drive_str)[source]¶
Prepare
qubesadmin.device_protocol.DeviceAssignmentobject for a given drive.If running in dom0, it will also take care about creating the appropriate loop device (if necessary). Otherwise, only existing block devices are supported.
- Parameters:
app – Qubes() instance
drive_str – drive argument
- Returns:
DeviceAssignment matching drive_str
qubesadmin.tools.qvm_start_daemon module¶
GUI/AUDIO daemon launcher tool
- class qubesadmin.tools.qvm_start_daemon.DAEMONLauncher(app: QubesBase, enabled_services, vm_names=None, kde=False)[source]¶
Bases:
objectLaunch GUI/AUDIO daemon for VMs
- cleanup_guid(xid)[source]¶
Clean up after qubes-guid.
Removes the auto-generated configuration file, if any.
- cleanup_pacat_process(xid)[source]¶
Clean up after pacat-simple-vchan.
Removes the auto-generated configuration file, if any.
- on_connection_established(_subject, _event, **_kwargs)[source]¶
Handler of ‘connection-established’ event, used to launch GUI/AUDIO daemon for domains started before this tool.
- on_domain_spawn(vm, _event, **kwargs)[source]¶
Handler of ‘domain-spawn’ event, starts GUI daemon for stubdomain
- on_domain_start(vm, _event, **kwargs)[source]¶
Handler of ‘domain-start’ event, starts GUI/AUDIO daemon for actual VM
- on_property_audiovm_set(vm, event, **kwargs)[source]¶
Handler for catching event related to dynamic AudioVM set/unset
- on_property_preload_set(vm, _event, **_kwargs)[source]¶
Handler of ‘property-reset:is_preload’ event, used to launch GUI/AUDIO daemon after preload is marked as used.
- async send_monitor_layout(vm, layout=None, startup=False)[source]¶
Send monitor layout to a given VM
This function is a coroutine.
- Parameters:
vm – VM to which send monitor layout
layout – monitor layout to send; if None, fetch it from local X server.
startup
- Returns:
None
- async start_audio(vm)[source]¶
Start AUDIO daemon regardless of start event.
This function is a coroutine.
- Parameters:
vm – VM for which AUDIO daemon should be started
- async start_audio_for_vm(vm)[source]¶
Start AUDIO daemon (pacat-simple-vchan) connected directly to a VM
This function is a coroutine.
- Parameters:
vm – VM for which start AUDIO daemon
- async start_gui(vm, force_stubdom=False, monitor_layout=None)[source]¶
Start GUI daemon regardless of start event.
This function is a coroutine.
- Parameters:
vm – VM for which GUI daemon should be started
force_stubdom – Force GUI daemon for stubdomain, even if the one for target AppVM is running.
monitor_layout – monitor layout configuration
- async start_gui_for_stubdomain(vm, force=False)[source]¶
Start GUI daemon (qubes-guid) connected to a stubdomain
This function is a coroutine.
- class qubesadmin.tools.qvm_start_daemon.KeyboardLayout(binary_string)[source]¶
Bases:
objectClass to store and parse X Keyboard layout data
- class qubesadmin.tools.qvm_start_daemon.XWatcher(conn, app)[source]¶
Bases:
objectWatch and react for X events related to the keyboard layout changes.
- qubesadmin.tools.qvm_start_daemon.escape_config_string(value)[source]¶
Convert a string to libconfig format.
Format specification: http://www.hyperrealm.com/libconfig/libconfig_manual.html#String-Values
See dump_string() for python-libconf: https://github.com/Grk0/python-libconf/blob/master/libconf.py
- qubesadmin.tools.qvm_start_daemon.get_monitor_layout()[source]¶
Get list of monitors and their size/position
- qubesadmin.tools.qvm_start_daemon.retrieve_gui_daemon_options(vm, guivm)[source]¶
Construct a list of GUI daemon options based on VM features.
This checks ‘gui-’ features on the VM, and if they’re absent, ‘gui-default-’ features on the GuiVM.
- qubesadmin.tools.qvm_start_daemon.serialize_gui_daemon_options(options)[source]¶
Prepare configuration file content for GUI daemon. Currently, uses libconfig format.
- qubesadmin.tools.qvm_start_daemon.validator_color(color: str) bool[source]¶
xside.c parse_color validation code is replicated here
qubesadmin.tools.qvm_template module¶
qubesadmin.tools.qvm_template_postprocess module¶
Tool for importing rpm-installed template
- async qubesadmin.tools.qvm_template_postprocess.call_postinstall_service(vm)[source]¶
Call qubes.PostInstall service
And adjust related settings (netvm, features).
- qubesadmin.tools.qvm_template_postprocess.get_root_img_size(source_dir)[source]¶
Extract size of root.img to be imported
Import appmenus settings into VM object (later: GUI VM)
- Parameters:
vm – QubesVM object of just imported template
source_dir – directory with source files
skip_generate – do not generate actual menu entries, only set item lists
- qubesadmin.tools.qvm_template_postprocess.import_root_img(vm, source_dir)[source]¶
Import root.img into VM object
- qubesadmin.tools.qvm_template_postprocess.import_template_config(args, conf_path, vm)[source]¶
Parse template.conf and apply its content to the just installed TemplateVM
- Parameters:
args – arguments for qvm-template-postprocess (used for –allow-pv option and possibly some other in the future)
conf_path – path to the template.conf
vm – Template to operate on
- Returns:
- qubesadmin.tools.qvm_template_postprocess.main(args=None, app=None)[source]¶
Main function of qvm-template-postprocess
- qubesadmin.tools.qvm_template_postprocess.parse_template_config(path)[source]¶
Parse template.conf from template package. (KEY=VALUE format)
qubesadmin.tools.qvm_unpause module¶
qvm-unpause - Unpause a domain
qubesadmin.tools.qvm_volume module¶
Qubes volume management
- class qubesadmin.tools.qvm_volume.VolumeData(volume)[source]¶
Bases:
objectWrapper object around
qubes.storage.Volume, mainly to track the domains a volume is attached to.
- qubesadmin.tools.qvm_volume.extend_volumes(args)[source]¶
Called by the parser to execute the qvm-volume extend subcommand
- qubesadmin.tools.qvm_volume.get_parser()[source]¶
Create
argparse.ArgumentParsersuitable for qvm-volume.
- qubesadmin.tools.qvm_volume.init_clear_parser(sub_parsers)[source]¶
Add ‘clear’ action related options
- qubesadmin.tools.qvm_volume.init_config_parser(sub_parsers)[source]¶
Add ‘info’ action related options
- qubesadmin.tools.qvm_volume.init_extend_parser(sub_parsers)[source]¶
Add ‘extend’ action related options
- qubesadmin.tools.qvm_volume.init_import_parser(sub_parsers)[source]¶
Add ‘import’ action related options
- qubesadmin.tools.qvm_volume.init_info_parser(sub_parsers)[source]¶
Add ‘info’ action related options
- qubesadmin.tools.qvm_volume.init_list_parser(sub_parsers)[source]¶
Configures the parser for the qvm-volume list subcommand
- qubesadmin.tools.qvm_volume.init_revert_parser(sub_parsers)[source]¶
Add ‘revert’ action related options
- qubesadmin.tools.qvm_volume.list_volumes(args)[source]¶
Called by the parser to execute the qvm-volume list subcommand.
- qubesadmin.tools.qvm_volume.prepare_table(vd_list, full=False)[source]¶
Converts a list of
VolumeDataobjects to a list of tupples for thequbes.tools.print_table().If qvm-volume is running in a TTY, it will ommit duplicate data.
- Parameters:
vd_list (list) – List of
VolumeDataobjects.full (bool) – If set to true duplicate data is printed even when running from TTY.
- Returns:
list of tupples
Module contents¶
Qubes’ command line tools
- class qubesadmin.tools.AliasedSubParsersAction(option_strings, prog, parser_class, dest='==SUPPRESS==', required=False, help=None, metavar=None)[source]¶
Bases:
_SubParsersActionSubParser with support for action aliases
- class qubesadmin.tools.PoolsAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
QubesActionAction for argument parser to gather multiple pools
- class qubesadmin.tools.PropertyAction(option_strings: list[str], dest: str, *, metavar: str = 'NAME=VALUE', required: bool = False, help: str = 'set property to a value')[source]¶
Bases:
ActionAction for argument parser that stores a property. Format: –<option_name> property=value
- class qubesadmin.tools.QubesAction(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]¶
Bases:
ActionCustom Action for Qubes
- class qubesadmin.tools.QubesArgumentParser(vmname_nargs=None, show_forceroot=False, version=None, **kwargs)[source]¶
Bases:
ArgumentParserParser preconfigured for use in most of the Qubes command-line tools.
- Parameters:
vmname_nargs (mixed) – The number of
VMNAMEarguments 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)show_forceroot – don’t hide –force-root parameter, prevent running as root unless it is given
kwargs are passed to
argparser.ArgumentParser.- Currenty supported options:
--force-root(optional, ignored, help is suppressed)--offline-modedo not talk to hypervisor (help is suppressed)--verboseand--quiet- Calling program should set the
versionargument for--versionoption The default is extracted from qubesadmin package information. Setting
versionargument to ‘’ will disable--versionoption.
- error_runtime(message, exit_code=1)[source]¶
Runtime error, without showing usage.
- Parameters:
message (str) – message to show
- class qubesadmin.tools.RunningVmNameAction(option_strings, nargs=1, dest='vmnames', help=None, **kwargs)[source]¶
Bases:
VmNameActionAction for argument parser that gets a running domain from VMNAME
- class qubesadmin.tools.SinglePropertyAction(option_strings, dest, *, metavar: str = 'VALUE', const: object = None, nargs: int | str | None = None, required: bool = False, help: str | None = None)[source]¶
Bases:
ActionAction for argument parser that stores a property. Format: –property_name value or –property_name
- class qubesadmin.tools.SubParsersHelpAction(option_strings, dest='==SUPPRESS==', default='==SUPPRESS==', help=None)[source]¶
Bases:
_HelpActionPrint help for all options and all subparsers
- class qubesadmin.tools.VMVolumeAction(help='A pool & volume id combination', required=True, **kwargs)[source]¶
Bases:
QubesActionAction for argument parser that gets the :py:class:
qubes.storage.Volumefrom a VM:VOLUME string.
- class qubesadmin.tools.VmNameAction(option_strings, nargs=1, dest='vmnames', help=None, **kwargs)[source]¶
Bases:
QubesActionAction for parsing one or multiple domains from provided VMNAMEs
- class qubesadmin.tools.VmNameGroup(container, required, vm_action=<class 'qubesadmin.tools.VmNameAction'>, help=None)[source]¶
Bases:
_MutuallyExclusiveGroupAdds an a VMNAME, –all & –exclude parameters to a :py:class:
argparse.ArgumentParser`.