Replies: 1 comment 2 replies
-
Clear guidance on this is great! Mixin also sounds great, the only reason it might be worth avoiding is because it might raise the barrier of entry a bit for new contributors. "Go learn about multiple inheritance" might be a bit much for new networker-turned-automators in the future. Though maybe that's over thinking it. In a use-case like this it's not so bad. Documentation can still be straightforward: If config or enable modes do not exist on a deviceInherit from class MyDevice(NoConfigMixin, NoEnableMixin, CiscoBaseConnection):
pass |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Netmiko has the following six methods.
If enable mode does not exist on a device, then the driver should do the following:
check_enable_mode
should always return True (with minor caveat below)enable
andexit_enable_mode
should return a null string.Reasoning: Being in enable mode from Netmiko's perspective means that you have the capability of making configuration changes (or more exactly, for cisco-ios like devices that you can execute
config term
). You are not in configuration mode, per se, but you can execute the commands to do this (if required). Or alternatively, you can directly execute configuration commands for platforms that do not have a separate configure mode.If the device has no capability of executing configuration changes from the CLI, then
check_enable_mode
should always return False andenable()
call should raise an exception. This driver would inherently be limited only to show command operations.If config mode does not exist on a device, then the driver should do the following:
check_config_mode
should always return True (with caveats below).config_mode
andexit_config_mode
should always return a null string.Reasoning: Being in config mode implies that configuration changes can be made on a device. So most platforms that do not have a configuration mode, allow you to directly make configuration changes. In other words, you don't need to execute
config term
or something similar to make configuration changes, you can just make your configuration changes (consequently, check_config_mode should return True in these cases).If the device does not actually allow any configuration changes to be made, then you should always return
False
. Additionally, in these casesconfig_mode
should return an exception.Type hints for these methods.
In general, you should always specify all of the arguments in the method signature for these six methods as they are unlikely to change and it helps with IDEs. Additionally, you should pass ALL of the arguments to any super() invocations so that if end-users actually pass-in the arguments, they work properly.
It is probable that I will create some sort of a mix-in that contains the proper code for all the drivers that fall into this category (to avoid all of the duplicate definitions of this code).
Beta Was this translation helpful? Give feedback.
All reactions