@@ -59,8 +59,8 @@ def search_ont(sn: str, host: str) -> tuple[dict, str | None] | None:
5959 sleep (0.1 )
6060 clear_buffer (channel )
6161
62- channel .send (bytes (f"display ont optical-info { ont_info ['interface' ]['port' ]} { ont_info ['ont_id' ]} \n " , 'utf-8' ))
6362 if ont_info .get ('online' ):
63+ channel .send (bytes (f"display ont optical-info { ont_info ['interface' ]['port' ]} { ont_info ['ont_id' ]} \n " , 'utf-8' ))
6464 optical_info = parse_optical_info (read_output (channel ))
6565 ont_info ['optical' ] = optical_info
6666
@@ -79,6 +79,7 @@ def search_ont(sn: str, host: str) -> tuple[dict, str | None] | None:
7979
8080 ont_info ['catv' ] = catv_results
8181 ont_info ['eth' ] = eth_results
82+ del ont_info ['_catv_ports' ]
8283
8384 channel .close ()
8485 ssh .close ()
@@ -172,13 +173,13 @@ def read_output(channel: Channel, force: bool = True):
172173 # print('no new data more than 1.5 seconds')
173174 # break
174175 # if no new data more than 15 seconds and output is empty
175- if time () - last_data_time > 15 and len (output .strip ().strip ('\n ' ).splitlines ()) <= 4 :
176+ if time () - last_data_time > 15 and len (output .strip ().strip ('\n ' ).splitlines ()) <= 5 :
176177 print ('warn: no new data more than 15 seconds' )
177178 print (output )
178179 break
179180 sleep (0.01 )
180181
181- return '\n ' .join (output .splitlines ()[1 :]) if output .count ('\n ' ) > 1 else ''
182+ return '\n ' .join (output .splitlines ()[1 :]) if output .count ('\n ' ) > 1 else output
182183
183184def _parse_output (raw : str ) -> tuple [dict , list [list [dict ]]]:
184185 def _parse_value (value : str ) -> str | float | int | bool | None :
@@ -322,11 +323,13 @@ def parse_basic_info(raw: str) -> dict:
322323 'seconds' : int (uptime .group (4 ))
323324 } if uptime else None ,
324325 '_catv_ports' : next ((item .get ('Port-number' ) for item in ports_table or [] if item .get ('Port-type' ) == 'CATV' ), None ),
325- '_eth_ports' : next ((item .get ('Port-number' ) for item in ports_table or [] if item .get ('Port-type' ) == 'ETH' ), None )
326+ # '_eth_ports': next((item.get('Port-number') for item in ports_table or [] if item.get('Port-type') == 'ETH'), None)
326327 }
327328
328329def parse_optical_info (raw : str ) -> dict :
329330 """Parse ONT optical info"""
331+ if 'The ONT is not online' in raw :
332+ return {'status' : 'fail' , 'detail' : 'ONT is not online' }
330333 data , _ = _parse_output (raw )
331334
332335 return {
0 commit comments