#NEWLINE# @ classmethod #NEWLINE# def execute( cls , task ) : #NEWLINE# #INDENT# logger . debug ( ( 'GenerateCapacityLogTask: task=%s' % task . uuid ) ) #NEWLINE# unallocated_nodes = db ( ) . query ( Node ) . filter_by ( cluster_id = None ) . count ( ) #NEWLINE# allocated_nodes = db ( ) . query ( Node ) . filter ( ( Node . cluster_id != None ) ) . count ( ) #NEWLINE# node_allocation = db ( ) . query ( Cluster , func . count ( Node . id ) ) . outerjoin ( Node ) . group_by ( Cluster ) #NEWLINE# env_stats = [ ] #NEWLINE# for allocation in node_allocation : #NEWLINE# #INDENT# env_stats . append ( { #NEWLINE# #INDENT# 'cluster' : allocation [ 0 ] . name , #NEWLINE# 'nodes' : allocation [ 1 ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# allocation_stats = { #NEWLINE# #INDENT# 'allocated' : allocated_nodes , #NEWLINE# 'unallocated' : unallocated_nodes , #NEWLINE# #UNINDENT# } #NEWLINE# fuel_data = { #NEWLINE# #INDENT# 'release' : settings . VERSION [ 'release' ] , #NEWLINE# 'uuid' : settings . FUEL_KEY , #NEWLINE# #UNINDENT# } #NEWLINE# roles_stat = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for node in db ( ) . query ( Node ) : #NEWLINE# #INDENT# if node . roles : #NEWLINE# #INDENT# roles_list = '+' . join ( sorted ( allocation_stats . roles ) ) #NEWLINE# if ( roles_list in roles_stat ) : #NEWLINE# #INDENT# roles_stat [ roles_list ] += 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# roles_stat [ roles_list ] = 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# capacity_data = { #NEWLINE# #INDENT# 'environment_stats' : env_stats , #NEWLINE# 'allocation_stats' : allocation_stats , #NEWLINE# 'fuel_data' : fuel_data , #NEWLINE# 'roles_stat' : roles_stat , #NEWLINE# #UNINDENT# } #NEWLINE# capacity_log = CapacityLog ( ) #NEWLINE# capacity_log . report = capacity_data #NEWLINE# db ( ) . add ( capacity_log ) #NEWLINE# db ( ) . flush ( ) #NEWLINE# task . result = { #NEWLINE# #INDENT# 'log_id' : capacity_log . id , #NEWLINE# #UNINDENT# } #NEWLINE# task . status = 'ready' #NEWLINE# task . progress = '100' #NEWLINE# db ( ) . commit ( )