#NEWLINE# def get_agent_network_active_port_count( session , agent_host , network_id ) : #NEWLINE# #INDENT# with session . begin ( subtransactions = True ) : #NEWLINE# #INDENT# query = session . query ( models_v2 . Port ) #NEWLINE# query1 = query . join ( ml2_models . PortBinding ) #NEWLINE# query1 = query1 . filter ( ( models_v2 . Port . network_id == network_id ) , ( models_v2 . Port . status == const . PORT_STATUS_ACTIVE ) , ( models_v2 . Port . device_owner != const . DEVICE_OWNER_DVR_INTERFACE ) , ( ml2_models . PortBinding . host == agent_host ) ) #NEWLINE# query2 = query . join ( ml2_models . DVRPortBinding ) #NEWLINE# query2 = query2 . filter ( ( models_v2 . Port . network_id == network_id ) , ( ml2_models . DVRPortBinding . status == const . PORT_STATUS_ACTIVE ) , ( models_v2 . Port . device_owner == const . DEVICE_OWNER_DVR_INTERFACE ) , ( ml2_models . DVRPortBinding . host == agent_host ) ) #NEWLINE# return ( query1 . count ( ) + query2 . count ( ) )