Skip to content

Commit

Permalink
Merge pull request netbox-community#587 from digitalocean/develop
Browse files Browse the repository at this point in the history
Release v1.6.2
  • Loading branch information
jeremystretch authored Sep 30, 2016
2 parents 1b59ab7 + b467652 commit 836cee3
Show file tree
Hide file tree
Showing 43 changed files with 463 additions and 237 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NetBox runs as a web application atop the [Django](https://www.djangoproject.com

The complete documentation for Netbox can be found at [Read the Docs](http://netbox.readthedocs.io/en/latest/).

Questions? Comments? Please subscribe to [the netbox-disucss mailing list](https://groups.google.com/forum/#!forum/netbox-discuss), or join us on IRC in **#netbox** on **irc.freenode.net**!
Questions? Comments? Please subscribe to [the netbox-discuss mailing list](https://groups.google.com/forum/#!forum/netbox-discuss), or join us on IRC in **#netbox** on **irc.freenode.net**!

### Build Status

Expand Down
12 changes: 12 additions & 0 deletions docs/configuration/optional-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ BANNER_BOTTOM = BANNER_TOP

---

## BASE_PATH

Default: None

The base URL path to use when accessing NetBox. Do not include the scheme or domain name. For example, if installed at http://example.com/netbox/, set:

```
BASE_PATH = 'netbox/'
```

---

## DEBUG

Default: False
Expand Down
37 changes: 21 additions & 16 deletions docs/installation/netbox.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# Installation

NetBox requires following system dependencies:
**Debian/Ubuntu**

* python2.7
* python-dev
* python-pip
* libxml2-dev
* libxslt1-dev
* libffi-dev
* graphviz
* libpq-dev
* libssl-dev
```
# apt-get install -y python2.7 python-dev python-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev
```

**CentOS/RHEL**

```
# sudo apt-get install -y python2.7 python-dev python-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev
# yum install -y epel-release
# yum install -y gcc python2 python-devel python-pip libxml2-devel libxslt-devel libffi-devel graphviz openssl-devel
```

You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub.
Expand Down Expand Up @@ -41,8 +38,16 @@ Create the base directory for the NetBox installation. For this guide, we'll use

If `git` is not already installed, install it:

**Debian/Ubuntu**

```
# sudo apt-get install -y git
# apt-get install -y git
```

**CentOS/RHEL**

```
# yum install -y git
```

Next, clone the **master** branch of the NetBox GitHub repository into the current directory:
Expand All @@ -63,7 +68,7 @@ Checking connectivity... done.
Install the required Python packages using pip. (If you encounter any compilation errors during this step, ensure that you've installed all of the system dependencies listed above.)

```
# sudo pip install -r requirements.txt
# pip install -r requirements.txt
```

# Configuration
Expand All @@ -76,7 +81,7 @@ Move into the NetBox configuration directory and make a copy of `configuration.e
```

Open `configuration.py` with your preferred editor and set the following variables:

* ALLOWED_HOSTS
* DATABASE
* SECRET_KEY
Expand Down Expand Up @@ -143,8 +148,8 @@ NetBox does not come with any predefined user accounts. You'll need to create a
# ./manage.py createsuperuser
Username: admin
Email address: admin@example.com
Password:
Password (again):
Password:
Password (again):
Superuser created successfully.
```

Expand Down
28 changes: 22 additions & 6 deletions docs/installation/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@ NetBox requires a PostgreSQL database to store data. MySQL is not supported, as

# Installation

The following packages are needed to install PostgreSQL with Python support:
**Debian/Ubuntu**

* postgresql
* libpq-dev
* python-psycopg2
```
# apt-get install -y postgresql libpq-dev python-psycopg2
```

**CentOS/RHEL**

```
# yum install -y postgresql postgresql-server postgresql-devel python-psycopg2
# postgresql-setup initdb
```

If using CentOS, modify the PostgreSQL configuration to accept password-based authentication by replacing `ident` with `md5` for all host entries within `/var/lib/pgsql/data/pg_hba.conf`. For example:

```
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
```

Then, start the service:

```
# sudo apt-get install -y postgresql libpq-dev python-psycopg2
# systemctl start postgresql
```

# Configuration
# Database Creation

At a minimum, we need to create a database for NetBox and assign it a username and password for authentication. This is done with the following commands.

Expand Down
22 changes: 12 additions & 10 deletions docs/installation/web-server.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# Web Server Installation

We'll set up a simple WSGI 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/) to enable service persistence.
We'll set up a simple WSGI 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/) to enable service persistence.

!!! info
Only Debian/Ubuntu instructions are provided here, but the installation process for CentOS/RHEL does not differ much. Please consult the documentation for those distributions for details.

```
# sudo apt-get install -y gunicorn supervisor
# apt-get install -y gunicorn supervisor
```

## Option A: nginx

The following will serve as a minimal nginx configuration. Be sure to modify your server name and installation path appropriately.

```
# sudo apt-get install -y nginx
# apt-get install -y nginx
```

Once nginx is installed, proceed with the following configuration:
Once nginx is installed, save the following configuration to `/etc/nginx/sites-available/netbox`. Be sure to replace `netbox.example.com` with the domain name or IP address of your installation. (This should match the value configured for `ALLOWED_HOSTS` in `configuration.py`.)

```
server {
Expand All @@ -38,27 +41,26 @@ server {
}
```

Save this configuration to `/etc/nginx/sites-available/netbox`. Then, delete `/etc/nginx/sites-enabled/default` and create a symlink in the `sites-enabled` directory to the configuration file you just created.
Then, delete `/etc/nginx/sites-enabled/default` and create a symlink in the `sites-enabled` directory to the configuration file you just created.

```
# cd /etc/nginx/sites-enabled/
# rm default
# ln -s /etc/nginx/sites-available/netbox
# ln -s /etc/nginx/sites-available/netbox
```

Restart the nginx service to use the new configuration.

```
# service nginx restart
* Restarting nginx nginx
```

To enable SSL, consider this guide on [securing nginx with Let's Encrypt](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04).

## Option B: Apache

```
# sudo apt-get install -y apache2
# apt-get install -y apache2
```

Once Apache is installed, proceed with the following configuration (Be sure to modify the `ServerName` appropriately):
Expand Down Expand Up @@ -99,7 +101,7 @@ To enable SSL, consider this guide on [securing Apache with Let's Encrypt](https

# gunicorn Installation

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. If using CentOS/RHEL change the username from `www-data` to `nginx` or `apache`.

```
command = '/usr/bin/gunicorn'
Expand All @@ -120,7 +122,7 @@ directory = /opt/netbox/netbox/
user = www-data
```

Finally, restart the supervisor service to detect and run the gunicorn service:
Then, restart the supervisor service to detect and run the gunicorn service:

```
# service supervisor restart
Expand Down
11 changes: 10 additions & 1 deletion netbox/dcim/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay, DeviceType,
DeviceRole, Interface, InterfaceConnection, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet,
PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, RackRole, RACK_FACE_FRONT, RACK_FACE_REAR, Site,
SUBDEVICE_ROLE_CHILD, SUBDEVICE_ROLE_PARENT,
)
from extras.api.serializers import CustomFieldSerializer
from tenancy.api.serializers import TenantNestedSerializer
Expand Down Expand Up @@ -131,11 +132,19 @@ class Meta(ManufacturerSerializer.Meta):

class DeviceTypeSerializer(serializers.ModelSerializer):
manufacturer = ManufacturerNestedSerializer()
subdevice_role = serializers.SerializerMethodField()

class Meta:
model = DeviceType
fields = ['id', 'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth',
'is_console_server', 'is_pdu', 'is_network_device']
'is_console_server', 'is_pdu', 'is_network_device', 'subdevice_role']

def get_subdevice_role(self, obj):
return {
SUBDEVICE_ROLE_PARENT: 'parent',
SUBDEVICE_ROLE_CHILD: 'child',
None: None,
}[obj.subdevice_role]


class DeviceTypeNestedSerializer(DeviceTypeSerializer):
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class DeviceBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
class DeviceFilterForm(BootstrapMixin, CustomFieldFilterForm):
model = Device
site = FilterChoiceField(queryset=Site.objects.annotate(filter_count=Count('racks__devices')), to_field_name='slug')
rack_group_id = FilterChoiceField(queryset=Site.objects.annotate(filter_count=Count('racks__devices')),
rack_group_id = FilterChoiceField(queryset=RackGroup.objects.annotate(filter_count=Count('racks__devices')),
label='Rack Group')
role = FilterChoiceField(queryset=DeviceRole.objects.annotate(filter_count=Count('devices')), to_field_name='slug')
tenant = FilterChoiceField(queryset=Tenant.objects.annotate(filter_count=Count('devices')), to_field_name='slug',
Expand Down
18 changes: 18 additions & 0 deletions netbox/dcim/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,29 @@ class Meta:
def __unicode__(self):
return u'{} {}'.format(self.manufacturer, self.model)

def __init__(self, *args, **kwargs):
super(DeviceType, self).__init__(*args, **kwargs)

# Save a copy of u_height for validation in clean()
self._original_u_height = self.u_height

def get_absolute_url(self):
return reverse('dcim:devicetype', args=[self.pk])

def clean(self):

# If editing an existing DeviceType to have a larger u_height, first validate that *all* instances of it have
# room to expand within their racks. This validation will impose a very high performance penalty when there are
# many instances to check, but increasing the u_height of a DeviceType should be a very rare occurrence.
if self.pk is not None and self.u_height > self._original_u_height:
for d in Device.objects.filter(device_type=self, position__isnull=False):
face_required = None if self.is_full_depth else d.face
u_available = d.rack.get_available_units(u_height=self.u_height, rack_face=face_required,
exclude=[d.pk])
if d.position not in u_available:
raise ValidationError("Device {} in rack {} does not have sufficient space to accommodate a height "
"of {}U".format(d, d.rack, self.u_height))

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.")
Expand Down
Loading

0 comments on commit 836cee3

Please sign in to comment.