netdev icon indicating copy to clipboard operation
netdev copied to clipboard

Code dup

Open Ali-aqrabawi opened this issue 6 years ago • 11 comments

Description

code refactoring:

  1. added new module connection: which has the protocol connection classes like ssh, telnet and serial. this approach is needed to split the business logic from external libraries , so we can easily change libraries without changing our code. also this is needed to add different connection types.

  2. added terminal_modes module: objects that handle entering and exiting from different terminal modes like config_mode , enable_mode ... etc. this approach is to eliminate code duplication in the Devices classes.

those are the major changes, there are some changes on the device level, like adding methods, removing methods ... etc.

a new main method added to BaseDevice is _session_preparation , which will be called to prepare each device session.

new features:

  1. telnet support.
  2. textfsm.

Ali-aqrabawi avatar May 18 '19 15:05 Ali-aqrabawi

Thank you for refactoring the code! I'm going to test it this weekend and plan to merge it on Monday if all is fine!

selfuryon avatar May 18 '19 16:05 selfuryon

Thanks, please note that this pr has vt100 as term_mod, you can change it from constants.py module.

Ali-aqrabawi avatar May 18 '19 16:05 Ali-aqrabawi

If I have any problems with that on Mikrotik I think I change it only for Mikrotik. I test it separately. Thank you for the information!

selfuryon avatar May 18 '19 16:05 selfuryon

@selfuryon please have a look at the updated pr. you need to pip install textfsm before running the code, i could not find requirements.txt file to add it.

Ali-aqrabawi avatar May 18 '19 19:05 Ali-aqrabawi

@selfuryon please have a look at the updated pr. you need to pip install textfsm before running the code, I could not find requirements.txt file to add it.

Yeah, I switched to use poetry for building the project and for dependency management. You can add it to pyproject.toml. This file is used not only poetry right now. You can find more information about that in PEP517 and PEP518

selfuryon avatar May 18 '19 20:05 selfuryon

Thanks for new commits! I'll check it more deeply tomorrow!

selfuryon avatar May 18 '19 20:05 selfuryon

please check updated pr

Ali-aqrabawi avatar May 19 '19 16:05 Ali-aqrabawi

I have some problems with HP Comware in testing. Need to go deeper

selfuryon avatar May 19 '19 18:05 selfuryon

Hello! I think for more than 2 weeks about the structure of code from this PR. It's a good new structure and new approaches but it still has some lack of isolation which can confuse.

As example:

  • We have a duplication for device hierarchy in vendor and terminal_modes folders: both have cisco, hp, and others
  • Terminal modes classes have a link to a device class and vice versa. They call the other one in their work
  • There are exist a send_command in both classes terminal mode and device
  • All constants for terminal modes still are included in the device class
  • Device class tracks current terminal mode
  • We still have a three level of inheritance

So I decided to get your idea, take some techniques and class and make a refactor for the module in a slight different another way (see #34)

selfuryon avatar Jun 01 '19 13:06 selfuryon

make sense, looking forward to see the new structure.

Ali-aqrabawi avatar Jun 01 '19 14:06 Ali-aqrabawi

is there any way to get structured output using asyncssh netdev library? it seems asyncio is not compatible with netconf? Please provide a way to get structured output using asyncio netdev. I am trying to run this on Juniper vMX devices

rishrapsody avatar Sep 26 '19 22:09 rishrapsody