diff --git a/virtManager/snapshots.py b/virtManager/snapshots.py index 0ef6647a..4278dea1 100644 --- a/virtManager/snapshots.py +++ b/virtManager/snapshots.py @@ -28,7 +28,7 @@ from gi.repository import Gtk import libvirt -import virtinst +from virtinst import DomainSnapshot from virtinst import util from virtManager import uihelpers @@ -216,7 +216,11 @@ class vmmSnapshotPage(vmmGObjectUI): ################## def _reset_new_state(self): - self.widget("snapshot-new-name").set_text("") + 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) self.widget("snapshot-new-name").emit("changed") self.widget("snapshot-new-description").get_buffer().set_text("") @@ -240,7 +244,7 @@ class vmmSnapshotPage(vmmGObjectUI): ).get_buffer().get_property("text") try: - newsnap = virtinst.DomainSnapshot(self.vm.conn.get_backend()) + newsnap = DomainSnapshot(self.vm.conn.get_backend()) newsnap.name = name newsnap.description = desc or None newsnap.validate() diff --git a/virtinst/snapshot.py b/virtinst/snapshot.py index 2138e869..56e5aa6f 100644 --- a/virtinst/snapshot.py +++ b/virtinst/snapshot.py @@ -17,10 +17,17 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301 USA. +from virtinst import util from virtinst.xmlbuilder import XMLBuilder, XMLProperty class DomainSnapshot(XMLBuilder): + @staticmethod + def find_free_name(vm, collidelist): + return util.generate_name("snapshot", vm.snapshotLookupByName, + sep="", start_num=1, force_num=True, + collidelist=collidelist) + _XML_ROOT_NAME = "domainsnapshot" _XML_PROP_ORDER = ["name", "description", "creationTime"] @@ -36,6 +43,11 @@ class DomainSnapshot(XMLBuilder): # block which tracks the snapshot guest XML # which should list active status for an internal snapshot + + ################## + # Public helpers # + ################## + def validate(self): if not self.name: raise RuntimeError(_("A name must be specified."))