pyqubes¶
Examples¶
Todo
Examples
- pythonic
- direct
API¶
This API documentation is automatically generated.
Pythonic Classes¶
VM¶
The top level VM
object holds common methods for VMs.
It should not be instanciated directly - use the
lower level TemplateVM
and AppVM
objects instead.
-
class
pyqubes.vm.
VM
(name, proactive=False, operating_system='fedora-23')[source]¶ The VM object represants a QubesOS VM. Its methods are common accross both AppVMs and TemplateVMs.
VM should not be instanciated directly - use TemplateVM or AppVM.
By default, all VMs are Fedora 23 based. Other values are listed in
pyqubes.constants
-
enact
(args)[source]¶ Enact a list of command arguments using the VM’s
enact_function
Any one of the functions in
pyqubes.qubes
,``pyqubes.qubesdb`` orpyqubes.qvm
will return arguments in the correct format.
-
firewall_open
()[source]¶ Can be explicity called to open the VM firewall to ‘allow’.
In most cases you should use``with vm.internet``:
vm = TemplateVM('foo') with vm.animate: # Templates are offline be default with vm.internet: # Template now has unrestricted internet access vm.run('curl http://ipecho.net/plain') # Firewall is restored automatically # This will now fail vm.run('curl http://ipecho.net/plain')
-
run
(command, quote=True, **kwargs)[source]¶ Run a command on the VM.
Please note: *
--pass-io
is always set, to run commands synchronously * Commands are automatically encapsulated in single quotes:vm = TemplateVM('spam') vm.run('echo "foo bar"') # produces: qvm-run spam 'echo "foo bar"'
Parameters: quote (bool) – By default command is single quoted - set False
to disable
-
TeamplateVM & AppVM¶
These represent the actual VMs within QubesOS.
Methods mentioned here are specific to the VM type.
-
class
pyqubes.vm.
TemplateVM
(*args, **kwargs)[source]¶ TemplateVM - for installing apps
-
clone
(clone_name, **kwargs)[source]¶ Clone the TemplateVM and return a new TemplateVM
Parameters: clone_name (string) – Name of the new VM Returns: The new TemplateVM
instance
-
Helper Classes¶
Direct command wrapping¶
qubes-
commands¶
qubesdb-
commands¶
qvm-
commands¶
-
pyqubes.qvm.
qvm_create
(vm_name, template='', label='', proxy=False, net=False, hvm=False, hvm_template=False, root_move_from='', root_copy_from='', standalone=False, mem=0, vcpus=0, internal=False, force_root=False, quiet=False)[source]¶ qvm-create
-
pyqubes.qvm.
qvm_firewall
(vm_name, list_view=False, add_rule='', del_rule='', set_policy='', set_icmp='', set_dns='', set_yum_proxy='', numeric=False)[source]¶ qvm-firewall
-
pyqubes.qvm.
qvm_run
(vm_name, command, quiet=False, auto=False, user='', tray=False, all_vms=False, exclude=[], wait=False, shutdown=False, pause=False, unpause=False, pass_io=False, localcmd='', force=False)[source]¶ qvm-run
Utilities¶
Compile¶
The compile
module converts instructions from pythonic data structures
into flat lists.abs
These may require further processing before being passed to the
enact
module for action.
-
pyqubes.compile.
flags_boolean
(flags)[source]¶ Return a list of string values, corresponding to the given keys whose values evaluate to True
All keys and values will be converted to strings.
Parameters: flags (dict) – A dictionary in the form {'--flag': boolean}
, whereboolean
is used to determine whether--flag
is included in the output.Returns: A flat list of strings
-
pyqubes.compile.
flags_store
(flags)[source]¶ Return a list of string values, corresponding to the given keys and values whose values evaluate to True
The output is a flat list of all strings.
All keys and values will be converted to strings.
Parameters: flags (dict) – A dictionary in the form {'--flag': value}
, wherevalue
is used to determine whether the entry is included in the output.Returns: A flat list of strings
-
pyqubes.compile.
flags_store_iterable
(flags)[source]¶ Calls
flags_store
for each value within each key inflags
.e.g. {‘–fruits’: [‘apple’, ‘pear’]} results in [‘–fruits’, ‘apple’, ‘–fruits’, ‘pear’]
Parameters: flags (dict) – A dictionary in the form {'--flag': value}
, wherevalue
is an iterable.Returns: A flat list of strings Raises: TypeError
if values are not iterable
-
pyqubes.compile.
info
(info, quote=True, style=True)[source]¶ Returns the given string
info
as a set of echo arguments.Optionally provides quoting and terminal styling.
Parameters: - info (string) – Info string to add to script
- quote (bool) – By default quote given sting in single quotes
- style (bool) – By default add
Returns: A flat list of strings
Constants¶
Enact¶
The enact module contains functions that act on a list of command-line arguments,
The two most important ones are:
* Direct execution with call
(proactive mode)
* Echoing an execution-ready script with echo
(reactive mode)
-
pyqubes.enact.
call_quiet
(args)[source]¶ Uses the
call
function, but throws away stdout and stderr.Should be used for internal unit tests wherever possible.
-
pyqubes.enact.
echo
(args, file=None)[source]¶ Echo a list of arguments (as given to
subprocess.call
) to the given stream.This defaults to
stdout
, but can be changed to any stream-like object such as a file handle.Parameters: - args – A string or list of strings
- file – A file-like object to stream output to. Defaults to
sys.stdout
Utils¶
Utility functions for pyqubes
Utilities have no dependencies.
-
pyqubes.utils.
assert_list_items_equal_in_nested
(actual_nested, expected_list)[source]¶ Assert that the given
expected_list
matches one pf the lists withinactual_nested
, using the comparisonsorted(list)
Parameters: - actual_nested (list) – A list of lists (usually generated by test)
- expected_list (list) – A list of expected values
Validate¶
Validate functions for pyqubes
These will return the original value if validation passes.
Otherwise, ValueError
will be raised
-
pyqubes.validate.
firewall_policy
(policy)[source]¶ qvm-firewall policy string should match
^(allow|deny)$
Parameters: policy (string) – Policy string to check Returns: policy
if valid, elseValueError
-
pyqubes.validate.
label_color
(color)[source]¶ VM label color should be one of: * red * orange * yellow * green * blue * purple * black * gray
Parameters: color (string) – Label color string to check Returns: color
if valid, elseValueError