Skip to content

Commit

Permalink
Remove ABC, deprecate and remove show_list and config_list methods, a…
Browse files Browse the repository at this point in the history
…dd fact properties (#275)

* deprecate list methods

* remove ABC and use standard python inheritance

* clean up commented out code

* bump version to alpha and prep changelog
  • Loading branch information
jeffkala authored Apr 5, 2023
1 parent c9c1a9d commit 5ca3906
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 315 deletions.
10 changes: 10 additions & 0 deletions docs/admin/release_notes/version_1_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# v1.0 Release Notes

## [1.0.0a0] 04-2023

### Added

### Changed

### Deprecated

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ nav:
- v0.18: "admin/release_notes/version_0_18.md"
- v0.19: "admin/release_notes/version_0_19.md"
- v0.20: "admin/release_notes/version_0_20.md"
- v1.0: "admin/release_notes/version_1_0.md"
- Developer Guide:
- Extending the Library: "dev/extending.md"
- Contributing to the Library: "dev/contributing.md"
Expand Down
62 changes: 1 addition & 61 deletions pyntc/devices/aireos_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time

from netmiko import ConnectHandler

from pyntc import log
from pyntc.errors import (
CommandError,
Expand Down Expand Up @@ -616,35 +617,6 @@ def config(self, command, **netmiko_args):
)
return command_responses

def config_list(self, commands, **netmiko_args): # noqa: D401
"""
DEPRECATED - Use the `config` method.
Send config commands to device.
By default, entering and exiting config mode is handled automatically.
To disable entering and exiting config mode, pass `enter_config_mode` and `exit_config_mode` in ``**netmiko_args``.
This supports all arguments supported by Netmiko's `send_config_set` method using ``netmiko_args``.
Args:
commands (list): The commands to send to the device.
**netmiko_args: Any argument supported by ``netmiko.base_connection.BaseConnection.send_config_set``.
Returns:
list: Each command's input and ouput from sending the command in ``commands``.
Raises:
TypeError: When sending an argument in ``**netmiko_args`` that is not supported.
CommandListError: When one of the commands reports an error on the device.
Example:
>>> device = AIREOSDevice(**connection_args)
>>> device.config_list(["interface hostname virtual wlc1.site.com", "config interface vlan airway 20"])
>>>
"""
log.warning("config_list() is deprecated; use config.")
return self.config(commands, **netmiko_args)

def confirm_is_active(self):
"""
Confirm that the device is either standalone or the active device in a high availability cluster.
Expand Down Expand Up @@ -1425,38 +1397,6 @@ def show(self, command, expect_string=None, **netmiko_args):
)
return command_responses

def show_list(self, commands, **netmiko_args): # noqa: D401
"""
DEPRECATED - Use the `show` method.
Send operational commands to the device.
Args:
commands (list): The list of commands to send to the device.
**netmiko_args: Any argument supported by ``netmiko.ConnectHandler.send_command``.
Returns:
list: The data returned from the device for all commands.
Raises:
TypeError: When sending an argument in ``**netmiko_args`` that is not supported.
CommandListError: When the returned data indicates one of the commands failed.
Example:
>>> device = AIREOSDevice(**connection_args)
>>> command_data = device._send_command(["show sysinfo", "show boot"])
>>> print(command_data[0])
Product Version.....8.2.170.0
System Up Time......3 days 2 hrs 20 mins 30 sec
...
>>> print(command_data[1])
Primary Boot Image............................... 8.2.170.0 (default) (active)
Backup Boot Image................................ 8.5.110.0
>>>
"""
log.warning("show_list() is deprecated; use show.")
return self.show(commands, **netmiko_args)

@property
def startup_config(self):
"""
Expand Down
22 changes: 0 additions & 22 deletions pyntc/devices/asa_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,17 +419,6 @@ def config(self, command):
self.native.exit_config_mode()
log.info("Host %s: Device configured with command %s.", self.host, command)

def config_list(self, commands):
"""Send configuration commands in list format to a device.
DEPRECATED - Use the `config` method.
Args:
commands (list): List with multiple commands.
"""
log.warning("config_list() is deprecated; use config().")
self.config(commands)

@property
def connected_interface(self) -> str:
"""
Expand Down Expand Up @@ -1124,17 +1113,6 @@ def show(self, command, expect_string=None):
return responses
return self._send_command(command, expect_string=expect_string)

def show_list(self, commands):
"""Send show commands in list format to a device.
DEPRECATED - Use the `show` method.
Args:
commands (list): List with multiple commands.
"""
log.warning("show_list() is deprecated; use show().")
return self.show(commands)

@property
def startup_config(self):
"""
Expand Down
62 changes: 0 additions & 62 deletions pyntc/devices/base_device.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The module contains the base class that all device classes must inherit from."""

import abc
import importlib
import warnings

Expand All @@ -27,8 +26,6 @@ def fix_docs(cls):
class BaseDevice: # pylint: disable=too-many-instance-attributes,too-many-public-methods
"""Base Device ABC."""

__metaclass__ = abc.ABCMeta

def __init__(
self, host, username, password, device_type=None, **kwargs
): # noqa: D403 # pylint: disable=unused-argument
Expand Down Expand Up @@ -67,10 +64,6 @@ def _image_booted(self, image_name, **vendor_specifics):
"""
raise NotImplementedError

####################
# ABSTRACT METHODS #
####################
@abc.abstractmethod
def backup_running_config(self, filename):
"""Save a local copy of the running config.
Expand All @@ -80,7 +73,6 @@ def backup_running_config(self, filename):
raise NotImplementedError

@property
@abc.abstractmethod
def boot_options(self):
"""Get current boot variables.
Expand All @@ -91,7 +83,6 @@ def boot_options(self):
"""
raise NotImplementedError

@abc.abstractmethod
def checkpoint(self, filename):
"""Save a checkpoint of the running configuration to the device.
Expand All @@ -100,12 +91,10 @@ def checkpoint(self, filename):
"""
raise NotImplementedError

@abc.abstractmethod
def close(self):
"""Close the connection to the device."""
raise NotImplementedError

@abc.abstractmethod
def config(self, command):
"""Send a configuration command.
Expand All @@ -117,20 +106,7 @@ def config(self, command):
"""
raise NotImplementedError

@abc.abstractmethod
def config_list(self, commands):
"""Send a list of configuration commands.
Args:
commands (list): A list of commands to send to the device.
Raises:
CommandListError: If there is a problem with one of the commands in the list.
"""
raise NotImplementedError

@property
@abc.abstractmethod
def uptime(self):
"""Uptime integer property, part of device facts.
Expand All @@ -140,7 +116,6 @@ def uptime(self):
raise NotImplementedError

@property
@abc.abstractmethod
def os_version(self):
"""Operating System string property, part of device facts.
Expand All @@ -150,7 +125,6 @@ def os_version(self):
raise NotImplementedError

@property
@abc.abstractmethod
def interfaces(self):
"""Interfaces list of strings property, part of device facts.
Expand All @@ -160,7 +134,6 @@ def interfaces(self):
raise NotImplementedError

@property
@abc.abstractmethod
def hostname(self):
"""Host name string property, part of device facts.
Expand All @@ -170,7 +143,6 @@ def hostname(self):
raise NotImplementedError

@property
@abc.abstractmethod
def fqdn(self):
"""
Get FQDN of the device.
Expand All @@ -181,7 +153,6 @@ def fqdn(self):
raise NotImplementedError

@property
@abc.abstractmethod
def uptime_string(self):
"""Uptime string string property, part of device facts.
Expand All @@ -191,7 +162,6 @@ def uptime_string(self):
raise NotImplementedError

@property
@abc.abstractmethod
def serial_number(self):
"""
Get serial number of the device.
Expand All @@ -202,7 +172,6 @@ def serial_number(self):
raise NotImplementedError

@property
@abc.abstractmethod
def model(self):
"""Model string property, part of device facts.
Expand All @@ -212,7 +181,6 @@ def model(self):
raise NotImplementedError

@property
@abc.abstractmethod
def vlans(self):
"""Vlans lost of strings property, part of device facts.
Expand Down Expand Up @@ -242,7 +210,6 @@ def facts(self): # noqa 401
if self.device_type == "cisco_ios_ssh":
facts[self.device_type] = {"config_register": self.config_register} # pylint: disable=no-member

@abc.abstractmethod
def file_copy(self, src, dest=None, **kwargs):
"""Send a local file to the device.
Expand All @@ -259,7 +226,6 @@ def file_copy(self, src, dest=None, **kwargs):
"""
raise NotImplementedError

@abc.abstractmethod
def file_copy_remote_exists(self, src, dest=None, **kwargs):
"""Check if a remote file exists.
Expand All @@ -281,7 +247,6 @@ def file_copy_remote_exists(self, src, dest=None, **kwargs):
True if the remote file exists, False if it doesn't.
"""

@abc.abstractmethod
def install_os(self, image_name, **vendor_specifics):
"""Install the OS from specified image_name.
Expand Down Expand Up @@ -314,12 +279,10 @@ def install_os(self, image_name, **vendor_specifics):
"""
raise NotImplementedError

@abc.abstractmethod
def open(self):
"""Open a connection to the device."""
raise NotImplementedError

@abc.abstractmethod
def reboot(self, timer=0):
"""Reboot the device.
Expand All @@ -329,7 +292,6 @@ def reboot(self, timer=0):
"""
raise NotImplementedError

@abc.abstractmethod
def rollback(self, checkpoint_file):
"""Rollback to a checkpoint file.
Expand All @@ -339,12 +301,10 @@ def rollback(self, checkpoint_file):
raise NotImplementedError

@property
@abc.abstractmethod
def running_config(self):
"""Return the running configuration of the device."""
raise NotImplementedError

@abc.abstractmethod
def save(self, filename=None):
"""Save a device's running configuration.
Expand All @@ -355,7 +315,6 @@ def save(self, filename=None):
"""
raise NotImplementedError

@abc.abstractmethod
def set_boot_options(self, image_name, **vendor_specifics):
"""Set boot variables like system image and kickstart image.
Expand All @@ -376,7 +335,6 @@ def set_boot_options(self, image_name, **vendor_specifics):
"""
raise NotImplementedError

@abc.abstractmethod
def show(self, command, raw_text=False):
"""Send a non-configuration command.
Expand All @@ -391,31 +349,11 @@ def show(self, command, raw_text=False):
"""
raise NotImplementedError

@abc.abstractmethod
def show_list(self, commands, raw_text=False):
"""Send a list of non-configuration commands.
Args:
commands (list): A list of commands to send to the device.
Keyword Args:
raw_text (bool): Whether to return raw text or structured data.
Returns:
A list of outputs for each show command
"""
raise NotImplementedError

@property
@abc.abstractmethod
def startup_config(self):
"""Return the startup configuration of the device."""
raise NotImplementedError

#################################
# Inherited implemented methods #
#################################

def feature(self, feature_name):
"""Return a feature class based on the ``feature_name`` for the appropriate subclassed device type."""
try:
Expand Down
Loading

0 comments on commit 5ca3906

Please sign in to comment.