mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Adapt napalm modules to the new library structure
Starting with November 2017, the NAPALM library has been reunified into a monolithic package. This falls with a couple of changes into the Salt codebase. While the users can continue using napalm_base, it is recommended to upgrade to napalm 2.0. At the same time, back in time, the napalm package used to have a different meaning, so we need to check if the release version is at least 2.0.
This commit is contained in:
parent
62c4addef8
commit
52f73835b8
2 changed files with 22 additions and 14 deletions
|
@ -129,17 +129,7 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
log = logging.getLogger(__file__)
|
||||
|
||||
# Import third party lib
|
||||
try:
|
||||
# will try to import NAPALM
|
||||
# https://github.com/napalm-automation/napalm
|
||||
# pylint: disable=W0611
|
||||
import napalm_base
|
||||
# pylint: enable=W0611
|
||||
HAS_NAPALM = True
|
||||
except ImportError:
|
||||
HAS_NAPALM = False
|
||||
|
||||
# Import Salt modules
|
||||
from salt.ext import six
|
||||
import salt.utils.napalm
|
||||
|
||||
|
@ -163,7 +153,7 @@ DETAILS = {}
|
|||
|
||||
|
||||
def __virtual__():
|
||||
return HAS_NAPALM or (False, 'Please install the NAPALM library: `pip install napalm`!')
|
||||
return salt.utils.napalm.virtual(__opts__, 'napalm', __file__)
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
# helper functions -- will not be exported
|
||||
|
|
|
@ -31,11 +31,27 @@ try:
|
|||
# will try to import NAPALM
|
||||
# https://github.com/napalm-automation/napalm
|
||||
# pylint: disable=W0611
|
||||
import napalm_base
|
||||
import napalm
|
||||
import napalm.base as napalm_base
|
||||
# pylint: enable=W0611
|
||||
HAS_NAPALM = True
|
||||
HAS_NAPALM_BASE = False # doesn't matter anymore, but needed for the logic below
|
||||
log.debug('napalm seems to be installed')
|
||||
try:
|
||||
NAPALM_MAJOR = int(napalm.__version__.split('.')[0])
|
||||
log.debug('napalm version: %s', napalm.__version__)
|
||||
except AttributeError:
|
||||
NAPALM_MAJOR = 0
|
||||
except ImportError:
|
||||
log.info('napalm doesnt seem to be installed, trying to import napalm_base')
|
||||
HAS_NAPALM = False
|
||||
try:
|
||||
import napalm_base
|
||||
log.debug('napalm_base seems to be installed')
|
||||
HAS_NAPALM_BASE = True
|
||||
except ImportError:
|
||||
log.info('napalm_base doesnt seem to be installed either')
|
||||
HAS_NAPALM_BASE = False
|
||||
|
||||
try:
|
||||
# try importing ConnectionClosedException
|
||||
|
@ -81,7 +97,9 @@ def virtual(opts, virtualname, filename):
|
|||
'''
|
||||
Returns the __virtual__.
|
||||
'''
|
||||
if HAS_NAPALM and (is_proxy(opts) or is_minion(opts)):
|
||||
if ( (HAS_NAPALM and NAPALM_MAJOR >= 2) or HAS_NAPALM_BASE ) and ( is_proxy(opts) or is_minion(opts) ):
|
||||
if HAS_NAPALM_BASE:
|
||||
log.info('You still seem to use napalm_base. Please consider upgrading to napalm >= 2.0.0')
|
||||
return virtualname
|
||||
else:
|
||||
return (
|
||||
|
|
Loading…
Add table
Reference in a new issue