From 1ea8f04c23eae58eeea3a060230f267b69efe001 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 15:23:06 -0400 Subject: [PATCH 1/9] Added a note about the IRC chanel to the README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ba736fee8..becf60963 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ NetBox is an IP address management (IPAM) and data center infrastructure managem NetBox runs as a web application atop the [Django](https://www.djangoproject.com/) Python framework with a [PostgreSQL](http://www.postgresql.org/) database. For a complete list of requirements, see `requirements.txt`. The code is available [on GitHub](https://github.com/digitalocean/netbox). +Questions? Comments? Please join us on IRC in **#netbox** on **irc.freenode.net**! + ![Screenshot of main page](docs/screenshot1.png "Main page") ![Screenshot of rack elevation](docs/screenshot2.png "Rack elevation") From ab880e105392ca3640eda4bc20368e0f57face2e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 15:51:47 -0400 Subject: [PATCH 2/9] Fixed IPAddress 'parent prefixes' display; added warning for duplicate IPs --- netbox/ipam/views.py | 16 ++++++++++---- netbox/templates/ipam/ipaddress.html | 33 +++++++--------------------- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 75c582b99..b230783fc 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -395,16 +395,24 @@ def ipaddress(request, pk): ipaddress = get_object_or_404(IPAddress.objects.select_related('interface__device'), pk=pk) + # Parent prefixes table parent_prefixes = Prefix.objects.filter(vrf=ipaddress.vrf, prefix__net_contains=str(ipaddress.address.ip)) - related_ips = IPAddress.objects.select_related('interface__device').exclude(pk=ipaddress.pk)\ - .filter(vrf=ipaddress.vrf, address__net_contained_or_equal=str(ipaddress.address)) + parent_prefixes_table = tables.PrefixBriefTable(parent_prefixes) + # Duplicate IPs table + duplicate_ips = IPAddress.objects.filter(vrf=ipaddress.vrf, address=str(ipaddress.address))\ + .exclude(pk=ipaddress.pk).select_related('interface__device', 'nat_inside') + duplicate_ips_table = tables.IPAddressBriefTable(duplicate_ips) + + # Related IP table + related_ips = IPAddress.objects.select_related('interface__device').exclude(address=str(ipaddress.address))\ + .filter(vrf=ipaddress.vrf, address__net_contained_or_equal=str(ipaddress.address)) related_ips_table = tables.IPAddressBriefTable(related_ips) - RequestConfig(request, paginate={'klass': EnhancedPaginator}).configure(related_ips_table) return render(request, 'ipam/ipaddress.html', { 'ipaddress': ipaddress, - 'parent_prefixes': parent_prefixes, + 'parent_prefixes_table': parent_prefixes_table, + 'duplicate_ips_table': duplicate_ips_table, 'related_ips_table': related_ips_table, }) diff --git a/netbox/templates/ipam/ipaddress.html b/netbox/templates/ipam/ipaddress.html index 4c2d11f10..6834ded9e 100644 --- a/netbox/templates/ipam/ipaddress.html +++ b/netbox/templates/ipam/ipaddress.html @@ -119,31 +119,14 @@
-
-
- Parent Prefixes -
- {% if parent_prefixes %} - - {% for p in parent_prefixes %} - - - - - - - {% endfor %} -
- {{ p }} - - {% if p.site %} - {{ p.site }} - {% endif %} - {{ p.status }}{{ p.role }}
- {% else %} -
None
- {% endif %} -
+ {% with heading='Parent Prefixes' %} + {% render_table parent_prefixes_table 'panel_table.html' %} + {% endwith %} + {% if duplicate_ips_table.rows %} + {% with heading='Duplicate IP Addresses' panel_class='danger' %} + {% render_table duplicate_ips_table 'panel_table.html' %} + {% endwith %} + {% endif %} {% with heading='Related IP Addresses' %} {% render_table related_ips_table 'panel_table.html' %} {% endwith %} From d5d4eb9fd5a3acac136f74ea6d99082d04982acf Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 27 Jun 2016 16:48:54 -0400 Subject: [PATCH 3/9] Add Travis CI build --- .gitignore | 2 +- .travis.yml | 7 +++++++ README.md | 2 ++ scripts/cibuild.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100755 scripts/cibuild.sh diff --git a/.gitignore b/.gitignore index e8ff56275..83343ee0a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.pyc configuration.py .idea -*.sh +./*.sh fabfile.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..a7f9cda45 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python +python: + - "2.7" +install: + - pip install -r requirements.txt +script: + - ./scripts/cibuild.sh diff --git a/README.md b/README.md index becf60963..e9bbf689b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# NetBox [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=master)](https://travis-ci.org/digitalocean/netbox) + NetBox is an IP address management (IPAM) and data center infrastructure management (DCIM) tool. Initially conceived by the network engineering team at [DigitalOcean](https://www.digitalocean.com/), NetBox was developed specifically to address the needs of network and infrastructure engineers. NetBox runs as a web application atop the [Django](https://www.djangoproject.com/) Python framework with a [PostgreSQL](http://www.postgresql.org/) database. For a complete list of requirements, see `requirements.txt`. The code is available [on GitHub](https://github.com/digitalocean/netbox). diff --git a/scripts/cibuild.sh b/scripts/cibuild.sh new file mode 100755 index 000000000..91a847c37 --- /dev/null +++ b/scripts/cibuild.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Exit code starts at 0 but is modified if any checks fail +EXIT=0 + +# Output a line prefixed with a timestamp +info() +{ + echo "$(date +'%F %T') |" +} + +# Track number of seconds required to run script +START=$(date +%s) +echo "$(info) starting build checks." + +# Syntax check all python source files +SYNTAX=$(find . -name "*.py" -type f -exec python -m py_compile {} \; 2>&1) +if [[ ! -z $SYNTAX ]]; then + echo -e "$SYNTAX" + echo -e "\n$(info) detected one or more syntax errors, failing build." + EXIT=1 +fi + +# Show build duration +END=$(date +%s) +echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds." + +exit $EXIT From e334c64a7cf0265a501090e2c6609771f97d620f Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 27 Jun 2016 19:49:57 -0400 Subject: [PATCH 4/9] Add Submitting Pull Requests section to CONTRIBUTING --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d5e9bd38e..3c36885ea 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,3 +48,9 @@ Even if it's not quite right for NetBox, we may be able to point you to a tool b * A use case for the feature; who would use it and what value it would add to NetBox * 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 + +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. From f0fb60734a2d9383af25a6f44aaf8b029e49977f Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Mon, 27 Jun 2016 19:55:17 -0400 Subject: [PATCH 5/9] Add Travis build badges for both master and develop against python 2.7 --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9bbf689b..ab739f9e3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# NetBox [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=master)](https://travis-ci.org/digitalocean/netbox) +# NetBox NetBox is an IP address management (IPAM) and data center infrastructure management (DCIM) tool. Initially conceived by the network engineering team at [DigitalOcean](https://www.digitalocean.com/), NetBox was developed specifically to address the needs of network and infrastructure engineers. @@ -6,6 +6,15 @@ NetBox runs as a web application atop the [Django](https://www.djangoproject.com Questions? Comments? Please join us on IRC in **#netbox** on **irc.freenode.net**! +### Build Status + +| | python 2.7 | +|-------------|------------| +| **master** | [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=master)](https://travis-ci.org/digitalocean/netbox) | +| **develop** | [![Build Status](https://travis-ci.org/digitalocean/netbox.svg?branch=develop)](https://travis-ci.org/digitalocean/netbox) | + +## Screenshots + ![Screenshot of main page](docs/screenshot1.png "Main page") ![Screenshot of rack elevation](docs/screenshot2.png "Rack elevation") From a4cbfd7d5b2289fd8f874391afa8c5b031d06b3b Mon Sep 17 00:00:00 2001 From: Alex Conrey Date: Mon, 27 Jun 2016 19:51:46 -0500 Subject: [PATCH 6/9] added apache config information to getting-started.md --- docs/getting-started.md | 47 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index 8f2688aef..7395fdace 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -206,20 +206,26 @@ Now if we navigate to the name or IP of the server (as defined in `ALLOWED_HOSTS If the test service does not run, or you cannot reach the NetBox home page, something has gone wrong. Do not proceed with the rest of this guide until the installation has been corrected. -# nginx and gunicorn +# Web Server and gunicorn ## Installation -We'll set up a simple HTTP front end using [nginx](https://www.nginx.com/resources/wiki/) and [gunicorn](http://gunicorn.org/) for the purposes of this guide. (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 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. ``` -# apt-get install nginx gunicorn supervisor +# apt-get install gunicorn supervisor ``` ## nginx Configuration The following will serve as a minimal nginx configuration. Be sure to modify your server name and installation path appropriately. +``` +# apt-get install nginx +``` + +Once nginx is installed, proceed with the following configuration: + ``` server { listen 80; @@ -256,6 +262,40 @@ Restart the nginx service to use the new configuration. # service nginx restart * Restarting nginx nginx ``` +## 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: + +``` + + ProxyPreserveHost On + + ServerName netbox.totallycool.tld + + Alias /static/ /opt/netbox/static/static + + + Options Indexes FollowSymLinks MultiViews + AllowOverride None + Order allow,deny + Allow from all + #Require all granted [UNCOMMENT THIS IF RUNNING APACHE 2.4] + + + + ProxyPass ! + + + ProxyPass / http://127.0.0.1:8001; + ProxyPassReverse / http://127.0.0.1:8001; + +``` + +Save the contents of the above example in `/etc/apache2/sites-available/netbox.conf`, add in the newly saved configuration and reload Apache: + +``` +# a2ensite netbox; service apache2 restart +``` ## gunicorn Configuration @@ -289,3 +329,4 @@ 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. + From 4dd31497e52013ec45d3b766d9b8345e2dd238bb Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 22:27:40 -0400 Subject: [PATCH 7/9] Fixes #26: Corrected rack validation to work when there are no devices within the rack --- netbox/dcim/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 5ff233c9c..0c587dd3d 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -188,10 +188,11 @@ class Rack(CreatedUpdatedModel): # Validate that Rack is tall enough to house the installed Devices if self.pk: top_device = Device.objects.filter(rack=self).order_by('-position').first() - min_height = top_device.position + top_device.device_type.u_height - 1 - if self.u_height < min_height: - raise ValidationError("Rack must be at least {}U tall with currently installed devices." - .format(min_height)) + if top_device: + min_height = top_device.position + top_device.device_type.u_height - 1 + if self.u_height < min_height: + raise ValidationError("Rack must be at least {}U tall with currently installed devices." + .format(min_height)) def to_csv(self): return ','.join([ From df01947c9ef9bf0c592e01722cb6a11d374ffd57 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 22:35:07 -0400 Subject: [PATCH 8/9] Corrected claim about RIRs being pre-populated --- docs/ipam.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ipam.md b/docs/ipam.md index 295b32ccc..d37a16319 100644 --- a/docs/ipam.md +++ b/docs/ipam.md @@ -36,7 +36,7 @@ Any prefixes you create in NetBox (discussed below) will be automatically organi 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. -Each aggregate must be assigned to one RIR. NetBox by default will be populated with the RIRs listed above, however you are free to remove these and/or create your own if you choose. +Each aggregate must be assigned to one RIR. You are free to define whichever RIRs you choose (or create your own). --- From 9aa0972a8c79aa531a4e3ceddb2e5100a61c23e6 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 27 Jun 2016 22:48:24 -0400 Subject: [PATCH 9/9] Corrected regex to ignore shell files in root dir --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 83343ee0a..7628f9af7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.pyc configuration.py .idea -./*.sh +/*.sh fabfile.py