Compare commits

..

129 Commits

Author SHA1 Message Date
Jeremy Stretch
4e4996e88f Merge branch 'develop' 2016-07-07 12:49:56 -04:00
Jeremy Stretch
ece16200a3 Resolved version conflict 2016-07-07 12:49:35 -04:00
Jeremy Stretch
bfe8979523 Version bump for v1.1.0 2016-07-07 12:27:27 -04:00
Jeremy Stretch
7228801cb0 Move membership evaluation to SecretRole 2016-07-07 12:07:02 -04:00
Jeremy Stretch
c19124fcac Clarified secret role permissions 2016-07-06 17:45:08 -04:00
Jeremy Stretch
edde021c85 Grant superusers permission to decrypt all secrets 2016-07-06 17:40:32 -04:00
Jeremy Stretch
966ea45050 #68: Improved permissions-related error handling 2016-07-06 17:22:10 -04:00
Jeremy Stretch
e7f21dea4b Optimize database query for user actions list 2016-07-06 16:36:07 -04:00
Jeremy Stretch
3276caa284 Fixes #214: Suppress status message if updated_count has not been provided 2016-07-06 16:25:15 -04:00
Jeremy Stretch
891a128736 Cleaned up 'not connected' text 2016-07-06 16:01:18 -04:00
Jeremy Stretch
a74ddd8527 Merge pull request #210 from peelman/develop
critical connections placeholder should span 5 rows now
2016-07-06 15:57:04 -04:00
Jeremy Stretch
24c48bece8 Fixes #209: Read pk list from POST instead of form 2016-07-06 15:55:42 -04:00
Nick Peelman
a069e92ce0 critical connections placeholder should span 5 rows now 2016-07-06 15:46:00 -04:00
Jeremy Stretch
c0ab9f70dc Standardized console/power/interface display 2016-07-06 14:40:40 -04:00
Jeremy Stretch
cc17604220 Force 48-bit MAC format for proper error messages during validation 2016-07-06 14:22:34 -04:00
Jeremy Stretch
9793b406e9 Merge pull request #170 from peelman/add-mac-address-to-interface
Add mac address to interface
2016-07-06 13:38:46 -04:00
Nick Peelman
7a2f6eaf34 Regenerate migration 2016-07-06 13:22:41 -04:00
Nick Peelman
dc847ce4d6 Fix connected interface template rendering... 2016-07-06 13:21:40 -04:00
Nick Peelman
578013fdd2 Fix PEP8 compliance...(again) 2016-07-06 13:21:40 -04:00
Nick Peelman
9f75d5bd23 Fix PEP8 compliance... 2016-07-06 13:21:40 -04:00
Nick Peelman
a6d41c95b8 Remove external macaddress package dependency 2016-07-06 13:21:40 -04:00
Nick Peelman
9da4c28cd5 Tests pass now 2016-07-06 13:21:40 -04:00
Nick Peelman
0ce92cb2ee Add fixtures for mac addresses. add mac addresses to api tests 2016-07-06 13:21:40 -04:00
Nick Peelman
6fb530b75d Relocate Add Interface button to match the style used in the rest of the view 2016-07-06 13:21:40 -04:00
Nick Peelman
5034b836ea Add MAC address field to interfaces 2016-07-06 13:21:40 -04:00
Jeremy Stretch
35f3355cfe Merge pull request #207 from ryanmerolle/develop
Updated Upgrade Instructions & apt-get install
2016-07-06 12:48:17 -04:00
ryanmerolle
65514102cd Updated Upgrade Instructions & apt-get install
I accidentally submitted my last 2 changes to master instead of develop.  This corrects the mistake.
2016-07-06 12:26:45 -04:00
Jeremy Stretch
343b65cb50 Merge pull request #205 from ryanmerolle/patch-2
Updated Upgrade Instructions
2016-07-06 11:50:01 -04:00
ryanmerolle
33d755d51a Updated Upgrade Instructions
Streamlined update process for newer users like myself.  Now includes exact instructions for downloading latest release or using git.
2016-07-06 10:10:57 -04:00
Jeremy Stretch
d974cecda3 Fixes #199: Moved prefix_validator from BaseIPField to IPNetworkField 2016-07-05 18:15:24 -04:00
Jeremy Stretch
5e9090a03a Revert "v1.1.0 release"
This reverts commit e8b8b015bb.
2016-07-05 18:12:05 -04:00
Jeremy Stretch
60b48f9e4e Merge branch 'master' of github.com:digitalocean/netbox into develop 2016-07-05 18:00:35 -04:00
Jeremy Stretch
e8b8b015bb v1.1.0 release 2016-07-05 18:00:12 -04:00
Jeremy Stretch
7021ce2ecf Merge branch 'develop' of github.com:digitalocean/netbox into develop 2016-07-05 17:36:44 -04:00
Jeremy Stretch
58e23a9773 Merge branch 'devicetype-fixes' into develop 2016-07-05 17:36:27 -04:00
Jeremy Stretch
064582f6c5 Improve DeviceType display (credit to @peelman); add validation for DeviceType components 2016-07-05 17:30:16 -04:00
Jeremy Stretch
75789fc956 Merge pull request #188 from ChristianKniep/no_local_mounts
No local mounts
2016-07-05 16:49:12 -04:00
Jeremy Stretch
1c159968bf Merge pull request #184 from koep/develop
Add vi swap files to gitignore
2016-07-05 16:47:03 -04:00
Jeremy Stretch
1b5231c188 Merge pull request #197 from digitalocean/device-bays
Device bays
2016-07-05 16:44:06 -04:00
Jeremy Stretch
dc3cbfcdd4 Fixes #199: Moved prefix_validator from BaseIPField to IPNetworkField 2016-07-05 16:39:43 -04:00
Jeremy Stretch
ee65d3f406 Fix DeviceBay inclusion in admin UI 2016-07-05 16:35:44 -04:00
Jeremy Stretch
fc9aa03dc1 Improved device bay documentation 2016-07-05 16:20:33 -04:00
Jeremy Stretch
34c332d165 Updated documentation to include device bays 2016-07-05 16:02:11 -04:00
Jeremy Stretch
c57e63ff00 Fixed API tests 2016-07-05 15:50:21 -04:00
Jeremy Stretch
14502123d8 Minor version increment for new feature (device bays) 2016-07-05 15:34:12 -04:00
Jeremy Stretch
80c8d2f0c0 Added parent_device to DeviceSerializer 2016-07-05 15:32:16 -04:00
Nick Peelman
acccdc09f2 Fixing dumb indent mistake... 2016-07-05 15:14:03 -04:00
Nick Peelman
20e3ef9a04 make device type network/console/power tables show based on device type settings 2016-07-05 15:00:25 -04:00
Nick Peelman
db9b0dcaef Fixing a nesting/logic issue on device type edit/delete buttons 2016-07-05 14:59:29 -04:00
Jeremy Stretch
97fbfeecc3 Extended API to include DeviceBays 2016-07-05 13:43:19 -04:00
Jeremy Stretch
7eae636562 Added DeviceType to device bays table 2016-07-05 13:42:14 -04:00
Christian Kniep
af87345637 remove debug port exposure for netbox 2016-07-04 10:51:52 +02:00
Christian Kniep
85c55cd27f use volumes of netbox, holding default config 2016-07-04 10:42:24 +02:00
Christian Kniep
6e1f8d3503 put config into netbox image 2016-07-04 10:42:01 +02:00
Christian Koep
60cc88bcde Add vi swap files to gitignore 2016-07-02 17:30:12 +02:00
Jeremy Stretch
8b7d86df5a Merge branch 'develop' of github.com:digitalocean/netbox into develop 2016-07-01 18:20:27 -04:00
Jeremy Stretch
a5066a905e Added a note to CONTRIBUTING about opening an issue before submitting a PR 2016-07-01 18:20:06 -04:00
Jeremy Stretch
aabe641d63 Merge pull request #107 from koep/develop
Add option to dockerize netbox
2016-07-01 18:02:33 -04:00
Jeremy Stretch
06a38d836c Merge branch 'device-bays' of github.com:digitalocean/netbox into device-bays
Conflicts:
	netbox/dcim/tables.py
2016-07-01 17:38:21 -04:00
Jeremy Stretch
0123dbcf5f Initial work on #91: Support for subdevices 2016-07-01 17:34:47 -04:00
Jeremy Stretch
35c5423127 Merge pull request #177 from digitalocean/upgrade-sudo
Optionally use sudo if not running upgrade.sh as root
2016-07-01 17:25:59 -04:00
Jeremy Stretch
7682b66034 Merge pull request #179 from peelman/develop
Fix interface connections list view glitch
2016-07-01 17:23:20 -04:00
Jeremy Stretch
067f22e444 Initial work on #91: Support for subdevices 2016-07-01 17:12:43 -04:00
Nick Peelman
f96171f529 Fix interface connections list view glitch 2016-07-01 13:55:44 -04:00
Matt Layher
49f06cfeb2 Optionally use sudo if not running upgrade.sh as root 2016-07-01 13:21:51 -04:00
Jeremy Stretch
1bb2a3f152 Fixes #169: Fallback to cancel_url if object is missing get_absolute_url() 2016-07-01 10:25:13 -04:00
Jeremy Stretch
7a68e1d901 Post-release version bump 2016-06-30 18:29:37 -04:00
Jeremy Stretch
7f353e88c9 Merge pull request #153 from digitalocean/develop
Release v1.0.7
2016-06-30 18:20:32 -04:00
Jeremy Stretch
2829303c74 Issue #140: Fixed Unicode bug in message (ObjectEditView) 2016-06-30 18:04:14 -04:00
Jeremy Stretch
c9bf10421b Fixes #136: Trigger error on prefix w/host bits set instead of silently converting it 2016-06-30 17:13:55 -04:00
Jeremy Stretch
d2bcd71b32 Fixes #143: Noted that the lowest occupied U is used for mounting multi-U devices 2016-06-30 16:19:48 -04:00
Jeremy Stretch
3ea12c646a Fixes #109: Hide navbar for anonymous users when LOGIN_REQUIRED = True 2016-06-30 16:02:18 -04:00
Christian Koep
24e361dc50 Add option to dockerize netbox 2016-06-30 21:43:32 +02:00
Jeremy Stretch
381639d4a7 Wrapped pip updates inside sudo 2016-06-30 14:59:52 -04:00
Jeremy Stretch
cf17088b0a Merge pull request #145 from ryanmerolle/patch-1
standardized app installation commands
2016-06-30 14:38:31 -04:00
ryanmerolle
a165445808 Update getting-started.md 2016-06-30 13:11:43 -04:00
ryanmerolle
66d8c27b1e standardized app installation commands
* Standardized all install commands to use sudo & -y to avoid new user confusion.
* Added required missing installation (apache2 missing in Web Server and gunicorn section)
* Consolidated installs for a section to follow same format (Web Server and gunicorn section nginx)
* Added missing install argument when installing the arbitrary precision calculator language.
2016-06-30 13:02:06 -04:00
Jeremy Stretch
85f3324d97 Fixes #141: Removed invalid character 2016-06-30 11:39:25 -04:00
Jeremy Stretch
a010a6dde5 Corrected instruction for cloning the repo 2016-06-29 23:49:59 -04:00
Jeremy Stretch
1c49909e2c Fixed typo 2016-06-29 23:16:16 -04:00
Jeremy Stretch
019daf5524 Fixes #135: Add button to toggle navbar on small screens 2016-06-29 22:51:10 -04:00
Jeremy Stretch
519ab21ba0 Version bump for next release 2016-06-29 17:48:11 -04:00
Jeremy Stretch
26286b6e36 Merge pull request #125 from digitalocean/develop
Release v1.0.6
2016-06-29 17:43:40 -04:00
Jeremy Stretch
d520d78380 Merge pull request #119 from bellwood/lets-encrypt-nginx-ssl
Update getting-started.md
2016-06-29 17:32:49 -04:00
Jeremy Stretch
46ae4b307c Removed note about graphviz being optional; installing graphviz prevents confusing error messages 2016-06-29 16:44:56 -04:00
Jeremy Stretch
1728d81677 Added a note abotu upgrade.sh to the README 2016-06-29 16:41:23 -04:00
Jeremy Stretch
fc5495eb3b Introduced a script to assist with upgrading NetBox 2016-06-29 15:43:42 -04:00
Jeremy Stretch
004f5c448e Fixes #117: Improved device import validation 2016-06-29 14:53:24 -04:00
Jeremy Stretch
995447ae0b Suppressed '__all__' field name in BulkImportForm validation 2016-06-29 14:52:02 -04:00
bellwood
76baa6fd2d Update getting-started.md
Adding instructions for Let's Encrypt SSL and enabling HTTPS in nginx
2016-06-29 14:38:28 -04:00
Jeremy Stretch
2e27389cda Corrected capitalization of rack face in example 2016-06-29 14:16:07 -04:00
Jeremy Stretch
48d607fb96 Added VERSION to settings and page footer 2016-06-29 14:05:01 -04:00
Jeremy Stretch
b8b173674f Fixed PEP8 error 2016-06-29 13:38:51 -04:00
Jeremy Stretch
d6920eceb1 Merge pull request #100 from pitkley/replace-pydot
Replace pydot with graphviz
2016-06-29 12:53:30 -04:00
Jeremy Stretch
fbbdb3807c Fixes #108: Added search for Sites 2016-06-29 12:06:37 -04:00
Jeremy Stretch
a1953bab8b Added a link to the GitHub issues page to the server error page 2016-06-29 11:04:34 -04:00
Jeremy Stretch
aa000bf26d Fixes #110: Added status field to bulk editing form for Prefixes and VLANs 2016-06-29 10:52:06 -04:00
Jeremy Stretch
c93bc40479 Merge pull request #106 from digitalocean/develop
Release v1.0.5
2016-06-29 10:00:46 -04:00
Jeremy Stretch
4ed3d54566 Fixes #103: Corrected VRF filters for Prefixes and IPAddresses 2016-06-29 09:45:59 -04:00
Pit Kleyersburg
522a0c20e7 Replace pydot by graphviz
This is in an effort to support Python 3: pydot is not compatible with
Python 3, while graphviz is.
2016-06-29 11:25:36 +02:00
Jeremy Stretch
b02c54ce52 A modest attempt at improving interface ordering; see #9 2016-06-28 23:22:41 -04:00
Jeremy Stretch
43e030f1db Fixes #83: Corrected example Apache configuration 2016-06-28 20:21:49 -04:00
Jeremy Stretch
945ca31460 Fixes #92: Redirect to module creation page on 'add another' 2016-06-28 17:12:09 -04:00
Jeremy Stretch
fc3cb72ab8 Merge pull request #82 from digitalocean/contributing-checklist
Add sanity check checklist for submitting pull requests
2016-06-28 16:26:20 -04:00
Jeremy Stretch
4a04af145b Fixed VRF filter for API 2016-06-28 16:01:48 -04:00
Jeremy Stretch
e7615cf32f Added instructions for upgrading NetBox 2016-06-28 15:58:50 -04:00
Jeremy Stretch
8b357a311d Fixes #61: Added list of RackGroups to Site view 2016-06-28 14:53:33 -04:00
Jeremy Stretch
fdfc32899d Fixes #75: Ignore a Device's occupied rack units when relocating it within a rack 2016-06-28 14:10:16 -04:00
Jeremy Stretch
03fa000d8d Merge pull request #86 from digitalocean/iface_form_factors
Fixes #84: Added IFACE_FF_10GE_COPPER
2016-06-28 13:38:51 -04:00
Jeremy Stretch
ec667eeed0 Fixes #84: Added IFACE_FF_10GE_COPPER 2016-06-28 13:32:47 -04:00
Jeremy Stretch
6c415794cd Corrected description of prefix and VLAN statuses 2016-06-28 12:53:43 -04:00
Jeremy Stretch
2ddb4b90c5 Merge pull request #85 from digitalocean/develop
Release v1.0.4
2016-06-28 12:17:12 -04:00
Jeremy Stretch
cce6c89810 Corrected static path in Apache config 2016-06-28 11:57:44 -04:00
Jeremy Stretch
b37503ed8f Corrected typos in the Apache config; cleaned up grammar 2016-06-28 11:50:25 -04:00
Jeremy Stretch
374702927b Fixes #80: Correct rack face (lowercase) to be consistent with export behavior (uppercase) 2016-06-28 11:38:09 -04:00
Jeremy Stretch
0eb8227044 Merge branch 'develop' of https://github.com/digitalocean/netbox into develop 2016-06-28 11:15:56 -04:00
Jeremy Stretch
98febf3979 Fixes #72: Check for re-used interfaces when importing interface connections 2016-06-28 11:11:53 -04:00
Jeremy Stretch
6a4a636794 Merge pull request #58 from digitalocean/travis-ci-pep-8
Add CI check for PEP 8 compliance
2016-06-28 10:56:42 -04:00
Matt Layher
9acd0e99f9 Add sanity check checklist for submitting pull requests 2016-06-28 10:55:38 -04:00
Matt Layher
f1857dd189 Add CI check for PEP 8 compliance 2016-06-28 10:43:38 -04:00
Jeremy Stretch
d22e4e7698 Merge pull request #59 from digitalocean/dcim-tests-pep-8
Fix PEP 8 error in DCIM tests
2016-06-28 10:42:38 -04:00
Jeremy Stretch
6848a3dc81 Fixes #67: Improved Aggregate validation; extended aggregate documentation 2016-06-28 10:04:03 -04:00
Jeremy Stretch
4dac43c1c9 Fixes #48: Set .container to auto with a max width 2016-06-28 09:50:00 -04:00
Jeremy Stretch
b392aa4a4a Fixes #45: Strip plus signs during slugification 2016-06-28 09:39:55 -04:00
Matt Layher
5181c97281 Fix PEP 8 error in DCIM tests 2016-06-28 00:25:12 -04:00
Jeremy Stretch
66a16dd06b Merge pull request #41 from digitalocean/travis-ci-tests
Run tests in CI
2016-06-28 00:10:19 -04:00
Matt Layher
c5d498ac14 Run tests in CI 2016-06-28 00:05:18 -04:00
Jeremy Stretch
2080abc6c3 Corrected SiteTest to account for earlier Graph model change 2016-06-27 23:56:39 -04:00
Jeremy Stretch
b379918295 Merge pull request #57 from digitalocean/develop
Release 1.0.3-r1
2016-06-27 23:24:01 -04:00
77 changed files with 1824 additions and 4618 deletions

3
.gitignore vendored
View File

@@ -2,5 +2,6 @@
configuration.py
.idea
/*.sh
!upgrade.sh
fabfile.py
*.swp

View File

@@ -3,5 +3,6 @@ python:
- "2.7"
install:
- pip install -r requirements.txt
- pip install pep8
script:
- ./scripts/cibuild.sh

View File

@@ -49,8 +49,18 @@ Even if it's not quite right for NetBox, we may be able to point you to a tool b
* A rough description of any changes necessary to the database schema (if applicable)
* Any third-party libraries or other resources which would be involved
# Submitting Pull Requests
## Submitting Pull Requests
When submitting a pull request, please be sure to work off of branch `develop`, rather than branch `master`.
* Be sure to open an issue before starting work on a pull request, and discuss your idea with the NetBox maintainers
before beginning work. This will help prevent wasting time on something that might we might not be able to implement.
When suggesting a new feature, also make sure it won't conflict with any work that's already in progress.
* When submitting a pull request, please be sure to work off of branch `develop`, rather than branch `master`.
In NetBox, the `develop` branch is used for ongoing development, while `master` is used for tagging new
stable releases.
* All code submissions should meet the following criteria (CI will enforce these checks):
* Python syntax is valid
* All tests pass when run with `./manage.py test netbox/`
* PEP 8 compliance is enforced, with the exception that lines may be greater than 80 characters in length

30
Dockerfile Normal file
View File

@@ -0,0 +1,30 @@
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y \
python2.7 \
python-dev \
git \
python-pip \
libxml2-dev \
libxslt1-dev \
libffi-dev \
graphviz \
libpq-dev \
build-essential \
gunicorn \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /opt/netbox \
&& cd /opt/netbox \
&& git clone --depth 1 https://github.com/digitalocean/netbox.git -b master . \
&& pip install -r requirements.txt \
&& apt-get purge -y --auto-remove git build-essential
ADD docker/docker-entrypoint.sh /docker-entrypoint.sh
ADD netbox/netbox/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
ENTRYPOINT [ "/docker-entrypoint.sh" ]
ADD docker/gunicorn_config.py /opt/netbox/
ADD docker/nginx.conf /etc/netbox-nginx/
VOLUME ["/etc/netbox-nginx/"]

View File

@@ -25,6 +25,8 @@ Questions? Comments? Please join us on IRC in **#netbox** on **irc.freenode.net*
Please see docs/getting-started.md for instructions on installing NetBox.
To upgrade NetBox, please download the [latest release](https://github.com/digitalocean/netbox/releases) and run `upgrade.sh`.
# Components
NetBox understands all of the physical and logical building blocks that comprise network infrastructure, and the manners in which they are all related.

52
docker-compose.yml Normal file
View File

@@ -0,0 +1,52 @@
version: '2'
services:
postgres:
image: postgres:9.6
container_name: postgres
environment:
POSTGRES_USER: netbox
POSTGRES_PASSWORD: J5brHrAXFLQSif0K
POSTGRES_DB: netbox
netbox:
image: digitalocean/netbox
links:
- postgres
container_name: netbox
depends_on:
- postgres
environment:
SUPERUSER_NAME: admin
SUPERUSER_EMAIL: admin@example.com
SUPERUSER_PASSWORD: admin
ALLOWED_HOSTS: localhost
DB_NAME: netbox
DB_USER: netbox
DB_PASSWORD: J5brHrAXFLQSif0K
DB_HOST: postgres
SECRET_KEY: r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
EMAIL_SERVER: localhost
EMAIL_PORT: 25
EMAIL_USERNAME: foo
EMAIL_PASSWORD: bar
EMAIL_TIMEOUT: 10
EMAIL_FROM: netbox@bar.com
NETBOX_USERNAME: guest
NETBOX_PASSWORD: guest
volumes:
- netbox-static-files:/opt/netbox/netbox/static
nginx:
image: nginx:1.11.1-alpine
links:
- netbox
container_name: nginx
command: nginx -g 'daemon off;' -c /etc/netbox-nginx/nginx.conf
depends_on:
- netbox
ports:
- 80:80
volumes_from:
- netbox
volumes:
netbox-static-files:
driver: local

22
docker/docker-entrypoint.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
set -e
# run db migrations (retry on error)
while ! /opt/netbox/netbox/manage.py migrate 2>&1; do
sleep 5
done
# create superuser silently
if [[ -z ${SUPERUSER_NAME} || -z ${SUPERUSER_EMAIL} || -z ${SUPERUSER_PASSWORD} ]]; then
SUPERUSER_NAME='admin'
SUPERUSER_EMAIL='admin@example.com'
SUPERUSER_PASSWORD='admin'
echo "Using defaults: Username: ${SUPERUSER_NAME}, E-Mail: ${SUPERUSER_EMAIL}, Password: ${SUPERUSER_PASSWORD}"
fi
echo "from django.contrib.auth.models import User; User.objects.create_superuser('${SUPERUSER_NAME}', '${SUPERUSER_EMAIL}', '${SUPERUSER_PASSWORD}')" | python /opt/netbox/netbox/manage.py shell
# copy static files
/opt/netbox/netbox/manage.py collectstatic --no-input
# start unicorn
gunicorn --log-level debug --debug --error-logfile /dev/stderr --log-file /dev/stdout -c /opt/netbox/gunicorn_config.py netbox.wsgi

View File

@@ -0,0 +1,5 @@
command = '/usr/bin/gunicorn'
pythonpath = '/opt/netbox/netbox'
bind = '0.0.0.0:8001'
workers = 3
user = 'root'

35
docker/nginx.conf Normal file
View File

@@ -0,0 +1,35 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server_tokens off;
server {
listen 80;
server_name localhost;
access_log off;
location /static/ {
alias /opt/netbox/netbox/static/;
}
location / {
proxy_pass http://netbox:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
}

View File

@@ -43,6 +43,7 @@ Each device type is assigned a number of component templates which describe the
* Power port templates
* Power outlet templates
* Interface templates
* Device bay templates
Whenever a new device is created, it is automatically assigned console, power, and interface components per the templates assigned to its device type. For example, suppose your network employs Juniper EX4300-48T switches. You would create a device type with a model name "EX4300-48T" and assign it to the manufacturer "Juniper." You might then also create the following templates for it:
@@ -59,12 +60,12 @@ Note that assignment of components from templates occurs only at the time of dev
# Devices
Every piece of hardware which is installed within a rack exists in NetBox as a device. Devices are measured in rack units (U) and whether they are full depth. 0U devices which can be installed in a rack but don't consume vertical rack space (such as a vertically-mounted power distribution unit) can also be defined.
Every piece of hardware which is installed within a rack exists in NetBox as a device. Devices are measured in rack units (U) and depth. 0U devices which can be installed in a rack but don't consume vertical rack space (such as a vertically-mounted power distribution unit) can also be defined.
When assigning a multi-U device to a rack, it is considered to be mounted in the lowest-numbered rack unit which it occupies. For example, a 3U device which occupies U8 through U10 shows as being mounted in U8.
A device is said to be "full depth" if its installation on one rack face prevents the installation of any other device on the opposite face within the same rack unit(s). This could be either because the device is physically too deep to allow a device behind it, or because the installation of an opposing device would impede air flow.
Each device has a physical device type (make and model), which is discussed below.
### Roles
NetBox allows for the definition of arbitrary device roles by which devices can be organized. For example, you might create roles for core switches, distribution switches, and access switches. In the interest of simplicity, device can only belong to one device role.
@@ -81,16 +82,19 @@ A device can be assigned modules which represent internal components. Currently,
### Components
There are five types of device components which comprise all of the interconnection logic with NetBox:
There are six types of device components which comprise all of the interconnection logic with NetBox:
* Console ports
* Console server ports
* Power ports
* Power outlets
* Interfaces
* Device bays
Console ports connect only to console server ports, and power ports connect only to power outlets. Interfaces connect to one another in a symmetric manner: If interface A connects to interface B, interface B therefore connects to interface A. (The relationship between two interfaces is actually represented in the database by an InterfaceConnection object, but this is transparent to the user.)
Each type of connection can be defined as either *planned* or *connected*. This allows for easily denoting connections which have not yet been installed.
Each type of connection can be classified as either *planned* or *connected*. This allows for easily denoting connections which have not yet been installed. In addition to a connecting peer, interfaces are also assigned a form factor and may be designated as management-only (for out-of-band management). Interfaces may also be assigned a short description.
In addition to a connecting peer, interfaces are also assigned a form factor and may be designated as management-only (for out-of-band management). Interfaces may also be assigned a short description.
Device bays represent the ability of a device to house child devices. For example, you might install four blade servers into a 2U chassis. The chassis would appear in the rack elevation as a 2U device with four device bays. Each server within it would be defined as a 0U device installed in one of the device bays. Child devices do not appear on rack elevations, but they are included in the "Non-Racked Devices" list within the rack view.
Note that child devices differ from modules in that they are still treated as independent devices, with their own console/power/data components, modules, and IP addresses. Modules, on the other hand, are parts within a device, such as a hard disk or power supply.

View File

@@ -0,0 +1,54 @@
<h1>Getting Started with NetBox and Docker</h1>
This guide assumes that the latest versions of [Docker](https://www.docker.com/) and [docker-compose](https://docs.docker.com/compose/) are already installed in your host.
# Quickstart
To get NetBox up and running:
```
git clone https://github.com/digitalocean/netbox.git
cd netbox
docker-compose up -d
```
The application will be available on http://localhost/ after a few minutes.
Default credentials:
* user: admin
* password: admin
# Configuration
You can configure the app at runtime using variables (see docker-compose.yml).
Possible environment variables:
* SUPERUSER_NAME
* SUPERUSER_EMAIL
* SUPERUSER_PASSWORD
* ALLOWED_HOSTS
* DB_NAME
* DB_USER
* DB_PASSWORD
* DB_HOST
* DB_PORT
* SECRET_KEY
* EMAIL_SERVER
* EMAIL_PORT
* EMAIL_USERNAME
* EMAIL_PASSWORD
* EMAIL_TIMEOUT
* EMAIL_FROM
* LOGIN_REQUIRED
* MAINTENANCE_MODE
* NETBOX_USERNAME
* NETBOX_PASSWORD
* PAGINATE_COUNT
* TIME_ZONE
* DATE_FORMAT
* SHORT_DATE_FORMAT
* TIME_FORMAT
* SHORT_TIME_FORMAT
* DATETIME_FORMAT
* SHORT_DATETIME_FORMAT

View File

@@ -15,7 +15,7 @@ The following packages are needed to install PostgreSQL:
* python-psycopg2
```
# apt-get install postgresql libpq-dev python-psycopg2
# sudo apt-get install -y postgresql libpq-dev python-psycopg2
```
## Configuration
@@ -48,24 +48,37 @@ You can verify that authentication works using the following command:
# NetBox
## Dependencies
## Installation
NetBox requires following dependencies:
* python2.7
* python-dev
* git
* python-pip
* libxml2-dev
* libxslt1-dev
* libffi-dev
* graphviz*
* graphviz
```
# apt-get install python2.7 python-dev git python-pip libxml2-dev libxslt1-dev libffi-dev graphviz
# sudo apt-get install -y python2.7 python-dev git python-pip libxml2-dev libxslt1-dev libffi-dev graphviz
```
*graphviz is needed to render topology maps. If you have no need for this feature, graphviz is not required.
You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub.
## Clone the Git Repository
### Option A: Download a Release
Download the [latest stable release](https://github.com/digitalocean/netbox/releases) from GitHub as a tarball or ZIP archive. Extract it to your desired path. In this example, we'll use `/opt/netbox`.
```
# wget https://github.com/digitalocean/netbox/archive/vX.Y.Z.tar.gz
# tar -xzf vX.Y.Z.tar.gz -C /opt
# cd /opt/
# ln -s netbox-1.0.4/ netbox
# cd /opt/netbox/
```
### Option B: Clone the Git Repository
Create the base directory for the NetBox installation. For this guide, we'll use `/opt/netbox`.
@@ -74,10 +87,16 @@ Create the base directory for the NetBox installation. For this guide, we'll use
# cd /opt/netbox/
```
Next, clone the NetBox git repository into the current directory:
If `git` is not already installed, install it:
```
# git clone https://github.com/digitalocean/netbox.git .
# sudo apt-get install -y git
```
Next, clone the **master** branch of the NetBox GitHub repository into the current directory:
```
# git clone -b master https://github.com/digitalocean/netbox.git .
Cloning into '.'...
remote: Counting objects: 1994, done.
remote: Compressing objects: 100% (150/150), done.
@@ -87,10 +106,12 @@ Resolving deltas: 100% (1495/1495), done.
Checking connectivity... done.
```
### Install Python Packages
Install the necessary Python packages using pip. (If you encounter any compilation errors during this step, ensure that you've installed all of the required dependencies.)
```
# pip install -r requirements.txt
# sudo pip install -r requirements.txt
```
## Configuration
@@ -145,6 +166,7 @@ You may use the script located at `netbox/generate_secret_key.py` to generate a
Before NetBox can run, we need to install the database schema. This is done by running `./manage.py migrate` from the `netbox` directory (`/opt/netbox/netbox/` in our example):
```
# cd /opt/netbox/netbox/
# ./manage.py migrate
Operations to perform:
Apply all migrations: dcim, sessions, admin, ipam, utilities, auth, circuits, contenttypes, extras, secrets, users
@@ -210,10 +232,10 @@ If the test service does not run, or you cannot reach the NetBox home page, some
## Installation
We'll set up a simple HTTP front end using [gunicorn](http://gunicorn.org/) for the purposes of this guide. For web servers, we have 2 configurations ready to go - we provide instructions for both [nginx](https://www.nginx.com/resources/wiki/)and [Apache](http://httpd.apache.org/docs/2.4). (You are of course free to use whichever combination of HTTP and WSGI services you'd like.) We'll also use [supervisord](http://supervisord.org/) for service persistence.
We'll set up a simple HTTP front end using [gunicorn](http://gunicorn.org/) for the purposes of this guide. For web servers, we provide example configurations for both [nginx](https://www.nginx.com/resources/wiki/) and [Apache](http://httpd.apache.org/docs/2.4). (You are of course free to use whichever combination of HTTP and WSGI services you'd like.) We'll also use [supervisord](http://supervisord.org/) for service persistence.
```
# apt-get install gunicorn supervisor
# sudo apt-get install -y gunicorn supervisor
```
## nginx Configuration
@@ -221,7 +243,7 @@ We'll set up a simple HTTP front end using [gunicorn](http://gunicorn.org/) for
The following will serve as a minimal nginx configuration. Be sure to modify your server name and installation path appropriately.
```
# apt-get install nginx
# sudo apt-get install -y nginx
```
Once nginx is installed, proceed with the following configuration:
@@ -264,42 +286,47 @@ Restart the nginx service to use the new configuration.
```
## Apache Configuration
If you're feeling adventurous, or you already have Apache installed and can't run a dual-stack on your server - an Apache configuration has been created:
```
# sudo apt-get install -y apache2
```
Once Apache is installed, proceed with the following configuration (Be sure to modify the `ServerName` appropriately):
```
<VirtualHost *:80>
ProxyPreserveHost On
ServerName netbox.totallycool.tld
Alias /static/ /opt/netbox/static/static
ServerName netbox.example.com
Alias /static /opt/netbox/netbox/static
<Directory /opt/netbox/netbox/static>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
#Require all granted [UNCOMMENT THIS IF RUNNING APACHE 2.4]
Require all granted
</Directory>
<Location /static>
ProxyPass !
</Location>
ProxyPass / http://127.0.0.1:8001;
ProxyPassReverse / http://127.0.0.1:8001;
ProxyPass / http://127.0.0.1:8001/
ProxyPassReverse / http://127.0.0.1:8001/
</VirtualHost>
```
Save the contents of the above example in `/etc/apache2/sites-available/netbox.conf`, add in the newly saved configuration and reload Apache:
Save the contents of the above example in `/etc/apache2/sites-available/netbox.conf`, enable the `proxy` and `proxy_http` modules, and reload Apache:
```
# a2ensite netbox; service apache2 restart
# a2enmod proxy
# a2enmod proxy_http
# a2ensite netbox
# service apache2 restart
```
## gunicorn Configuration
Save the following configuration file in the root netbox installation path (in this example, `/opt/netbox/`.) as `gunicorn_config.py`. Be sure to verify the location of the gunicorn executable (e.g. `which gunicorn`) and to update the `pythonpath` variable if needed.
Save the following configuration file in the root netbox installation path (in this example, `/opt/netbox/`) as `gunicorn_config.py`. Be sure to verify the location of the gunicorn executable (e.g. `which gunicorn`) and to update the `pythonpath` variable if needed.
```
command = '/usr/bin/gunicorn'
@@ -328,5 +355,148 @@ Finally, restart the supervisor service to detect and run the gunicorn service:
At this point, you should be able to connect to the nginx HTTP service at the server name or IP address you provided. If you are unable to connect, check that the nginx service is running and properly configured. If you receive a 502 (bad gateway) error, this indicates that gunicorn is misconfigured or not running.
Please keep in mind that the configurations provided here are a bare minimum to get NetBox up and running. You will almost certainly want to make some changes to better suit your production environment.
Please keep in mind that the configurations provided here are bare minimums required to get NetBox up and running. You will almost certainly want to make some changes to better suit your production environment.
## Let's Encrypt SSL + nginx
To add SSL support to the installation we'll start by installing the arbitrary precision calculator language.
```
# sudo apt-get install -y bc
```
Next we'll clone Let's Encrypt into /opt/:
```
# sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
```
To ensure Let's Encrypt can publicly access the directory it needs for certificate validation you'll need to edit `/etc/nginx/sites-available/netbox` and add:
```
location /.well-known/ {
alias /opt/netbox/netbox/.well-known/;
allow all;
}
```
Then restart nginix:
```
# sudo services nginx restart
```
To create the certificate use the following commands ensuring to change `netbox.example.com` to the domain name of the server:
```
# cd /opt/letsencrypt
# ./letsencrypt-auto certonly -a webroot --webroot-path=/opt/netbox/netbox/ -d netbox.example.com
```
If you wish to add support for the `www` prefix you'd use:
```
# cd /opt/letsencrypt
# ./letsencrypt-auto certonly -a webroot --webroot-path=/opt/netbox/netbox/ -d netbox.example.com -d www.netbox.example.com
```
Make sure you have DNS records setup for the hostnames you use and that they resolve back the netbox server.
You will be prompted for your email address to receive notifications about your SSL and then asked to accept the subscriber agreement.
If successful you'll now have four files in `/etc/letsencrypt/live/netbox.example.com` (remember, your hostname is different)
```
cert.pem
chain.pem
fullchain.pem
privkey.pem
```
Now edit your nginx configuration `/etc/nginx/sites-available/netbox` and at the top edit to the following:
```
#listen 80;
#listen [::]80;
listen 443;
listen [::]443;
ssl on;
ssl_certificate /etc/letsencrypt/live/netbox.example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/netbox.example.com/privkey.pem;
```
If you are not using IPv6 then you do not need `listen [::]443;` The two commented lines are for non-SSL for both IPv4 and IPv6.
Lastly, restart nginx:
```
# sudo services nginx restart
```
You should now have netbox running on a SSL protected connection.
# Upgrading
## Installation of Upgrade
As with the initial installation, you can upgrade NetBox by either downloading the latest release package or by cloning the `master` branch of the git repository.
### Option A: Download a Release
Download the [latest stable release](https://github.com/digitalocean/netbox/releases) from GitHub as a tarball or ZIP archive. Extract it to your desired path. In this example, we'll use `/opt/netbox`. For this guide we are using 1.0.4 as the old version and 1.0.7 as the new version.
Download & extract latest version:
```
# wget https://github.com/digitalocean/netbox/archive/vX.Y.Z.tar.gz
# tar -xzf vX.Y.Z.tar.gz -C /opt
# cd /opt/
# ln -sf netbox-1.0.7/ netbox
```
Copy the 'configuration.py' you created when first installing to the new version:
```
# cp /opt/netbox-1.0.4/configuration.py /opt/netbox/configuration.py
```
### Option B: Clone the Git Repository (latest master release)
For this guide, we'll use `/opt/netbox`.
Check that your git branch is up to date & is set to master:
```
# cd /opt/netbox
# git status
```
If not on branch master, set it and verify status:
```
# git checkout master
# git status
```
Pull down the set branch from git status above:
```
# git pull
```
## Upgrade Script & Netbox Restart
Once the new code is in place, run the upgrade script (which may need to be run as root depending on how your environment is configured).
```
# ./upgrade.sh
```
This script:
* Installs or upgrades any new required Python packages
* Applies any database migrations that were included in the release
* Collects all static files to be served by the HTTP service
Finally, restart the WSGI service to run the new code. If you followed this guide for the initial installation, this is done using `supervisorctl`:
```
# sudo supervisorctl restart netbox
```

View File

@@ -32,6 +32,8 @@ Additionally, you might define an aggregate for each large swath of public IPv4
Any prefixes you create in NetBox (discussed below) will be automatically organized under their respective aggregates. Any space within an aggregate which is not covered by an existing prefix will be annotated as available for allocation.
Aggregates cannot overlap with one another; they can only exist in parallel. For instance, you cannot define both 10.0.0.0/8 and 10.16.0.0/16 as aggregates, because they overlap. 10.16.0.0/16 in this example would be created as a prefix.
### RIRs
Regional Internet Registries (RIRs) are responsible for the allocation of global address space. The five RIRs are ARIN, RIPE, APNIC, LACNIC, and AFRINIC. However, some address space has been set aside for private or internal use only, such as defined in RFCs 1918 and 6598. NetBox considers these RFCs as a sort of RIR as well; that is, an authority which "owns" certain address space.
@@ -50,15 +52,13 @@ A prefix may optionally be assigned to one VLAN; a VLAN may have multiple prefix
### Statuses
Each prefix is assigned an operational status. This may be one of the following:
Each prefix is assigned an operational status. This is one of the following:
* Container - A summary of child prefixes
* Active - Provisioned and in use
* Reserved - Earmarked for future use
* Deprecated - No longer in use
NetBox provides several statuses by default, but you are free to change them to suit the needs of your organization.
### Roles
Whereas a status describes a prefix's operational state, a role describes its function. For example, roles might include:
@@ -69,7 +69,7 @@ Whereas a status describes a prefix's operational state, a role describes its fu
* Lab
* Out-of-band
Role assignment is optional. And like statuses, you are free to create your own.
Role assignment is optional and you are free to create as many as you'd like.
---

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,8 @@ Each secret is assigned a functional role which indicates what it is used for. T
* IKE key strings
* Routing protocol shared secrets
Roles are also used to control access to secrets. Each role is assigned an arbitrary number of groups and/or users. Only the users associated with a role have permission to decrypt the secrets assigned to that role. (A superuser has permission to decrypt all secrets, provided they have an active user key.)
---
# User Keys

View File

@@ -2,9 +2,9 @@ from django.contrib import admin
from django.db.models import Count
from .models import (
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType,
Interface, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet, PowerOutletTemplate, PowerPort,
PowerPortTemplate, Rack, RackGroup, Site,
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceTemplate, Manufacturer, Module, Platform,
PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, Site,
)
@@ -61,6 +61,10 @@ class InterfaceTemplateAdmin(admin.TabularInline):
model = InterfaceTemplate
class DeviceBayTemplateAdmin(admin.TabularInline):
model = DeviceBayTemplate
@admin.register(DeviceType)
class DeviceTypeAdmin(admin.ModelAdmin):
prepopulated_fields = {
@@ -72,9 +76,10 @@ class DeviceTypeAdmin(admin.ModelAdmin):
PowerPortTemplateAdmin,
PowerOutletTemplateAdmin,
InterfaceTemplateAdmin,
DeviceBayTemplateAdmin,
]
list_display = ['model', 'manufacturer', 'slug', 'u_height', 'console_ports', 'console_server_ports', 'power_ports',
'power_outlets', 'interfaces']
'power_outlets', 'interfaces', 'device_bays']
list_filter = ['manufacturer']
def get_queryset(self, request):
@@ -84,6 +89,7 @@ class DeviceTypeAdmin(admin.ModelAdmin):
power_port_count=Count('power_port_templates', distinct=True),
power_outlet_count=Count('power_outlet_templates', distinct=True),
interface_count=Count('interface_templates', distinct=True),
devicebay_count=Count('devicebay_templates', distinct=True),
)
def console_ports(self, instance):
@@ -101,6 +107,9 @@ class DeviceTypeAdmin(admin.ModelAdmin):
def interfaces(self, instance):
return instance.interface_count
def device_bays(self, instance):
return instance.devicebay_count
#
# Devices
@@ -144,6 +153,12 @@ class InterfaceAdmin(admin.TabularInline):
model = Interface
class DeviceBayAdmin(admin.TabularInline):
model = DeviceBay
fk_name = 'device'
readonly_fields = ['installed_device']
class ModuleAdmin(admin.TabularInline):
model = Module
readonly_fields = ['parent', 'discovered']
@@ -157,6 +172,7 @@ class DeviceAdmin(admin.ModelAdmin):
PowerPortAdmin,
PowerOutletAdmin,
InterfaceAdmin,
DeviceBayAdmin,
ModuleAdmin,
]
list_display = ['display_name', 'device_type', 'device_role', 'primary_ip', 'rack', 'position', 'serial']

View File

@@ -2,9 +2,9 @@ from rest_framework import serializers
from ipam.models import IPAddress
from dcim.models import (
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceType, DeviceRole,
Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, Platform, PowerOutlet, PowerOutletTemplate,
PowerPort, PowerPortTemplate, Rack, RackGroup, RACK_FACE_FRONT, RACK_FACE_REAR, Site,
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay, DeviceType,
DeviceRole, Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, Platform, PowerOutlet,
PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, RACK_FACE_FRONT, RACK_FACE_REAR, Site,
)
@@ -221,16 +221,31 @@ class DeviceSerializer(serializers.ModelSerializer):
platform = PlatformNestedSerializer()
rack = RackNestedSerializer()
primary_ip = DeviceIPAddressNestedSerializer()
parent_device = serializers.SerializerMethodField()
class Meta:
model = Device
fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'platform', 'serial', 'rack', 'position',
'face', 'status', 'primary_ip', 'comments']
'face', 'parent_device', 'status', 'primary_ip', 'comments']
def get_parent_device(self, obj):
try:
device_bay = obj.parent_bay
except DeviceBay.DoesNotExist:
return None
return {
'id': device_bay.device.pk,
'name': device_bay.device.name,
'device_bay': {
'id': device_bay.pk,
'name': device_bay.name,
}
}
class DeviceNestedSerializer(DeviceSerializer):
class DeviceNestedSerializer(serializers.ModelSerializer):
class Meta(DeviceSerializer.Meta):
class Meta:
model = Device
fields = ['id', 'name', 'display_name']
@@ -319,7 +334,7 @@ class InterfaceSerializer(serializers.ModelSerializer):
class Meta:
model = Interface
fields = ['id', 'device', 'name', 'form_factor', 'mgmt_only', 'description', 'is_connected']
fields = ['id', 'device', 'name', 'form_factor', 'mac_address', 'mgmt_only', 'description', 'is_connected']
class InterfaceNestedSerializer(InterfaceSerializer):
@@ -333,10 +348,36 @@ class InterfaceDetailSerializer(InterfaceSerializer):
connected_interface = InterfaceSerializer(source='get_connected_interface')
class Meta(InterfaceSerializer.Meta):
fields = ['id', 'device', 'name', 'form_factor', 'mgmt_only', 'description', 'is_connected',
fields = ['id', 'device', 'name', 'form_factor', 'mac_address', 'mgmt_only', 'description', 'is_connected',
'connected_interface']
#
# Device bays
#
class DeviceBaySerializer(serializers.ModelSerializer):
device = DeviceNestedSerializer()
class Meta:
model = DeviceBay
fields = ['id', 'device', 'name']
class DeviceBayNestedSerializer(DeviceBaySerializer):
installed_device = DeviceNestedSerializer()
class Meta(DeviceBaySerializer.Meta):
fields = ['id', 'name', 'installed_device']
class DeviceBayDetailSerializer(DeviceBaySerializer):
installed_device = DeviceNestedSerializer()
class Meta(DeviceBaySerializer.Meta):
fields = ['id', 'device', 'name', 'installed_device']
#
# Interface connections
#

View File

@@ -49,6 +49,7 @@ urlpatterns = [
url(r'^devices/(?P<pk>\d+)/power-ports/$', PowerPortListView.as_view(), name='device_powerports'),
url(r'^devices/(?P<pk>\d+)/power-outlets/$', PowerOutletListView.as_view(), name='device_poweroutlets'),
url(r'^devices/(?P<pk>\d+)/interfaces/$', InterfaceListView.as_view(), name='device_interfaces'),
url(r'^devices/(?P<pk>\d+)/device-bays/$', DeviceBayListView.as_view(), name='device_devicebays'),
# Console ports
url(r'^console-ports/(?P<pk>\d+)/$', ConsolePortView.as_view(), name='consoleport'),

View File

@@ -9,8 +9,8 @@ from django.http import Http404
from django.shortcuts import get_object_or_404
from dcim.models import (
ConsolePort, ConsoleServerPort, Device, DeviceRole, DeviceType, IFACE_FF_VIRTUAL, Interface, InterfaceConnection,
Manufacturer, Platform, PowerOutlet, PowerPort, Rack, RackGroup, Site,
ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceRole, DeviceType, IFACE_FF_VIRTUAL, Interface,
InterfaceConnection, Manufacturer, Platform, PowerOutlet, PowerPort, Rack, RackGroup, Site,
)
from dcim import filters
from .exceptions import MissingFilterException
@@ -326,6 +326,33 @@ class InterfaceConnectionView(generics.RetrieveUpdateDestroyAPIView):
queryset = InterfaceConnection.objects.all()
#
# Device bays
#
class DeviceBayListView(generics.ListAPIView):
"""
List device bays (by device)
"""
serializer_class = serializers.DeviceBayNestedSerializer
def get_queryset(self):
device = get_object_or_404(Device, pk=self.kwargs['pk'])
queryset = DeviceBay.objects.filter(device=device).select_related('installed_device')
# Filter by type (physical or virtual)
iface_type = self.request.query_params.get('type')
if iface_type == 'physical':
queryset = queryset.exclude(form_factor=IFACE_FF_VIRTUAL)
elif iface_type == 'virtual':
queryset = queryset.filter(form_factor=IFACE_FF_VIRTUAL)
elif iface_type is not None:
queryset = queryset.empty()
return queryset
#
# Live queries
#

44
netbox/dcim/fields.py Normal file
View File

@@ -0,0 +1,44 @@
from netaddr import EUI, mac_unix_expanded
from django.core.exceptions import ValidationError
from django.db import models
from .formfields import MACAddressFormField
class mac_unix_expanded_uppercase(mac_unix_expanded):
word_fmt = '%.2X'
class MACAddressField(models.Field):
description = "PostgreSQL MAC Address field"
def python_type(self):
return EUI
def from_db_value(self, value, expression, connection, context):
return self.to_python(value)
def to_python(self, value):
if value is None:
return value
try:
return EUI(value, version=48, dialect=mac_unix_expanded_uppercase)
except ValueError as e:
raise ValidationError(e)
def db_type(self, connection):
return 'macaddr'
def get_prep_value(self, value):
if not value:
return None
return str(self.to_python(value))
def form_class(self):
return MACAddressFormField
def formfield(self, **kwargs):
defaults = {'form_class': self.form_class()}
defaults.update(kwargs)
return super(MACAddressField, self).formfield(**defaults)

View File

@@ -8,6 +8,27 @@ from .models import (
)
class SiteFilter(django_filters.FilterSet):
q = django_filters.MethodFilter(
action='search',
label='Search',
)
class Meta:
model = Site
fields = ['q', 'name', 'facility', 'asn']
def search(self, queryset, value):
value = value.strip()
qs_filter = Q(name__icontains=value) | Q(facility__icontains=value) | Q(physical_address__icontains=value) | \
Q(shipping_address__icontains=value)
try:
qs_filter |= Q(asn=int(value))
except ValueError:
pass
return queryset.filter(qs_filter)
class RackGroupFilter(django_filters.FilterSet):
site_id = django_filters.ModelMultipleChoiceFilter(
name='site',

View File

@@ -3419,6 +3419,7 @@
"fields": {
"device": 3,
"name": "em0",
"mac_address": "00-00-00-AA-BB-CC",
"form_factor": 800,
"mgmt_only": true,
"description": ""
@@ -3772,6 +3773,7 @@
"device": 4,
"name": "em0",
"form_factor": 1000,
"mac_address": "ff-ee-dd-33-22-11",
"mgmt_only": true,
"description": ""
}
@@ -5686,6 +5688,7 @@
"device": 9,
"name": "eth0",
"form_factor": 1000,
"mac_address": "44-55-66-77-88-99",
"mgmt_only": true,
"description": ""
}
@@ -5865,4 +5868,4 @@
"connection_status": true
}
}
]
]

26
netbox/dcim/formfields.py Normal file
View File

@@ -0,0 +1,26 @@
from netaddr import EUI, AddrFormatError
from django import forms
from django.core.exceptions import ValidationError
#
# Form fields
#
class MACAddressFormField(forms.Field):
default_error_messages = {
'invalid': "Enter a valid MAC address.",
}
def to_python(self, value):
if not value:
return None
if isinstance(value, EUI):
return value
try:
return EUI(value, version=48)
except AddrFormatError:
raise ValidationError("Please specify a valid MAC address.")

View File

@@ -10,10 +10,10 @@ from utilities.forms import (
)
from .models import (
CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED, ConsolePort, ConsolePortTemplate,
ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType, Interface, IFACE_FF_VIRTUAL,
InterfaceConnection, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet, PowerOutletTemplate, PowerPort,
PowerPortTemplate, Rack, RackGroup, Site, STATUS_CHOICES
DeviceBay, DeviceBayTemplate, CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED,
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType,
Interface, IFACE_FF_VIRTUAL, InterfaceConnection, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet,
PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, Site, STATUS_CHOICES, SUBDEVICE_ROLE_CHILD
)
@@ -216,7 +216,7 @@ class DeviceTypeForm(forms.ModelForm, BootstrapMixin):
class Meta:
model = DeviceType
fields = ['manufacturer', 'model', 'slug', 'u_height', 'is_full_depth', 'is_console_server', 'is_pdu',
'is_network_device']
'is_network_device', 'subdevice_role']
class DeviceTypeBulkEditForm(forms.Form, BootstrapMixin):
@@ -283,6 +283,14 @@ class InterfaceTemplateForm(forms.ModelForm, BootstrapMixin):
fields = ['name_pattern', 'form_factor', 'mgmt_only']
class DeviceBayTemplateForm(forms.ModelForm, BootstrapMixin):
name_pattern = ExpandableNameField(label='Name')
class Meta:
model = DeviceBayTemplate
fields = ['name_pattern']
#
# Device roles
#
@@ -326,10 +334,10 @@ class DeviceForm(forms.ModelForm, BootstrapMixin):
display_field='display_name',
attrs={'filter-for': 'position'}
))
position = forms.TypedChoiceField(required=False, empty_value=None, widget=APISelect(
api_url='/api/dcim/racks/{{rack}}/rack-units/?face={{face}}',
disabled_indicator='device',
))
position = forms.TypedChoiceField(required=False, empty_value=None,
help_text="For multi-U devices, this is the lowest occupied rack unit.",
widget=APISelect(api_url='/api/dcim/racks/{{rack}}/rack-units/?face={{face}}',
disabled_indicator='device'))
manufacturer = forms.ModelChoiceField(queryset=Manufacturer.objects.all(),
widget=forms.Select(attrs={'filter-for': 'device_type'}))
device_type = forms.ModelChoiceField(queryset=DeviceType.objects.all(), label='Model', widget=APISelect(
@@ -386,10 +394,13 @@ class DeviceForm(forms.ModelForm, BootstrapMixin):
# Rack position
try:
pk = self.instance.pk if self.instance.pk else None
if self.is_bound and self.data.get('rack') and str(self.data.get('face')):
position_choices = Rack.objects.get(pk=self.data['rack']).get_rack_units(face=self.data.get('face'))
position_choices = Rack.objects.get(pk=self.data['rack'])\
.get_rack_units(face=self.data.get('face'), exclude=pk)
elif self.initial.get('rack') and str(self.initial.get('face')):
position_choices = Rack.objects.get(pk=self.initial['rack']).get_rack_units(face=self.initial.get('face'))
position_choices = Rack.objects.get(pk=self.initial['rack'])\
.get_rack_units(face=self.initial.get('face'), exclude=pk)
else:
position_choices = []
except Rack.DoesNotExist:
@@ -424,7 +435,7 @@ class DeviceFromCSVForm(forms.ModelForm):
'invalid_choice': 'Invalid site name.',
})
rack_name = forms.CharField()
face = forms.ChoiceField(choices=[('front', 'Front'), ('rear', 'Rear')])
face = forms.CharField(required=False)
class Meta:
model = Device
@@ -443,7 +454,7 @@ class DeviceFromCSVForm(forms.ModelForm):
try:
self.instance.device_type = DeviceType.objects.get(manufacturer=manufacturer, model=model_name)
except DeviceType.DoesNotExist:
self.add_error('model_name', "Invalid device type ({})".format(model_name))
self.add_error('model_name', "Invalid device type ({} {})".format(manufacturer, model_name))
# Validate rack
if site and rack_name:
@@ -454,11 +465,15 @@ class DeviceFromCSVForm(forms.ModelForm):
def clean_face(self):
face = self.cleaned_data['face']
if face.lower() == 'front':
return 0
if face.lower() == 'rear':
return 1
raise forms.ValidationError("Invalid rack face ({})".format(face))
if face:
try:
return {
'front': 0,
'rear': 1,
}[face.lower()]
except KeyError:
raise forms.ValidationError('Invalid rack face ({}); must be "front" or "rear".'.format(face))
return face
class DeviceImportForm(BulkImportForm, BootstrapMixin):
@@ -910,7 +925,7 @@ class InterfaceForm(forms.ModelForm, BootstrapMixin):
class Meta:
model = Interface
fields = ['device', 'name', 'form_factor', 'mgmt_only', 'description']
fields = ['device', 'name', 'form_factor', 'mac_address', 'mgmt_only', 'description']
widgets = {
'device': forms.HiddenInput(),
}
@@ -921,7 +936,7 @@ class InterfaceCreateForm(forms.ModelForm, BootstrapMixin):
class Meta:
model = Interface
fields = ['name_pattern', 'form_factor', 'mgmt_only', 'description']
fields = ['name_pattern', 'form_factor', 'mac_address', 'mgmt_only', 'description']
class InterfaceBulkCreateForm(InterfaceCreateForm, BootstrapMixin):
@@ -1036,20 +1051,29 @@ class InterfaceConnectionImportForm(BulkImportForm, BootstrapMixin):
return
connection_list = []
occupied_interfaces = []
for i, record in enumerate(records, start=1):
form = self.fields['csv'].csv_form(data=record)
if form.is_valid():
interface_a = Interface.objects.get(device=form.cleaned_data['device_a'],
name=form.cleaned_data['interface_a'])
if interface_a in occupied_interfaces:
raise forms.ValidationError("{} {} found in multiple connections"
.format(interface_a.device.name, interface_a.name))
interface_b = Interface.objects.get(device=form.cleaned_data['device_b'],
name=form.cleaned_data['interface_b'])
if interface_b in occupied_interfaces:
raise forms.ValidationError("{} {} found in multiple connections"
.format(interface_b.device.name, interface_b.name))
connection = InterfaceConnection(interface_a=interface_a, interface_b=interface_b)
if form.cleaned_data['status'] == 'planned':
connection.connection_status = CONNECTION_STATUS_PLANNED
else:
connection.connection_status = CONNECTION_STATUS_CONNECTED
connection_list.append(connection)
occupied_interfaces.append(interface_a)
occupied_interfaces.append(interface_b)
else:
for field, errors in form.errors.items():
for e in errors:
@@ -1064,6 +1088,41 @@ class InterfaceConnectionDeletionForm(forms.Form, BootstrapMixin):
device = forms.ModelChoiceField(queryset=Device.objects.all(), widget=forms.HiddenInput(), required=False)
#
# Device bays
#
class DeviceBayForm(forms.ModelForm, BootstrapMixin):
class Meta:
model = DeviceBay
fields = ['device', 'name']
widgets = {
'device': forms.HiddenInput(),
}
class DeviceBayCreateForm(forms.Form, BootstrapMixin):
name_pattern = ExpandableNameField(label='Name')
class PopulateDeviceBayForm(forms.Form, BootstrapMixin):
installed_device = forms.ModelChoiceField(queryset=Device.objects.all(), label='Child Device',
help_text="Child devices must first be created within the rack occupied "
"by the parent device. Then they can be assigned to a bay.")
def __init__(self, device_bay, *args, **kwargs):
super(PopulateDeviceBayForm, self).__init__(*args, **kwargs)
children_queryset = Device.objects.filter(rack=device_bay.device.rack,
parent_bay__isnull=True,
device_type__u_height=0,
device_type__subdevice_role=SUBDEVICE_ROLE_CHILD)\
.exclude(pk=device_bay.device.pk)
self.fields['installed_device'].queryset = children_queryset
#
# Connections
#

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-28 17:21
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dcim', '0002_auto_20160622_1821'),
]
operations = [
migrations.AlterField(
model_name='interface',
name='form_factor',
field=models.PositiveSmallIntegerField(choices=[[0, b'Virtual'], [800, b'10/100M (100BASE-TX)'], [1000, b'1GE (1000BASE-T)'], [1100, b'1GE (SFP)'], [1150, b'10GE (10GBASE-T)'], [1200, b'10GE (SFP+)'], [1300, b'10GE (XFP)'], [1400, b'40GE (QSFP+)']], default=1200),
),
migrations.AlterField(
model_name='interfacetemplate',
name='form_factor',
field=models.PositiveSmallIntegerField(choices=[[0, b'Virtual'], [800, b'10/100M (100BASE-TX)'], [1000, b'1GE (1000BASE-T)'], [1100, b'1GE (SFP)'], [1150, b'10GE (10GBASE-T)'], [1200, b'10GE (SFP+)'], [1300, b'10GE (XFP)'], [1400, b'40GE (QSFP+)']], default=1200),
),
]

View File

@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-01 20:49
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('dcim', '0003_auto_20160628_1721'),
]
operations = [
migrations.CreateModel(
name='DeviceBay',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, verbose_name=b'Name')),
('device', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='device_bays', to='dcim.Device')),
('installed_device', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='parent_bay', to='dcim.Device')),
],
options={
'ordering': ['device', 'name'],
},
),
migrations.CreateModel(
name='DeviceBayTemplate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=30)),
],
options={
'ordering': ['device_type', 'name'],
},
),
migrations.AddField(
model_name='devicetype',
name='subdevice_role',
field=models.NullBooleanField(choices=[(None, b'N/A'), (True, b'Parent'), (False, b'Child')], default=None, help_text=b'Parent devices house child devices in device bays. Select "None" if this device type is neither a parent nor a child.', verbose_name=b'Parent/child status'),
),
migrations.AddField(
model_name='devicebaytemplate',
name='device_type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='device_bay_templates', to='dcim.DeviceType'),
),
migrations.AlterUniqueTogether(
name='devicebaytemplate',
unique_together=set([('device_type', 'name')]),
),
migrations.AlterUniqueTogether(
name='devicebay',
unique_together=set([('device', 'name')]),
),
]

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-06 17:22
from __future__ import unicode_literals
import dcim.fields
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dcim', '0004_auto_20160701_2049'),
]
operations = [
migrations.AddField(
model_name='interface',
name='mac_address',
field=dcim.fields.MACAddressField(blank=True, null=True, verbose_name=b'MAC Address'),
),
migrations.AlterField(
model_name='devicetype',
name='subdevice_role',
field=models.NullBooleanField(choices=[(None, b'None'), (True, b'Parent'), (False, b'Child')], default=None, help_text=b'Parent devices house child devices in device bays. Select "None" if this device type is neither a parent nor a child.', verbose_name=b'Parent/child status'),
),
]

View File

@@ -4,12 +4,13 @@ from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import Q, ObjectDoesNotExist
from django.db.models import Count, Q, ObjectDoesNotExist
from extras.rpc import RPC_CLIENTS
from utilities.fields import NullableCharField
from utilities.models import CreatedUpdatedModel
from .fields import MACAddressField
RACK_FACE_FRONT = 0
RACK_FACE_REAR = 1
@@ -18,6 +19,14 @@ RACK_FACE_CHOICES = [
[RACK_FACE_REAR, 'Rear'],
]
SUBDEVICE_ROLE_PARENT = True
SUBDEVICE_ROLE_CHILD = False
SUBDEVICE_ROLE_CHOICES = (
(None, 'None'),
(SUBDEVICE_ROLE_PARENT, 'Parent'),
(SUBDEVICE_ROLE_CHILD, 'Child'),
)
COLOR_TEAL = 'teal'
COLOR_GREEN = 'green'
COLOR_BLUE = 'blue'
@@ -45,14 +54,16 @@ IFACE_FF_VIRTUAL = 0
IFACE_FF_100M_COPPER = 800
IFACE_FF_1GE_COPPER = 1000
IFACE_FF_SFP = 1100
IFACE_FF_10GE_COPPER = 1150
IFACE_FF_SFP_PLUS = 1200
IFACE_FF_XFP = 1300
IFACE_FF_QSFP_PLUS = 1400
IFACE_FF_CHOICES = [
[IFACE_FF_VIRTUAL, 'Virtual'],
[IFACE_FF_100M_COPPER, '10/100M (Copper)'],
[IFACE_FF_1GE_COPPER, '1GE (Copper)'],
[IFACE_FF_100M_COPPER, '10/100M (100BASE-TX)'],
[IFACE_FF_1GE_COPPER, '1GE (1000BASE-T)'],
[IFACE_FF_SFP, '1GE (SFP)'],
[IFACE_FF_10GE_COPPER, '10GE (10GBASE-T)'],
[IFACE_FF_SFP_PLUS, '10GE (SFP+)'],
[IFACE_FF_XFP, '10GE (XFP)'],
[IFACE_FF_QSFP_PLUS, '40GE (QSFP+)'],
@@ -83,6 +94,48 @@ RPC_CLIENT_CHOICES = [
]
def order_interfaces(queryset, sql_col, primary_ordering=tuple()):
"""
Attempt to match interface names by their slot/position identifiers and order according. Matching is done using the
following pattern:
{a}/{b}/{c}:{d}
Interfaces are ordered first by field a, then b, then c, and finally d. Leading text (which typically indicates the
interface's type) is ignored. If any fields are not contained by an interface name, those fields are treated as
None. 'None' is ordered after all other values. For example:
et-0/0/0
et-0/0/1
et-0/1/0
xe-0/1/1:0
xe-0/1/1:1
xe-0/1/1:2
xe-0/1/1:3
et-0/1/2
...
et-0/1/9
et-0/1/10
et-0/1/11
et-1/0/0
et-1/0/1
...
vlan1
vlan10
:param queryset: The base queryset to be ordered
:param sql_col: Table and name of the SQL column which contains the interface name (ex: ''dcim_interface.name')
:param primary_ordering: A tuple of fields which take ordering precedence before the interface name (optional)
"""
ordering = primary_ordering + ('_id1', '_id2', '_id3', '_id4')
return queryset.extra(select={
'_id1': "CAST(SUBSTRING({} FROM '([0-9]+)\/[0-9]+\/[0-9]+(:[0-9]+)?$') AS integer)".format(sql_col),
'_id2': "CAST(SUBSTRING({} FROM '([0-9]+)\/[0-9]+(:[0-9]+)?$') AS integer)".format(sql_col),
'_id3': "CAST(SUBSTRING({} FROM '([0-9]+)(:[0-9]+)?$') AS integer)".format(sql_col),
'_id4': "CAST(SUBSTRING({} FROM ':([0-9]+)$') AS integer)".format(sql_col),
}).order_by(*ordering)
class Site(CreatedUpdatedModel):
"""
A Site represents a geographic location within a network; typically a building or campus. The optional facility
@@ -213,12 +266,13 @@ class Rack(CreatedUpdatedModel):
return "{} ({})".format(self.name, self.facility_id)
return self.name
def get_rack_units(self, face=RACK_FACE_FRONT, remove_redundant=False):
def get_rack_units(self, face=RACK_FACE_FRONT, exclude=None, remove_redundant=False):
"""
Return a list of rack units as dictionaries. Example: {'device': None, 'face': 0, 'id': 48, 'name': 'U48'}
Each key 'device' is either a Device or None. By default, multi-U devices are repeated for each U they occupy.
:param face: Rack face (front or rear)
:param exclude: PK of a Device to exclude (optional); helpful when relocating a Device within a Rack
:param remove_redundant: If True, rack units occupied by a device already listed will be omitted
"""
@@ -229,7 +283,10 @@ class Rack(CreatedUpdatedModel):
# Add devices to rack units list
if self.pk:
for device in Device.objects.select_related('device_type__manufacturer', 'device_role')\
.filter(rack=self, position__gt=0).filter(Q(face=face) | Q(device_type__is_full_depth=True)):
.annotate(devicebay_count=Count('device_bays'))\
.exclude(pk=exclude)\
.filter(rack=self, position__gt=0)\
.filter(Q(face=face) | Q(device_type__is_full_depth=True)):
if remove_redundant:
elevation[device.position]['device'] = device
for u in range(device.position + 1, device.position + device.device_type.u_height):
@@ -333,6 +390,10 @@ class DeviceType(models.Model):
help_text="This type of device has power outlets")
is_network_device = models.BooleanField(default=True, verbose_name='Is a network device',
help_text="This type of device has network interfaces")
subdevice_role = models.NullBooleanField(default=None, verbose_name='Parent/child status',
choices=SUBDEVICE_ROLE_CHOICES,
help_text="Parent devices house child devices in device bays. Select "
"\"None\" if this device type is neither a parent nor a child.")
class Meta:
ordering = ['manufacturer', 'model']
@@ -342,11 +403,40 @@ class DeviceType(models.Model):
]
def __unicode__(self):
return "{0} {1}".format(self.manufacturer, self.model)
return "{} {}".format(self.manufacturer, self.model)
def get_absolute_url(self):
return reverse('dcim:devicetype', args=[self.pk])
def clean(self):
if not self.is_console_server and self.cs_port_templates.count():
raise ValidationError("Must delete all console server port templates associated with this device before "
"declassifying it as a console server.")
if not self.is_pdu and self.power_outlet_templates.count():
raise ValidationError("Must delete all power outlet templates associated with this device before "
"declassifying it as a PDU.")
if not self.is_network_device and self.interface_templates.filter(mgmt_only=False).count():
raise ValidationError("Must delete all non-management-only interface templates associated with this device "
"before declassifying it as a network device.")
if self.subdevice_role != SUBDEVICE_ROLE_PARENT and self.device_bay_templates.count():
raise ValidationError("Must delete all device bay templates associated with this device before "
"declassifying it as a parent device.")
if self.u_height and self.subdevice_role == SUBDEVICE_ROLE_CHILD:
raise ValidationError("Child device types must be 0U.")
@property
def is_parent_device(self):
return bool(self.subdevice_role)
@property
def is_child_device(self):
return bool(self.subdevice_role is False)
class ConsolePortTemplate(models.Model):
"""
@@ -408,6 +498,13 @@ class PowerOutletTemplate(models.Model):
return self.name
class InterfaceTemplateManager(models.Manager):
def get_queryset(self):
qs = super(InterfaceTemplateManager, self).get_queryset()
return order_interfaces(qs, 'dcim_interfacetemplate.name', ('device_type',))
class InterfaceTemplate(models.Model):
"""
A template for a physical data interface on a new Device.
@@ -417,6 +514,23 @@ class InterfaceTemplate(models.Model):
form_factor = models.PositiveSmallIntegerField(choices=IFACE_FF_CHOICES, default=IFACE_FF_SFP_PLUS)
mgmt_only = models.BooleanField(default=False, verbose_name='Management only')
objects = InterfaceTemplateManager()
class Meta:
ordering = ['device_type', 'name']
unique_together = ['device_type', 'name']
def __unicode__(self):
return self.name
class DeviceBayTemplate(models.Model):
"""
A template for a DeviceBay to be created for a new parent Device.
"""
device_type = models.ForeignKey('DeviceType', related_name='device_bay_templates', on_delete=models.CASCADE)
name = models.CharField(max_length=30)
class Meta:
ordering = ['device_type', 'name']
unique_together = ['device_type', 'name']
@@ -507,12 +621,19 @@ class Device(CreatedUpdatedModel):
def clean(self):
# Child devices cannot be assigned to a rack face/unit
if self.device_type.is_child_device and (self.face is not None or self.position):
raise ValidationError("Child device types cannot be assigned a rack face or position.")
# Validate position/face combination
if self.position and self.face is None:
raise ValidationError("Must specify rack face with rack position.")
# Validate rack space
rack_face = self.face if not self.device_type.is_full_depth else None
try:
rack_face = self.face if not self.device_type.is_full_depth else None
except DeviceType.DoesNotExist:
raise ValidationError("Must specify device type.")
exclude_list = [self.pk] if self.pk else []
try:
available_units = self.rack.get_available_units(u_height=self.device_type.u_height, rack_face=rack_face,
@@ -551,6 +672,10 @@ class Device(CreatedUpdatedModel):
[Interface(device=self, name=template.name, form_factor=template.form_factor,
mgmt_only=template.mgmt_only) for template in self.device_type.interface_templates.all()]
)
DeviceBay.objects.bulk_create(
[DeviceBay(device=self, name=template.name) for template in
self.device_type.device_bay_templates.all()]
)
def to_csv(self):
return ','.join([
@@ -584,6 +709,12 @@ class Device(CreatedUpdatedModel):
return self.name
return '{{{}}}'.format(self.pk)
def get_children(self):
"""
Return the set of child Devices installed in DeviceBays within this Device.
"""
return Device.objects.filter(parent_bay__device=self.pk)
def get_rpc_client(self):
"""
Return the appropriate RPC (e.g. NETCONF, ssh, etc.) client for this device's platform, if one is defined.
@@ -708,18 +839,8 @@ class PowerOutlet(models.Model):
class InterfaceManager(models.Manager):
def get_queryset(self):
"""
Cast up to three interface slot/position IDs as independent integers and order appropriately. This ensures that
interfaces are ordered numerically without regard to type. For example:
xe-0/0/0, xe-0/0/1, xe-0/0/2 ... et-0/0/47, et-0/0/48, et-0/0/49 ...
instead of:
et-0/0/48, et-0/0/49, et-0/0/50 ... et-0/0/53, xe-0/0/0, xe-0/0/1 ...
"""
return super(InterfaceManager, self).get_queryset().extra(select={
'_id1': "CAST(SUBSTRING(dcim_interface.name FROM '([0-9]+)\/([0-9]+)\/([0-9]+)$') AS integer)",
'_id2': "CAST(SUBSTRING(dcim_interface.name FROM '([0-9]+)\/([0-9]+)$') AS integer)",
'_id3': "CAST(SUBSTRING(dcim_interface.name FROM '([0-9]+)$') AS integer)",
}).order_by('device', '_id1', '_id2', '_id3')
qs = super(InterfaceManager, self).get_queryset()
return order_interfaces(qs, 'dcim_interface.name', ('device',))
def virtual(self):
return self.get_queryset().filter(form_factor=IFACE_FF_VIRTUAL)
@@ -736,6 +857,7 @@ class Interface(models.Model):
device = models.ForeignKey('Device', related_name='interfaces', on_delete=models.CASCADE)
name = models.CharField(max_length=30)
form_factor = models.PositiveSmallIntegerField(choices=IFACE_FF_CHOICES, default=IFACE_FF_SFP_PLUS)
mac_address = MACAddressField(null=True, blank=True, verbose_name='MAC Address')
mgmt_only = models.BooleanField(default=False, verbose_name='OOB Management',
help_text="This interface is used only for out-of-band management")
description = models.CharField(max_length=100, blank=True)
@@ -811,6 +933,33 @@ class InterfaceConnection(models.Model):
])
class DeviceBay(models.Model):
"""
An empty space within a Device which can house a child device
"""
device = models.ForeignKey('Device', related_name='device_bays', on_delete=models.CASCADE)
name = models.CharField(max_length=50, verbose_name='Name')
installed_device = models.OneToOneField('Device', related_name='parent_bay', blank=True, null=True)
class Meta:
ordering = ['device', 'name']
unique_together = ['device', 'name']
def __unicode__(self):
return '{} - {}'.format(self.device.name, self.name)
def clean(self):
# Validate that the parent Device can have DeviceBays
if not self.device.device_type.is_parent_device:
raise ValidationError("This type of device ({}) does not support device bays."
.format(self.device.device_type))
# Cannot install a device into itself, obviously
if self.device == self.installed_device:
raise ValidationError("Cannot install a device into itself.")
class Module(models.Model):
"""
A Module represents a piece of hardware within a Device, such as a line card or power supply. Modules are used only

View File

@@ -4,8 +4,9 @@ from django_tables2.utils import Accessor
from utilities.tables import BaseTable, ToggleColumn
from .models import (
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType, InterfaceTemplate,
Manufacturer, Platform, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, Site,
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
Interface, InterfaceTemplate, Manufacturer, Platform, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack,
RackGroup, Site,
)
@@ -201,6 +202,19 @@ class InterfaceTemplateTable(tables.Table):
}
class DeviceBayTemplateTable(tables.Table):
pk = ToggleColumn()
class Meta:
model = DeviceBayTemplate
fields = ('pk', 'name')
empty_text = "None"
show_header = False
attrs = {
'class': 'table table-hover panel-body',
}
#
# Device roles
#
@@ -305,5 +319,5 @@ class InterfaceConnectionTable(BaseTable):
interface_b = tables.Column(verbose_name='Interface B')
class Meta(BaseTable.Meta):
model = PowerPort
model = Interface
fields = ('device_a', 'interface_a', 'device_b', 'interface_b')

View File

@@ -47,7 +47,7 @@ class SiteTest(APITestCase):
graph_fields = [
'name',
'embed_url',
'link',
'embed_link',
]
def test_get_list(self, endpoint='/api/dcim/sites/'):
@@ -315,6 +315,7 @@ class DeviceTest(APITestCase):
'rack',
'position',
'face',
'parent_device',
'status',
'primary_ip',
'comments',
@@ -366,6 +367,7 @@ class DeviceTest(APITestCase):
'face',
'id',
'name',
'parent_device',
'platform_id',
'platform_name',
'platform_slug',
@@ -527,6 +529,7 @@ class InterfaceTest(APITestCase):
'device',
'name',
'form_factor',
'mac_address',
'mgmt_only',
'description',
'is_connected'
@@ -539,6 +542,7 @@ class InterfaceTest(APITestCase):
'device',
'name',
'form_factor',
'mac_address',
'mgmt_only',
'description',
'is_connected',

View File

@@ -64,7 +64,7 @@ class RackTestCase(TestCase):
rack=rack1,
position=10,
face=RACK_FACE_REAR,
)
)
device1.save()
# Validate rack height

View File

@@ -4,7 +4,8 @@ from secrets.views import secret_add
from . import views
from .models import (
ConsolePortTemplate, ConsoleServerPortTemplate, PowerPortTemplate, PowerOutletTemplate, InterfaceTemplate,
ConsolePortTemplate, ConsoleServerPortTemplate, DeviceBayTemplate, PowerPortTemplate, PowerOutletTemplate,
InterfaceTemplate,
)
@@ -70,6 +71,10 @@ urlpatterns = [
name='devicetype_add_interface'),
url(r'^device-types/(?P<pk>\d+)/interfaces/delete/$', views.component_template_delete,
{'model': InterfaceTemplate}, name='devicetype_delete_interface'),
url(r'^device-types/(?P<pk>\d+)/device-bays/add/$', views.DeviceBayTemplateAddView.as_view(),
name='devicetype_add_devicebay'),
url(r'^device-types/(?P<pk>\d+)/device-bays/delete/$', views.component_template_delete,
{'model': DeviceBayTemplate}, name='devicetype_delete_devicebay'),
# Device roles
url(r'^device-roles/$', views.DeviceRoleListView.as_view(), name='devicerole_list'),
@@ -125,6 +130,13 @@ urlpatterns = [
url(r'^power-outlets/(?P<pk>\d+)/edit/$', views.poweroutlet_edit, name='poweroutlet_edit'),
url(r'^power-outlets/(?P<pk>\d+)/delete/$', views.poweroutlet_delete, name='poweroutlet_delete'),
# Device bays
url(r'^devices/(?P<pk>\d+)/bays/add/$', views.devicebay_add, name='devicebay_add'),
url(r'^device-bays/(?P<pk>\d+)/edit/$', views.devicebay_edit, name='devicebay_edit'),
url(r'^device-bays/(?P<pk>\d+)/delete/$', views.devicebay_delete, name='devicebay_delete'),
url(r'^device-bays/(?P<pk>\d+)/populate/$', views.devicebay_populate, name='devicebay_populate'),
url(r'^device-bays/(?P<pk>\d+)/depopulate/$', views.devicebay_depopulate, name='devicebay_depopulate'),
# Console/power/interface connections
url(r'^console-connections/$', views.ConsoleConnectionsListView.as_view(), name='console_connections_list'),
url(r'^console-connections/import/$', views.ConsoleConnectionsBulkImportView.as_view(), name='console_connections_import'),

View File

@@ -24,8 +24,9 @@ from utilities.views import (
from . import filters, forms, tables
from .models import (
CONNECTION_STATUS_CONNECTED, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device,
DeviceRole, DeviceType, Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, Module, Platform,
PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, Site,
DeviceBay, DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceConnection, InterfaceTemplate,
Manufacturer, Module, Platform, PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup,
Site,
)
@@ -61,6 +62,7 @@ def expand_pattern(string):
class SiteListView(ObjectListView):
queryset = Site.objects.all()
filter = filters.SiteFilter
table = tables.SiteTable
template_name = 'dcim/site_list.html'
@@ -75,11 +77,13 @@ def site(request, slug):
'vlan_count': VLAN.objects.filter(site=site).count(),
'circuit_count': Circuit.objects.filter(site=site).count(),
}
rack_groups = RackGroup.objects.filter(site=site).annotate(rack_count=Count('racks'))
topology_maps = TopologyMap.objects.filter(site=site)
return render(request, 'dcim/site.html', {
'site': site,
'stats': stats,
'rack_groups': rack_groups,
'topology_maps': topology_maps,
})
@@ -150,7 +154,8 @@ def rack(request, pk):
rack = get_object_or_404(Rack, pk=pk)
nonracked_devices = Device.objects.filter(rack=rack, position__isnull=True)
nonracked_devices = Device.objects.filter(rack=rack, position__isnull=True)\
.select_related('device_type__manufacturer')
next_rack = Rack.objects.filter(site=rack.site, name__gt=rack.name).order_by('name').first()
prev_rack = Rack.objects.filter(site=rack.site, name__lt=rack.name).order_by('-name').first()
@@ -260,12 +265,14 @@ def devicetype(request, pk):
powerport_table = tables.PowerPortTemplateTable(PowerPortTemplate.objects.filter(device_type=devicetype))
poweroutlet_table = tables.PowerOutletTemplateTable(PowerOutletTemplate.objects.filter(device_type=devicetype))
interface_table = tables.InterfaceTemplateTable(InterfaceTemplate.objects.filter(device_type=devicetype))
devicebay_table = tables.DeviceBayTemplateTable(DeviceBayTemplate.objects.filter(device_type=devicetype))
if request.user.has_perm('dcim.change_devicetype'):
consoleport_table.base_columns['pk'].visible = True
consoleserverport_table.base_columns['pk'].visible = True
powerport_table.base_columns['pk'].visible = True
poweroutlet_table.base_columns['pk'].visible = True
interface_table.base_columns['pk'].visible = True
devicebay_table.base_columns['pk'].visible = True
return render(request, 'dcim/devicetype.html', {
'devicetype': devicetype,
@@ -274,6 +281,7 @@ def devicetype(request, pk):
'powerport_table': powerport_table,
'poweroutlet_table': poweroutlet_table,
'interface_table': interface_table,
'devicebay_table': devicebay_table,
})
@@ -392,6 +400,11 @@ class InterfaceTemplateAddView(ComponentTemplateCreateView):
form = forms.InterfaceTemplateForm
class DeviceBayTemplateAddView(ComponentTemplateCreateView):
model = DeviceBayTemplate
form = forms.DeviceBayTemplateForm
def component_template_delete(request, pk, model):
devicetype = get_object_or_404(DeviceType, pk=pk)
@@ -418,7 +431,7 @@ def component_template_delete(request, pk, model):
else:
form = ComponentTemplateBulkDeleteForm(initial={'pk': request.POST.getlist('pk')})
selected_objects = model.objects.filter(pk__in=form.initial.get('pk'))
selected_objects = model.objects.filter(pk__in=request.POST.getlist('pk'))
if not selected_objects:
messages.warning(request, "No {} were selected for deletion.".format(model._meta.verbose_name_plural))
return redirect('dcim:devicetype', pk=devicetype.pk)
@@ -507,6 +520,7 @@ def device(request, pk):
.select_related('connected_as_a', 'connected_as_b', 'circuit')
mgmt_interfaces = Interface.objects.filter(device=device, mgmt_only=True)\
.select_related('connected_as_a', 'connected_as_b', 'circuit')
device_bays = DeviceBay.objects.filter(device=device).select_related('installed_device__device_type__manufacturer')
# Gather any secrets which belong to this device
secrets = device.secrets.all()
@@ -537,6 +551,7 @@ def device(request, pk):
'power_outlets': power_outlets,
'interfaces': interfaces,
'mgmt_interfaces': mgmt_interfaces,
'device_bays': device_bays,
'ip_addresses': ip_addresses,
'secrets': secrets,
'related_devices': related_devices,
@@ -547,7 +562,7 @@ class DeviceEditView(PermissionRequiredMixin, ObjectEditView):
permission_required = 'dcim.change_device'
model = Device
form_class = forms.DeviceForm
fields_initial = ['site', 'rack', 'position', 'face']
fields_initial = ['site', 'rack', 'position', 'face', 'device_bay']
template_name = 'dcim/device_edit.html'
cancel_url = 'dcim:device_list'
@@ -1237,6 +1252,7 @@ def interface_add(request, pk):
'device': device.pk,
'name': name,
'form_factor': form.cleaned_data['form_factor'],
'mac_address': form.cleaned_data['mac_address'],
'mgmt_only': form.cleaned_data['mgmt_only'],
'description': form.cleaned_data['description'],
})
@@ -1324,6 +1340,7 @@ class InterfaceBulkAddView(PermissionRequiredMixin, BulkEditView):
iface_form = forms.InterfaceForm({
'device': device.pk,
'name': name,
'mac_address': form.cleaned_data['mac_address'],
'form_factor': form.cleaned_data['form_factor'],
'mgmt_only': form.cleaned_data['mgmt_only'],
'description': form.cleaned_data['description'],
@@ -1339,6 +1356,143 @@ class InterfaceBulkAddView(PermissionRequiredMixin, BulkEditView):
len(selected_devices)))
#
# Device bays
#
@permission_required('dcim.add_devicebay')
def devicebay_add(request, pk):
device = get_object_or_404(Device, pk=pk)
if request.method == 'POST':
form = forms.DeviceBayCreateForm(request.POST)
if form.is_valid():
device_bays = []
for name in form.cleaned_data['name_pattern']:
devicebay_form = forms.DeviceBayForm({
'device': device.pk,
'name': name,
})
if devicebay_form.is_valid():
device_bays.append(devicebay_form.save(commit=False))
else:
for err in devicebay_form.errors.get('__all__', []):
form.add_error('name_pattern', err)
if not form.errors:
DeviceBay.objects.bulk_create(device_bays)
messages.success(request, "Added {} device bay(s) to {}".format(len(device_bays), device))
if '_addanother' in request.POST:
return redirect('dcim:devicebay_add', pk=device.pk)
else:
return redirect('dcim:device', pk=device.pk)
else:
form = forms.DeviceBayCreateForm()
return render(request, 'dcim/devicebay_edit.html', {
'device': device,
'form': form,
'cancel_url': reverse('dcim:device', kwargs={'pk': device.pk}),
})
@permission_required('dcim.change_devicebay')
def devicebay_edit(request, pk):
devicebay = get_object_or_404(DeviceBay, pk=pk)
if request.method == 'POST':
form = forms.DeviceBayForm(request.POST, instance=devicebay)
if form.is_valid():
devicebay = form.save()
messages.success(request, "Modified {} bay {}".format(devicebay.device.name, devicebay.name))
return redirect('dcim:device', pk=devicebay.device.pk)
else:
form = forms.DeviceBayForm(instance=devicebay)
return render(request, 'dcim/devicebay_edit.html', {
'devicebay': devicebay,
'form': form,
'cancel_url': reverse('dcim:device', kwargs={'pk': devicebay.device.pk}),
})
@permission_required('dcim.delete_devicebay')
def devicebay_delete(request, pk):
devicebay = get_object_or_404(DeviceBay, pk=pk)
if request.method == 'POST':
form = ConfirmationForm(request.POST)
if form.is_valid():
devicebay.delete()
messages.success(request, "Device bay {} has been deleted from {}".format(devicebay, devicebay.device))
return redirect('dcim:device', pk=devicebay.device.pk)
else:
form = ConfirmationForm()
return render(request, 'dcim/devicebay_delete.html', {
'devicebay': devicebay,
'form': form,
'cancel_url': reverse('dcim:device', kwargs={'pk': devicebay.device.pk}),
})
@permission_required('dcim.change_devicebay')
def devicebay_populate(request, pk):
device_bay = get_object_or_404(DeviceBay, pk=pk)
if request.method == 'POST':
form = forms.PopulateDeviceBayForm(device_bay, request.POST)
if form.is_valid():
device_bay.installed_device = form.cleaned_data['installed_device']
device_bay.save()
if not form.errors:
messages.success(request, "Added {} to {}".format(device_bay.installed_device, device_bay))
return redirect('dcim:device', pk=device_bay.device.pk)
else:
form = forms.PopulateDeviceBayForm(device_bay)
return render(request, 'dcim/devicebay_populate.html', {
'device_bay': device_bay,
'form': form,
'cancel_url': reverse('dcim:device', kwargs={'pk': device_bay.device.pk}),
})
@permission_required('dcim.change_devicebay')
def devicebay_depopulate(request, pk):
device_bay = get_object_or_404(DeviceBay, pk=pk)
if request.method == 'POST':
form = ConfirmationForm(request.POST)
if form.is_valid():
removed_device = device_bay.installed_device
device_bay.installed_device = None
device_bay.save()
messages.success(request, "{} has been removed from {}".format(removed_device, device_bay))
return redirect('dcim:device', pk=device_bay.device.pk)
else:
form = ConfirmationForm()
return render(request, 'dcim/devicebay_depopulate.html', {
'device_bay': device_bay,
'form': form,
'cancel_url': reverse('dcim:device', kwargs={'pk': device_bay.device.pk}),
})
#
# Interface connections
#
@@ -1514,7 +1668,10 @@ def module_add(request, pk):
module.device = device
module.save()
messages.success(request, "Added module {} to {}".format(module.name, module.device.name))
return redirect('dcim:device_inventory', pk=module.device.pk)
if '_addanother' in request.POST:
return redirect('dcim:module_add', pk=module.device.pk)
else:
return redirect('dcim:device_inventory', pk=module.device.pk)
else:
form = forms.ModuleForm()

View File

@@ -1,4 +1,4 @@
import pydot
import graphviz
from rest_framework import generics
from rest_framework.views import APIView
import tempfile
@@ -49,32 +49,30 @@ class TopologyMapView(APIView):
tmap = get_object_or_404(TopologyMap, slug=slug)
# Construct the graph
graph = pydot.Dot(graph_type='graph', ranksep='1')
graph = graphviz.Graph()
graph.graph_attr['ranksep'] = '1'
for i, device_set in enumerate(tmap.device_sets):
subgraph = pydot.Subgraph('sg{}'.format(i), rank='same')
subgraph = graphviz.Graph(name='sg{}'.format(i))
subgraph.graph_attr['rank'] = 'same'
# Add a pseudonode for each device_set to enforce hierarchical layout
subgraph.add_node(pydot.Node('set{}'.format(i), shape='none', width='0', label=''))
subgraph.node('set{}'.format(i), label='', shape='none', width='0')
if i:
graph.add_edge(pydot.Edge('set{}'.format(i - 1), 'set{}'.format(i), style='invis'))
graph.edge('set{}'.format(i - 1), 'set{}'.format(i), style='invis')
# Add each device to the graph
devices = []
for query in device_set.split(','):
devices += Device.objects.filter(name__regex=query)
for d in devices:
node = pydot.Node(d.name)
subgraph.add_node(node)
subgraph.node(d.name)
# Add an invisible connection to each successive device in a set to enforce horizontal order
for j in range(0, len(devices) - 1):
edge = pydot.Edge(devices[j].name, devices[j + 1].name)
# edge.set('style', 'invis') doesn't seem to work for some reason
edge.set_style('invis')
subgraph.add_edge(edge)
subgraph.edge(devices[j].name, devices[j + 1].name, style='invis')
graph.add_subgraph(subgraph)
graph.subgraph(subgraph)
# Compile list of all devices
device_superset = Q()
@@ -87,17 +85,14 @@ class TopologyMapView(APIView):
connections = InterfaceConnection.objects.filter(interface_a__device__in=devices,
interface_b__device__in=devices)
for c in connections:
edge = pydot.Edge(c.interface_a.device.name, c.interface_b.device.name)
graph.add_edge(edge)
graph.edge(c.interface_a.device.name, c.interface_b.device.name)
# Write the image to disk and return
topo_file = tempfile.NamedTemporaryFile()
# Get the image data and return
try:
graph.write(topo_file.name, format='png')
topo_data = graph.pipe(format='png')
except:
return HttpResponse("There was an error generating the requested graph. Ensure that the GraphViz "
"executables have been installed correctly.")
response = HttpResponse(FileWrapper(topo_file), content_type='image/png')
topo_file.close()
response = HttpResponse(topo_data, content_type='image/png')
return response

View File

@@ -1,7 +1,7 @@
from rest_framework import generics
from ipam.models import VRF, Role, RIR, Aggregate, Prefix, IPAddress, VLAN
from ipam.filters import AggregateFilter, PrefixFilter, IPAddressFilter, VLANFilter
from ipam.filters import AggregateFilter, PrefixFilter, IPAddressFilter, VLANFilter, VRFFilter
from . import serializers
@@ -12,6 +12,7 @@ class VRFListView(generics.ListAPIView):
"""
queryset = VRF.objects.all()
serializer_class = serializers.VRFSerializer
filter_class = VRFFilter
class VRFDetailView(generics.RetrieveAPIView):

View File

@@ -10,6 +10,11 @@ from .lookups import (
)
def prefix_validator(prefix):
if prefix.ip != prefix.cidr.ip:
raise ValidationError("{} is not a valid prefix. Did you mean {}?".format(prefix, prefix.cidr))
class BaseIPField(models.Field):
def python_type(self):
@@ -45,6 +50,7 @@ class IPNetworkField(BaseIPField):
IP prefix (network and mask)
"""
description = "PostgreSQL CIDR field"
default_validators = [prefix_validator]
def db_type(self, connection):
return 'cidr'

View File

@@ -46,9 +46,14 @@ class PrefixFilter(django_filters.FilterSet):
action='search_by_parent',
label='Parent prefix',
)
vrf = django_filters.MethodFilter(
action='_vrf',
label='VRF',
)
# Duplicate of `vrf` for backward-compatibility
vrf_id = django_filters.MethodFilter(
action='vrf',
label='VRF (ID)',
action='_vrf',
label='VRF',
)
site_id = django_filters.ModelMultipleChoiceFilter(
name='site',
@@ -84,7 +89,7 @@ class PrefixFilter(django_filters.FilterSet):
class Meta:
model = Prefix
fields = ['family', 'site_id', 'site', 'vrf_id', 'vrf', 'vlan_id', 'vlan_vid', 'status', 'role_id', 'role']
fields = ['family', 'site_id', 'site', 'vrf', 'vrf_id', 'vlan_id', 'vlan_vid', 'status', 'role_id', 'role']
def search(self, queryset, value):
value = value.strip()
@@ -104,7 +109,7 @@ class PrefixFilter(django_filters.FilterSet):
except AddrFormatError:
return queryset.none()
def vrf(self, queryset, value):
def _vrf(self, queryset, value):
if str(value) == '':
return queryset
try:
@@ -121,10 +126,14 @@ class IPAddressFilter(django_filters.FilterSet):
action='search',
label='Search',
)
vrf_id = django_filters.ModelMultipleChoiceFilter(
name='vrf',
queryset=VRF.objects.all(),
label='VRF (ID)',
vrf = django_filters.MethodFilter(
action='_vrf',
label='VRF',
)
# Duplicate of `vrf` for backward-compatibility
vrf_id = django_filters.MethodFilter(
action='_vrf',
label='VRF',
)
device_id = django_filters.ModelMultipleChoiceFilter(
name='interface__device',
@@ -155,6 +164,17 @@ class IPAddressFilter(django_filters.FilterSet):
except AddrFormatError:
return queryset.none()
def _vrf(self, queryset, value):
if str(value) == '':
return queryset
try:
vrf_id = int(value)
except ValueError:
return queryset.none()
if vrf_id == 0:
return queryset.filter(vrf__isnull=True)
return queryset.filter(vrf__pk=value)
class VLANFilter(django_filters.FilterSet):
site_id = django_filters.ModelMultipleChoiceFilter(

View File

@@ -13,6 +13,10 @@ from .models import (
)
FORM_PREFIX_STATUS_CHOICES = (('', '---------'),) + PREFIX_STATUS_CHOICES
FORM_VLAN_STATUS_CHOICES = (('', '---------'),) + VLAN_STATUS_CHOICES
#
# VRFs
#
@@ -215,6 +219,7 @@ class PrefixBulkEditForm(forms.Form, BootstrapMixin):
vrf = forms.ModelChoiceField(queryset=VRF.objects.all(), required=False, label='VRF',
help_text="Select the VRF to assign, or check below to remove VRF assignment")
vrf_global = forms.BooleanField(required=False, label='Set VRF to global')
status = forms.ChoiceField(choices=FORM_PREFIX_STATUS_CHOICES, required=False)
role = forms.ModelChoiceField(queryset=Role.objects.all(), required=False)
description = forms.CharField(max_length=50, required=False)
@@ -444,6 +449,7 @@ class VLANImportForm(BulkImportForm, BootstrapMixin):
class VLANBulkEditForm(forms.Form, BootstrapMixin):
pk = forms.ModelMultipleChoiceField(queryset=VLAN.objects.all(), widget=forms.MultipleHiddenInput)
site = forms.ModelChoiceField(queryset=Site.objects.all(), required=False)
status = forms.ChoiceField(choices=FORM_VLAN_STATUS_CHOICES, required=False)
role = forms.ModelChoiceField(queryset=Role.objects.all(), required=False)

View File

@@ -121,6 +121,12 @@ class Aggregate(CreatedUpdatedModel):
raise ValidationError("{} is already covered by an existing aggregate ({})"
.format(self.prefix, covering_aggregates[0]))
# Ensure that the aggregate being added does not cover an existing aggregate
covered_aggregates = Aggregate.objects.filter(prefix__net_contained=str(self.prefix))
if covered_aggregates:
raise ValidationError("{} is overlaps with an existing aggregate ({})"
.format(self.prefix, covered_aggregates[0]))
def save(self, *args, **kwargs):
if self.prefix:
# Infer address family from IPNetwork object

View File

@@ -0,0 +1,75 @@
import os
#########################
# #
# Required settings #
# #
#########################
# This is a list of valid fully-qualified domain names (FQDNs) for the NetBox server. NetBox will not permit write
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
#
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
ALLOWED_HOSTS = [os.environ.get('ALLOWED_HOSTS', '')]
# PostgreSQL database configuration.
DATABASE = {
'NAME': os.environ.get('DB_NAME', 'netbox'), # Database name
'USER': os.environ.get('DB_USER', ''), # PostgreSQL username
'PASSWORD': os.environ.get('DB_PASSWORD', ''), # PostgreSQL password
'HOST': os.environ.get('DB_HOST', 'localhost'), # Database server
'PORT': os.environ.get('DB_PORT', ''), # Database port (leave blank for default)
}
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
# symbols. NetBox will not run without this defined. For more information, see
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
SECRET_KEY = os.environ.get('SECRET_KEY', '')
#########################
# #
# Optional settings #
# #
#########################
# Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
# application errors (assuming correct email settings are provided).
ADMINS = [
# ['John Doe', 'jdoe@example.com'],
]
# Email settings
EMAIL = {
'SERVER': os.environ.get('EMAIL_SERVER', 'localhost'),
'PORT': os.environ.get('EMAIL_PORT', 25),
'USERNAME': os.environ.get('EMAIL_USERNAME', ''),
'PASSWORD': os.environ.get('EMAIL_PASSWORD', ''),
'TIMEOUT': os.environ.get('EMAIL_TIMEOUT', 10), # seconds
'FROM_EMAIL': os.environ.get('EMAIL_FROM', ''),
}
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
LOGIN_REQUIRED = os.environ.get('LOGIN_REQUIRED', False)
# Setting this to True will display a "maintenance mode" banner at the top of every page.
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', '')
# Determine how many objects to display per page within a list. (Default: 50)
PAGINATE_COUNT = os.environ.get('PAGINATE_COUNT', 50)
# Time zone (default: UTC)
TIME_ZONE = os.environ.get('TIME_ZONE', 'UTC')
# Date/time formatting. See the following link for supported formats:
# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
DATE_FORMAT = os.environ.get('DATE_FORMAT', 'N j, Y')
SHORT_DATE_FORMAT = os.environ.get('SHORT_DATE_FORMAT', 'Y-m-d')
TIME_FORMAT = os.environ.get('TIME_FORMAT', 'g:i a')
SHORT_TIME_FORMAT = os.environ.get('SHORT_TIME_FORMAT', 'H:i:s')
DATETIME_FORMAT = os.environ.get('DATETIME_FORMAT', 'N j, Y g:i a')
SHORT_DATETIME_FORMAT = os.environ.get('SHORT_DATETIME_FORMAT', 'Y-m-d H:i')

View File

@@ -11,6 +11,8 @@ except ImportError:
"the documentation.")
VERSION = '1.1.0'
# Import local configuration
for setting in ['ALLOWED_HOSTS', 'DATABASE', 'SECRET_KEY']:
try:

View File

@@ -41,7 +41,7 @@ def home(request):
return render(request, 'home.html', {
'stats': stats,
'recent_activity': UserAction.objects.all()[:15]
'recent_activity': UserAction.objects.select_related('user')[:15]
})

View File

@@ -9,7 +9,8 @@ body {
padding-top: 70px;
}
.container {
width: 1340px;
width: auto;
max-width: 1340px;
}
.wrapper {
min-height: 100%;

View File

@@ -7,9 +7,9 @@ $(document).ready(function() {
// Slugify
function slugify(s, num_chars) {
s = s.replace(/[^-\.\+\w\s]/g, ''); // Remove unneeded chars
s = s.replace(/[^\-\.\w\s]/g, ''); // Remove unneeded chars
s = s.replace(/^\s+|\s+$/g, ''); // Trim leading/trailing spaces
s = s.replace(/[-\s]+/g, '-'); // Convert spaces to hyphens
s = s.replace(/[\-\.\s]+/g, '-'); // Convert spaces and decimals to hyphens
s = s.toLowerCase(); // Convert to lowercase
return s.substring(0, num_chars); // Trim to first num_chars chars
}

View File

@@ -4,6 +4,7 @@ from django.shortcuts import get_object_or_404
from rest_framework import generics
from rest_framework import status
from rest_framework.exceptions import PermissionDenied
from rest_framework.permissions import IsAuthenticated
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response
@@ -108,14 +109,15 @@ class SecretDetailView(generics.GenericAPIView):
{'error': ERR_USERKEY_INACTIVE},
status=status.HTTP_400_BAD_REQUEST
)
if secret.decryptable_by(request.user):
master_key = uk.get_master_key(private_key)
if master_key is None:
return Response(
{'error': ERR_PRIVKEY_INVALID},
status=status.HTTP_400_BAD_REQUEST
)
secret.decrypt(master_key)
if not secret.decryptable_by(request.user):
raise PermissionDenied(detail="You do not have permission to decrypt this secret.")
master_key = uk.get_master_key(private_key)
if master_key is None:
return Response(
{'error': ERR_PRIVKEY_INVALID},
status=status.HTTP_400_BAD_REQUEST
)
secret.decrypt(master_key)
serializer = self.get_serializer(secret)
return Response(serializer.data)

View File

@@ -182,6 +182,14 @@ class SecretRole(models.Model):
def get_absolute_url(self):
return "{}?role={}".format(reverse('secrets:secret_list'), self.slug)
def has_member(self, user):
"""
Check whether the given user has belongs to this SecretRole. Note that superusers belong to all roles.
"""
if user.is_superuser:
return True
return user in self.users.all() or user.groups.filter(pk__in=self.groups.all()).exists()
class Secret(CreatedUpdatedModel):
"""
@@ -304,4 +312,4 @@ class Secret(CreatedUpdatedModel):
"""
Check whether the given user has permission to decrypt this Secret.
"""
return user in self.role.users.all() or user.groups.filter(pk__in=self.role.groups.all()).exists()
return self.role.has_member(user)

View File

View File

@@ -0,0 +1,12 @@
from django import template
register = template.Library()
@register.filter()
def decryptable_by(secret, user):
"""
Determine whether a given User is permitted to decrypt a Secret.
"""
return secret.decryptable_by(user)

View File

@@ -17,6 +17,8 @@
<div class="panel-body">
<p>There was a problem with your request. This error has been logged and administrative staff have
been notified. Please return to the home page and try again.</p>
<p>If you are responsible for this installation, please consider
<a href="https://github.com/digitalocean/netbox/issues">filing a bug report</a>.</p>
<div class="text-right">
<a href="/" class="btn btn-primary">Home Page</a>
</div>

View File

@@ -13,9 +13,16 @@
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">NetBox</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
{% if request.user.is_authenticated or not settings.LOGIN_REQUIRED %}
<ul class="nav navbar-nav">
<li class="dropdown{% if request.path|startswith:'/dcim/sites/' %} active{% endif %}">
{% if perms.dcim.add_site %}
@@ -201,11 +208,12 @@
</li>
{% endif %}
</ul>
{% endif %}
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_staff %}
<li><a href="{% url 'admin:index' %}"><i class="glyphicon glyphicon-cog" aria-hidden="true"></i> Admin</a></li>
{% endif %}
{% if request.user.is_authenticated %}
{% if request.user.is_staff %}
<li><a href="{% url 'admin:index' %}"><i class="glyphicon glyphicon-cog" aria-hidden="true"></i> Admin</a></li>
{% endif %}
<li><a href="{% url 'users:profile' %}"><i class="glyphicon glyphicon-user" aria-hidden="true"></i> Profile</a></li>
<li><a href="{% url 'logout' %}"><i class="glyphicon glyphicon-log-out" aria-hidden="true"></i> Log out</a></li>
{% else %}
@@ -237,7 +245,7 @@
<div class="container">
<div class="row">
<div class="col-md-4">
<p class="text-muted">{{ settings.HOSTNAME }}</p>
<p class="text-muted">{{ settings.HOSTNAME }} (v{{ settings.VERSION }})</p>
</div>
<div class="col-md-4 text-center">
<p class="text-muted">{% now 'Y-m-d H:i:s T' %}</p>

View File

@@ -31,7 +31,12 @@
<li class="occupied h{{ u.device.device_type.u_height }}u{% ifequal u.device.face face_id %} {{ u.device.device_role.color }}{% endifequal %}">
{% ifequal u.device.face face_id %}
<a href="{% url 'dcim:device' pk=u.device.pk %}" data-toggle="popover" data-trigger="hover" data-container="body" data-html="true"
data-content="{{ u.device.device_role }}<br />{{ u.device.device_type }} ({{ u.device.device_type.u_height }}U)">{{ u.device.name|default:u.device.device_role }}</a>
data-content="{{ u.device.device_role }}<br />{{ u.device.device_type }} ({{ u.device.device_type.u_height }}U)">
{{ u.device.name|default:u.device.device_role }}
{% if u.device.devicebay_count %}
({{ u.device.get_children.count }}/{{ u.device.devicebay_count }})
{% endif %}
</a>
{% else %}
<span>{{ u.device.name|default:u.device.device_role }}</span>
{% endifequal %}

View File

@@ -1,7 +1,7 @@
{% extends 'utilities/confirmation_form.html' %}
{% load form_helpers %}
{% block title %}Delete devie type components?{% endblock %}
{% block title %}Delete device type components?{% endblock %}
{% block message %}
<p>Are you sure you want to delete these components from <strong>{{ devicetype }}</strong>?</p>

View File

@@ -29,7 +29,12 @@
<tr>
<td>Position</td>
<td>
{% if device.position %}
{% if device.parent_bay %}
{% with device.parent_bay.device as parent %}
<span>U{{ parent.position }} / {{ parent.get_face_display }}
(<a href="{{ parent.get_absolute_url }}">{{ parent }}</a> - {{ device.parent_bay.name }})</span>
{% endwith %}
{% elif device.position %}
<span>U{{ device.position }} / {{ device.get_face_display }}</span>
{% elif device.device_type.u_height %}
<span class="label label-warning">Not racked</span>
@@ -160,7 +165,7 @@
<div class="panel-footer text-right">
<a href="{% url 'dcim:ipaddress_assign' pk=device.pk %}" class="btn btn-xs btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Assign IP Address
Assign IP address
</a>
</div>
{% endif %}
@@ -174,7 +179,7 @@
{% include 'dcim/inc/_interface.html' with icon='wrench' %}
{% empty %}
<tr>
<td colspan="4" class="alert-warning">
<td colspan="5" class="alert-warning">
<i class="fa fa-fw fa-warning"></i> No management interfaces defined!
{% if perms.dcim.add_interface %}
<a href="{% url 'dcim:interface_add' pk=device.pk %}?mgmt_only=1" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
@@ -186,7 +191,7 @@
{% include 'dcim/inc/_consoleport.html' %}
{% empty %}
<tr>
<td colspan="4" class="alert-warning">
<td colspan="5" class="alert-warning">
<i class="fa fa-fw fa-warning"></i> No console ports defined!
{% if perms.dcim.add_consoleport %}
<a href="{% url 'dcim:consoleport_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
@@ -199,7 +204,7 @@
{% empty %}
{% if not device.device_type.is_pdu %}
<tr>
<td colspan="4" class="alert-warning">
<td colspan="5" class="alert-warning">
<i class="fa fa-fw fa-warning"></i> No power ports defined!
{% if perms.dcim.add_powerport %}
<a href="{% url 'dcim:powerport_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></a>
@@ -268,12 +273,33 @@
</div>
</div>
<div class="col-md-6">
{% if device_bays or device.device_type.is_parent_device %}
<div class="panel panel-default">
<div class="panel-heading">
<strong>Device Bays</strong>
</div>
<table class="table table-hover panel-body">
{% for devicebay in device_bays %}
{% include 'dcim/inc/_devicebay.html' %}
{% empty %}
<tr>
<td colspan="4">No device bays defined</td>
</tr>
{% endfor %}
</table>
{% if perms.dcim.add_devicebay %}
<div class="panel-footer text-right">
<a href="{% url 'dcim:devicebay_add' pk=device.pk %}" class="btn btn-primary btn-xs">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add device bays
</a>
</div>
{% endif %}
</div>
{% endif %}
{% if interfaces or device.device_type.is_network_device %}
<div class="panel panel-default">
<div class="panel-heading">
{% if perms.dcim.add_interface %}
<a href="{% url 'dcim:interface_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Interfaces</a>
{% endif %}
<strong>Interfaces</strong>
</div>
<table class="table table-hover panel-body">
@@ -285,14 +311,19 @@
</tr>
{% endfor %}
</table>
{% if perms.dcim.add_interface %}
<div class="panel-footer text-right">
<a href="{% url 'dcim:interface_add' pk=device.pk %}" class="btn btn-primary btn-xs">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add interface
</a>
</div>
{% endif %}
</div>
{% endif %}
{% if cs_ports or device.device_type.is_console_server %}
<div class="panel panel-default">
<div class="panel-heading">
{% if perms.dcim.add_consoleserverport %}
<a href="{% url 'dcim:consoleserverport_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Console Server Ports</a>
{% endif %}
<strong>Console Server Ports</strong>
</div>
<table class="table table-hover panel-body">
@@ -304,14 +335,19 @@
</tr>
{% endfor %}
</table>
{% if perms.dcim.add_consoleserverport %}
<div class="panel-footer text-right">
<a href="{% url 'dcim:consoleserverport_add' pk=device.pk %}" class="btn btn-primary btn-xs">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add console server ports
</a>
</div>
{% endif %}
</div>
{% endif %}
{% if power_outlets or device.device_type.is_pdu %}
<div class="panel panel-default">
<div class="panel-heading">
{% if perms.dcim.add_poweroutlet %}
<a href="{% url 'dcim:poweroutlet_add' pk=device.pk %}" class="btn btn-primary btn-xs pull-right"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add Power Outlets</a>
{% endif %}
<strong>Power Outlets</strong>
</div>
<table class="table table-hover panel-body">
@@ -323,6 +359,14 @@
</tr>
{% endfor %}
</table>
{% if perms.dcim.add_poweroutlet %}
<div class="panel-footer text-right">
<a href="{% url 'dcim:poweroutlet_add' pk=device.pk %}" class="btn btn-primary btn-xs">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Add power outlets
</a>
</div>
{% endif %}
</div>
{% endif %}
</div>

View File

@@ -68,18 +68,18 @@
</tr>
<tr>
<td>Position (U)</td>
<td>Numeric rack position (optional)</td>
<td>Lowest rack unit occupied by the device (optional)</td>
<td>21</td>
</tr>
<tr>
<td>Face</td>
<td>Rack face; front or rear (optional)</td>
<td>rear</td>
<td>Rear</td>
</tr>
</tbody>
</table>
<h4>Example</h4>
<pre>rack101_sw1,ToR Switch,Juniper,EX4300-48T,Juniper Junos,CAB00577291,Ashburn-VA,R101,21,rear</pre>
<pre>rack101_sw1,ToR Switch,Juniper,EX4300-48T,Juniper Junos,CAB00577291,Ashburn-VA,R101,21,Rear</pre>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,8 @@
{% extends 'utilities/confirmation_form.html' %}
{% load form_helpers %}
{% block title %}Delete device bay {{ devicebay }}?{% endblock %}
{% block message %}
<p>Are you sure you want to delete this device bay from <strong>{{ devicebay.device }}</strong>?</p>
{% endblock %}

View File

@@ -0,0 +1,8 @@
{% extends 'utilities/confirmation_form.html' %}
{% load form_helpers %}
{% block title %}Remove {{ device_bay.installed_device }} from {{ device_bay }}?{% endblock %}
{% block message %}
<p>Are you sure you want to remove <strong>{{ device_bay.installed_device }}</strong> from <strong>{{ device_bay }}</strong>?</p>
{% endblock %}

View File

@@ -0,0 +1,51 @@
{% extends '_base.html' %}
{% load form_helpers %}
{% block title %}{% if devicebay.pk %}Editing {{ devicebay.device }} {{ devicebay }}{% else %}Add a Device Bay ({{ device }}){% endif %}{% endblock %}
{% block content %}
<form action="." method="post" class="form form-horizontal">
{% csrf_token %}
<div class="row">
<div class="col-md-6 col-md-offset-3">
{% if form.non_field_errors %}
<div class="panel panel-danger">
<div class="panel-heading"><strong>Errors</strong></div>
<div class="panel-body">
{{ form.non_field_errors }}
</div>
</div>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
{% if poweroutlet.pk %}
<strong>Editing {{ devicebay }}</strong>
{% else %}
<strong>Add a Device Bay</strong>
{% endif %}
</div>
<div class="panel-body">
<div class="form-group">
<label class="col-md-3 control-label required">Device</label>
<div class="col-md-9">
<p class="form-control-static">{% if devicebay %}{{ devicebay.device }}{% else %}{{ device }}{% endif %}</p>
</div>
</div>
{% render_form form %}
</div>
</div>
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
{% if devicebay.pk %}
<button type="submit" name="_update" class="btn btn-primary">Save</button>
{% else %}
<button type="submit" name="_create" class="btn btn-primary">Create</button>
<button type="submit" name="_addanother" class="btn btn-primary">Create and Add More</button>
{% endif %}
<a href="{{ cancel_url }}" class="btn btn-default">Cancel</a>
</div>
</div>
</div>
</div>
</form>
{% endblock %}

View File

@@ -0,0 +1,46 @@
{% extends '_base.html' %}
{% load form_helpers %}
{% block title %}Populate {{ device_bay }}{% endblock %}
{% block content %}
<form action="." method="post" class="form form-horizontal">
{% csrf_token %}
<div class="row">
<div class="col-md-6 col-md-offset-3">
{% if form.non_field_errors %}
<div class="panel panel-danger">
<div class="panel-heading"><strong>Errors</strong></div>
<div class="panel-body">
{{ form.non_field_errors }}
</div>
</div>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">Populate {{ device_bay }}</div>
<div class="panel-body">
<div class="form-group">
<label class="col-md-3 control-label required">Parent Device</label>
<div class="col-md-9">
<p class="form-control-static">{{ device_bay.device }}</p>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label required">Bay</label>
<div class="col-md-9">
<p class="form-control-static">{{ device_bay.name }}</p>
</div>
</div>
{% render_form form %}
</div>
</div>
<div class="form-group">
<div class="col-md-9 col-md-offset-3">
<button type="submit" name="_update" class="btn btn-primary">Save</button>
<a href="{{ cancel_url }}" class="btn btn-default">Cancel</a>
</div>
</div>
</div>
</div>
</form>
{% endblock %}

View File

@@ -14,23 +14,27 @@
</ol>
</div>
</div>
{% if perms.dcim.change_devicetype %}
{% if perms.dcim.change_devicetype or perms.dcim.delete_devicetype %}
<div class="pull-right">
<a href="{% url 'dcim:devicetype_edit' pk=devicetype.pk %}" class="btn btn-warning">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Edit this device type
</a>
{% endif %}
{% if perms.dcim.delete_devicetype %}
<a href="{% url 'dcim:devicetype_delete' pk=devicetype.pk %}" class="btn btn-danger">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
Delete this device type
</a>
{% if perms.dcim.change_devicetype %}
<a href="{% url 'dcim:devicetype_edit' pk=devicetype.pk %}" class="btn btn-warning">
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Edit this device type
</a>
{% endif %}
{% if perms.dcim.delete_devicetype %}
<a href="{% url 'dcim:devicetype_delete' pk=devicetype.pk %}" class="btn btn-danger">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
Delete this device type
</a>
{% endif %}
</div>
{% endif %}
<h1>{{ devicetype }}</h1>
<div class="row">
<div class="col-md-6">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Chassis</strong>
@@ -76,10 +80,19 @@
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleport_table title='Console Ports' add_url='dcim:devicetype_add_consoleport' delete_url='dcim:devicetype_delete_consoleport' %}
{% include 'dcim/inc/devicetype_component_table.html' with table=powerport_table title='Power Ports' add_url='dcim:devicetype_add_powerport' delete_url='dcim:devicetype_delete_powerport' %}
</div>
<div class="col-md-6">
{% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfaces' add_url='dcim:devicetype_add_interface' delete_url='dcim:devicetype_delete_interface' %}
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' add_url='dcim:devicetype_add_consoleserverport' delete_url='dcim:devicetype_delete_consoleserverport' %}
{% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' add_url='dcim:devicetype_add_poweroutlet' delete_url='dcim:devicetype_delete_poweroutlet' %}
<div class="col-md-6">
{% if devicetype.is_network_device %}
{% include 'dcim/inc/devicetype_component_table.html' with table=devicebay_table title='Device Bays' add_url='dcim:devicetype_add_devicebay' delete_url='dcim:devicetype_delete_devicebay' %}
{% endif %}
{% if devicetype.is_network_device %}
{% include 'dcim/inc/devicetype_component_table.html' with table=interface_table title='Interfaces' add_url='dcim:devicetype_add_interface' delete_url='dcim:devicetype_delete_interface' %}
{% endif %}
{% if devicetype.is_console_server %}
{% include 'dcim/inc/devicetype_component_table.html' with table=consoleserverport_table title='Console Server Ports' add_url='dcim:devicetype_add_consoleserverport' delete_url='dcim:devicetype_delete_consoleserverport' %}
{% endif %}
{% if devicetype.is_pdu %}
{% include 'dcim/inc/devicetype_component_table.html' with table=poweroutlet_table title='Power Outlets' add_url='dcim:devicetype_add_poweroutlet' delete_url='dcim:devicetype_delete_poweroutlet' %}
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -2,6 +2,7 @@
<td>
<i class="fa fa-fw fa-keyboard-o"></i> {{ cp.name }}
</td>
<td></td>
{% if cp.cs_port %}
<td>
<a href="{% url 'dcim:device' pk=cp.cs_port.device.pk %}">{{ cp.cs_port.device }}</a>
@@ -10,7 +11,9 @@
{{ cp.cs_port.name }}
</td>
{% else %}
<td colspan="2">Not connected</td>
<td colspan="2">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
<td class="text-right">
{% if perms.dcim.change_consoleport %}

View File

@@ -10,7 +10,9 @@
{{ csp.connected_console.name }}
</td>
{% else %}
<td colspan="2">Not connected</td>
<td colspan="2">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
<td class="text-right">
{% if perms.dcim.change_consoleserverport %}

View File

@@ -5,6 +5,10 @@
<li><a href="{% url 'dcim:site' slug=device.rack.site.slug %}">{{ device.rack.site }}</a></li>
<li><a href="{% url 'dcim:rack_list' %}?site={{ device.rack.site.slug }}">Racks</a></li>
<li><a href="{% url 'dcim:rack' pk=device.rack.pk %}">{{ device.rack }}</a></li>
{% if device.parent_bay %}
<li><a href="{% url 'dcim:device' pk=device.parent_bay.device.pk %}">{{ device.parent_bay.device }}</a></li>
<li>{{ device.parent_bay.name }}</li>
{% endif %}
<li>{{ device }}</li>
</ol>
{% endif %}

View File

@@ -0,0 +1,44 @@
<tr>
<td>
<i class="fa fa-fw fa-{% if devicebay.installed_device %}dot-circle-o{% else %}circle-o{% endif %}"></i> {{ devicebay.name }}
</td>
{% if devicebay.installed_device %}
<td>
<a href="{% url 'dcim:device' pk=devicebay.installed_device.pk %}">{{ devicebay.installed_device }}</a>
</td>
<td>
<span>{{ devicebay.installed_device.device_type }}</span>
</td>
{% else %}
<td colspan="2">
<span class="text-muted">Vacant</span>
</td>
{% endif %}
<td class="text-right">
{% if perms.dcim.change_devicebay %}
{% if devicebay.installed_device %}
<a href="{% url 'dcim:devicebay_depopulate' pk=devicebay.pk %}" class="btn btn-danger btn-xs">
<i class="glyphicon glyphicon-remove" aria-hidden="true" title="Remove device"></i>
</a>
{% else %}
<a href="{% url 'dcim:devicebay_populate' pk=devicebay.pk %}" class="btn btn-success btn-xs">
<i class="glyphicon glyphicon-plus" aria-hidden="true" title="Install device"></i>
</a>
{% endif %}
<a href="{% url 'dcim:devicebay_edit' pk=devicebay.pk %}" class="btn btn-info btn-xs">
<i class="glyphicon glyphicon-pencil" aria-hidden="true" title="Edit device bay"></i>
</a>
{% endif %}
{% if perms.dcim.delete_devicebay %}
{% if devicebay.installed_device %}
<button class="btn btn-danger btn-xs" disabled="disabled">
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
</button>
{% else %}
<a href="{% url 'dcim:devicebay_delete' pk=devicebay.pk %}" class="btn btn-danger btn-xs">
<i class="glyphicon glyphicon-trash" aria-hidden="true" title="Delete device bay"></i>
</a>
{% endif %}
{% endif %}
</td>
</tr>

View File

@@ -5,6 +5,9 @@
<i class="fa fa-fw fa-comment-o" title="{{ iface.description }}"></i>
{% endif %}
</td>
<td>
<small>{{ iface.mac_address|default:'' }}</small>
</td>
{% if not iface.is_physical %}
<td colspan="2">Virtual</td>
{% elif iface.connection %}
@@ -21,7 +24,9 @@
<a href="{% url 'circuits:circuit' pk=iface.circuit.pk %}">{{ iface.circuit }}</a>
</td>
{% else %}
<td colspan="2">Not connected</td>
<td colspan="2">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
<td class="text-right">
{% if iface.circuit or iface.connection %}

View File

@@ -10,7 +10,9 @@
{{ po.connected_port.name }}
</td>
{% else %}
<td colspan="2">Not connected</td>
<td colspan="2">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
<td class="text-right">
{% if perms.dcim.change_poweroutlet %}

View File

@@ -2,6 +2,7 @@
<td>
<i class="fa fa-fw fa-bolt"></i> {{ pp.name }}
</td>
<td></td>
{% if pp.power_outlet %}
<td>
<a href="{% url 'dcim:device' pk=pp.power_outlet.device.pk %}">{{ pp.power_outlet.device }}</a>
@@ -10,7 +11,9 @@
{{ pp.power_outlet.name }}
</td>
{% else %}
<td colspan="2">Not connected</td>
<td colspan="2">
<span class="text-muted">Not connected</span>
</td>
{% endif %}
<td class="text-right">
{% if perms.dcim.change_powerport %}

View File

@@ -8,6 +8,14 @@
<h1>Interface Connections Import</h1>
<div class="row">
<div class="col-md-6">
{% if form.non_field_errors %}
<div class="panel panel-danger">
<div class="panel-heading"><strong>Errors</strong></div>
<div class="panel-body">
{{ form.non_field_errors }}
</div>
</div>
{% endif %}
<form action="." method="post" class="form">
{% csrf_token %}
{% render_form form %}

View File

@@ -112,6 +112,12 @@
</div>
{% if nonracked_devices %}
<table class="table table-hover panel-body">
<tr>
<th>Name</th>
<th>Role</th>
<th>Type</th>
<th>Parent</th>
</tr>
{% for device in nonracked_devices %}
<tr{% if device.device_type.u_height %} class="warning"{% endif %}>
<td>
@@ -119,6 +125,7 @@
</td>
<td>{{ device.device_role }}</td>
<td>{{ device.device_type }}</td>
<td>{% if device.parent_bay %}<a href="{{ device.parent_bay.device.get_absolute_url }}">{{ device.parent_bay }}</a>{% endif %}</td>
</tr>
{% endfor %}
</table>

View File

@@ -6,6 +6,26 @@
{% block title %}{{ site }}{% endblock %}
{% block content %}
<div class="row">
<div class="col-md-9">
<ol class="breadcrumb">
<li><a href="{% url 'dcim:site_list' %}">Sites</a></li>
<li>{{ site }}</li>
</ol>
</div>
<div class="col-md-3">
<form action="{% url 'dcim:site_list' %}" method="get">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Search" />
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</button>
</span>
</div>
</form>
</div>
</div>
<div class="pull-right">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#graphs_modal" data-obj="{{ site.name }}" data-url="{% url 'dcim-api:site_graphs' pk=site.pk %}" title="Show graphs">
<i class="glyphicon glyphicon-signal" aria-hidden="true"></i>
@@ -124,6 +144,25 @@
</tr>
</table>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<strong>Rack Groups</strong>
</div>
{% if rack_groups %}
<table class="table table-hover panel-body">
{% for rg in rack_groups %}
<tr>
<td><i class="fa fa-fw fa-folder"></i> <a href="{{ rg.get_absolute_url }}">{{ rg.name }}</a></td>
<td>{{ rg.rack_count }}</td>
</tr>
{% endfor %}
</table>
{% else %}
<div class="panel-body text-muted">
None
</div>
{% endif %}
</div>
<div class="panel panel-default">
<div class="panel-heading">
<strong>Topology Maps</strong>
@@ -132,7 +171,7 @@
<table class="table table-hover panel-body">
{% for tm in topology_maps %}
<tr>
<td><i class="fa fa-fw fa-map text-success"></i> <a href="{% url 'dcim-api:topology_map' slug=tm.slug %}" target="_blank">{{ tm }}</a></td>
<td><i class="fa fa-fw fa-map"></i> <a href="{% url 'dcim-api:topology_map' slug=tm.slug %}" target="_blank">{{ tm }}</a></td>
<td>{{ tm.description }}</td>
</tr>
{% endfor %}

View File

@@ -14,5 +14,28 @@
{% include 'inc/export_button.html' with obj_type='sites' %}
</div>
<h1>Sites</h1>
{% render_table table 'table.html' %}
<div class="row">
<div class="col-md-9">
{% render_table table 'table.html' %}
</div>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Search</strong>
</div>
<div class="panel-body">
<form action="{% url 'dcim:site_list' %}" method="get">
<div class="input-group">
<input type="text" name="q" class="form-control" placeholder="Name" {% if request.GET.q %}value="{{ request.GET.q }}" {% endif %}/>
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -1,13 +1,20 @@
{% load secret_helpers %}
<tr>
<td><a href="{% url 'secrets:secret' pk=secret.pk %}">{{ secret.role }}</a></td>
<td>{{ secret.name }}</td>
<td id="secret_{{ secret.pk }}">********</td>
<td class="text-right">
<button class="btn btn-xs btn-success unlock-secret" secret-id="{{ secret.pk }}">
<i class="fa fa-lock"></i> Unlock
</button>
<button class="btn btn-xs btn-danger lock-secret collapse" secret-id="{{ secret.pk }}">
<i class="fa fa-unlock-alt"></i> Lock
</button>
{% if secret|decryptable_by:request.user %}
<button class="btn btn-xs btn-success unlock-secret" secret-id="{{ secret.pk }}">
<i class="fa fa-lock"></i> Unlock
</button>
<button class="btn btn-xs btn-danger lock-secret collapse" secret-id="{{ secret.pk }}">
<i class="fa fa-unlock-alt"></i> Lock
</button>
{% else %}
<button class="btn btn-xs btn-default" disabled="disabled" title="Permission denied">
<i class="fa fa-lock"></i> Unlock
</button>
{% endif %}
</td>
</tr>

View File

@@ -1,5 +1,6 @@
{% extends '_base.html' %}
{% load static from staticfiles %}
{% load secret_helpers %}
{% block title %}Secret: {{ secret }}{% endblock %}
@@ -67,28 +68,35 @@
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Secret Data</strong>
</div>
<div class="panel-body">
<form id="secret_form">
{% csrf_token %}
</form>
<div class="row">
<div class="col-md-2">Secret</div>
<div class="col-md-8" id="secret_{{ secret.pk }}">********</div>
<div class="col-md-2 text-right">
<button class="btn btn-xs btn-success unlock-secret" secret-id="{{ secret.pk }}">
<i class="fa fa-lock"></i> Unlock
</button>
<button class="btn btn-xs btn-danger lock-secret collapse" secret-id="{{ secret.pk }}">
<i class="fa fa-unlock-alt"></i> Lock
</button>
{% if secret|decryptable_by:request.user %}
<div class="panel panel-default">
<div class="panel-heading">
<strong>Secret Data</strong>
</div>
<div class="panel-body">
<form id="secret_form">
{% csrf_token %}
</form>
<div class="row">
<div class="col-md-2">Secret</div>
<div class="col-md-8" id="secret_{{ secret.pk }}">********</div>
<div class="col-md-2 text-right">
<button class="btn btn-xs btn-success unlock-secret" secret-id="{{ secret.pk }}">
<i class="fa fa-lock"></i> Unlock
</button>
<button class="btn btn-xs btn-danger lock-secret collapse" secret-id="{{ secret.pk }}">
<i class="fa fa-unlock-alt"></i> Lock
</button>
</div>
</div>
</div>
</div>
</div>
{% else %}
<div class="alert alert-warning">
<i class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></i>
You do not have permission to decrypt this secret.
</div>
{% endif %}
</div>
</div>

View File

@@ -253,6 +253,9 @@ class BulkImportForm(forms.Form):
else:
for field, errors in obj_form.errors.items():
for e in errors:
self.add_error('csv', "Record {} ({}): {}".format(i, field, e))
if field == '__all__':
self.add_error('csv', "Record {}: {}".format(i, e))
else:
self.add_error('csv', "Record {} ({}): {}".format(i, field, e))
self.cleaned_data['csv'] = obj_list

View File

@@ -120,7 +120,7 @@ class ObjectEditView(View):
'obj': obj,
'obj_type': self.model._meta.verbose_name,
'form': form,
'cancel_url': obj.get_absolute_url() if obj else reverse(self.cancel_url),
'cancel_url': obj.get_absolute_url() if hasattr(obj, 'get_absolute_url') else reverse(self.cancel_url),
})
def post(self, request, *args, **kwargs):
@@ -137,9 +137,9 @@ class ObjectEditView(View):
msg = 'Created ' if obj_created else 'Modified '
msg += self.model._meta.verbose_name
if hasattr(obj, 'get_absolute_url'):
msg += ' <a href="{}">{}</a>'.format(obj.get_absolute_url(), obj)
msg = '{} <a href="{}">{}</a>'.format(msg, obj.get_absolute_url(), obj)
else:
msg += ' {}'.format(obj)
msg = '{} {}'.format(msg, obj)
messages.success(request, msg)
if obj_created:
UserAction.objects.log_create(request.user, obj, msg)
@@ -157,7 +157,7 @@ class ObjectEditView(View):
'obj': obj,
'obj_type': self.model._meta.verbose_name,
'form': form,
'cancel_url': obj.get_absolute_url() if obj else reverse(self.cancel_url),
'cancel_url': obj.get_absolute_url() if hasattr(obj, 'get_absolute_url') else reverse(self.cancel_url),
})
@@ -280,10 +280,10 @@ class BulkEditView(View):
form = self.form(request.POST)
if form.is_valid():
updated_count = self.update_objects(pk_list, form)
msg = 'Updated {} {}'.format(updated_count, self.cls._meta.verbose_name_plural)
messages.success(self.request, msg)
UserAction.objects.log_bulk_edit(request.user, ContentType.objects.get_for_model(self.cls), msg)
if updated_count:
msg = 'Updated {} {}'.format(updated_count, self.cls._meta.verbose_name_plural)
messages.success(self.request, msg)
UserAction.objects.log_bulk_edit(request.user, ContentType.objects.get_for_model(self.cls), msg)
return redirect(redirect_url)
else:

View File

@@ -5,6 +5,7 @@ django-filter==0.13.0
django-rest-swagger==0.3.7
django-tables2==1.2.1
djangorestframework==3.3.3
graphviz==0.4.10
Markdown==2.6.6
ncclient==0.4.7
netaddr==0.7.18
@@ -12,6 +13,5 @@ paramiko==2.0.0
psycopg2==2.6.1
py-gfm==0.1.3
pycrypto==2.6.1
pydot==1.0.2
sqlparse==0.1.19
xmltodict==0.10.2

View File

@@ -21,6 +21,30 @@ if [[ ! -z $SYNTAX ]]; then
EXIT=1
fi
# Check all python source files for PEP 8 compliance, but explicitly
# ignore:
# - E501: line greater than 80 characters in length
pep8 --ignore=E501 netbox/
RC=$?
if [[ $RC != 0 ]]; then
echo -e "\n$(info) one or more PEP 8 errors detected, failing build."
EXIT=$RC
fi
# Prepare configuration file for use in CI
CONFIG="netbox/netbox/configuration.py"
cp netbox/netbox/configuration.example.py $CONFIG
sed -i -e "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \['*'\]/g" $CONFIG
sed -i -e "s/SECRET_KEY = ''/SECRET_KEY = 'netboxci'/g" $CONFIG
# Run NetBox tests
./netbox/manage.py test netbox/
RC=$?
if [[ $RC != 0 ]]; then
echo -e "\n$(info) one or more tests failed, failing build."
EXIT=$RC
fi
# Show build duration
END=$(date +%s)
echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."

27
upgrade.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
# This script will prepare NetBox to run after the code has been upgraded to
# its most recent release.
#
# Once the script completes, remember to restart the WSGI service (e.g.
# gunicorn or uWSGI).
# Optionally use sudo if not already root, and always prompt for password
# before running the command
PREFIX="sudo -k "
if [ "$(whoami)" = "root" ]; then
# When running upgrade as root, ask user to confirm if they wish to
# continue
read -n1 -rsp $'Running NetBox upgrade as root, press any key to continue or ^C to cancel\n'
PREFIX=""
fi
# Install any new Python packages
COMMAND="${PREFIX}pip install -r requirements.txt --upgrade"
echo "Updating required Python packages ($COMMAND)..."
eval $COMMAND
# Apply any database migrations
./netbox/manage.py migrate
# Collect static files
./netbox/manage.py collectstatic --noinput