snapshots: new: Automatically generate a snapshot name

This commit is contained in:
Cole Robinson 2013-09-30 16:33:45 -04:00
parent 34c502560f
commit b3e2d26337
2 changed files with 19 additions and 3 deletions

View File

@ -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()

View File

@ -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):
# <domain> block which tracks the snapshot guest XML
# <active> 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."))