2017-08-04 17:02:52 -04:00
|
|
|
import django_tables2 as tables
|
2021-02-15 21:01:55 +10:30
|
|
|
from django.conf import settings
|
2020-10-16 10:39:13 -04:00
|
|
|
from dcim.tables.devices import BaseInterfaceTable
|
2021-03-04 16:07:55 -05:00
|
|
|
from tenancy.tables import TenantColumn
|
2020-09-25 12:42:17 -04:00
|
|
|
from utilities.tables import (
|
|
|
|
BaseTable, ButtonsColumn, ChoiceFieldColumn, ColoredLabelColumn, LinkedCountColumn, TagColumn, ToggleColumn,
|
|
|
|
)
|
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',
|
|
|
|
'VirtualMachineDetailTable',
|
|
|
|
'VirtualMachineTable',
|
|
|
|
'VirtualMachineVMInterfaceTable',
|
|
|
|
'VMInterfaceTable',
|
|
|
|
)
|
|
|
|
|
|
|
|
VMINTERFACE_BUTTONS = """
|
|
|
|
{% if perms.ipam.add_ipaddress %}
|
2021-04-17 18:15:53 -07:00
|
|
|
<a href="{% url 'ipam:ipaddress_add' %}?vminterface={{ record.pk }}&return_url={{ virtualmachine.get_absolute_url }}" 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
|
|
|
|
#
|
|
|
|
|
|
|
|
class ClusterTypeTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
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'
|
|
|
|
)
|
2021-02-26 17:23:23 -05:00
|
|
|
actions = ButtonsColumn(ClusterType)
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ClusterType
|
2020-04-29 11:42:44 -04:00
|
|
|
fields = ('pk', 'name', 'slug', 'cluster_count', 'description', 'actions')
|
|
|
|
default_columns = ('pk', 'name', 'cluster_count', 'description', 'actions')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Cluster groups
|
|
|
|
#
|
|
|
|
|
|
|
|
class ClusterGroupTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
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'
|
|
|
|
)
|
2021-02-26 17:23:23 -05:00
|
|
|
actions = ButtonsColumn(ClusterGroup)
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = ClusterGroup
|
2020-04-29 11:42:44 -04:00
|
|
|
fields = ('pk', 'name', 'slug', 'cluster_count', 'description', 'actions')
|
|
|
|
default_columns = ('pk', 'name', 'cluster_count', 'description', 'actions')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Clusters
|
|
|
|
#
|
|
|
|
|
|
|
|
class ClusterTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2021-04-02 16:59:53 -04:00
|
|
|
name = 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
|
|
|
)
|
2020-09-25 12:42:17 -04:00
|
|
|
device_count = LinkedCountColumn(
|
|
|
|
viewname='dcim:device_list',
|
|
|
|
url_params={'cluster_id': 'pk'},
|
2020-04-29 11:42:44 -04:00
|
|
|
verbose_name='Devices'
|
|
|
|
)
|
2020-09-25 12:42:17 -04:00
|
|
|
vm_count = LinkedCountColumn(
|
|
|
|
viewname='virtualization:virtualmachine_list',
|
|
|
|
url_params={'cluster_id': 'pk'},
|
2020-04-29 11:42:44 -04:00
|
|
|
verbose_name='VMs'
|
|
|
|
)
|
2020-05-06 14:42:51 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='virtualization:cluster_list'
|
|
|
|
)
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = Cluster
|
2020-05-06 14:42:51 -04:00
|
|
|
fields = ('pk', 'name', 'type', 'group', 'tenant', 'site', 'device_count', 'vm_count', 'tags')
|
|
|
|
default_columns = ('pk', 'name', 'type', 'group', 'tenant', 'site', 'device_count', 'vm_count')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Virtual machines
|
|
|
|
#
|
|
|
|
|
|
|
|
class VirtualMachineTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
2021-04-02 16:59:53 -04:00
|
|
|
name = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-09-25 10:52:14 -04:00
|
|
|
status = ChoiceFieldColumn()
|
2020-07-16 16:52:45 -04:00
|
|
|
cluster = tables.Column(
|
|
|
|
linkify=True
|
2020-04-29 11:42:44 -04:00
|
|
|
)
|
2020-06-10 11:38:23 -04:00
|
|
|
role = ColoredLabelColumn()
|
2021-03-04 16:07:55 -05:00
|
|
|
tenant = TenantColumn()
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = VirtualMachine
|
2017-09-29 11:13:41 -04:00
|
|
|
fields = ('pk', 'name', 'status', 'cluster', 'role', 'tenant', 'vcpus', 'memory', 'disk')
|
2017-08-18 14:37:19 -04:00
|
|
|
|
|
|
|
|
2017-09-15 11:47:29 -04:00
|
|
|
class VirtualMachineDetailTable(VirtualMachineTable):
|
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-02-15 21:01:55 +10:30
|
|
|
if settings.PREFER_IPV4:
|
|
|
|
primary_ip = tables.Column(
|
|
|
|
linkify=True,
|
|
|
|
order_by=('primary_ip4', 'primary_ip6'),
|
|
|
|
verbose_name='IP Address'
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
primary_ip = tables.Column(
|
|
|
|
linkify=True,
|
|
|
|
order_by=('primary_ip6', 'primary_ip4'),
|
|
|
|
verbose_name='IP Address'
|
|
|
|
)
|
2020-05-06 14:42:51 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='virtualization:virtualmachine_list'
|
|
|
|
)
|
2017-09-15 11:47:29 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = VirtualMachine
|
2020-04-29 11:42:44 -04:00
|
|
|
fields = (
|
|
|
|
'pk', 'name', 'status', 'cluster', 'role', 'tenant', 'platform', 'vcpus', 'memory', 'disk', 'primary_ip4',
|
2020-05-06 14:42:51 -04:00
|
|
|
'primary_ip6', 'primary_ip', 'tags',
|
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):
|
2020-07-10 10:26:43 -04:00
|
|
|
pk = ToggleColumn()
|
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
|
|
|
|
)
|
2021-04-09 10:53:05 -04:00
|
|
|
parent = tables.Column(
|
|
|
|
linkify=True
|
|
|
|
)
|
2020-09-04 16:09:05 -04:00
|
|
|
tags = TagColumn(
|
|
|
|
url_name='virtualization:vminterface_list'
|
|
|
|
)
|
2017-08-18 14:37:19 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
2020-06-23 13:16:21 -04:00
|
|
|
model = VMInterface
|
2020-07-13 16:18:17 -04:00
|
|
|
fields = (
|
2021-04-09 10:53:05 -04:00
|
|
|
'pk', 'virtual_machine', 'name', 'enabled', 'parent', 'mac_address', 'mtu', 'mode', 'description', 'tags',
|
2020-11-19 09:45:01 -05:00
|
|
|
'ip_addresses', 'untagged_vlan', 'tagged_vlans',
|
2020-07-13 16:18:17 -04:00
|
|
|
)
|
2021-04-09 10:53:05 -04:00
|
|
|
default_columns = ('pk', 'virtual_machine', 'name', 'enabled', 'parent', 'description')
|
2020-10-16 17:01:55 -04:00
|
|
|
|
|
|
|
|
|
|
|
class VirtualMachineVMInterfaceTable(VMInterfaceTable):
|
|
|
|
actions = ButtonsColumn(
|
|
|
|
model=VMInterface,
|
|
|
|
buttons=('edit', 'delete'),
|
|
|
|
prepend_template=VMINTERFACE_BUTTONS
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = VMInterface
|
|
|
|
fields = (
|
|
|
|
'pk', 'name', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'tags', 'ip_addresses',
|
|
|
|
'untagged_vlan', 'tagged_vlans', 'actions',
|
|
|
|
)
|
2020-11-19 09:45:01 -05:00
|
|
|
default_columns = (
|
|
|
|
'pk', 'name', 'enabled', 'mac_address', 'mtu', 'mode', 'description', 'ip_addresses', 'actions',
|
|
|
|
)
|
2020-12-18 15:02:52 -05:00
|
|
|
row_attrs = {
|
|
|
|
'data-name': lambda record: record.name,
|
|
|
|
}
|