2013-08-05 17:20:35 -04:00
#
2014-07-31 12:19:53 +02:00
# Copyright 2013-2014 Red Hat, Inc.
2013-08-05 17:20:35 -04:00
# Cole Robinson <crobinso@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
2013-10-27 21:59:47 +01:00
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
2013-08-05 17:20:35 -04:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2013-09-30 17:11:22 -04:00
import libvirt
2013-09-30 16:33:45 -04:00
from virtinst import util
2013-09-30 17:53:55 -04:00
from virtinst . xmlbuilder import XMLBuilder , XMLChildProperty , XMLProperty
class _SnapshotDisk ( XMLBuilder ) :
_XML_ROOT_NAME = " disk "
name = XMLProperty ( " ./@name " )
snapshot = XMLProperty ( " ./@snapshot " )
2013-08-05 17:20:35 -04:00
class DomainSnapshot ( XMLBuilder ) :
2013-09-30 16:33:45 -04:00
@staticmethod
def find_free_name ( vm , collidelist ) :
return util . generate_name ( " snapshot " , vm . snapshotLookupByName ,
sep = " " , start_num = 1 , force_num = True ,
collidelist = collidelist )
2013-09-30 17:11:22 -04:00
@staticmethod
def state_str_to_int ( state ) :
statemap = {
" nostate " : libvirt . VIR_DOMAIN_NOSTATE ,
" running " : libvirt . VIR_DOMAIN_RUNNING ,
" blocked " : libvirt . VIR_DOMAIN_BLOCKED ,
" paused " : libvirt . VIR_DOMAIN_PAUSED ,
" shutdown " : libvirt . VIR_DOMAIN_SHUTDOWN ,
" shutoff " : libvirt . VIR_DOMAIN_SHUTOFF ,
" crashed " : libvirt . VIR_DOMAIN_CRASHED ,
2014-07-31 12:19:53 +02:00
" pmsuspended " : getattr ( libvirt , " VIR_DOMAIN_PMSUSPENDED " , 7 )
2013-09-30 17:11:22 -04:00
}
if state == " disk-snapshot " or state not in statemap :
state = " shutoff "
return statemap . get ( state , libvirt . VIR_DOMAIN_NOSTATE )
2013-09-11 11:47:09 -04:00
_XML_ROOT_NAME = " domainsnapshot "
2013-08-05 17:20:35 -04:00
_XML_PROP_ORDER = [ " name " , " description " , " creationTime " ]
2013-09-19 13:27:30 -04:00
name = XMLProperty ( " ./name " )
description = XMLProperty ( " ./description " )
state = XMLProperty ( " ./state " )
creationTime = XMLProperty ( " ./creationTime " , is_int = True )
parent = XMLProperty ( " ./parent/name " )
2013-08-05 17:20:35 -04:00
2013-09-30 17:53:55 -04:00
memory_type = XMLProperty ( " ./memory/@snapshot " )
disks = XMLChildProperty ( _SnapshotDisk , relative_xpath = " ./disks " )
2013-09-30 14:28:43 -04:00
2013-09-30 16:33:45 -04:00
##################
# Public helpers #
##################
2013-09-30 14:28:43 -04:00
def validate ( self ) :
if not self . name :
raise RuntimeError ( _ ( " A name must be specified. " ) )