Skip to content

Commit

Permalink
Develop package model (#4)
Browse files Browse the repository at this point in the history
* Initial model for Packages model

* Add package_list

* Add migrations

* Adding package add form

* Import CSV Packages feature

* Adding filters

* Working bulkedit functionality for packages

* Require a package for a customer circuit

* Add edit and delete views for packages

* Add API support

* Expose package detail via the API endpoint

* NETOPS-704 Rename Tenant Group to Service Providers and Tenants to Customers

* NETOPS-704 Some small detail names fixed

* Import Rich's changes
  • Loading branch information
funzoneq authored Mar 7, 2018
1 parent f85b668 commit 2b5c6dc
Show file tree
Hide file tree
Showing 40 changed files with 709 additions and 55 deletions.
7 changes: 4 additions & 3 deletions netbox/circuits/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from circuits.models import Provider, Circuit, CircuitTermination, CircuitType
from dcim.api.serializers import NestedSiteSerializer, InterfaceSerializer
from extras.api.customfields import CustomFieldModelSerializer
from tenancy.api.serializers import NestedTenantSerializer
from tenancy.api.serializers import NestedTenantSerializer, NestedPackageSerializer
from utilities.api import ValidatedModelSerializer


Expand Down Expand Up @@ -68,11 +68,12 @@ class CircuitSerializer(CustomFieldModelSerializer):
provider = NestedProviderSerializer()
type = NestedCircuitTypeSerializer()
tenant = NestedTenantSerializer()
package = NestedPackageSerializer()

class Meta:
model = Circuit
fields = [
'id', 'cid', 'provider', 'type', 'tenant', 'install_date', 'commit_rate', 'description', 'comments',
'id', 'cid', 'provider', 'type', 'tenant', 'package', 'install_date', 'commit_rate', 'description', 'comments',
'custom_fields',
]

Expand All @@ -90,7 +91,7 @@ class WritableCircuitSerializer(CustomFieldModelSerializer):
class Meta:
model = Circuit
fields = [
'id', 'cid', 'provider', 'type', 'tenant', 'install_date', 'commit_rate', 'description', 'comments',
'id', 'cid', 'provider', 'type', 'tenant', 'package', 'install_date', 'commit_rate', 'description', 'comments',
'custom_fields',
]

Expand Down
14 changes: 12 additions & 2 deletions netbox/circuits/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)
from .models import Circuit, CircuitTermination, CircuitType, Provider


#
# Providers
#
Expand Down Expand Up @@ -105,7 +104,7 @@ class CircuitForm(BootstrapMixin, TenancyForm, CustomFieldForm):
class Meta:
model = Circuit
fields = [
'cid', 'type', 'provider', 'install_date', 'commit_rate', 'description', 'tenant_group', 'tenant',
'cid', 'type', 'provider', 'install_date', 'commit_rate', 'description', 'tenant_group', 'tenant', 'package',
'comments',
]
help_texts = {
Expand All @@ -114,6 +113,17 @@ class Meta:
'commit_rate': "Committed rate",
}

def clean(self):

super(CircuitForm, self).clean()

ctype = self.cleaned_data.get('type')
package = self.cleaned_data.get('package')

# Validate interface
if ctype.slug == 'customer' and package == None:
raise forms.ValidationError("A package is required for a customer circuit")


class CircuitCSVForm(forms.ModelForm):
provider = forms.ModelChoiceField(
Expand Down
27 changes: 27 additions & 0 deletions netbox/circuits/migrations/0010_circuit_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-26 10:35
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('tenancy', '0004_package_model'),
('circuits', '0009_unicode_literals'),
]

operations = [
migrations.AddField(
model_name='circuit',
name='package',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='package', to='tenancy.Package'),
),
migrations.AlterField(
model_name='circuittermination',
name='term_side',
field=models.CharField(choices=[('A', 'A'), ('Y', 'Y'), ('Z', 'Z')], max_length=1, verbose_name='Termination'),
),
]
5 changes: 3 additions & 2 deletions netbox/circuits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dcim.fields import ASNField
from extras.models import CustomFieldModel, CustomFieldValue
from tenancy.models import Tenant
from tenancy.models import Tenant, Package
from utilities.models import CreatedUpdatedModel
from .constants import *

Expand Down Expand Up @@ -90,13 +90,14 @@ class Circuit(CreatedUpdatedModel, CustomFieldModel):
provider = models.ForeignKey('Provider', related_name='circuits', on_delete=models.PROTECT)
type = models.ForeignKey('CircuitType', related_name='circuits', on_delete=models.PROTECT)
tenant = models.ForeignKey(Tenant, related_name='circuits', blank=True, null=True, on_delete=models.PROTECT)
package = models.ForeignKey(Package, related_name='package', blank=True, null=True, on_delete=models.SET_NULL)
install_date = models.DateField(blank=True, null=True, verbose_name='Date installed')
commit_rate = models.PositiveIntegerField(blank=True, null=True, verbose_name='Commit rate (Kbps)')
description = models.CharField(max_length=100, blank=True)
comments = models.TextField(blank=True)
custom_field_values = GenericRelation(CustomFieldValue, content_type_field='obj_type', object_id_field='obj_id')

csv_headers = ['cid', 'provider', 'type', 'tenant', 'install_date', 'commit_rate', 'description', 'comments']
csv_headers = ['cid', 'provider', 'type', 'tenant', 'package', 'install_date', 'commit_rate', 'description', 'comments']

class Meta:
ordering = ['provider', 'cid']
Expand Down
16 changes: 16 additions & 0 deletions netbox/ipam/migrations/0022_merge_20180222_1114.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-02-22 11:14
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ipam', '0021_outer_vlan_id'),
('ipam', '0021_vrf_ordering'),
]

operations = [
]
20 changes: 20 additions & 0 deletions netbox/ipam/migrations/0023_package_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-22 15:38
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ipam', '0022_merge_20180222_1114'),
]

operations = [
migrations.AlterField(
model_name='ipaddress',
name='role',
field=models.PositiveSmallIntegerField(blank=True, choices=[(10, 'Loopback'), (15, 'Static route'), (20, 'Secondary'), (30, 'Anycast'), (40, 'VIP'), (41, 'VRRP'), (42, 'HSRP'), (43, 'GLBP'), (44, 'CARP')], help_text='The functional role of this IP', null=True, verbose_name='Role'),
),
]
3 changes: 2 additions & 1 deletion netbox/netbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from secrets.models import Secret
from secrets.tables import SecretTable
from tenancy.filters import TenantFilter
from tenancy.models import Tenant
from tenancy.models import Tenant, Package
from tenancy.tables import TenantTable
from virtualization.filters import ClusterFilter, VirtualMachineFilter
from virtualization.models import Cluster, VirtualMachine
Expand Down Expand Up @@ -145,6 +145,7 @@ def get(self, request):
# Organization
'site_count': Site.objects.count(),
'tenant_count': Tenant.objects.count(),
'package_count': Package.objects.count(),

# DCIM
'rack_count': Rack.objects.count(),
Expand Down
10 changes: 10 additions & 0 deletions netbox/templates/circuits/circuit.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ <h1>{% block title %}{{ circuit.provider }} - {{ circuit.cid }}{% endblock %}</h
{% endif %}
</td>
</tr>
<tr>
<td>Package</td>
<td>
{% if circuit.package %}
<a href="{{ circuit.package.get_absolute_url }}">{{ circuit.package }}</a>
{% else %}
<span class="text-muted">N/A</span>
{% endif %}
</td>
</tr>
<tr>
<td>Install Date</td>
<td>
Expand Down
3 changes: 2 additions & 1 deletion netbox/templates/circuits/circuit_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{% render_field form.provider %}
{% render_field form.cid %}
{% render_field form.type %}
{% render_field form.package %}
{% render_field form.install_date %}
<div class="form-group">
<label class="col-md-3 control-label" for="id_commit_rate">{{ form.commit_rate.label }}</label>
Expand All @@ -23,7 +24,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/dcim/device_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/dcim/rack_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/dcim/site_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
8 changes: 6 additions & 2 deletions netbox/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ <h4 class="list-group-item-heading"><a href="{% url 'dcim:site_list' %}">Sites</
</div>
<div class="list-group-item">
<span class="badge pull-right">{{ stats.tenant_count }}</span>
<h4 class="list-group-item-heading"><a href="{% url 'tenancy:tenant_list' %}">Tenants</a></h4>
<p class="list-group-item-text text-muted">Customers or departments</p>
<h4 class="list-group-item-heading"><a href="{% url 'tenancy:tenant_list' %}">Customers</a></h4>
</div>
<div class="list-group-item">
<span class="badge pull-right">{{ stats.package_count }}</span>
<h4 class="list-group-item-heading"><a href="{% url 'tenancy:package_list' %}">Packages</a></h4>
<p class="list-group-item-text text-muted">Sales packages</p>
</div>
</div>
</div>
Expand Down
15 changes: 12 additions & 3 deletions netbox/templates/inc/nav_menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
<a href="{% url 'dcim:region_list' %}">Regions</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Tenancy</li>
<li class="dropdown-header">{{ form.tenant_group.label }}/{{ form.tenant.label }}</li>
<li>
{% if perms.tenancy.add_tenant %}
<div class="buttons pull-right">
<a href="{% url 'tenancy:tenant_add' %}" class="btn btn-xs btn-success" title="Add"><i class="fa fa-plus"></i></a>
<a href="{% url 'tenancy:tenant_import' %}" class="btn btn-xs btn-info" title="Import"><i class="fa fa-download"></i></a>
</div>
{% endif %}
<a href="{% url 'tenancy:tenant_list' %}">Tenants</a>
<a href="{% url 'tenancy:tenant_list' %}">Customers</a>
</li>
<li>
{% if perms.tenancy.add_tenantgroup %}
Expand All @@ -56,7 +56,16 @@
<a href="{% url 'tenancy:tenantgroup_import' %}" class="btn btn-xs btn-info" title="Import"><i class="fa fa-download"></i></a>
</div>
{% endif %}
<a href="{% url 'tenancy:tenantgroup_list' %}">Tenant Groups</a>
<a href="{% url 'tenancy:tenantgroup_list' %}">Service providers</a>
</li>
<li>
{% if perms.tenancy.add_package %}
<div class="buttons pull-right">
<a href="{% url 'tenancy:package_add' %}" class="btn btn-xs btn-success" title="Add"><i class="fa fa-plus"></i></a>
<a href="{% url 'tenancy:package_import' %}" class="btn btn-xs btn-info" title="Import"><i class="fa fa-download"></i></a>
</div>
{% endif %}
<a href="{% url 'tenancy:package_list' %}">Packages</a>
</li>
<li class="divider"></li>
<li class="dropdown-header">Miscellaneous</li>
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/ipaddress_bulk_add.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field model_form.tenant_group %}
{% render_field model_form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/ipaddress_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/prefix_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/vlan_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/ipam/vrf_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading"><strong>Tenancy</strong></div>
<div class="panel-heading"><strong>{{ form.tenant_group.label }}/{{ form.tenant.label }}</strong></div>
<div class="panel-body">
{% render_field form.tenant_group %}
{% render_field form.tenant %}
Expand Down
12 changes: 12 additions & 0 deletions netbox/templates/tenancy/inc/speed_widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<span class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li><a href="#" target="{{ target_field }}" data="50000" class="set_speed">50 Mbps</a></li>
<li><a href="#" target="{{ target_field }}" data="100000" class="set_speed">100 Mbps</a></li>
<li><a href="#" target="{{ target_field }}" data="250000" class="set_speed">250 Mbps</a></li>
<li><a href="#" target="{{ target_field }}" data="1000000" class="set_speed">1 Gbps</a></li>
<li><a href="#" target="{{ target_field }}" data="10000000" class="set_speed">10 Gbps</a></li>
</ul>
</span>
Loading

0 comments on commit 2b5c6dc

Please sign in to comment.