You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
The first thing I want to separate the connection and the class which knows how to work with device.
The second thing I want to use the Strategy pattern instead of Inheritance due to lack of isolation.
Common class structure:
IOConnection as an interface for working for a particular connection
As examples of a particular connection are SSHConnection and Telnet Connection
DeviceStream adds some logic to basic IOConnection: it understands the end of the output: it recognizes the prompt
LayerManager manages all levels of layers or terminal modes
Layer is an entity for working with a particular layer or terminal mode
Particular set of device type classes (like CiscoIOS, JuniperJunOS) for working with devices. They contain a set of strategy class instances
Try to show the concept of these changes.
Public factory method:
# Public Factory function for creating netdev classesdefcreate(device_type, connection_type, *args, **kwargs):
# Create IOConnection separatelyifconnection_type=="ssh":
IOConnection=SSHConnectiom(*args, **kwargs) # As Example for SSHConnection# Create DeviceStream and all needed instances for a particular devicedevice_stream=DeviceStream(IOConnection)
# Create Device separatelyifdevice_type=="cisco_ios":
layer_manager=LayerManager(device_stream, cisco_checker)
.add_layer(UserExecMode())
.add_layer(PrivilegeExecMode())
.add_layer(ConfigMode())
returnCisco_IOS(layer_manager)
IOConnection is an abstract class with a public interface which can be used by all particular device type classes.
IOConnection can be implemented in SSHConnection, TelnetConnection and SerialConnection.
DeviceStream adds some logic to IOConnection. It understands the end of the output for commands: it understands the prompt
classDeviceStream():
""" Class which know how to work with the device in a stream mode """def__init__ (self, IOConnection, prompt_pattern=r"", ):
self._conn=IOConnectionself._prompt_pattern=prompt_patternasyncdefsend(self, cmd_list):
passasyncdefread_until(self, pattern, re_flags, until_prompt=True):
pass
Device type classes are particular classes for working with network devices.
classCiscoIOS():
""" Abstract Device type"""def__init__ (device_stream, layer_manager):
self._device_stream=device_streamself._layer_manager=layer_managerasyncdefsend_command(self, cmd_list, terminal_mode):
""" Go to specific terminal mode and run list of commands in there"""self._layer_manager.switch_to_layer(terminal_mode)
self.device_stream(cmd_list)
asyncdefsend_config_set(self, cmd_list):
""" Go to configuration mode and run list of commands in there"""self._layer_manager.switch_to_layer('config_mode')
self.device_stream(cmd_list)
self._layer_manager.switch_to_layer('privilege exec')
We have universal class LayerManager for working with terminal modes:
Hello!
I want to make the module refactoring.
The first thing I want to separate the connection and the class which knows how to work with device.
The second thing I want to use the Strategy pattern instead of Inheritance due to lack of isolation.
Common class structure:
Try to show the concept of these changes.
Public factory method:
IOConnection is an abstract class with a public interface which can be used by all particular device type classes.
IOConnection can be implemented in SSHConnection, TelnetConnection and SerialConnection.
DeviceStream adds some logic to IOConnection. It understands the end of the output for commands: it understands the prompt
Device type classes are particular classes for working with network devices.
We have universal class
LayerManager
for working with terminal modes:Specific function for checking the cisco like terminal modes:
We have universal class
Layer
for working with particular layer/terminal mode:And cisco like layers:
The text was updated successfully, but these errors were encountered: