Skip to content
This repository was archived by the owner on Sep 17, 2019. It is now read-only.

Commit 6e7f0e8

Browse files
authored
Merge pull request #102 from napalm-automation/develop
Release 0.17.0
2 parents 1a64f42 + 07bfbb3 commit 6e7f0e8

File tree

395 files changed

+976
-67521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

395 files changed

+976
-67521
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ python:
55

66
install:
77
- pip install .
8+
- pip install -r requirements-dev.txt
89
- pip install -r test/unit/requirements.txt
910

1011
deploy:
@@ -20,3 +21,4 @@ script:
2021
- nosetests ./test/unit/TestGetNetworkDriver.py
2122
- nosetests ./test/unit/TestHelpers.py
2223
- nosetests ./test/unit/TestNapalmTestFramework.py
24+
- pylama .

napalm_base/__init__.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
import inspect
2020
import importlib
2121

22-
from pkg_resources import get_distribution
22+
import pkg_resources
2323

2424
# NAPALM base
2525

2626
from napalm_base.base import NetworkDriver
2727
from napalm_base.exceptions import ModuleImportError
2828

29-
__version__ = get_distribution('napalm-base').version
29+
try:
30+
__version__ = pkg_resources.get_distribution('napalm-ios').version
31+
except pkg_resources.DistributionNotFound:
32+
__version__ = "Not installed"
33+
3034

3135
__all__ = [
3236
'get_network_driver', # export the function
@@ -39,19 +43,22 @@
3943

4044

4145
def get_network_driver(module_name):
42-
4346
"""
4447
Searches for a class derived form the base NAPALM class NetworkDriver in a specific library.
4548
The library name must repect the following pattern: napalm_[DEVICE_OS].
46-
NAPALM community supports a list of devices and provides the corresponding libraries; for full reference
47-
please refer to the `Supported Network Operation Systems`_ paragraph on `Read the Docs`_.
49+
NAPALM community supports a list of devices and provides the corresponding libraries; for
50+
full reference please refer to the `Supported Network Operation Systems`_ paragraph on
51+
`Read the Docs`_.
4852
49-
.. _`Supported Network Operation Systems`: http://napalm.readthedocs.io/en/latest/#supported-network-operating-systems
50-
.. _`Read the Docs`: http://napalm.readthedocs.io/
53+
.. _`Supported Network Operation Systems`: \
54+
http://napalm.readthedocs.io/en/latest/#supported-network-operating-systems
55+
.. _`Read the Docs`: \
56+
http://napalm.readthedocs.io/
5157
52-
:param module_name: the name of the device operating system, or the name of the library.
58+
:param module_name: the name of the device operating system or the name of the library.
5359
:return: the first class derived from NetworkDriver, found in the library.
54-
:raise ModuleImportError: when the library is not installed, or a derived class from NetworkDriver was not found.
60+
:raise ModuleImportError: when the library is not installed or a derived class from \
61+
NetworkDriver was not found.
5562
5663
Example::
5764
@@ -64,16 +71,20 @@ def get_network_driver(module_name):
6471
>>> get_network_driver('napalm_eos')
6572
<class 'napalm_eos.eos.EOSDriver'>
6673
>>> get_network_driver('wrong')
67-
napalm_base.exceptions.ModuleImportError: Cannot import "napalm_wrong". Is the library installed?
74+
napalm_base.exceptions.ModuleImportError: Cannot import "napalm_wrong". Is the library \
75+
installed?
6876
"""
6977

7078
if not (isinstance(module_name, basestring) and len(module_name) > 0):
7179
raise ModuleImportError('Please provide a valid driver name.')
7280

7381
try:
74-
module_name = module_name.lower() # only lowercase allowed
75-
module_install_name = module_name.replace('-', '') # to not raise error when users requests IOS-XR for e.g.
76-
if 'napalm_' not in module_install_name: # can also request using napalm_[SOMETHING]
82+
# Only lowercase allowed
83+
module_name = module_name.lower()
84+
# Try to not raise error when users requests IOS-XR for e.g.
85+
module_install_name = module_name.replace('-', '')
86+
# Can also request using napalm_[SOMETHING]
87+
if 'napalm_' not in module_install_name:
7788
module_install_name = 'napalm_{name}'.format(name=module_install_name)
7889
module = importlib.import_module(module_install_name)
7990
except ImportError:
@@ -89,7 +100,5 @@ def get_network_driver(module_name):
89100

90101
# looks like you don't have any Driver class in your module...
91102
raise ModuleImportError(
92-
'No class inheriting "napalm_base.base.NetworkDriver" found in "{install_name}".'.format(
93-
install_name=module_install_name
94-
)
95-
)
103+
'No class inheriting "napalm_base.base.NetworkDriver" found in "{install_name}".'
104+
.format(install_name=module_install_name))

0 commit comments

Comments
 (0)