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 BaseVMTable(Table
):
13 status
= TemplateColumn(
14 template_name
="ganeti/virtual_machine/vmfield_status.html",
15 attrs
={"th": {"class": "status_indicator"}}
19 args
=[A("cluster.slug")],
20 accessor
="cluster.slug",
21 verbose_name
='cluster'
23 hostname
= LinkColumn(
25 kwargs
={"cluster_slug": A("cluster.slug"),
26 "instance": A("hostname")},
33 node
= Column(verbose_name
='node', accessor
="primary_node")
34 operating_system
= Column(verbose_name
='OS')
35 ram
= Column(verbose_name
='RAM')
36 disk_size
= Column(verbose_name
='disk space')
37 virtual_cpus
= Column(verbose_name
='vCPUs')
40 sequence
= ("status", "hostname", "cluster", "...")
41 order_by
= ("hostname")
42 empty_text
= "No Virtual Machines"
44 def __init__(self
, *args
, **kwargs
):
45 self
.template
= "table.html"
46 return super(BaseVMTable
, self
).__init
__(*args
, **kwargs
)
48 def render_disk_size(self
, value
):
49 return render_storage(value
)
51 def render_ram(self
, value
):
52 return render_storage(value
)
54 def render_operating_system(self
, value
):
55 return render_os(value
)
57 def render_node(self
, value
):
58 return abbreviate_fqdn(value
)
61 class VMTable(BaseVMTable
):
63 sequence
= ("status", "hostname", "cluster", "...")
64 order_by
= ("hostname")
65 empty_text
= "No Virtual Machines"
68 class ClusterVMTable(BaseVMTable
):
70 exclude
= ("cluster",)
71 order_by
= ("hostname")
72 empty_text
= "This cluster has no Virtual Machines"
75 class NodeVMTable(BaseVMTable
):
77 exclude
= ("cluster", "node")
78 order_by
= ("hostname")
79 empty_text
= ("This node has no Virtual Machines "
80 "assigned to it as this role.")
83 class VMTemplateTable(Table
):
85 template_name
= LinkColumn(
87 args
=[A("cluster.slug"), A("template_name")],
90 description
= Column()
93 args
=[A("cluster.slug")],
94 accessor
="cluster.slug",
95 verbose_name
="cluster"
97 os
= Column(verbose_name
='OS')
98 memory
= Column(verbose_name
='RAM')
100 vcpus
= Column(verbose_name
='vCPUs')
103 sequence
= ("template_name", "description", "cluster", "os", "memory",
104 "disk_space", "vcpus")
105 order_by
= ("template_name")
106 empty_text
= "No Templates"
108 def render_os(self
, value
):
109 return render_os(value
)
111 def render_memory(self
, value
):
112 return render_storage(value
)
114 def render_disk_space(self
, value
):
115 return render_storage(value
)
118 class ClusterTable(Table
):
120 cluster
= LinkColumn(
124 verbose_name
='cluster'
126 description
= Column()
128 accessor
="info.software_version",
133 accessor
="info.default_hypervisor",
137 master_node
= LinkColumn(
139 kwargs
={"cluster_slug": A("slug"),
140 "host": A("info.master")},
141 accessor
="info.master",
145 nodes
= Column(accessor
="nodes.count", orderable
=False)
146 vms
= Column(accessor
="virtual_machines.count", verbose_name
='VMs',
150 empty_text
= "No Clusters"
151 sequence
= ("cluster", "description", "version", "hypervisor",
152 "master_node", "nodes", "vms")
153 order_by
= ("cluster")
155 def render_hypervisor(self
, value
):
156 return hv_prettify(value
)
159 class JobTable(Table
):
162 args
=[A("cluster.slug"), A("job_id")]
164 cluster
= LinkColumn(
166 args
=[A("cluster.slug")],
167 accessor
="cluster.slug",
168 verbose_name
='cluster'
170 object = TemplateColumn(
171 template_name
="ganeti/overview/object_link.html",
173 orderable
=False # Cannot access generic fk to get obj name for sort
175 operation
= Column(accessor
="op", verbose_name
="operation")
176 # Extra space is because it doesn't like the word status for some reason.
177 status
= Column(verbose_name
="status ")
178 finished
= DateTimeColumn()
181 empty_text
= "No jobs"
182 order_by
= ("job_id")
184 def render_operation(self
, value
):
185 return format_job_op(value
)
188 class ClusterJobTable(JobTable
):
191 exclude
= ("cluster",)
192 empty_text
= "No jobs available for this cluster"