#NEWLINE# def get_stats_from_cluster( session , cluster ) : #NEWLINE# #INDENT# 'Get the aggregate resource stats of a cluster.' #NEWLINE# vcpus = 0 #NEWLINE# mem_info = { #NEWLINE# #INDENT# 'total' : 0 , #NEWLINE# 'free' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# prop_dict = session . _call_method ( vutil , 'get_object_properties_dict' , cluster , [ 'host' , 'resourcePool' ] ) #NEWLINE# if prop_dict : #NEWLINE# #INDENT# host_ret = prop_dict . get ( 'host' ) #NEWLINE# if host_ret : #NEWLINE# #INDENT# host_mors = host_ret . ManagedObjectReference #NEWLINE# result = session . _call_method ( vim_util , 'get_properties_for_a_collection_of_objects' , 'HostSystem' , host_mors , [ 'summary.hardware' , 'summary.runtime' ] ) #NEWLINE# for obj in result . objects : #NEWLINE# #INDENT# hardware_summary = obj . propSet [ 0 ] . val #NEWLINE# runtime_summary = obj . propSet [ 1 ] . val #NEWLINE# if ( ( runtime_summary . inMaintenanceMode is False ) and ( runtime_summary . connectionState == 'connected' ) ) : #NEWLINE# #INDENT# vcpus += hardware_summary . numCpuThreads #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# res_mor = prop_dict . get ( 'resourcePool' ) #NEWLINE# if res_mor : #NEWLINE# #INDENT# res_usage = session . _call_method ( vutil , 'get_object_property' , res_mor , 'summary.runtime.memory' ) #NEWLINE# if res_usage : #NEWLINE# #INDENT# mem_info [ 'total' ] = int ( ( res_usage . maxUsage / units . Mi ) ) #NEWLINE# consumed = int ( ( res_usage . overallUsage / units . Mi ) ) #NEWLINE# mem_info [ 'free' ] = ( mem_info [ 'total' ] - consumed ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# stats = { #NEWLINE# #INDENT# 'vcpus' : vcpus , #NEWLINE# 'mem' : mem_info , #NEWLINE# #UNINDENT# } #NEWLINE# return stats