mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
snapshots: new: Automatically generate a snapshot name
This commit is contained in:
parent
34c502560f
commit
b3e2d26337
@ -28,7 +28,7 @@ from gi.repository import Gtk
|
|||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
import virtinst
|
from virtinst import DomainSnapshot
|
||||||
from virtinst import util
|
from virtinst import util
|
||||||
|
|
||||||
from virtManager import uihelpers
|
from virtManager import uihelpers
|
||||||
@ -216,7 +216,11 @@ class vmmSnapshotPage(vmmGObjectUI):
|
|||||||
##################
|
##################
|
||||||
|
|
||||||
def _reset_new_state(self):
|
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-name").emit("changed")
|
||||||
self.widget("snapshot-new-description").get_buffer().set_text("")
|
self.widget("snapshot-new-description").get_buffer().set_text("")
|
||||||
|
|
||||||
@ -240,7 +244,7 @@ class vmmSnapshotPage(vmmGObjectUI):
|
|||||||
).get_buffer().get_property("text")
|
).get_buffer().get_property("text")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
newsnap = virtinst.DomainSnapshot(self.vm.conn.get_backend())
|
newsnap = DomainSnapshot(self.vm.conn.get_backend())
|
||||||
newsnap.name = name
|
newsnap.name = name
|
||||||
newsnap.description = desc or None
|
newsnap.description = desc or None
|
||||||
newsnap.validate()
|
newsnap.validate()
|
||||||
|
@ -17,10 +17,17 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA.
|
# MA 02110-1301 USA.
|
||||||
|
|
||||||
|
from virtinst import util
|
||||||
from virtinst.xmlbuilder import XMLBuilder, XMLProperty
|
from virtinst.xmlbuilder import XMLBuilder, XMLProperty
|
||||||
|
|
||||||
|
|
||||||
class DomainSnapshot(XMLBuilder):
|
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_ROOT_NAME = "domainsnapshot"
|
||||||
_XML_PROP_ORDER = ["name", "description", "creationTime"]
|
_XML_PROP_ORDER = ["name", "description", "creationTime"]
|
||||||
|
|
||||||
@ -36,6 +43,11 @@ class DomainSnapshot(XMLBuilder):
|
|||||||
# <domain> block which tracks the snapshot guest XML
|
# <domain> block which tracks the snapshot guest XML
|
||||||
# <active> which should list active status for an internal snapshot
|
# <active> which should list active status for an internal snapshot
|
||||||
|
|
||||||
|
|
||||||
|
##################
|
||||||
|
# Public helpers #
|
||||||
|
##################
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if not self.name:
|
if not self.name:
|
||||||
raise RuntimeError(_("A name must be specified."))
|
raise RuntimeError(_("A name must be specified."))
|
||||||
|
Loading…
Reference in New Issue
Block a user