1 from django_tables2
import (Table
, Column
, LinkColumn
, TemplateColumn
,
3 from django_tables2
.utils
import A
5 from ganeti_web
.templatetags
.webmgr_tags
import (render_storage
, render_os
,
8 from ganeti_web
.utilities
import hv_prettify
11 class BaseTable(Table
):
12 def __init__(self
, *args
, **kwargs
):
13 kwargs
['template'] = kwargs
.get("template", "table.html")
14 return super(BaseTable
, self
).__init
__(*args
, **kwargs
)
17 class BaseVMTable(BaseTable
):
19 status
= TemplateColumn(
20 template_name
="ganeti/virtual_machine/vmfield_status.html",
21 attrs
={"th": {"class": "status_indicator"}}
25 args
=[A("cluster.slug")],
26 accessor
="cluster.slug",
27 verbose_name
='cluster'
29 hostname
= LinkColumn(
31 kwargs
={"cluster_slug": A("cluster.slug"),
32 "instance": A("hostname")},
39 node
= Column(verbose_name
='node', accessor
="primary_node")
40 operating_system
= Column(verbose_name
='OS')
41 ram
= Column(verbose_name
='RAM')
42 disk_size
= Column(verbose_name
='disk space')
43 virtual_cpus
= Column(verbose_name
='vCPUs')
46 sequence
= ("status", "hostname", "cluster", "...")
47 order_by
= ("hostname")
48 empty_text
= "No Virtual Machines"
50 def render_disk_size(self
, value
):
51 return render_storage(value
)
53 def render_ram(self
, value
):
54 return render_storage(value
)
56 def render_operating_system(self
, value
):
57 return render_os(value
)
59 def render_node(self
, value
):
60 return abbreviate_fqdn(value
)
63 class VMTable(BaseVMTable
):
65 sequence
= ("status", "hostname", "cluster", "...")
66 order_by
= ("hostname")
67 empty_text
= "No Virtual Machines"
70 class ClusterVMTable(BaseVMTable
):
72 exclude
= ("cluster",)
73 order_by
= ("hostname")
74 empty_text
= "This cluster has no Virtual Machines"
77 class NodeVMTable(BaseVMTable
):
79 exclude
= ("cluster", "node")
80 order_by
= ("hostname")
81 empty_text
= ("This node has no Virtual Machines "
82 "assigned to it as this role.")
85 class VMTemplateTable(BaseTable
):
87 template_name
= LinkColumn(
89 args
=[A("cluster.slug"), A("template_name")],
92 description
= Column()
95 args
=[A("cluster.slug")],
96 accessor
="cluster.slug",
97 verbose_name
="cluster"
99 os
= Column(verbose_name
='OS')
100 memory
= Column(verbose_name
='RAM')
101 disk_space
= Column()
102 vcpus
= Column(verbose_name
='vCPUs')
105 sequence
= ("template_name", "description", "cluster", "os", "memory",
106 "disk_space", "vcpus")
107 order_by
= ("template_name")
108 empty_text
= "No Templates"
110 def render_os(self
, value
):
111 return render_os(value
)
113 def render_memory(self
, value
):
114 return render_storage(value
)
116 def render_disk_space(self
, value
):
117 return render_storage(value
)
120 class ClusterTable(BaseTable
):
122 cluster
= LinkColumn(
126 verbose_name
='cluster'
128 description
= Column()
130 accessor
="info.software_version",
135 accessor
="info.default_hypervisor",
139 master_node
= LinkColumn(
141 kwargs
={"cluster_slug": A("slug"),
142 "host": A("info.master")},
143 accessor
="info.master",
147 nodes
= Column(accessor
="nodes.count", orderable
=False)
148 vms
= Column(accessor
="virtual_machines.count", verbose_name
='VMs',
152 empty_text
= "No Clusters"
153 sequence
= ("cluster", "description", "version", "hypervisor",
154 "master_node", "nodes", "vms")
155 order_by
= ("cluster")
157 def render_hypervisor(self
, value
):
158 return hv_prettify(value
)
161 class JobTable(BaseTable
):
164 args
=[A("cluster.slug"), A("job_id")]
166 cluster
= LinkColumn(
168 args
=[A("cluster.slug")],
169 accessor
="cluster.slug",
170 verbose_name
='cluster'
172 object = TemplateColumn(
173 template_name
="ganeti/overview/object_link.html",
175 orderable
=False # Cannot access generic fk to get obj name for sort
177 operation
= Column(accessor
="op", verbose_name
="operation")
178 # Extra space is because it doesn't like the word status for some reason.
179 status
= Column(verbose_name
="status ")
180 finished
= DateTimeColumn()
183 empty_text
= "No jobs"
184 order_by
= ("job_id")
186 def render_operation(self
, value
):
187 return format_job_op(value
)
190 class ClusterJobTable(JobTable
):
193 exclude
= ("cluster",)
194 empty_text
= "No jobs available for this cluster"