1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

97 lines
2.4 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
import django_tables2 as tables
from django_tables2.utils import Accessor
from utilities.tables import BaseTable, ToggleColumn
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterface
CLUSTERTYPE_ACTIONS = """
{% if perms.virtualization.change_clustertype %}
2017-08-08 16:33:34 -04:00
<a href="{% url 'virtualization:clustertype_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
CLUSTERGROUP_ACTIONS = """
{% if perms.virtualization.change_clustergroup %}
2017-08-08 16:33:34 -04:00
<a href="{% url 'virtualization:clustergroup_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
{% endif %}
"""
#
# Cluster types
#
class ClusterTypeTable(BaseTable):
pk = ToggleColumn()
cluster_count = tables.Column(verbose_name='Clusters')
actions = tables.TemplateColumn(
template_code=CLUSTERTYPE_ACTIONS,
attrs={'td': {'class': 'text-right'}},
verbose_name=''
)
class Meta(BaseTable.Meta):
model = ClusterType
fields = ('pk', 'name', 'cluster_count', 'actions')
#
# Cluster groups
#
class ClusterGroupTable(BaseTable):
pk = ToggleColumn()
cluster_count = tables.Column(verbose_name='Clusters')
actions = tables.TemplateColumn(
template_code=CLUSTERGROUP_ACTIONS,
attrs={'td': {'class': 'text-right'}},
verbose_name=''
)
class Meta(BaseTable.Meta):
model = ClusterGroup
fields = ('pk', 'name', 'cluster_count', 'actions')
#
# Clusters
#
class ClusterTable(BaseTable):
pk = ToggleColumn()
name = tables.LinkColumn()
vm_count = tables.Column(verbose_name='VMs')
class Meta(BaseTable.Meta):
model = Cluster
fields = ('pk', 'name', 'type', 'group', 'vm_count')
#
# Virtual machines
#
class VirtualMachineTable(BaseTable):
pk = ToggleColumn()
name = tables.LinkColumn()
2017-08-16 17:00:17 -04:00
cluster = tables.LinkColumn('virtualization:cluster', args=[Accessor('cluster.pk')])
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')])
class Meta(BaseTable.Meta):
model = VirtualMachine
2017-08-16 17:00:17 -04:00
fields = ('pk', 'name', 'cluster', 'tenant', 'vcpus', 'memory', 'disk')
2017-08-18 14:37:19 -04:00
#
# VM components
#
class VMInterfaceTable(BaseTable):
class Meta(BaseTable.Meta):
model = VMInterface
fields = ('name', 'enabled', 'description')