Skip to content

Commit

Permalink
Closes netbox-community#1375: Renamed NETBOX_USERNAME and NETBOX_PASS…
Browse files Browse the repository at this point in the history
…WORD configuration parameters to NAPALM_USERNAME and NAPALM_PASSWORD
  • Loading branch information
jeremystretch committed Jul 26, 2017
1 parent 02314ee commit 329b7a1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
16 changes: 13 additions & 3 deletions docs/configuration/optional-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,21 @@ An API consumer can request an arbitrary number of objects by appending the "lim

---

## NETBOX_USERNAME
## NAPALM_USERNAME

## NETBOX_PASSWORD
## NAPALM_PASSWORD

If provided, NetBox will use these credentials to authenticate against devices when collecting data.
NetBox will use these credentials when authenticating to remote devices via the NAPALM library. Both parameters are optional.

Note: If SSH public key authentication has been set up for the system account under which NetBox runs, these parameters are not needed.

---

## NETBOX_USERNAME (Deprecated)

## NETBOX_PASSWORD (Deprecated)

These settings have been deprecated and will be removed in NetBox v2.2. Please use `NAPALM_USERNAME` and `NAPALM_PASSWORD` instead.

---

Expand Down
4 changes: 2 additions & 2 deletions netbox/dcim/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ def napalm(self, request, pk):
ip_address = str(device.primary_ip.address.ip)
d = driver(
hostname=ip_address,
username=settings.NETBOX_USERNAME,
password=settings.NETBOX_PASSWORD
username=settings.NAPALM_USERNAME,
password=settings.NAPALM_PASSWORD
)
try:
d.open()
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/management/commands/run_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

class Command(BaseCommand):
help = "Update inventory information for specified devices"
username = settings.NETBOX_USERNAME
password = settings.NETBOX_PASSWORD
username = settings.NAPALM_USERNAME
password = settings.NAPALM_PASSWORD

def add_arguments(self, parser):
parser.add_argument('-u', '--username', dest='username', help="Specify the username to use")
Expand Down
4 changes: 2 additions & 2 deletions netbox/netbox/configuration.docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
MAINTENANCE_MODE = os.environ.get('MAINTENANCE_MODE', False)

# Credentials that NetBox will use to access live devices.
NETBOX_USERNAME = os.environ.get('NETBOX_USERNAME', '')
NETBOX_PASSWORD = os.environ.get('NETBOX_PASSWORD', '')
NAPALM_USERNAME = os.environ.get('NAPALM_USERNAME', '')
NAPALM_PASSWORD = os.environ.get('NAPALM_PASSWORD', '')

# Determine how many objects to display per page within a list. (Default: 50)
PAGINATE_COUNT = os.environ.get('PAGINATE_COUNT', 50)
Expand Down
6 changes: 3 additions & 3 deletions netbox/netbox/configuration.example.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@
# all objects by specifying "?limit=0".
MAX_PAGE_SIZE = 1000

# Credentials that NetBox will use to access live devices (future use).
NETBOX_USERNAME = ''
NETBOX_PASSWORD = ''
# Credentials that NetBox will uses to authenticate to devices when connecting via NAPALM.
NAPALM_USERNAME = ''
NAPALM_PASSWORD = ''

# Determine how many objects to display per page within a list. (Default: 50)
PAGINATE_COUNT = 50
Expand Down
25 changes: 20 additions & 5 deletions netbox/netbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
MAX_PAGE_SIZE = getattr(configuration, 'MAX_PAGE_SIZE', 1000)
PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '')
NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '')
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '')
NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '') # Deprecated
NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') # Deprecated
SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')
SHORT_DATETIME_FORMAT = getattr(configuration, 'SHORT_DATETIME_FORMAT', 'Y-m-d H:i')
SHORT_TIME_FORMAT = getattr(configuration, 'SHORT_TIME_FORMAT', 'H:i:s')
Expand All @@ -56,6 +58,19 @@

CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS

# Check for deprecated configuration parameters
config_logger = logging.getLogger('configuration')
config_logger.addHandler(logging.StreamHandler())
config_logger.setLevel(logging.WARNING)
if NETBOX_USERNAME:
config_logger.warning('NETBOX_USERNAME is deprecated and will be removed in v2.2. Please use NAPALM_USERNAME instead.')
if not NAPALM_USERNAME:
NAPALM_USERNAME = NETBOX_USERNAME
if NETBOX_PASSWORD:
config_logger.warning('NETBOX_PASSWORD is deprecated and will be removed in v2.2. Please use NAPALM_PASSWORD instead.')
if not NAPALM_PASSWORD:
NAPALM_PASSWORD = NETBOX_PASSWORD

# Attempt to import LDAP configuration if it has been defined
LDAP_IGNORE_CERT_ERRORS = False
try:
Expand All @@ -78,9 +93,9 @@
if LDAP_IGNORE_CERT_ERRORS:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
# Enable logging for django_auth_ldap
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
ldap_logger = logging.getLogger('django_auth_ldap')
ldap_logger.addHandler(logging.StreamHandler())
ldap_logger.setLevel(logging.DEBUG)
except ImportError:
raise ImproperlyConfigured(
"LDAP authentication has been configured, but django-auth-ldap is not installed. You can remove "
Expand Down
8 changes: 8 additions & 0 deletions netbox/templates/home.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{% extends '_base.html' %}

{% block content %}
{% if settings.NETBOX_USERNAME or settings.NETBOX_PASSWORD %}
<div class="alert alert-warning alert-dismissable" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<strong>Warning:</strong> The <code>NETBOX_USERNAME</code> and <code>NETBOX_PASSWORD</code> configuration parameters have been deprecated. Please replace them in configuration.py with <code>NAPALM_USERNAME</code> and <code>NAPALM_PASSWORD</code>.
</div>
{% endif %}
{% include 'search_form.html' %}
<div class="row">
<div class="col-sm-6 col-md-4">
Expand Down

0 comments on commit 329b7a1

Please sign in to comment.