Skip to content

Commit

Permalink
Merge pull request #44 from netdevopsbr/support-v320
Browse files Browse the repository at this point in the history
Closes #36 and #42 - Add support to Netbox >v3.2
  • Loading branch information
emersonfelipesp authored May 7, 2022
2 parents 1a09734 + d88e903 commit d758092
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 651 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ PLUGINS_CONFIG = {

Edit **/opt/netbox/netbox/netbox** and find TEMPLATE_DIR section

- How it is configured:
- How it is configured (Netbox >= v3.2.0):
```python
TEMPLATES_DIR = BASE_DIR + '/templates'
TEMPLATES = [
Expand All @@ -173,6 +173,10 @@ TEMPLATES = [
'DIRS': [TEMPLATES_DIR],
'APP_DIRS': True,
'OPTIONS': {
'builtins': [
'utilities.templatetags.builtins.filters',
'utilities.templatetags.builtins.tags',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
Expand Down Expand Up @@ -201,6 +205,10 @@ TEMPLATES = [
'DIRS': [TEMPLATES_DIR, PROXBOX_TEMPLATE_DIR],
'APP_DIRS': True,
'OPTIONS': {
'builtins': [
'utilities.templatetags.builtins.filters',
'utilities.templatetags.builtins.tags',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
Expand Down
33 changes: 18 additions & 15 deletions netbox_proxbox/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

menu_items = (
PluginMenuItem(
link="plugins:netbox_proxbox:proxmoxvm_list",
link_text="Proxmox VM/CT",
buttons=(
PluginMenuButton(
# match the names of the path for create view defined in ./urls.py
link="plugins:netbox_proxbox:proxmoxvm_add",
# text that appears when hovering the ubtton
title="Add",
# font-awesome icon to use
icon_class="mdi mdi-plus-thick", # 'fa fa-plus' didn't work
# defines color button to green
color=ButtonColorChoices.GREEN,
permissions=["netbox_proxbox.add_proxmoxvm"],
),
),
link="plugins:netbox_proxbox:home",
link_text="Home",
),
)

'''
buttons=(
PluginMenuButton(
# match the names of the path for create view defined in ./urls.py
link="plugins:netbox_proxbox:proxmoxvm_add",
# text that appears when hovering the ubtton
title="Add",
# font-awesome icon to use
icon_class="mdi mdi-plus-thick", # 'fa fa-plus' didn't work
# defines color button to green
color=ButtonColorChoices.GREEN,
permissions=["netbox_proxbox.add_proxmoxvm"],
),
),
'''
8 changes: 4 additions & 4 deletions netbox_proxbox/tables.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# tables.py
import django_tables2 as tables
from utilities.tables import BaseTable
from .models import ProxmoxVM

from netbox.tables import NetBoxTable, ChoiceFieldColumn
from .models import ProxmoxVM

class ProxmoxVMTable(BaseTable):
class ProxmoxVMTable(NetBoxTable):
"""Table for displaying BGP Peering objects."""

id = tables.LinkColumn()
cluster = tables.LinkColumn()
virtual_machine = tables.LinkColumn()
proxmox_vm_id = tables.LinkColumn()

class Meta(BaseTable.Meta):
class Meta(NetBoxTable.Meta):
model = ProxmoxVM
fields = (
"id",
Expand Down
16 changes: 16 additions & 0 deletions netbox_proxbox/templates/netbox_proxbox/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends 'base/layout.html' %}

{% block content %}
{# Full Update Button#}
<div class="pull-right noprint">
{% if perms.netbox_proxbox.add_proxmoxvm %}
<a href="{% url 'plugins:netbox_proxbox:proxmoxvm_full_update' %}" target="_blank" class="btn btn-primary">Proxmox Full Update</a>
{% endif %}
</div>
{% endblock %}

{% block footer_links %}
{{ block.super }}

{% include "footer.html" %}
{% endblock %}
7 changes: 6 additions & 1 deletion netbox_proxbox/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.urls import path

from .views import (
HomeView,
ProxmoxVMCreateView,
ProxmoxVMDeleteView,
ProxmoxVMEditView,
Expand All @@ -15,7 +16,11 @@
import json

urlpatterns = [
path("", ProxmoxVMListView.as_view(), name="proxmoxvm_list"),
# Home View
path('', HomeView.as_view(), name='home'),

# Base Views
path("list/", ProxmoxVMListView.as_view(), name="proxmoxvm_list"),
# <int:pk> = plugins/netbox_proxmoxvm/<pk> | example: plugins/netbox_proxmoxvm/1/
# ProxmoxVMView.as_view() - as.view() is need so that our view class can process requests.
# as_view() takes request and returns well-formed response, that is a class based view.
Expand Down
20 changes: 19 additions & 1 deletion netbox_proxbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
from netbox_proxbox import proxbox_api
import json


class HomeView(View):
"""Homepage"""
template_name = 'netbox_proxbox/home.html'

# service incoming GET HTTP requests
def get(self, request):
"""Get request."""
return render(
request,
self.template_name,
)


class ProxmoxFullUpdate(PermissionRequiredMixin, View):
"""Full Update of Proxmox information on Netbox."""

Expand All @@ -41,6 +55,7 @@ def get(self, request):
},
)


class ProxmoxVMView(PermissionRequiredMixin, View):
"""Display Virtual Machine details"""

Expand Down Expand Up @@ -68,6 +83,7 @@ def get(self, request, pk):
},
)


class ProxmoxVMListView(PermissionRequiredMixin, View):
"""View for listing all existing Virtual Machines."""

Expand Down Expand Up @@ -106,7 +122,7 @@ def get(self, request):
}
)


# 'CreateView' is provided by Django
class ProxmoxVMCreateView(PermissionRequiredMixin, CreateView):
"""View for creating a new ProxmoxVM instance."""
Expand All @@ -116,6 +132,7 @@ class ProxmoxVMCreateView(PermissionRequiredMixin, CreateView):
form_class = ProxmoxVMForm
template_name = "netbox_proxbox/proxmox_vm_edit.html"


class ProxmoxVMDeleteView(PermissionRequiredMixin, DeleteView):
"""View for deleting ProxmoxVM instance."""

Expand All @@ -129,6 +146,7 @@ class ProxmoxVMDeleteView(PermissionRequiredMixin, DeleteView):
# template_name = points to the template that will be rendred when asked to confirm the deletion
template_name = "netbox_proxbox/proxmox_vm_delete.html"


class ProxmoxVMEditView(PermissionRequiredMixin, UpdateView):
"""View for editing a ProxmoxVM instance."""

Expand Down
Loading

0 comments on commit d758092

Please sign in to comment.