Ejemplo n.º 1
0
 def fakeAcquireFile(filename, fullurl=None):
     log.debug("Fake acquiring filename=%s fullurl=%s", filename, fullurl)
     return filename
Ejemplo n.º 2
0
# Copyright (C) 2006 Daniel P. Berrange <*****@*****.**>
#
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.

# pylint: disable=wrong-import-order,ungrouped-imports
import gi
from gi.repository import Gdk
from gi.repository import Gtk

from virtinst import log

# We can use either 2.91 or 2.90. This is just to silence runtime warnings
try:
    gi.require_version("Vte", "2.91")
    log.debug("Using VTE API 2.91")
except ValueError:
    gi.require_version("Vte", "2.90")
    log.debug("Using VTE API 2.90")
from gi.repository import Vte

import libvirt

from ..baseclass import vmmGObject


class ConsoleConnection(vmmGObject):
    def __init__(self, vm):
        vmmGObject.__init__(self)

        self.vm = vm
Ejemplo n.º 3
0
 def close(self, ignore1=None, ignore2=None):
     log.debug("Closing open connection")
     self.topwin.hide()
Ejemplo n.º 4
0
 def _auth_failure_cb(self, ignore, msg):
     log.debug("VNC auth failure. msg=%s", msg)
     self.emit("auth-error", msg, True)
Ejemplo n.º 5
0
 def __init__(self, url):
     log.debug("mocking requests session for url=%s", url)
     fn = _make_mock_url(url, filesyntax=False)
     self._content = open(fn).read()
     self.headers = {'content-length': len(self._content)}
Ejemplo n.º 6
0
 def resume(src, vm):
     log.debug("Unpausing vm '%s'", vm.get_name())
     vmmAsyncJob.simple_async_noshow(vm.resume, [], src,
                                     _("Error unpausing domain"))
Ejemplo n.º 7
0
 def show(self, parent):
     log.debug("Showing preferences")
     self.topwin.set_transient_for(parent)
     self.topwin.present()
Ejemplo n.º 8
0
 def _build_xmlobj_from_xmleditor(self):
     xml = self._xmleditor.get_xml()
     log.debug("Using XML from xmleditor:\n%s", xml)
     return Network(self.conn.get_backend(), parsexml=xml)
Ejemplo n.º 9
0
 def show(self, parent):
     log.debug("Showing new network wizard")
     self.reset_state()
     self.topwin.set_transient_for(parent)
     self.topwin.present()
Ejemplo n.º 10
0
 def show(self, parent, vm):
     log.debug("Showing migrate wizard")
     self._set_vm(vm)
     self._reset_state()
     self.topwin.set_transient_for(parent)
     self.topwin.present()
Ejemplo n.º 11
0
 def close(self, ignore1=None, ignore2=None):
     log.debug("Closing migrate wizard")
     self.topwin.hide()
     self._set_vm(None)
     return 1
Ejemplo n.º 12
0
    def _viewer_connected(self, ignore):
        log.debug("Viewer connected")
        self._activate_gfx_viewer_page()

        # Make sure modifiers are set correctly
        self._viewer_sync_modifiers()
Ejemplo n.º 13
0
def wrap_func(module, funcobj):
    name = funcobj.__name__
    log.debug("wrapfunc %s %s", funcobj, name)

    newfunc = generate_wrapper(funcobj, name)
    setattr(module, name, newfunc)
Ejemplo n.º 14
0
 def show(self, parent):
     log.debug("Showing new snapshot wizard")
     self._reset_state()
     self.topwin.set_transient_for(parent)
     self.topwin.present()
Ejemplo n.º 15
0
 def _XMLDesc(self, flags):
     try:
         return self._backend.XMLDesc(flags)
     except Exception as e:  # pragma: no cover
         log.debug("XMLDesc for vol=%s failed: %s", self._backend.key(), e)
         raise
Ejemplo n.º 16
0
 def close(self, ignore1=None, ignore2=None):
     log.debug("Closing new network wizard")
     self.topwin.hide()
     return 1
Ejemplo n.º 17
0
    def check_all_storage(self):
        """
        Determine which storage is cloneable, and which isn't
        """
        diskinfos = self.vm.xmlobj.devices.disk
        cd = self.clone_design

        storage_list = {}

        # We need to determine which disks fail (and why).
        all_targets = [d.target for d in diskinfos]

        for disk in diskinfos:
            force_target = disk.target
            path = disk.path
            ro = disk.read_only
            shared = disk.shareable
            devtype = disk.device

            size = None
            clone_path = None
            failinfo = ""
            definfo = ""

            storage_row = []
            storage_row.insert(STORAGE_INFO_ORIG_PATH, path or "-")
            storage_row.insert(STORAGE_INFO_NEW_PATH, clone_path)
            storage_row.insert(STORAGE_INFO_TARGET, force_target)
            storage_row.insert(STORAGE_INFO_SIZE, size)
            storage_row.insert(STORAGE_INFO_DEVTYPE, devtype)
            storage_row.insert(STORAGE_INFO_DO_CLONE, False)
            storage_row.insert(STORAGE_INFO_CAN_CLONE, False)
            storage_row.insert(STORAGE_INFO_CAN_SHARE, False)
            storage_row.insert(STORAGE_INFO_DO_DEFAULT, False)
            storage_row.insert(STORAGE_INFO_DEFINFO, definfo)
            storage_row.insert(STORAGE_INFO_FAILINFO, failinfo)
            storage_row.insert(STORAGE_INFO_COMBO, None)
            storage_row.insert(STORAGE_INFO_MANUAL_PATH, False)

            skip_targets = all_targets[:]
            skip_targets.remove(force_target)

            vol = self.conn.get_vol_by_path(path)
            default, definfo, can_default = do_we_default(
                self.conn, vol, path, ro, shared, devtype)

            def storage_add(failinfo=None):
                # pylint: disable=cell-var-from-loop
                storage_row[STORAGE_INFO_DEFINFO] = definfo
                storage_row[STORAGE_INFO_DO_DEFAULT] = default
                storage_row[STORAGE_INFO_CAN_SHARE] = bool(definfo)
                if failinfo:
                    storage_row[STORAGE_INFO_FAILINFO] = failinfo
                    storage_row[STORAGE_INFO_DO_CLONE] = False

                storage_list[force_target] = storage_row

            # If origdisk is empty, deliberately make it fail
            if not path:
                storage_add(_("Nothing to clone."))
                continue

            try:
                cd.skip_target = skip_targets
                cd.setup_original()
            except Exception as e:
                log.exception("Disk target '%s' caused clone error",
                              force_target)
                storage_add(str(e))
                continue

            can_clone, cloneinfo = can_we_clone(self.conn, vol, path)
            if not can_clone:
                storage_add(cloneinfo)
                continue

            storage_row[STORAGE_INFO_CAN_CLONE] = True

            # If we cannot create default clone_path don't even try to do that
            if not can_default:
                storage_add()
                continue

            try:
                # Generate disk path, make sure that works
                clone_path = self.generate_clone_path_name(path)

                log.debug("Original path: %s\nGenerated clone path: %s", path,
                          clone_path)

                cd.clone_paths = clone_path
                size = cd.original_disks[0].get_size()
            except Exception as e:
                log.exception("Error setting generated path '%s'", clone_path)
                storage_add(str(e))

            storage_row[STORAGE_INFO_NEW_PATH] = clone_path
            storage_row[STORAGE_INFO_SIZE] = self.pretty_storage(size)
            storage_add()

        return storage_list, all_targets
Ejemplo n.º 18
0
 def _logtrace(self, msg=""):
     if msg:
         msg += " "
     log.debug("%s(%s %s)\n:%s", msg, self.object_key, self._refcount(),
               "".join(traceback.format_stack()))
Ejemplo n.º 19
0
 def close(self, ignore1=None, ignore2=None):
     log.debug("Closing preferences")
     self.topwin.hide()
     return 1
Ejemplo n.º 20
0
 def _volume_chosen(self, src, volume):
     ignore = src
     log.debug("Chosen volume XML:\n%s", volume.xmlobj.get_xml())
     self._finish(volume.get_target_path())
Ejemplo n.º 21
0
 def refresh_dhcp_leases(self):
     try:
         self._leases = self._backend.DHCPLeases()
     except Exception as e:
         log.debug("Error getting %s DHCP leases: %s", self, str(e))
         self._leases = []
Ejemplo n.º 22
0
 def close(self, ignore1=None, ignore2=None):
     if self.is_visible():
         log.debug("Closing storage browser")
         self.topwin.hide()
     self.storagelist.close()
     return 1
Ejemplo n.º 23
0
 def _open_host(self):
     host, port, ignore = self._ginfo.get_conn_host()
     log.debug("VNC connecting to host=%s port=%s", host, port)
     self._display.open_host(host, port)
Ejemplo n.º 24
0
                "/org/freedesktop/DBus",
                "org.freedesktop.DBus", None)
        if dbus.NameHasOwner("(s)", "org.kde.StatusNotifierWatcher"):
            return True
        if dbus.NameHasOwner("(s)", "org.freedesktop.StatusNotifierWatcher"):
            return True
        return False
    except Exception:
        log.exception("Error checking for appindicator dbus")
        return False


_USING_APPINDICATOR = False
if AppIndicator3:  # pragma: no cover
    if not _has_appindicator_dbus():
        log.debug("AppIndicator3 is available, but didn't "
                              "find any dbus watcher.")
    else:
        _USING_APPINDICATOR = True
        log.debug("Using AppIndicator3 for systray")


###########################
# systray backend classes #
###########################

class _Systray(object):
    def is_embedded(self):
        raise NotImplementedError()
    def show(self):
        raise NotImplementedError()
    def hide(self):
Ejemplo n.º 25
0
 def fakeAcquireFile(filename):
     log.debug("Fake acquiring %s", filename)
     return filename
Ejemplo n.º 26
0
def main():
    (options, leftovers) = parse_commandline()

    cli.setupLogging("virt-manager", options.debug, False, False)

    log.debug("virt-manager version: %s", BuildConfig.version)
    log.debug("virtManager import: %s", os.path.dirname(__file__))

    if BuildConfig.running_from_srcdir:
        _setup_gsettings_path(BuildConfig.gsettings_dir)

    if options.trace_libvirt:
        log.debug("Libvirt tracing requested")
        from .lib import module_trace
        import libvirt
        module_trace.wrap_module(
            libvirt,
            mainloop=(options.trace_libvirt == "mainloop"),
            regex=None)

    CLITestOptions = CLITestOptionsClass(options.test_options)
    if options.test_first_run:
        CLITestOptions.first_run = True
    if options.test_leak_debug:
        CLITestOptions.leak_debug = True
    if options.test_no_events:
        CLITestOptions.no_events = True

    # With F27 gnome+wayland we need to set these before GTK import
    os.environ["GSETTINGS_SCHEMA_DIR"] = BuildConfig.gsettings_dir
    if CLITestOptions.first_run:
        os.environ["GSETTINGS_BACKEND"] = "memory"

    # Now we've got basic environment up & running we can fork
    do_drop_stdio = False
    if not options.no_fork and not options.debug:
        drop_tty()
        do_drop_stdio = True

        # Ignore SIGHUP, otherwise a serial console closing drops the whole app
        signal.signal(signal.SIGHUP, signal.SIG_IGN)

    leftovers = _import_gtk(leftovers)
    Gtk = globals()["Gtk"]

    # Do this after the Gtk import so the user has a chance of seeing any error
    if do_drop_stdio:
        drop_stdio()

    if leftovers:
        raise RuntimeError("Unhandled command line options '%s'" % leftovers)

    log.debug("PyGObject version: %d.%d.%d", gi.version_info[0],
              gi.version_info[1], gi.version_info[2])
    log.debug("GTK version: %d.%d.%d", Gtk.get_major_version(),
              Gtk.get_minor_version(), Gtk.get_micro_version())

    if not VirtinstConnection.libvirt_new_enough_for_virtmanager(6000):
        # We need this version for threaded virConnect access
        _show_startup_error(_("virt-manager requires libvirt 0.6.0 or later."),
                            "")
        return

    # Prime the vmmConfig cache
    from . import config
    config.vmmConfig.get_instance(BuildConfig, CLITestOptions)

    # Add our icon dir to icon theme
    icon_theme = Gtk.IconTheme.get_default()
    icon_theme.prepend_search_path(BuildConfig.icon_dir)

    from .engine import vmmEngine
    Gtk.Window.set_default_icon_name("virt-manager")

    show_window = None
    domain = None
    if options.show_domain_creator:
        show_window = vmmEngine.CLI_SHOW_DOMAIN_CREATOR
    elif options.show_host_summary:
        show_window = vmmEngine.CLI_SHOW_HOST_SUMMARY
    elif options.show_domain_editor:
        show_window = vmmEngine.CLI_SHOW_DOMAIN_EDITOR
        domain = options.show_domain_editor
    elif options.show_domain_performance:
        show_window = vmmEngine.CLI_SHOW_DOMAIN_PERFORMANCE
        domain = options.show_domain_performance
    elif options.show_domain_console:
        show_window = vmmEngine.CLI_SHOW_DOMAIN_CONSOLE
        domain = options.show_domain_console
    elif options.show_domain_delete:
        show_window = vmmEngine.CLI_SHOW_DOMAIN_DELETE
        domain = options.show_domain_delete

    if show_window and options.uri is None:
        raise RuntimeError("can't use --show-* options without --connect")

    skip_autostart = False
    if show_window:
        skip_autostart = True

    # Hook libvirt events into glib main loop
    LibvirtGLib.init(None)
    LibvirtGLib.event_register()

    engine = vmmEngine.get_instance()

    # Actually exit when we receive ctrl-c
    from gi.repository import GLib

    def _sigint_handler(user_data):
        ignore = user_data
        log.debug("Received KeyboardInterrupt. Exiting application.")
        engine.exit_app()

    GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, _sigint_handler,
                         None)

    engine.start(options.uri, show_window, domain, skip_autostart)
Ejemplo n.º 27
0
 def cancel(self, ignore1=None, ignore2=None):
     log.debug("Cancelling open connection")
     self.close()
     return 1
Ejemplo n.º 28
0
 def _sigint_handler(user_data):
     ignore = user_data
     log.debug("Received KeyboardInterrupt. Exiting application.")
     engine.exit_app()
Ejemplo n.º 29
0
    def _viewer_connected(self, ignore):
        log.debug("Viewer connected")
        self._activate_viewer_page()

        # Make sure modifiers are set correctly
        self._viewer_focus_changed()
Ejemplo n.º 30
0
 def _destroy_vm(self, vm):
     if vm.is_active():
         log.debug("Forcing VM '%s' power off.", vm.get_name())
         vm.destroy()