2008-08-08 01: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.
#
import virtinst
2011-04-11 01:08:23 +04:00
from virtManager import util
2010-12-09 20:37:48 +03:00
from virtManager . libvirtobject import vmmLibvirtObject
2008-08-08 01:37:16 +04:00
from virtManager . storagevol import vmmStorageVolume
2010-12-09 20:37:48 +03:00
class vmmStoragePool ( vmmLibvirtObject ) :
2011-07-23 00:43:26 +04:00
def __init__ ( self , conn , pool , uuid , active ) :
vmmLibvirtObject . __init__ ( self , conn )
2010-12-09 20:37:48 +03:00
2008-08-08 01:37:16 +04:00
self . pool = pool # Libvirt pool object
self . uuid = uuid # String UUID
self . active = active # bool indicating if it is running
self . _volumes = { } # UUID->vmmStorageVolume mapping of the
# pools associated volumes
2010-03-08 20:08:59 +03:00
self . refresh ( )
2008-08-08 01:37:16 +04:00
2010-12-09 20:37:48 +03:00
# Required class methods
def get_name ( self ) :
return self . pool . name ( )
def _XMLDesc ( self , flags ) :
return self . pool . XMLDesc ( flags )
def _define ( self , xml ) :
2011-07-23 00:43:26 +04:00
return self . conn . vmm . storagePoolDefineXML ( xml , 0 )
2010-12-09 20:37:48 +03:00
2008-08-08 01:37:16 +04:00
def set_active ( self , state ) :
self . active = state
2010-12-10 17:57:42 +03:00
self . refresh_xml ( )
2008-08-08 01:37:16 +04:00
def is_active ( self ) :
return self . active
def can_change_alloc ( self ) :
2008-11-18 23:42:51 +03:00
typ = self . get_type ( )
return ( typ in [ virtinst . Storage . StoragePool . TYPE_LOGICAL ] )
2008-08-08 01:37:16 +04:00
def get_uuid ( self ) :
return self . uuid
def start ( self ) :
self . pool . create ( 0 )
2012-02-10 23:07:51 +04:00
self . idle_add ( self . refresh_xml )
2008-08-08 01:37:16 +04:00
def stop ( self ) :
self . pool . destroy ( )
2012-02-10 23:07:51 +04:00
self . idle_add ( self . refresh_xml )
2008-08-08 01:37:16 +04:00
2008-08-11 04:58:36 +04:00
def delete ( self , nodelete = True ) :
if nodelete :
self . pool . undefine ( )
else :
self . pool . delete ( 0 )
2008-08-08 01:37:16 +04:00
del ( self . pool )
def set_autostart ( self , value ) :
self . pool . setAutostart ( value )
def get_autostart ( self ) :
return self . pool . autostart ( )
def get_target_path ( self ) :
2011-04-11 01:08:23 +04:00
return util . xpath ( self . get_xml ( ) , " /pool/target/path " )
2008-08-08 01:37:16 +04:00
def get_allocation ( self ) :
2011-04-11 01:08:23 +04:00
return long ( util . xpath ( self . get_xml ( ) , " /pool/allocation " ) )
2008-08-08 01:37:16 +04:00
def get_available ( self ) :
2011-04-11 01:08:23 +04:00
return long ( util . xpath ( self . get_xml ( ) , " /pool/available " ) )
2008-08-08 01:37:16 +04:00
def get_capacity ( self ) :
2011-04-11 01:08:23 +04:00
return long ( util . xpath ( self . get_xml ( ) , " /pool/capacity " ) )
2008-08-08 01:37:16 +04:00
def get_pretty_allocation ( self ) :
2011-04-11 01:08:23 +04:00
return util . pretty_bytes ( self . get_allocation ( ) )
2008-08-08 01:37:16 +04:00
def get_pretty_available ( self ) :
2011-04-11 01:08:23 +04:00
return util . pretty_bytes ( self . get_available ( ) )
2008-08-08 01:37:16 +04:00
def get_pretty_capacity ( self ) :
2011-04-11 01:08:23 +04:00
return util . pretty_bytes ( self . get_capacity ( ) )
2008-08-08 01:37:16 +04:00
def get_type ( self ) :
2011-04-11 01:08:23 +04:00
return util . xpath ( self . get_xml ( ) , " /pool/@type " )
2008-08-08 01:37:16 +04:00
def get_volumes ( self ) :
self . update_volumes ( )
return self . _volumes
def get_volume ( self , uuid ) :
return self . _volumes [ uuid ]
2008-09-06 05:53:26 +04:00
def refresh ( self ) :
2010-04-21 18:56:06 +04:00
if not self . active :
return
2012-02-10 23:07:51 +04:00
def cb ( ) :
self . refresh_xml ( )
self . update_volumes ( refresh = True )
self . emit ( " refreshed " )
2010-04-21 18:56:06 +04:00
self . pool . refresh ( 0 )
2012-02-10 23:07:51 +04:00
self . idle_add ( cb )
2008-09-06 05:53:26 +04:00
2012-01-30 07:15:01 +04:00
def update_volumes ( self , refresh = False ) :
2008-08-08 01:37:16 +04:00
if not self . is_active ( ) :
self . _volumes = { }
return
vols = self . pool . listVolumes ( )
new_vol_list = { }
for volname in vols :
2010-12-10 19:47:07 +03:00
if volname in self . _volumes :
2008-08-08 01:37:16 +04:00
new_vol_list [ volname ] = self . _volumes [ volname ]
2012-01-30 07:15:01 +04:00
if refresh :
new_vol_list [ volname ] . refresh_xml ( )
2008-08-08 01:37:16 +04:00
else :
2011-07-23 00:43:26 +04:00
new_vol_list [ volname ] = vmmStorageVolume ( self . conn ,
2010-12-09 20:37:48 +03:00
self . pool . storageVolLookupByName ( volname ) ,
volname )
2008-08-08 01:37:16 +04:00
self . _volumes = new_vol_list
2010-12-09 20:37:48 +03:00
vmmLibvirtObject . type_register ( vmmStoragePool )
2011-04-18 20:39:53 +04:00
vmmStoragePool . signal_new ( vmmStoragePool , " refreshed " , [ ] )