Skip to content

Commit

Permalink
Merge pull request #91 from netdevopsbr/change_tables
Browse files Browse the repository at this point in the history
Close #90 - Change how tables are displayed using django_tables2
  • Loading branch information
emersonfelipesp authored Mar 16, 2023
2 parents 3686219 + 2be7041 commit 2ab77f4
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 101 deletions.
1 change: 1 addition & 0 deletions netbox_proxbox/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example = {'virtualmachines': [{'name': 'EVE-NG', 'changes': {'status': False, 'custom_fields': None, 'local_context': True, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'containerlab', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'NS1', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'wikijs-test', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'ISPTools', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'RSYSLOG-CGNAT', 'changes': {'status': False, 'custom_fields': None, 'local_context': True, 'resources': None, 'tag': False, 'interfaces': None, 'ips': False}, 'result': True}, {'name': 'SPEEDTEST', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'TESTE-DEFENSE-IA', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'KRILL-RPKI-AS265234', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'netbox-dev2', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'VM-TESTE', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': None, 'ips': False}, 'result': True}, {'name': 'elastiflow', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'ELK-NETFLOW', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'ZEUS', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'SPEEDTEST-OOKLA', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'RADIUS-BKP', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'ZABBIX-GRAFANA', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'netbox-template', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'VMforDocker', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'Win10-LAB', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'netbox-beta', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'testing', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'teste', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'netbox-v3-dev', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'Ubuntu-SRV-20.04', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'DOKUWIKI-PUBLICO-OLD', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'wikijs-testing', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'WIN10-ALVOCOM', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'asstat-deb10', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'EVE-NG', 'changes': {'status': False, 'custom_fields': None, 'local_context': True, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'ELASTIC-ISAC', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': None, 'ips': False}, 'result': True}, {'name': 'nfsen-debian', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'PNETLAB', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'ZABBIX', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'GRAYLOG', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'NS3', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'netbox-devop2', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'DEFENSE-IA', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'LAB-GRAFANA', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'BKP', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'Ubuntu-SRV-20.04', 'changes': {'status': False, 'custom_fields': None, 'local_context': True, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'NetDev-CentOs-LAB', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'GenieACS', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': None, 'ips': False}, 'result': True}, {'name': 'vault', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'KRILL-RPKI-AS268881', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'netbox-v3-huawei', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'RSYSLOG-CGNAT', 'changes': {'status': False, 'custom_fields': None, 'local_context': True, 'resources': None, 'tag': False, 'interfaces': None, 'ips': False}, 'result': True}, {'name': 'NS4', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'planos', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}, {'name': 'speedtest-servers', 'changes': {'status': False, 'custom_fields': None, 'local_context': False, 'resources': None, 'tag': False, 'interfaces': False, 'ips': False}, 'result': True}], 'nodes': [{'changes': {'status': False, 'cluster': False, 'interfaces': False}, 'result': True}, {'changes': {'status': False, 'cluster': False, 'interfaces': False}, 'result': True}, {'changes': {'status': False, 'cluster': False, 'interfaces': False}, 'result': True}], 'remove_unused': [{'name': 'DEFENSE', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> DEFENSE']}, {'name': 'DOKUWIKI-PUBLICO-OLD', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> DOKUWIKI-PUBLICO-OLD']}, {'name': 'ELASTIC-ISAC', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> ELASTIC-ISAC']}, {'name': 'ELK-NETFLOW', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> ELK-NETFLOW']}, {'name': 'EVE-NG', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> EVE-NG']}, {'name': 'GRAYLOG', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> GRAYLOG']}, {'name': 'GenieACS', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> GenieACS']}, {'name': 'ISPTools', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> ISPTools']}, {'name': 'BKP', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> BKP']}, {'name': 'KRILL-RPKI-AS265234', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> KRILL-RPKI-AS265234']}, {'name': 'KRILL-RPKI-AS268881', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> KRILL-RPKI-AS268881']}, {'name': 'LAB-GRAFANA', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> LAB-GRAFANA']}, {'name': 'LAB-ZABBIX-6', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> LAB-ZABBIX-6']}, {'name': 'NS1', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> NS1']}, {'name': 'NS3', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> NS3']}, {'name': 'NS4', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> NS4']}, {'name': 'NetDev-CentOs-LAB', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> NetDev-CentOs-LAB']}, {'name': 'PNETLAB', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> PNETLAB']}, {'name': 'RADIUS-BKP', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> RADIUS-BKP']}, {'name': 'RSYSLOG-CGNAT', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> RSYSLOG-CGNAT']}, {'name': 'SPEEDTEST', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> SPEEDTEST']}, {'name': 'SPEEDTEST-OOKLA', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> SPEEDTEST-OOKLA']}, {'name': 'TESTE-DEFENSE-IA', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> TESTE-DEFENSE-IA']}, {'name': 'Ubuntu-SRV-20.04', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> Ubuntu-SRV-20.04']}, {'name': 'VM-TESTE', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> VM-TESTE']}, {'name': 'VMforDocker', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> VMforDocker']}, {'name': 'WIN10-ALVOCOM', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> WIN10-ALVOCOM']}, {'name': 'Win10-LAB', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> Win10-LAB']}, {'name': 'ZABBIX-GRAFANA', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> ZABBIX-GRAFANA']}, {'name': 'ZEUS', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> ZEUS']}, {'name': 'asstat-deb10', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> asstat-deb10']}, {'name': 'containerlab', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> containerlab']}, {'name': 'elastiflow', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> elastiflow']}, {'name': 'testing', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> testing']}, {'name': 'netbox-beta', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> netbox-beta']}, {'name': 'netbox-dev2', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> netbox-dev2']}, {'name': 'netbox-devop2', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> netbox-devop2']}, {'name': 'netbox-template', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> netbox-template']}, {'name': 'netbox-v3-dev', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> netbox-v3-dev']}, {'name': 'netbox-v3-huawei', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> netbox-v3-huawei']}, {'name': 'nfsen-debian', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> nfsen-debian']}, {'name': 'planos', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> planos']}, {'name': 'speedtest-servers', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> speedtest-servers']}, {'name': 'teste', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> teste']}, {'name': 'vault', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> vault']}, {'name': 'wikijs-test', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> wikijs-test']}, {'name': 'wikijs-testing', 'result': False, 'log': ['[OK] VM exists on both systems (Netbox and Proxmox) -> wikijs-testing']}]}
1 change: 1 addition & 0 deletions netbox_proxbox/proxbox_api/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def all():

json_vm_all.append(json_vm)

print(f"json_vm: {json_vm}")
return json_vm_all


9 changes: 6 additions & 3 deletions netbox_proxbox/proxbox_api/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ def virtual_machine(**kwargs):

if vm_on_netbox == True:
# Update Netbox information
full_update = vm_full_update(netbox_vm, proxmox_json)
json_vm["changes"] = full_update
full_update = vm_full_update(netbox_vm, proxmox_json)

# 'changes' json
json_vm = full_update

full_update_list = list(full_update.values())

Expand All @@ -301,7 +303,7 @@ def virtual_machine(**kwargs):
if netbox_vm != None:
# Update rest of configuration
full_update = vm_full_update(netbox_vm, proxmox_json)
json_vm["changes"] = full_update
json_vm = full_update

full_update_list = list(full_update.values())

Expand Down Expand Up @@ -331,6 +333,7 @@ def virtual_machine(**kwargs):
# Unexpected error
json_vm["result"] = False

print('(update) json_vm:', json_vm)
return json_vm


Expand Down
46 changes: 39 additions & 7 deletions netbox_proxbox/tables.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# tables.py
import django_tables2 as tables
import django_tables2 as table

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

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

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

class Meta(NetBoxTable.Meta):
model = ProxmoxVM
Expand All @@ -22,4 +22,36 @@ class Meta(NetBoxTable.Meta):
"type",
"node",
"cluster",
)
)

class VMUpdateResult(table.Table):
"""Table for displaying VM/CT update results"""

name = table.Column()
status = table.Column()
custom_fields = table.Column(verbose_name = "Custom Fields")
local_context = table.Column(verbose_name = "Local Context")
resources = table.Column()
tag = table.Column()
interfaces = table.Column()
ips = table.Column(verbose_name = "IP Address")

class Meta(NetBoxTable.Meta):
fields = ('name', 'status', 'custom_fields', 'local_context', 'resources', 'tag', 'interfaces', 'ips')
default_columns = ('name')
#fields = ('name', 'status', 'custom_fields', 'local_context', 'resources', 'tag', 'result')
#default_columns = ('name', 'status', 'custom_fields', 'local_context', 'resources', 'tag', 'result')


class NodeUpdateResult(table.Table):
"""Table for displaying VM/CT update results"""

status = table.Column()
cluster = table.Column()
interfaces = table.Column()
result = table.Column()


class Meta(NetBoxTable.Meta):
fields = ('status', 'cluster', 'interfaces', 'result')
default_columns = ('name')
Loading

0 comments on commit 2ab77f4

Please sign in to comment.