2014-07-31 15:26:56 +04:00
# Copyright (C) 2013-2014 Red Hat, Inc.
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
# Copyright (C) 2013 Cole Robinson <crobinso@redhat.com>
#
2018-03-20 22:00:02 +03:00
# This work is licensed under the GNU GPLv2.
# See the COPYING file in the top-level directory.
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
import datetime
2013-10-01 05:41:10 +04:00
import glob
2017-10-11 14:35:50 +03:00
import io
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
import logging
2013-10-01 05:41:10 +04:00
import os
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
from gi . repository import Gdk
2013-10-01 05:41:10 +04:00
from gi . repository import GdkPixbuf
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
from gi . repository import Gtk
2014-02-14 19:20:37 +04:00
from gi . repository import Pango
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 00:33:45 +04:00
from virtinst import DomainSnapshot
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
from virtinst import util
2014-09-13 00:10:45 +04:00
from . import uiutil
from . baseclass import vmmGObjectUI
from . asyncjob import vmmAsyncJob
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 05:41:10 +04:00
mimemap = {
" image/x-portable-pixmap " : " ppm " ,
" image/png " : " png " ,
}
def _mime_to_ext ( val , reverse = False ) :
for m , e in mimemap . items ( ) :
if val == m and not reverse :
return e
if val == e and reverse :
return m
logging . debug ( " Don ' t know how to convert %s = %s to %s " ,
reverse and " extension " or " mime " , val ,
reverse and " mime " or " extension " )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
class vmmSnapshotPage ( vmmGObjectUI ) :
def __init__ ( self , vm , builder , topwin ) :
2013-09-23 00:10:16 +04:00
vmmGObjectUI . __init__ ( self , " snapshots.ui " ,
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
None , builder = builder , topwin = topwin )
self . vm = vm
self . _initial_populate = False
2014-07-31 18:42:35 +04:00
self . _unapplied_changes = False
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-05 22:57:58 +04:00
self . _snapmenu = None
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . _init_ui ( )
self . _snapshot_new = self . widget ( " snapshot-new " )
self . _snapshot_new . set_transient_for ( self . topwin )
2013-10-01 00:37:46 +04:00
self . bind_escape_key_close_helper ( self . _snapshot_new ,
self . _snapshot_new_close )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . builder . connect_signals ( {
" on_snapshot_add_clicked " : self . _on_add_clicked ,
" on_snapshot_delete_clicked " : self . _on_delete_clicked ,
" on_snapshot_start_clicked " : self . _on_start_clicked ,
" on_snapshot_apply_clicked " : self . _on_apply_clicked ,
2013-10-01 00:04:11 +04:00
" on_snapshot_list_changed " : self . _snapshot_selected ,
2013-10-05 22:57:58 +04:00
" on_snapshot_list_button_press_event " : self . _popup_snapshot_menu ,
2018-01-19 00:44:35 +03:00
" on_snapshot_refresh_clicked " : self . _on_refresh_clicked ,
2016-07-29 12:44:46 +03:00
" on_snapshot_list_row_activated " : self . _on_start_clicked ,
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
# 'Create' dialog
" on_snapshot_new_delete_event " : self . _snapshot_new_close ,
" on_snapshot_new_ok_clicked " : self . _on_new_ok_clicked ,
2017-08-05 09:39:32 +03:00
" on_snapshot_new_cancel_clicked " : self . _snapshot_new_close ,
" on_snapshot_new_name_changed " : self . _snapshot_new_name_changed ,
2013-10-05 22:47:10 +04:00
" on_snapshot_new_name_activate " : self . _on_new_ok_clicked ,
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
} )
self . top_box = self . widget ( " snapshot-top-box " )
self . widget ( " snapshot-top-window " ) . remove ( self . top_box )
2014-07-31 16:28:54 +04:00
selection = self . widget ( " snapshot-list " ) . get_selection ( )
selection . emit ( " changed " )
selection . set_mode ( Gtk . SelectionMode . MULTIPLE )
2014-07-31 18:42:35 +04:00
selection . set_select_function ( self . _confirm_changes , None )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
##############
# Init stuff #
##############
def _cleanup ( self ) :
self . vm = None
self . _snapshot_new . destroy ( )
self . _snapshot_new = None
2018-03-15 14:43:56 +03:00
self . _snapmenu = None
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
def _init_ui ( self ) :
2016-04-18 23:42:12 +03:00
# pylint: disable=redefined-variable-type
2013-09-30 22:28:43 +04:00
blue = Gdk . color_parse ( " #0072A8 " )
self . widget ( " header " ) . modify_bg ( Gtk . StateType . NORMAL , blue )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . widget ( " snapshot-notebook " ) . set_show_tabs ( False )
buf = Gtk . TextBuffer ( )
buf . connect ( " changed " , self . _description_changed )
self . widget ( " snapshot-description " ) . set_buffer ( buf )
2013-09-30 22:28:43 +04:00
buf = Gtk . TextBuffer ( )
self . widget ( " snapshot-new-description " ) . set_buffer ( buf )
2014-02-01 20:25:35 +04:00
# [name, row label, tooltip, icon name, sortname, current]
model = Gtk . ListStore ( str , str , str , str , str , bool )
2013-10-01 01:53:55 +04:00
model . set_sort_column_id ( 4 , Gtk . SortType . ASCENDING )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
col = Gtk . TreeViewColumn ( " " )
col . set_min_width ( 150 )
col . set_spacing ( 6 )
2014-02-01 20:25:35 +04:00
2013-10-01 01:36:38 +04:00
img = Gtk . CellRendererPixbuf ( )
img . set_property ( " stock-size " , Gtk . IconSize . LARGE_TOOLBAR )
col . pack_start ( img , False )
2014-02-01 20:25:35 +04:00
col . add_attribute ( img , ' icon-name ' , 3 )
txt = Gtk . CellRendererText ( )
2014-02-14 19:20:37 +04:00
txt . set_property ( " ellipsize " , Pango . EllipsizeMode . END )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
col . pack_start ( txt , False )
2013-10-01 01:36:38 +04:00
col . add_attribute ( txt , ' markup ' , 1 )
2014-02-01 20:25:35 +04:00
img = Gtk . CellRendererPixbuf ( )
img . set_property ( " stock-size " , Gtk . IconSize . MENU )
img . set_property ( " icon-name " , Gtk . STOCK_APPLY )
2014-02-14 19:20:37 +04:00
img . set_property ( " xalign " , 0.0 )
col . pack_start ( img , False )
2014-02-01 20:25:35 +04:00
col . add_attribute ( img , " visible " , 5 )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 01:53:55 +04:00
def _sep_cb ( _model , _iter , ignore ) :
return not bool ( _model [ _iter ] [ 0 ] )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
slist = self . widget ( " snapshot-list " )
slist . set_model ( model )
slist . set_tooltip_column ( 2 )
slist . append_column ( col )
2013-10-01 01:53:55 +04:00
slist . set_row_separator_func ( _sep_cb , None )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-05 22:57:58 +04:00
# Snapshot popup menu
menu = Gtk . Menu ( )
2014-02-26 00:57:38 +04:00
item = Gtk . ImageMenuItem . new_with_label ( _ ( " _Start snapshot " ) )
2013-10-05 22:57:58 +04:00
item . set_use_underline ( True )
img = Gtk . Image ( )
img . set_from_stock ( Gtk . STOCK_MEDIA_PLAY , Gtk . IconSize . MENU )
item . set_image ( img )
item . show ( )
item . connect ( " activate " , self . _on_start_clicked )
menu . add ( item )
2014-02-26 00:57:38 +04:00
item = Gtk . ImageMenuItem . new_with_label ( _ ( " _Delete snapshot " ) )
2013-10-05 22:57:58 +04:00
item . set_use_underline ( True )
img = Gtk . Image ( )
img . set_from_stock ( Gtk . STOCK_DELETE , Gtk . IconSize . MENU )
item . set_image ( img )
item . show ( )
item . connect ( " activate " , self . _on_delete_clicked )
menu . add ( item )
self . _snapmenu = menu
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
###################
# Functional bits #
###################
2014-07-31 16:28:54 +04:00
def _get_selected_snapshots ( self ) :
selection = self . widget ( " snapshot-list " ) . get_selection ( )
def add_snap ( treemodel , path , it , snaps ) :
ignore = path
try :
name = treemodel [ it ] [ 0 ]
for snap in self . vm . list_snapshots ( ) :
if name == snap . get_name ( ) :
snaps . append ( snap )
2017-07-24 11:26:48 +03:00
except Exception :
2014-07-31 16:28:54 +04:00
pass
2014-01-27 05:21:12 +04:00
2014-07-31 16:28:54 +04:00
snaps = [ ]
selection . selected_foreach ( add_snap , snaps )
return snaps
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 05:41:10 +04:00
def _refresh_snapshots ( self , select_name = None ) :
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . vm . refresh_snapshots ( )
2013-10-01 05:41:10 +04:00
self . _populate_snapshot_list ( select_name )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
def show_page ( self ) :
if not self . _initial_populate :
self . _populate_snapshot_list ( )
def _set_error_page ( self , msg ) :
self . _set_snapshot_state ( None )
self . widget ( " snapshot-notebook " ) . set_current_page ( 1 )
self . widget ( " snapshot-error-label " ) . set_text ( msg )
2013-10-01 05:41:10 +04:00
def _populate_snapshot_list ( self , select_name = None ) :
2014-07-31 16:28:54 +04:00
cursnaps = [ ]
for i in self . _get_selected_snapshots ( ) :
cursnaps . append ( i . get_name ( ) )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
model = self . widget ( " snapshot-list " ) . get_model ( )
model . clear ( )
try :
snapshots = self . vm . list_snapshots ( )
2017-05-05 19:47:21 +03:00
except Exception as e :
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
logging . exception ( e )
self . _set_error_page ( _ ( " Error refreshing snapshot list: %s " ) %
str ( e ) )
return
2013-10-01 01:53:55 +04:00
has_external = False
has_internal = False
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
for snap in snapshots :
2013-09-23 16:34:50 +04:00
desc = snap . get_xmlobj ( ) . description
2013-10-01 01:36:38 +04:00
name = snap . get_name ( )
2017-07-11 00:51:04 +03:00
state = snap . run_status ( )
2013-10-01 01:53:55 +04:00
if snap . is_external ( ) :
has_external = True
sortname = " 3 %s " % name
external = " ( %s ) " % _ ( " External " )
else :
has_internal = True
external = " "
sortname = " 1 %s " % name
label = " %s \n <span size= ' small ' > %s : %s %s </span> " % (
2017-07-11 00:51:04 +03:00
( util . xml_escape ( name ) , _ ( " VM State " ) ,
util . xml_escape ( state ) , external ) )
2013-10-01 02:46:54 +04:00
model . append ( [ name , label , desc , snap . run_status_icon_name ( ) ,
2014-02-01 20:25:35 +04:00
sortname , snap . is_current ( ) ] )
2013-10-01 01:53:55 +04:00
if has_internal and has_external :
2014-02-01 20:25:35 +04:00
model . append ( [ None , None , None , None , " 2 " , False ] )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2014-07-31 16:28:54 +04:00
def check_selection ( treemodel , path , it , snaps ) :
if select_name :
if treemodel [ it ] [ 0 ] == select_name :
selection . select_path ( path )
elif treemodel [ it ] [ 0 ] in snaps :
selection . select_path ( path )
selection = self . widget ( " snapshot-list " ) . get_selection ( )
model = self . widget ( " snapshot-list " ) . get_model ( )
selection . unselect_all ( )
model . foreach ( check_selection , cursnaps )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . _initial_populate = True
2013-10-01 05:41:10 +04:00
def _make_screenshot_pixbuf ( self , mime , sdata ) :
loader = GdkPixbuf . PixbufLoader . new_with_mime_type ( mime )
loader . write ( sdata )
pixbuf = loader . get_pixbuf ( )
loader . close ( )
maxsize = 450
def _scale ( big , small , maxsize ) :
if big < = maxsize :
return big , small
factor = float ( maxsize ) / float ( big )
return maxsize , int ( factor * float ( small ) )
width = pixbuf . get_width ( )
height = pixbuf . get_height ( )
if width > height :
width , height = _scale ( width , height , maxsize )
else :
height , width = _scale ( height , width , maxsize )
return pixbuf . scale_simple ( width , height ,
GdkPixbuf . InterpType . BILINEAR )
def _read_screenshot_file ( self , name ) :
if not name :
return
cache_dir = self . vm . get_cache_dir ( )
basename = os . path . join ( cache_dir , " snap-screenshot- %s " % name )
files = glob . glob ( basename + " .* " )
if not files :
return
filename = files [ 0 ]
mime = _mime_to_ext ( os . path . splitext ( filename ) [ 1 ] [ 1 : ] , reverse = True )
if not mime :
return
2017-05-05 21:19:54 +03:00
return self . _make_screenshot_pixbuf ( mime , open ( filename , " rb " ) . read ( ) )
2013-10-01 05:41:10 +04:00
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
def _set_snapshot_state ( self , snap = None ) :
self . widget ( " snapshot-notebook " ) . set_current_page ( 0 )
2013-09-23 16:34:50 +04:00
xmlobj = snap and snap . get_xmlobj ( ) or None
name = snap and xmlobj . name or " "
desc = snap and xmlobj . description or " "
2013-10-01 01:11:22 +04:00
state = snap and snap . run_status ( ) or " "
icon = snap and snap . run_status_icon_name ( ) or None
2013-10-01 01:53:55 +04:00
is_external = snap and snap . is_external ( ) or False
2014-02-01 20:25:35 +04:00
is_current = snap and snap . is_current ( ) or False
2013-10-01 01:53:55 +04:00
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
timestamp = " "
if snap :
timestamp = str ( datetime . datetime . fromtimestamp (
2013-09-23 16:34:50 +04:00
xmlobj . creationTime ) )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
title = " "
if name :
2013-09-30 23:56:09 +04:00
title = " <b>Snapshot ' %s ' :</b> " % util . xml_escape ( name )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2014-02-01 20:25:35 +04:00
uiutil . set_grid_row_visible (
self . widget ( " snapshot-is-current " ) , is_current )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . widget ( " snapshot-title " ) . set_markup ( title )
self . widget ( " snapshot-timestamp " ) . set_text ( timestamp )
self . widget ( " snapshot-description " ) . get_buffer ( ) . set_text ( desc )
self . widget ( " snapshot-status-text " ) . set_text ( state )
2013-10-01 01:11:22 +04:00
if icon :
self . widget ( " snapshot-status-icon " ) . set_from_icon_name (
2014-01-12 23:36:03 +04:00
icon , Gtk . IconSize . BUTTON )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible ( self . widget ( " snapshot-mode " ) ,
2013-10-01 01:53:55 +04:00
is_external )
if is_external :
is_mem = xmlobj . memory_type == " external "
is_disk = [ d . snapshot == " external " for d in xmlobj . disks ]
if is_mem and is_disk :
mode = _ ( " External disk and memory " )
elif is_mem :
mode = _ ( " External memory only " )
else :
mode = _ ( " External disk only " )
self . widget ( " snapshot-mode " ) . set_text ( mode )
2013-10-01 05:41:10 +04:00
sn = self . _read_screenshot_file ( name )
self . widget ( " snapshot-screenshot " ) . set_visible ( bool ( sn ) )
self . widget ( " snapshot-screenshot-label " ) . set_visible ( not bool ( sn ) )
if sn :
self . widget ( " snapshot-screenshot " ) . set_from_pixbuf ( sn )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . widget ( " snapshot-add " ) . set_sensitive ( True )
self . widget ( " snapshot-delete " ) . set_sensitive ( bool ( snap ) )
self . widget ( " snapshot-start " ) . set_sensitive ( bool ( snap ) )
self . widget ( " snapshot-apply " ) . set_sensitive ( False )
2014-07-31 18:42:35 +04:00
self . _unapplied_changes = False
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2014-07-31 18:42:35 +04:00
def _confirm_changes ( self , sel , model , path , path_selected , user_data ) :
ignore1 = sel
ignore2 = path
ignore3 = model
ignore4 = user_data
if not self . _unapplied_changes or not path_selected :
return True
if self . err . chkbox_helper (
self . config . get_confirm_unapplied ,
self . config . set_confirm_unapplied ,
text1 = ( _ ( " There are unapplied changes. "
" Would you like to apply them now? " ) ) ,
chktext = _ ( " Don ' t warn me again. " ) ,
default = False ) :
self . _apply ( )
return True
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-09-30 22:28:43 +04:00
##################
# 'New' handling #
##################
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 05:41:10 +04:00
def _take_screenshot ( self ) :
stream = None
try :
stream = self . vm . conn . get_backend ( ) . newStream ( 0 )
screen = 0
flags = 0
mime = self . vm . get_backend ( ) . screenshot ( stream , screen , flags )
2018-03-15 22:54:37 +03:00
ret = io . BytesIO ( )
2013-10-01 05:41:10 +04:00
def _write_cb ( _stream , data , userdata ) :
ignore = stream
ignore = userdata
ret . write ( data )
stream . recvAll ( _write_cb , None )
return mime , ret . getvalue ( )
finally :
try :
if stream :
stream . finish ( )
2017-07-24 11:26:48 +03:00
except Exception :
2013-10-01 05:41:10 +04:00
pass
def _get_screenshot ( self ) :
if not self . vm . is_active ( ) :
logging . debug ( " Skipping screenshot since VM is not active " )
return
2018-03-21 21:42:50 +03:00
if not self . vm . xmlobj . devices . graphics :
2013-10-01 05:41:10 +04:00
logging . debug ( " Skipping screenshot since VM has no graphics " )
return
try :
2014-04-29 21:26:26 +04:00
# Perform two screenshots, because qemu + qxl has a bug where
# screenshot generally only shows the data from the previous
# screenshot request:
# https://bugs.launchpad.net/qemu/+bug/1314293
self . _take_screenshot ( )
2013-10-01 05:41:10 +04:00
mime , sdata = self . _take_screenshot ( )
2017-07-24 11:26:48 +03:00
except Exception :
2013-10-01 05:41:10 +04:00
logging . exception ( " Error taking screenshot " )
return
ext = _mime_to_ext ( mime )
if not ext :
return
newpix = self . _make_screenshot_pixbuf ( mime , sdata )
setattr ( newpix , " vmm_mimetype " , mime )
setattr ( newpix , " vmm_sndata " , sdata )
return newpix
2013-09-30 22:28:43 +04:00
def _reset_new_state ( self ) :
2013-10-01 00:33:45 +04:00
collidelist = [ s . get_xmlobj ( ) . name for s in self . vm . list_snapshots ( ) ]
default_name = DomainSnapshot . find_free_name (
self . vm . get_backend ( ) , collidelist )
self . widget ( " snapshot-new-name " ) . set_text ( default_name )
2013-10-01 00:04:11 +04:00
self . widget ( " snapshot-new-name " ) . emit ( " changed " )
2013-09-30 22:28:43 +04:00
self . widget ( " snapshot-new-description " ) . get_buffer ( ) . set_text ( " " )
2013-10-01 00:37:46 +04:00
self . widget ( " snapshot-new-ok " ) . grab_focus ( )
2013-10-01 01:40:01 +04:00
self . widget ( " snapshot-new-status-text " ) . set_text ( self . vm . run_status ( ) )
self . widget ( " snapshot-new-status-icon " ) . set_from_icon_name (
2014-01-12 23:36:03 +04:00
self . vm . run_status_icon_name ( ) , Gtk . IconSize . BUTTON )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 05:41:10 +04:00
sn = self . _get_screenshot ( )
2014-01-27 03:15:50 +04:00
uiutil . set_grid_row_visible (
2013-10-01 05:41:10 +04:00
self . widget ( " snapshot-new-screenshot " ) , bool ( sn ) )
if sn :
self . widget ( " snapshot-new-screenshot " ) . set_from_pixbuf ( sn )
2013-10-01 00:04:11 +04:00
def _snapshot_new_name_changed ( self , src ) :
self . widget ( " snapshot-new-ok " ) . set_sensitive ( bool ( src . get_text ( ) ) )
2013-10-01 05:41:10 +04:00
def _new_finish_cb ( self , error , details , newname ) :
2017-04-27 22:00:17 +03:00
self . reset_finish_cursor ( )
2013-09-07 04:59:01 +04:00
if error is not None :
error = _ ( " Error creating snapshot: %s " ) % error
self . err . show_err ( error , details = details )
return
2013-10-01 05:41:10 +04:00
self . _refresh_snapshots ( newname )
2013-09-07 04:59:01 +04:00
2013-09-30 22:28:43 +04:00
def _validate_new_snapshot ( self ) :
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
name = self . widget ( " snapshot-new-name " ) . get_text ( )
2013-09-30 22:28:43 +04:00
desc = self . widget ( " snapshot-new-description "
2017-09-07 12:03:04 +03:00
) . get_buffer ( ) . get_property ( " text " )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-09-30 22:28:43 +04:00
try :
2013-10-01 00:33:45 +04:00
newsnap = DomainSnapshot ( self . vm . conn . get_backend ( ) )
2013-09-30 22:28:43 +04:00
newsnap . name = name
newsnap . description = desc or None
newsnap . validate ( )
2013-10-01 05:41:10 +04:00
newsnap . get_xml_config ( )
return newsnap
2017-05-05 19:47:21 +03:00
except Exception as e :
2015-06-02 15:21:58 +03:00
return self . err . val_err ( _ ( " Error validating snapshot: %s " ) % e )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 05:41:10 +04:00
def _get_screenshot_data_for_save ( self ) :
snwidget = self . widget ( " snapshot-new-screenshot " )
if not snwidget . is_visible ( ) :
return None , None
sn = snwidget . get_pixbuf ( )
if not sn :
return None , None
mime = getattr ( sn , " vmm_mimetype " , None )
sndata = getattr ( sn , " vmm_sndata " , None )
return mime , sndata
def _do_create_snapshot ( self , asyncjob , xml , name , mime , sndata ) :
ignore = asyncjob
self . vm . create_snapshot ( xml )
try :
cachedir = self . vm . get_cache_dir ( )
basesn = os . path . join ( cachedir , " snap-screenshot- %s " % name )
# Remove any pre-existing screenshots so we don't show stale data
2017-10-11 14:35:46 +03:00
for ext in list ( mimemap . values ( ) ) :
2013-10-01 05:41:10 +04:00
p = basesn + " . " + ext
if os . path . exists ( basesn + " . " + ext ) :
os . unlink ( p )
if not mime or not sndata :
return
filename = basesn + " . " + _mime_to_ext ( mime )
logging . debug ( " Writing screenshot to %s " , filename )
2017-05-05 21:19:54 +03:00
open ( filename , " wb " ) . write ( sndata )
2017-07-24 11:26:48 +03:00
except Exception :
2013-10-01 05:41:10 +04:00
logging . exception ( " Error saving screenshot " )
2013-09-30 22:28:43 +04:00
def _create_new_snapshot ( self ) :
2013-10-01 05:41:10 +04:00
snap = self . _validate_new_snapshot ( )
if not snap :
2013-09-30 22:28:43 +04:00
return
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-10-01 05:41:10 +04:00
xml = snap . get_xml_config ( )
name = snap . name
mime , sndata = self . _get_screenshot_data_for_save ( )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . _snapshot_new_close ( )
2017-04-27 22:00:17 +03:00
self . set_finish_cursor ( )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
progWin = vmmAsyncJob (
2013-10-01 05:41:10 +04:00
self . _do_create_snapshot , [ xml , name , mime , sndata ] ,
self . _new_finish_cb , [ name ] ,
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
_ ( " Creating snapshot " ) ,
_ ( " Creating virtual machine snapshot " ) ,
self . topwin )
2013-09-07 04:59:01 +04:00
progWin . run ( )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2014-07-31 18:42:35 +04:00
def _apply ( self ) :
snaps = self . _get_selected_snapshots ( )
if not snaps or len ( snaps ) > 1 :
return False
snap = snaps [ 0 ]
desc_widget = self . widget ( " snapshot-description " )
desc = desc_widget . get_buffer ( ) . get_property ( " text " ) or " "
xmlobj = snap . get_xmlobj ( )
origxml = xmlobj . get_xml_config ( )
xmlobj . description = desc
newxml = xmlobj . get_xml_config ( )
self . vm . log_redefine_xml_diff ( snap , origxml , newxml )
if newxml == origxml :
return True
2015-04-11 00:50:06 +03:00
2014-07-31 18:42:35 +04:00
self . vm . create_snapshot ( newxml , redefine = True )
2015-04-11 00:50:06 +03:00
snap . ensure_latest_xml ( )
2014-07-31 18:42:35 +04:00
return True
2013-09-30 22:28:43 +04:00
#############
# Listeners #
#############
2013-10-05 22:57:58 +04:00
def _popup_snapshot_menu ( self , src , event ) :
ignore = src
if event . button != 3 :
return
self . _snapmenu . popup ( None , None , None , None , 0 , event . time )
2013-09-30 22:28:43 +04:00
def _snapshot_new_close ( self , * args , * * kwargs ) :
ignore = args
ignore = kwargs
self . _snapshot_new . hide ( )
return 1
def _description_changed ( self , ignore ) :
2014-07-31 18:42:35 +04:00
snaps = self . _get_selected_snapshots ( )
2013-09-30 22:28:43 +04:00
desc_widget = self . widget ( " snapshot-description " )
desc = desc_widget . get_buffer ( ) . get_property ( " text " ) or " "
2014-07-31 18:42:35 +04:00
if len ( snaps ) == 1 and snaps [ 0 ] . get_xmlobj ( ) . description != desc :
self . _unapplied_changes = True
2013-09-30 22:28:43 +04:00
2014-07-31 18:42:35 +04:00
self . widget ( " snapshot-apply " ) . set_sensitive ( True )
def _on_apply_clicked ( self , ignore ) :
self . _apply ( )
2013-09-30 22:28:43 +04:00
self . _refresh_snapshots ( )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2013-09-30 22:28:43 +04:00
def _on_new_ok_clicked ( self , ignore ) :
return self . _create_new_snapshot ( )
def _on_add_clicked ( self , ignore ) :
if self . _snapshot_new . is_visible ( ) :
return
self . _reset_new_state ( )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . _snapshot_new . show ( )
2013-10-05 22:47:10 +04:00
self . widget ( " snapshot-new-name " ) . grab_focus ( )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
2018-01-19 00:44:35 +03:00
def _on_refresh_clicked ( self , ignore ) :
self . _refresh_snapshots ( )
2016-07-29 12:44:46 +03:00
def _on_start_clicked ( self , ignore , ignore2 = None , ignore3 = None ) :
2014-07-31 16:28:54 +04:00
snaps = self . _get_selected_snapshots ( )
if not snaps or len ( snaps ) > 1 :
return
snap = snaps [ 0 ]
2014-03-26 16:54:10 +04:00
msg = _ ( " Are you sure you want to run snapshot ' %s ' ? "
" All %s changes since the last snapshot was created will be "
" discarded. " )
if self . vm . is_active ( ) :
msg = msg % ( snap . get_name ( ) , _ ( " disk " ) )
else :
msg = msg % ( snap . get_name ( ) , _ ( " disk and configuration " ) )
result = self . err . yes_no ( msg )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
if not result :
return
2013-10-05 22:57:58 +04:00
logging . debug ( " Running snapshot ' %s ' " , snap . get_name ( ) )
2013-10-05 18:03:56 +04:00
vmmAsyncJob . simple_async ( self . vm . revert_to_snapshot ,
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
[ snap ] , self ,
2013-10-05 22:57:58 +04:00
_ ( " Running snapshot " ) ,
_ ( " Running snapshot ' %s ' " ) % snap . get_name ( ) ,
_ ( " Error running snapshot ' %s ' " ) %
2013-09-07 04:59:01 +04:00
snap . get_name ( ) ,
finish_cb = self . _refresh_snapshots )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
def _on_delete_clicked ( self , ignore ) :
2014-07-31 16:28:54 +04:00
snaps = self . _get_selected_snapshots ( )
if not snaps :
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
return
result = self . err . yes_no ( _ ( " Are you sure you want to permanently "
2014-07-31 16:28:54 +04:00
" delete the selected snapshots? " ) )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
if not result :
return
2014-07-31 16:28:54 +04:00
for snap in snaps :
logging . debug ( " Deleting snapshot ' %s ' " , snap . get_name ( ) )
vmmAsyncJob . simple_async ( snap . delete , [ ] , self ,
_ ( " Deleting snapshot " ) ,
_ ( " Deleting snapshot ' %s ' " ) % snap . get_name ( ) ,
_ ( " Error deleting snapshot ' %s ' " ) % snap . get_name ( ) ,
finish_cb = self . _refresh_snapshots )
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
def _snapshot_selected ( self , selection ) :
2013-10-01 02:46:54 +04:00
ignore = selection
2014-07-31 16:28:54 +04:00
snap = self . _get_selected_snapshots ( )
2013-10-01 02:46:54 +04:00
if not snap :
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
self . _set_error_page ( _ ( " No snapshot selected. " ) )
return
2014-07-31 16:28:54 +04:00
if len ( snap ) > 1 :
self . _set_error_page ( _ ( " Multiple snapshots selected. " ) )
self . widget ( " snapshot-start " ) . set_sensitive ( False )
self . widget ( " snapshot-apply " ) . set_sensitive ( False )
self . widget ( " snapshot-delete " ) . set_sensitive ( True )
return
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
try :
2014-07-31 16:28:54 +04:00
self . _set_snapshot_state ( snap [ 0 ] )
2017-05-05 19:47:21 +03:00
except Exception as e :
Initial snapshot support
This adds initial UI for managing snapshots: list, run/revert, delete,
add, and redefining (for changing <description>) supported, but currently
only for internal snapshots. The UI is mostly in its final form except for
some bells and whistles.
The real remaining question is what do we want to advertise and support.
Internal (qcow2) snapshots are by far the simplest to manage, very
mature, and already have the semantics we want.
However most recent libvirt and qemu work has been to facilitate
external snapshots, which are more extensible and can be performed
live, and with qemu-ga coordination for extra safety. However
they make things much harder for virt-manager at the moment.
Until we have a plan, this work should be considered experimental
and not be relied upon.
2013-08-02 18:18:47 +04:00
logging . exception ( e )
self . _set_error_page ( _ ( " Error selecting snapshot: %s " ) % str ( e ) )