1 from django
.utils
.safestring
import mark_safe
3 from django_tables2
import (Table
, Column
, LinkColumn
, TemplateColumn
,
5 from django_tables2
.utils
import A
7 from ganeti_web
.templatetags
.webmgr_tags
import (render_storage
, render_os
,
10 from ganeti_web
.utilities
import hv_prettify
13 class BaseTable(Table
):
14 def __init__(self
, *args
, **kwargs
):
15 kwargs
['template'] = kwargs
.get("template", "table.html")
16 return super(BaseTable
, self
).__init
__(*args
, **kwargs
)
19 class BaseVMTable(BaseTable
):
21 status
= TemplateColumn(
22 template_name
="ganeti/virtual_machine/vmfield_status.html",
23 attrs
={"th": {"class": "status_indicator"}}
27 args
=[A("cluster.slug")],
28 accessor
="cluster.slug",
29 verbose_name
='cluster'
31 hostname
= LinkColumn(
33 kwargs
={"cluster_slug": A("cluster.slug"),
34 "instance": A("hostname")},
38 node
= Column(verbose_name
='node', accessor
="primary_node")
39 operating_system
= Column(verbose_name
='OS')
40 ram
= Column(verbose_name
='RAM')
41 disk_size
= Column(verbose_name
='disk space')
42 virtual_cpus
= Column(verbose_name
='vCPUs')
45 sequence
= ("status", "hostname", "cluster", "...")
46 order_by
= ("hostname")
47 empty_text
= "No Virtual Machines"
49 def render_disk_size(self
, value
):
50 return render_storage(value
)
52 def render_ram(self
, value
):
53 return render_storage(value
)
55 def render_operating_system(self
, value
):
56 return render_os(value
)
58 def render_node(self
, value
):
59 return abbreviate_fqdn(value
)
61 def render_owner(self
, value
):
62 url
= value
.get_absolute_url()
63 url_str
= '<a href="{}">{}</a>'
64 return mark_safe(url_str
.format(url
, value
))
67 class VMTable(BaseVMTable
):
69 sequence
= ("status", "hostname", "cluster", "...")
70 order_by
= ("hostname")
71 empty_text
= "No Virtual Machines"
74 class ClusterVMTable(BaseVMTable
):
76 exclude
= ("cluster",)
77 order_by
= ("hostname")
78 empty_text
= "This cluster has no Virtual Machines"
81 class NodeVMTable(BaseVMTable
):
83 exclude
= ("cluster", "node")
84 order_by
= ("hostname")
85 empty_text
= ("This node has no Virtual Machines "
86 "assigned to it as this role.")
89 class VMTemplateTable(BaseTable
):
91 template_name
= LinkColumn(
93 args
=[A("cluster.slug"), A("template_name")],
96 description
= Column()
99 args
=[A("cluster.slug")],
100 accessor
="cluster.slug",
101 verbose_name
="cluster"
103 os
= Column(verbose_name
='OS')
104 memory
= Column(verbose_name
='RAM')
105 disk_space
= Column()
106 vcpus
= Column(verbose_name
='vCPUs')
109 sequence
= ("template_name", "description", "cluster", "os", "memory",
110 "disk_space", "vcpus")
111 order_by
= ("template_name")
112 empty_text
= "No Templates"
114 def render_os(self
, value
):
115 return render_os(value
)
117 def render_memory(self
, value
):
118 return render_storage(value
)
120 def render_disk_space(self
, value
):
121 return render_storage(value
)
124 class ClusterTable(BaseTable
):
126 cluster
= LinkColumn(
130 verbose_name
='cluster'
132 description
= Column()
134 accessor
="info.software_version",
139 accessor
="info.default_hypervisor",
143 master_node
= LinkColumn(
145 kwargs
={"cluster_slug": A("slug"),
146 "host": A("info.master")},
147 accessor
="info.master",
151 nodes
= Column(accessor
="nodes.count", orderable
=False)
152 vms
= Column(accessor
="virtual_machines.count", verbose_name
='VMs',
156 empty_text
= "No Clusters"
157 sequence
= ("cluster", "description", "version", "hypervisor",
158 "master_node", "nodes", "vms")
159 order_by
= ("cluster")
161 def render_hypervisor(self
, value
):
162 return hv_prettify(value
)
165 class JobTable(BaseTable
):
168 args
=[A("cluster.slug"), A("job_id")]
170 cluster
= LinkColumn(
172 args
=[A("cluster.slug")],
173 accessor
="cluster.slug",
174 verbose_name
='cluster'
176 object = TemplateColumn(
177 template_name
="ganeti/overview/object_link.html",
179 orderable
=False # Cannot access generic fk to get obj name for sort
181 operation
= Column(accessor
="op", verbose_name
="operation")
182 # Extra space is because it doesn't like the word status for some reason.
183 status
= Column(verbose_name
="status ")
184 finished
= DateTimeColumn()
187 empty_text
= "No jobs"
188 order_by
= ("job_id")
190 def render_operation(self
, value
):
191 return format_job_op(value
)
194 class ClusterJobTable(JobTable
):
197 exclude
= ("cluster",)
198 empty_text
= "No jobs available for this cluster"