Commit Graph

21 Commits

Author SHA1 Message Date
Marek Marczykowski-Górecki
e6186239ef
Make pylint happy
- fix super-with-arguments
- ignore raise-missing-from - too many intentional usages
2020-08-23 03:31:39 +02:00
Marek Marczykowski-Górecki
7425a5359b
Cleanup Admin API denial reporting
Rename QubesDaemonNoResponseError to more intuitive
QubesDaemonAccessError (keep legacy name still working).
Use QubesPropertyAccessError whenever the access is about @property -
this makes it easy to use `getattr` to use default value instead.

QubesOS/qubes-issues#5811
2020-08-11 02:06:42 +02:00
Marek Marczykowski-Górecki
02cfab8257
Try to use new property.GetAll method to pre-fill the cache
When caching is enabled, reduce number of calls by getting all the
properties at once. If the call is not available (for example because of
the policy), fallback to getting individual values.

QubesOS/qubes-issues#5415
2020-05-22 19:01:24 +02:00
Marek Marczykowski-Górecki
218d43a2e0
Add simple properties caching
Reduce Admin API calls by caching returned values. The cache is not
enabled by default, because it could result in stale values being
returned. It can be enabled by setting 'cache_enabled' to True on
Qubes() object. This is safe in two cases:
 - the application don't care about changed values - like a short-lived
   process that retrieve values once (for example qvm-ls)
 - the application listen for events and invalidate cache when property
   is changed

For the second case, invalidating the cache on appropriate event
(property-set:*, property-reset:*) is done before calling other event
handlers. This is because the event may try to access the property value
(not necessary from the event arguments), so we need to be sure it will
see the new value.

Fixes QubesOS/qubes-issues#5415
2020-05-22 18:59:44 +02:00
Marek Marczykowski-Górecki
5315bbf8f9
Do not check for object existence when got it with another Admin API call
When qubesd returns an name of VM or other object, as part of another
call (reading a property, listing devices etc), it's safe to assume that
object exists. Do not try to list it, which could be prevented by qrexec
policy. This means a VM object would be returned (for example in
vm.netvm property), which potentially could not be listed through
app.domains collection. This may lead to some corner cases, but
generally should ease handling of restricted policy.

This does not affect practical information the management VM have access
too, as those names are already returned. It's just client side python
wrapper that didn't allowed to access them.

QubesOS/qubes-issues#5099
2020-05-18 04:37:48 +02:00
Marek Marczykowski-Górecki
2d736f5aa8
Make pylint happy 2019-10-05 21:57:48 +02:00
Marek Marczykowski-Górecki
d7430d42ce
Make pylint happy
no-else-raise warning
2019-03-07 03:17:29 +01:00
Marek Marczykowski-Górecki
16064f6fb4
Fixes for pylint 2.0
Ignore most of them - we still support python 2.7 here.
Fix no-else-return.
2018-07-16 02:25:25 +02:00
Marek Marczykowski-Górecki
4a28c560d9
Merge remote-tracking branch 'qubesos/pr/50'
* qubesos/pr/50:
  Add property_get_default method
2018-01-15 03:23:00 +01:00
Marek Marczykowski-Górecki
ce0d230866
Add property_get_default method
It is useful to get property default value, without changing it to
default. For example to list it in GUI tools

Fixes QubesOS/qubes-issues#3197
2018-01-12 23:40:05 +01:00
Marek Marczykowski-Górecki
04f8d85819
base: make WrapperObjectsCollection behave like a dict
In core-admin matching collections are real dicts, so clone this API
behaviour here too. Specific changes:
 - iteration yields keys, not values
 - implement values and items methods

Additionally fix keys method, it was broken on python2 (list have no
copy method).
2018-01-12 05:29:40 +01:00
qubesuser
14b3acec24
don't use ast.literal_eval, just directly convert to the desired type
It's slow and unnecessary
2017-12-05 22:40:40 +01:00
qubesuser
565bdf8549
don't lookup list of labels just to read VM properties
If qubesd returns a label name, we can just assume it's valid.

This makes qvm-ls take only one qubesd call.
2017-12-05 22:36:07 +01:00
qubesuser
6e844940cc replace key in dir(self) with faster and better code 2017-11-10 16:31:45 +01:00
Marek Marczykowski-Górecki
b28ddb6621
Implement "blind mode" to avoid listing objects
This allows to perform actions on objects (VM, storage etc), without
listing them. This is useful when calling VM have minimal permissions
and only selected actions are allowed.

This means that app.domains['some-name'] will not raise KeyError, even
when domain do not exists. But performing actual action (like
vm.start()) will fail in that case.
2017-09-20 20:18:59 +02:00
Marek Marczykowski-Górecki
5b7947b51a
Improve QubesDaemonNoResponseError error message
Include hint to look into dom0 logs

QubesOS/qubes-issues#3016
2017-08-12 15:15:52 +02:00
Marek Marczykowski-Górecki
e94bdca206
base: add PropertyHolder.clone_properties
Be compatible with core-admin
2017-06-20 01:34:17 +02:00
Marek Marczykowski-Górecki
c988ef41a3
Fix setting VM property to None
None value should be encoded as empty string.
2017-05-26 00:42:47 +02:00
Marek Marczykowski-Górecki
0b2f7ac958
Add efficient method to handle large payloads for Admin API methods
Add qubesd_call(..., payload_stream=...) argument to allow streaming
payload directly from some file/process stdout. This is mainly (only?)
useful for admin.vm.volume.Import, where disk volume raw data is passed
to the service.
2017-05-26 00:42:46 +02:00
Marek Marczykowski-Górecki
cfc9ff2ce5
Rename Mgmt API to Admin API: methods names
QubesOS/qubes-issues#853
2017-05-12 19:36:03 +02:00
Marek Marczykowski-Górecki
4ceff0f8c0
Rename qubesmgmt to qubesadmin module
QubesOS/qubes-issues#853
2017-05-11 23:40:03 +02:00