2017-08-04 17:02:52 -04:00
|
|
|
import django_tables2 as tables
|
2022-01-07 10:36:58 -05:00
|
|
|
|
2020-10-16 10:39:13 -04:00
|
|
|
from dcim.tables.devices import BaseInterfaceTable
|
2022-01-27 15:48:05 -05:00
|
|
|
from netbox.tables import NetBoxTable, columns
|
2021-03-04 16:07:55 -05:00
|
|
|
from tenancy.tables import TenantColumn
|
2020-06-23 13:16:21 -04:00
|
|
|
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
|
2017-08-04 17:02:52 -04:00
|
|
|
|
2020-10-16 17:01:55 -04:00
|
|
|
__all__ = (
|
|
|
|
'ClusterTable',
|
|
|
|
'ClusterGroupTable',
|
|
|
|
'ClusterTypeTable',
|
|
|
|
'VirtualMachineTable',
|
|
|
|
'VirtualMachineVMInterfaceTable',
|
|
|
|
'VMInterfaceTable',
|
|
|
|
)
|
|
|
|
|
|
|
|
VMINTERFACE_BUTTONS = """
|
|
|
|
{% if perms.ipam.add_ipaddress %}
|
2021-12-30 09:46:02 -05:00
|
|
|
<a href="{% url 'ipam:ipaddress_add' %}?vminterface={{ record.pk }}&return_url={% url 'virtualization:virtualmachine_interfaces' pk=object.pk %}" class="btn btn-sm btn-success" title="Add IP Address">
|
2020-11-06 14:49:14 -05:00
|
|
|
<i class="mdi mdi-plus-thick" aria-hidden="true"></i>
|
2020-10-16 17:01:55 -04:00
|
|
|
</a>
|
|
|
|
{% endif %}
|
|
|
|
"""
|
|
|
|
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Cluster types
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ClusterTypeTable(NetBoxTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-04-29 11:42:44 -04:00
|
|
|
cluster_count = tables.Column(
|
|
|
|
verbose_name='Clusters'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='virtualization:clustertype_list'
|
|
|
|
)
|
2017-08-04 17:02:52 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2017-08-04 17:02:52 -04:00
|
|
|
model = ClusterType
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'created', 'last_updated', 'tags', 'actions',
|
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'cluster_count', 'description')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Cluster groups
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ClusterGroupTable(NetBoxTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-04-29 11:42:44 -04:00
|
|
|
cluster_count = tables.Column(
|
|
|
|
verbose_name='Clusters'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2021-10-21 10:51:02 -04:00
|
|
|
url_name='virtualization:clustergroup_list'
|
|
|
|
)
|
2017-08-04 17:02:52 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2017-08-04 17:02:52 -04:00
|
|
|
model = ClusterGroup
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'id', 'name', 'slug', 'cluster_count', 'description', 'tags', 'created', 'last_updated', 'actions',
|
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'cluster_count', 'description')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Clusters
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class ClusterTable(NetBoxTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-05 21:36:20 -05:00
|
|
|
type = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
group = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-07-16 16:52:45 -04:00
|
|
|
tenant = tables.Column(
|
|
|
|
linkify=True
|
2020-04-29 11:42:44 -04:00
|
|
|
)
|
2020-07-16 16:52:45 -04:00
|
|
|
site = tables.Column(
|
|
|
|
linkify=True
|
2020-04-29 11:42:44 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
device_count = columns.LinkedCountColumn(
|
2020-09-25 12:42:17 -04:00
|
|
|
viewname='dcim:device_list',
|
|
|
|
url_params={'cluster_id': 'pk'},
|
2020-04-29 11:42:44 -04:00
|
|
|
verbose_name='Devices'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
vm_count = columns.LinkedCountColumn(
|
2020-09-25 12:42:17 -04:00
|
|
|
viewname='virtualization:virtualmachine_list',
|
|
|
|
url_params={'cluster_id': 'pk'},
|
2020-04-29 11:42:44 -04:00
|
|
|
verbose_name='VMs'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
comments = columns.MarkdownColumn()
|
|
|
|
tags = columns.TagColumn(
|
2020-05-06 14:42:51 -04:00
|
|
|
url_name='virtualization:cluster_list'
|
|
|
|
)
|
2017-08-04 17:02:52 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2017-08-04 17:02:52 -04:00
|
|
|
model = Cluster
|
2022-01-17 11:12:54 -05:00
|
|
|
fields = (
|
|
|
|
'pk', 'id', 'name', 'type', 'group', 'tenant', 'site', 'comments', 'device_count', 'vm_count', 'tags',
|
|
|
|
'created', 'last_updated',
|
|
|
|
)
|
2020-05-06 14:42:51 -04:00
|
|
|
default_columns = ('pk', 'name', 'type', 'group', 'tenant', 'site', 'device_count', 'vm_count')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Virtual machines
|
|
|
|
#
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class VirtualMachineTable(NetBoxTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
2021-12-14 17:03:03 -05:00
|
|
|
order_by=('_name',),
|
2021-04-02 16:59:53 -04:00
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
status = columns.ChoiceFieldColumn()
|
2020-07-16 16:52:45 -04:00
|
|
|
cluster = tables.Column(
|
|
|
|
linkify=True
|
2020-04-29 11:42:44 -04:00
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
role = columns.ColoredLabelColumn()
|
2021-03-04 16:07:55 -05:00
|
|
|
tenant = TenantColumn()
|
2022-01-27 15:00:10 -05:00
|
|
|
comments = columns.MarkdownColumn()
|
2020-07-16 16:52:45 -04:00
|
|
|
primary_ip4 = tables.Column(
|
|
|
|
linkify=True,
|
2020-04-29 11:42:44 -04:00
|
|
|
verbose_name='IPv4 Address'
|
|
|
|
)
|
2020-07-16 16:52:45 -04:00
|
|
|
primary_ip6 = tables.Column(
|
|
|
|
linkify=True,
|
2020-04-29 11:42:44 -04:00
|
|
|
verbose_name='IPv6 Address'
|
|
|
|
)
|
2021-09-17 13:55:32 -04:00
|
|
|
primary_ip = tables.Column(
|
|
|
|
linkify=True,
|
2021-10-25 14:42:20 -04:00
|
|
|
order_by=('primary_ip4', 'primary_ip6'),
|
2021-09-17 13:55:32 -04:00
|
|
|
verbose_name='IP Address'
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2020-05-06 14:42:51 -04:00
|
|
|
url_name='virtualization:virtualmachine_list'
|
|
|
|
)
|
2017-09-15 11:47:29 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2017-09-15 11:47:29 -04:00
|
|
|
model = VirtualMachine
|
2020-04-29 11:42:44 -04:00
|
|
|
fields = (
|
2022-01-17 11:12:54 -05:00
|
|
|
'pk', 'id', 'name', 'status', 'cluster', 'role', 'tenant', 'platform', 'vcpus', 'memory', 'disk',
|
|
|
|
'primary_ip4', 'primary_ip6', 'primary_ip', 'comments', 'tags', 'created', 'last_updated',
|
2020-04-29 11:42:44 -04:00
|
|
|
)
|
|
|
|
default_columns = (
|
|
|
|
'pk', 'name', 'status', 'cluster', 'role', 'tenant', 'vcpus', 'memory', 'disk', 'primary_ip',
|
|
|
|
)
|
2017-09-15 11:47:29 -04:00
|
|
|
|
|
|
|
|
2017-08-18 14:37:19 -04:00
|
|
|
#
|
|
|
|
# VM components
|
|
|
|
#
|
|
|
|
|
2020-07-13 16:18:17 -04:00
|
|
|
class VMInterfaceTable(BaseInterfaceTable):
|
2021-04-02 16:59:53 -04:00
|
|
|
virtual_machine = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-06-23 16:52:05 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
tags = columns.TagColumn(
|
2020-09-04 16:09:05 -04:00
|
|
|
url_name='virtualization:vminterface_list'
|
|
|
|
)
|
2017-08-18 14:37:19 -04:00
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2020-06-23 13:16:21 -04:00
|
|
|
model = VMInterface
|
2020-07-13 16:18:17 -04:00
|
|
|
fields = (
|
2021-11-03 10:29:02 -04:00
|
|
|
'pk', 'id', 'name', 'virtual_machine', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'tags',
|
2022-01-17 11:12:54 -05:00
|
|
|
'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'created', 'last_updated',
|
2020-07-13 16:18:17 -04:00
|
|
|
)
|
2021-10-21 16:30:18 -04:00
|
|
|
default_columns = ('pk', 'name', 'virtual_machine', 'enabled', 'description')
|
2020-10-16 17:01:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
class VirtualMachineVMInterfaceTable(VMInterfaceTable):
|
2021-10-21 16:30:18 -04:00
|
|
|
parent = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
|
|
|
bridge = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2022-01-27 15:00:10 -05:00
|
|
|
actions = columns.ActionsColumn(
|
2022-01-10 11:17:40 -05:00
|
|
|
sequence=('edit', 'delete'),
|
|
|
|
extra_buttons=VMINTERFACE_BUTTONS
|
2020-10-16 17:01:55 -04:00
|
|
|
)
|
|
|
|
|
2022-01-27 15:48:05 -05:00
|
|
|
class Meta(NetBoxTable.Meta):
|
2020-10-16 17:01:55 -04:00
|
|
|
model = VMInterface
|
|
|
|
fields = (
|
2021-11-03 10:29:02 -04:00
|
|
|
'pk', 'id', 'name', 'enabled', 'parent', 'bridge', 'mac_address', 'mtu', 'mode', 'description', 'tags',
|
2021-11-19 10:27:56 -05:00
|
|
|
'ip_addresses', 'fhrp_groups', 'untagged_vlan', 'tagged_vlans', 'actions',
|
2020-10-16 17:01:55 -04:00
|
|
|
)
|
2022-01-07 10:36:58 -05:00
|
|
|
default_columns = ('pk', 'name', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'ip_addresses')
|
2020-12-18 15:02:52 -05:00
|
|
|
row_attrs = {
|
|
|
|
'data-name': lambda record: record.name,
|
|
|
|
}
|