2017-08-04 17:02:52 -04:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import django_tables2 as tables
|
|
|
|
from django_tables2.utils import Accessor
|
|
|
|
|
2017-08-29 14:24:58 -04:00
|
|
|
from dcim.models import Interface
|
2017-08-04 17:02:52 -04:00
|
|
|
from utilities.tables import BaseTable, ToggleColumn
|
2017-08-29 14:24:58 -04:00
|
|
|
from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
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>
|
2017-08-04 17:02:52 -04:00
|
|
|
{% 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>
|
2017-08-04 17:02:52 -04:00
|
|
|
{% endif %}
|
|
|
|
"""
|
|
|
|
|
2017-09-14 14:35:34 -04:00
|
|
|
VIRTUALMACHINE_STATUS = """
|
|
|
|
<span class="label label-{{ record.get_status_class }}">{{ record.get_status_display }}</span>
|
|
|
|
"""
|
|
|
|
|
2017-09-15 11:47:29 -04:00
|
|
|
VIRTUALMACHINE_PRIMARY_IP = """
|
|
|
|
{{ record.primary_ip6.address.ip|default:"" }}
|
|
|
|
{% if record.primary_ip6 and record.primary_ip4 %}<br />{% endif %}
|
|
|
|
{{ record.primary_ip4.address.ip|default:"" }}
|
|
|
|
"""
|
|
|
|
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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()
|
2017-09-11 15:51:03 -04:00
|
|
|
device_count = tables.Column(verbose_name='Devices')
|
2017-08-04 17:02:52 -04:00
|
|
|
vm_count = tables.Column(verbose_name='VMs')
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = Cluster
|
2017-09-22 12:53:09 -04:00
|
|
|
fields = ('pk', 'name', 'type', 'group', 'site', 'device_count', 'vm_count')
|
2017-08-04 17:02:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Virtual machines
|
|
|
|
#
|
|
|
|
|
|
|
|
class VirtualMachineTable(BaseTable):
|
|
|
|
pk = ToggleColumn()
|
|
|
|
name = tables.LinkColumn()
|
2017-09-14 14:35:34 -04:00
|
|
|
status = tables.TemplateColumn(template_code=VIRTUALMACHINE_STATUS)
|
2017-08-16 17:00:17 -04:00
|
|
|
cluster = tables.LinkColumn('virtualization:cluster', args=[Accessor('cluster.pk')])
|
2017-08-04 17:02:52 -04:00
|
|
|
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')])
|
|
|
|
|
|
|
|
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):
|
|
|
|
primary_ip = tables.TemplateColumn(
|
|
|
|
orderable=False, verbose_name='IP Address', template_code=VIRTUALMACHINE_PRIMARY_IP
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
|
|
|
model = VirtualMachine
|
2017-09-29 11:13:41 -04:00
|
|
|
fields = ('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
|
|
|
|
#
|
|
|
|
|
2017-08-29 14:24:58 -04:00
|
|
|
class InterfaceTable(BaseTable):
|
2017-08-18 14:37:19 -04:00
|
|
|
|
|
|
|
class Meta(BaseTable.Meta):
|
2017-08-29 14:24:58 -04:00
|
|
|
model = Interface
|
2017-08-18 14:37:19 -04:00
|
|
|
fields = ('name', 'enabled', 'description')
|