#NEWLINE# def vm_diskstats( vm_ = None ) : #NEWLINE# #INDENT# "\n    Return disk usage counters used by the vms on this hyper in a\n    list of dicts:\n\n    .. code-block:: python\n\n        [\n            'your-vm': {\n                'rd_req'   : 0,\n                'rd_bytes' : 0,\n                'wr_req'   : 0,\n                'wr_bytes' : 0,\n                'errs'     : 0\n                },\n            ...\n            ]\n\n    If you pass a VM name in as an argument then it will return info\n    for just the named VM, otherwise it will return all VMs.\n\n    CLI Example:\n\n    .. code-block:: bash\n\n        salt '*' virt.vm_blockstats\n    " #NEWLINE# def get_disk_devs( vm_ ) : #NEWLINE# #INDENT# doc = minidom . parse ( _StringIO ( get_xml ( vm_ ) ) ) #NEWLINE# disks = [ ] #NEWLINE# for elem in doc . getElementsByTagName ( 'disk' ) : #NEWLINE# #INDENT# targets = elem . getElementsByTagName ( 'target' ) #NEWLINE# target = targets [ 0 ] #NEWLINE# disks . append ( target . getAttribute ( 'dev' ) ) #NEWLINE# #UNINDENT# return disks #NEWLINE# #UNINDENT# def _info( vm_ ) : #NEWLINE# #INDENT# dom = _get_domain ( vm_ ) #NEWLINE# disks = get_disk_devs ( vm_ ) #NEWLINE# ret = { #NEWLINE# #INDENT# 'rd_req' : 0 , #NEWLINE# 'rd_bytes' : 0 , #NEWLINE# 'wr_req' : 0 , #NEWLINE# 'wr_bytes' : 0 , #NEWLINE# 'errs' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# for disk in disks : #NEWLINE# #INDENT# stats = dom . blockStats ( disk ) #NEWLINE# ret [ 'rd_req' ] += stats [ 0 ] #NEWLINE# ret [ 'rd_bytes' ] += stats [ 1 ] #NEWLINE# ret [ 'wr_req' ] += stats [ 2 ] #NEWLINE# ret [ 'wr_bytes' ] += stats [ 3 ] #NEWLINE# ret [ 'errs' ] += stats [ 4 ] #NEWLINE# #UNINDENT# return ret #NEWLINE# #UNINDENT# info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# if info : #NEWLINE# #INDENT# info [ vm_ ] = _info ( vm_ ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for vm_ in list_active_vms ( ) : #NEWLINE# #INDENT# info [ vm_ ] = _info ( vm_ ) #NEWLINE# #UNINDENT# #UNINDENT# return info