Commit Graph

46 Commits

Author SHA1 Message Date
Pino Toscano
83f1544d32 inspection: create and use a separate vmmInspectionApplication
Instead of passing around the raw results of
g.inspect_list_applications(), create an helper vmmInspectionApplication
object with the data of an inspected application that we use.  This is
done for different reasons:
- when using the data, it is easier to use member variables instead of
  looking up values in a dictionary
- we keep only the data needed, slightly lowering the memory/objects
  used for the inspected applications
- it will be easier to switch from g.inspect_list_applications() to
  g.inspect_list_applications2() without changing code outside the
  inspection code

Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-18 13:44:34 -04:00
Pino Toscano
6a5b06b8ed inspection: save the package format
Save the package format of a guest as part of its inspection data, so
later on it can be used to tweak other results (like the version of
installed packages).

Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-17 19:11:12 -04:00
Pino Toscano
ceed47558c inspection: fix check of mounted filesystems
The old code basically always set filesystems_mounted to True, even when
no filesystems were mounted successfully, unless
g.inspect_get_mountpoints() failed (very unlikely).

Instead, set it when at least one filesystem is mounted; considering
that the first filesystem to be mounted is usually /, then failing to
mount it will usually prevent the mounting of the others.  In any case,
we can try to extract data even when only / is mounted, which can work
depending on the mount points of the guest.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-17 19:11:12 -04:00
Pino Toscano
ac2949bab3 inspection: simplify mount points sort/mount
Rely on the Python 3 sorting facilities to sort the mount points using
a key based on the length of the mount point, doing the same effect as
the old compare function.

As side change required by this, enable python_return_dict on the
GuestFS handle, so we get proper hashes instead of lists.  This requires
libguestfs 1.22, which is 6 years old by now (and other virt-manager
requires are way more recent than that).

Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-17 19:11:12 -04:00
Pino Toscano
cf9f4a73f4 inspection: remove extra try/catch block
This block only catches failures in g.inspect_get_mountpoints(), as the
g.mount_ro() calls are already within own try/catch blocks.  Considering
that:
- g.inspect_get_mountpoints() is a simple API to query one of the
  results of the inspection, it is very unlikely that it fails
- the whole _inspect_vm function (that contains the inspection code) is
  already run within an own try/catch block, so even a failure in
  g.inspect_get_mountpoints() will not crash virt-manager
then just remove this extra try/catch block.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-17 19:11:12 -04:00
Pino Toscano
1018ab4484 inspection: handle failures in application listing
The Python binding of libguestfs errors out in case any of the details
(e.g. summary, description) of an application are not proper UTF-8.
This seems a rare situation, which nevertheless causes the failure of
the inspection of a guest, making the rest of the metadata not used.

While these encoding issues are tackled, and fixed in python-libguestfs
(or libguestfs itself), gracefully handle the failure of
inspect_list_applications(), so at least the rest of the details of a
guest are used/shown.
2019-02-07 09:59:28 -05:00
Pino Toscano
bce4cc4ef8 inspection: fix check of null icon
Recently the Python binding of libguestfs was adapted to properly use
bytes in APIs that return data, instead of (ab)using strings [1].
This change was done only when built for Python 3, which has this
distinct bytes and strings.

Because of that, now the 'icon == ""' (empty string) checks fail, using
whatever inspect_get_icon() returns, including empty arrays of bytes.
Hence, change the checks to use the length of the data as condition, as
also the libguestfs Python API documentation says.  Leave also the
checks for None, in the remote case the API will return None in the
future for no data.

[1] 0ee02e0117
2019-01-30 18:06:26 -05:00
Daniel P. Berrangé
48e32b429d Fix copyright header to specify GPLv2 or later, not GPLv2 only.
The copyright headers in every file were chjanged in this previous commit

  commit b6dcee8eb7
  Author: Cole Robinson <crobinso@redhat.com>
  Date:   Tue Mar 20 15:00:02 2018 -0400

    Use consistent and minimal license header for every file

Where before this they said "

  "either version 2 of the License, or (at your option) any later version."

Now they just say

  "GNU GPLv2"

This fixes it to say "GNU GPLv2 or later" again.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-04-04 16:51:37 -04:00
Cole Robinson
b6dcee8eb7 Use consistent and minimal license header for every file 2018-03-21 07:29:40 -04:00
Cole Robinson
3c1e0a8a12 virtManager/*: Give pylint hints about singleton classes
It can't seem to figure out that what 'cls' is in this context,
so make it explicit.
2018-03-17 18:46:39 -04:00
Cole Robinson
cad809fe80 Make all dialogs clean up when vm/conn disappears
Moves all the window cleanup handling to each class and audit for
all --test-leak-debug errors and fix
2018-03-15 21:24:48 -04:00
Cole Robinson
1780d0e9f0 details: Call inspection VM refresh directly 2018-03-15 21:24:48 -04:00
Cole Robinson
f088537798 engine: break out vmmConnectionManager
Have a separate class for tracking the connection list, and emitting
conn-added and conn-removed signals. It exists as a singleton instance
that UI classes can talk directly to
2018-03-15 21:24:48 -04:00
Cole Robinson
befafe9dc7 engine: connect conn-added in UI classes
This creates a weird situation where we pass the engine to those
classes UI functions, but this is a step towards untangling that.

While here, get rid of the conn-added connect magic and add a
simpler way to access the connection list from the engine
2018-03-15 21:24:48 -04:00
Cole Robinson
2dcfaafcac inspection: Show inspection error in details page 2018-03-15 21:24:48 -04:00
Cole Robinson
c21e0db6ea inspection: Remove startup delay
Like the comment says it shouldn't matter
2018-03-15 21:24:48 -04:00
Cole Robinson
48e97e85a6 inspection: Skip for test connections 2018-03-15 21:24:48 -04:00
Cole Robinson
6b1278ccda prefs: Add a setting to enable/disable libguestfs inspection
Rather than key it on the library being available. Makes it much
easier to test both modes of behavior.

Fix up a few inspection bugs while I'm in the area, and convert
it to be more singleton like.
2018-03-15 21:24:48 -04:00
Cole Robinson
6959a41ff2 connection: Drop vm-added emission on connect
We don't use this for most other signals and it's kind of unexpected
2018-03-15 21:24:48 -04:00
Radostin Stoyanov
5854b7bb17 Replace "Queue" with "queue"
The Queue module has been renamed to queue in Python 3. [1]

[1] https://docs.python.org/2/library/queue.html
2018-02-06 18:49:17 -05:00
Radostin Stoyanov
b93cc3bbc9 pycodestyle: Do not use bare 'except:'
A bare 'except:' catches all exceptions [1], including SystemExit,
KeyboardInterrupt, and GeneratorExit (which is not an error and should
not normally be caught by user code). In situations where you need to
catch all “normal” errors, you can catch the base class for all normal
exceptions, Exception [2].

[1] https://docs.python.org/2/howto/doanddont.html#except
[2] https://docs.python.org/2/library/exceptions.html#Exception
2017-08-02 13:57:43 -04:00
Pino Toscano
45d0be9805 inspection: add vmmInspection.vm_refresh helper
Add a simple helper to force a new inspection of a VM.
2017-03-01 16:25:47 -05:00
Pino Toscano
67ed3e86df inspection: filter libguestfs VMs earlier
No need to do any job for them, so skip processing them altogether when
a new one is added.
2017-03-01 16:25:47 -05:00
Pino Toscano
d2ca54fce4 inspection: remove queue draining
Now we act for each item in the queue, so there is no more need to drain
it fully before doing anything.  Thus, turn _run into a simple
get+process+done loop.
2017-03-01 16:25:47 -05:00
Pino Toscano
7a696c8db8 inspection: handle duplicated conn-added signals
We might get 'conn-added' signals for the same connections more than
once, so make sure to skip a new connection notification when the
connection is already known.
2017-03-01 16:25:47 -05:00
Pino Toscano
ea5a6a3014 inspection: simplify VMs visit
Currently, the handling of the 'vm_added' element in the queue (added as
consequence of the 'vm-added' signal) is to act as trigger to rescan
every VM in every local connection; this operation is "fast" because
every VM except the newly added is already marked as visited. Still, it
is an not really efficient way to visit new VMs.

Instead, just push in the queue all the data we get in vm_added, so when
processing the queue we can process each VM straight away.  Because of
this, make sure to gracefully handle VMs that were removed while the
'vm_added' item for them was sitting in the queue (which is something
the old code did not handle properly).
2017-03-01 16:25:47 -05:00
Pino Toscano
0c019fb8e3 inspection: rename vmmInspection._process to _inspect_vm
It fits more the actual job of the function.
2017-03-01 16:25:47 -05:00
Pino Toscano
ad47e80ec2 inspection: extract vmmInspection._process_vm
Move the code that does the inspection handling of a VM to an own
function, so it can be used as-is later on.

It is just code motion.
2017-03-01 16:25:47 -05:00
Pino Toscano
46f4abbb50 inspection: try low quality icons as fallback
When there is no high quality icon for a guest, try getting the low
quality icon.  This should make virt-manager show icons for Ubuntu and
Windows guests.
2017-02-09 16:29:27 -05:00
Pino Toscano
f7a726dc70 inspection: rename variable for OS type
'type' is ambiguous as name, it might conflict with the Python builtin.
Instead, rename it to 'os_type' to get rid of the issue altogether.
2017-02-09 16:29:27 -05:00
Richard W.M. Jones
22b338a65a virt-manager, inspection: use add_libvirt_dom
Enable inspection only if the add_libvirt_dom function is present at
runtime.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1075143

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-01-09 12:32:45 +01:00
Cole Robinson
226c4562d5 virtManager: Switch to relative imports 2014-09-12 16:28:38 -04:00
Cole Robinson
aefd4c4824 connection: Use name instead of uuid for object keys
And clean up the API mess while we are at it. Treat the key as an opaque
value that users shouldn't depend on.

Besides the improved code clarity and API layout, this will help diagnose
'key error' issues, since we'll see an object name instead of UUID which
is hard to trace back.
2014-06-02 17:48:32 -04:00
Cole Robinson
a398d245cb Clean up pylint integration
- Drop no longer needed disable= bits
- Use string names for all skipped pylint messages
2014-04-02 19:00:24 -04:00
Cole Robinson
5c1ed03b89 Fix some pylint 2013-12-18 16:34:10 -05:00
Richard W.M. Jones
006fcd3856 guestfs: As virt-manager is multithreaded, don't use an atexit handler.
libguestfs adds an atexit handler to clean up handles on exit.  This
is convenient in single-threaded programs, but causes problems in
multithreaded programs, for example:

https://bugzilla.redhat.com/show_bug.cgi?id=1043520

Disable the atexit handler for all guestfs handles created by
virt-manager.

Note this change requires libguestfs >= 1.20.  However the change to
config.py should ensure that if an earlier version of libguestfs is
installed it should silently fall back to not using inspection.
2013-12-16 12:55:33 -05:00
Giuseppe Scrivano
b3131e828e inspection: report guest inspection errors
Add an `error' flag to the inspection data for a guest and set it when
the inspection failed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2013-12-03 11:39:23 +01:00
Giuseppe Scrivano
0df75c7603 headers: update "Red Hat, Inc." copyright for the year 2013
Ensure that any file touched by a @redhat.com author in 2013 has an
updated copyright header.

The files were updated using the build-aux/update-copyright gnulib
script and manually added where the copyright line wasn't present.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2013-10-28 17:22:26 +01:00
Richard W.M. Jones
ab312910f2 inspection: Don't recursively try to inspect guestfs-* temporary VMs.
This is a hack.  Should libvirt have a way to mark these VMs?

Note you'll only come across this problem if you run virt-manager as
root with libguestfs >= 1.20 on Fedora >= 18 (libguestfs using libvirt).
2013-06-28 13:05:16 -04:00
Cole Robinson
04f0113c2d libguestfs: Work around a pylint error
Not sure why it's triggering a warning here, thinks the return result
is a dict()
2013-06-13 16:12:55 -04:00
Cole Robinson
cbe8665948 libguestfs: Don't try to create icon if none found 2013-06-13 16:10:44 -04:00
Cole Robinson
f3751e6fe9 libguestfs: Start the inspection thread earlier 2013-06-13 16:04:16 -04:00
Cole Robinson
5a46e7420a libguestfs: Drop all version checks
Now that virt-manager requires very modern versions of gtk, it's
quite unlikely that we will even run on a system with an old
libguestfs version, so don't bother checking versions.
2013-06-13 16:04:16 -04:00
Cole Robinson
0d243983d0 Revive pep8 and clean up the code
autopep8 is pretty cool :)
2013-04-13 15:22:43 -04:00
Cole Robinson
ae471007fc Tons of misc pylint fixes 2013-04-13 13:40:29 -04:00
Cole Robinson
9d05583c26 Remove autotools, replace with distutils-extra
Despite being a known quantity, autotools is so overkill for our needs,
so let's drop it and replace it with a much simpler and easy to customize
system.
2013-04-03 18:20:51 -04:00