2008-08-07 17:37:16 -04:00
#
# Copyright (C) 2008 Red Hat, Inc.
# Copyright (C) 2008 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
2011-04-10 17:08:23 -04:00
from virtManager import util
2010-12-09 12:37:48 -05:00
from virtManager . libvirtobject import vmmLibvirtObject
2013-04-13 14:34:52 -04:00
2010-12-09 12:37:48 -05:00
class vmmStorageVolume ( vmmLibvirtObject ) :
2011-07-22 16:43:26 -04:00
def __init__ ( self , conn , vol , name ) :
vmmLibvirtObject . __init__ ( self , conn )
2008-08-07 17:37:16 -04:00
2010-12-09 12:37:48 -05:00
self . vol = vol # Libvirt storage volume object
self . name = name
2008-08-07 17:37:16 -04:00
2010-12-09 12:37:48 -05:00
# Required class methods
2008-08-07 17:37:16 -04:00
def get_name ( self ) :
return self . name
2010-12-09 12:37:48 -05:00
def _XMLDesc ( self , flags ) :
return self . vol . XMLDesc ( flags )
2008-08-07 17:37:16 -04:00
def get_path ( self ) :
return self . vol . path ( )
2009-03-09 16:17:09 -04:00
def get_pool ( self ) :
pobj = self . vol . storagePoolLookupByVolume ( )
2011-07-22 16:43:26 -04:00
return self . conn . get_pool_by_name ( pobj . name ( ) )
2009-03-09 16:17:09 -04:00
2008-08-07 17:37:16 -04:00
def delete ( self ) :
2008-08-10 20:58:36 -04:00
self . vol . delete ( 0 )
2008-08-07 17:37:16 -04:00
del ( self . vol )
def get_target_path ( self ) :
2011-04-10 17:08:23 -04:00
return util . xpath ( self . get_xml ( ) , " /volume/target/path " )
2008-08-07 17:37:16 -04:00
def get_format ( self ) :
2011-04-10 17:08:23 -04:00
return util . xpath ( self . get_xml ( ) , " /volume/target/format/@type " )
2008-08-07 17:37:16 -04:00
def get_allocation ( self ) :
2011-04-10 17:08:23 -04:00
return long ( util . xpath ( self . get_xml ( ) , " /volume/allocation " ) )
2008-08-07 17:37:16 -04:00
def get_capacity ( self ) :
2011-04-10 17:08:23 -04:00
return long ( util . xpath ( self . get_xml ( ) , " /volume/capacity " ) )
2008-08-07 17:37:16 -04:00
def get_pretty_capacity ( self ) :
2011-04-10 17:08:23 -04:00
return util . pretty_bytes ( self . get_capacity ( ) )
2008-08-07 17:37:16 -04:00
def get_pretty_allocation ( self ) :
2011-04-10 17:08:23 -04:00
return util . pretty_bytes ( self . get_allocation ( ) )
2008-08-07 17:37:16 -04:00
def get_type ( self ) :
2011-04-10 17:08:23 -04:00
return util . xpath ( self . get_xml ( ) , " /volume/format/@type " )