1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# Copyright 2012 OpenStack Foundation
# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.template.defaultfilters import title
from django import urls
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from keystoneclient import exceptions as keystone_exceptions
from horizon import tables
from horizon.utils import filters
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.instances import audit_tables
from openstack_dashboard.dashboards.project.instances \
import tables as project_tables
from openstack_dashboard import policy
from openstack_dashboard.views import get_url_with_pagination
class AdminEditInstance(project_tables.EditInstance):
url = "horizon:admin:instances:update"
class AdminConsoleLink(project_tables.ConsoleLink):
url = "horizon:admin:instances:detail"
class AdminLogLink(project_tables.LogLink):
url = "horizon:admin:instances:detail"
class RescueInstance(project_tables.RescueInstance):
url = "horizon:admin:instances:rescue"
class MigrateInstance(policy.PolicyTargetMixin, tables.BatchAction):
name = "migrate"
classes = ("btn-migrate",)
policy_rules = (("compute", "os_compute_api:os-migrate-server:migrate"),)
help_text = _("Migrating instances may cause some unrecoverable results.")
action_type = "danger"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Migrate Instance",
u"Migrate Instances",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Scheduled migration (pending confirmation) of Instance",
u"Scheduled migration (pending confirmation) of Instances",
count
)
def allowed(self, request, instance):
return ((instance.status in project_tables.ACTIVE_STATES or
instance.status == 'SHUTOFF') and
not project_tables.is_deleting(instance))
def action(self, request, obj_id):
api.nova.server_migrate(request, obj_id)
class LiveMigrateInstance(policy.PolicyTargetMixin,
tables.LinkAction):
name = "live_migrate"
verbose_name = _("Live Migrate Instance")
url = "horizon:admin:instances:live_migrate"
classes = ("ajax-modal", "btn-migrate")
policy_rules = (
("compute", "os_compute_api:os-migrate-server:migrate_live"),)
def allowed(self, request, instance):
return (instance.status in project_tables.ACTIVE_STATES and
not project_tables.is_deleting(instance))
class AdminUpdateRow(project_tables.UpdateRow):
def get_data(self, request, instance_id):
instance = super().get_data(request, instance_id)
try:
tenant = api.keystone.tenant_get(request,
instance.tenant_id,
admin=True)
instance.tenant_name = getattr(tenant, "name", instance.tenant_id)
except keystone_exceptions.NotFound:
instance.tenant_name = None
return instance
class AdminInstanceFilterAction(tables.FilterAction):
# Change default name of 'filter' to distinguish this one from the
# project instances table filter, since this is used as part of the
# session property used for persisting the filter.
name = "filter_admin_instances"
filter_type = "server"
filter_choices = (
('project', _("Project Name ="), True),
('tenant_id', _("Project ID ="), True),
('host', _("Host Name ="), True),
) + project_tables.INSTANCE_FILTER_CHOICES
def get_server_detail_link(obj, request):
return get_url_with_pagination(
request, AdminInstancesTable._meta.pagination_param,
AdminInstancesTable._meta.prev_pagination_param,
"horizon:admin:instances:detail", obj.id)
class AdminInstancesTable(tables.DataTable):
TASK_STATUS_CHOICES = (
(None, True),
("none", True)
)
STATUS_CHOICES = (
("active", True),
("shutoff", True),
("suspended", True),
("paused", True),
("error", False),
("rescue", True),
("shelved", True),
("shelved_offloaded", True),
)
tenant = tables.Column("tenant_name", verbose_name=_("Project"))
# NOTE(gabriel): Commenting out the user column because all we have
# is an ID, and correlating that at production scale using our current
# techniques isn't practical. It can be added back in when we have names
# returned in a practical manner by the API.
# user = tables.Column("user_id", verbose_name=_("User"))
host = tables.Column("OS-EXT-SRV-ATTR:host",
verbose_name=_("Host"),
classes=('nowrap-col',))
name = tables.WrappingColumn("name",
link=get_server_detail_link,
verbose_name=_("Name"))
image_name = tables.Column("image_name",
verbose_name=_("Image Name"))
ip = tables.Column(project_tables.get_ips,
verbose_name=_("IP Address"),
attrs={'data-type': "ip"})
flavor = tables.Column(project_tables.get_flavor,
sortable=False,
verbose_name=_("Flavor"))
status = tables.Column(
"status",
filters=(title, filters.replace_underscores),
verbose_name=_("Status"),
status=True,
status_choices=STATUS_CHOICES,
display_choices=project_tables.STATUS_DISPLAY_CHOICES)
locked = tables.Column(project_tables.render_locked,
verbose_name="",
sortable=False)
task = tables.Column("OS-EXT-STS:task_state",
verbose_name=_("Task"),
empty_value=project_tables.TASK_DISPLAY_NONE,
status=True,
status_choices=TASK_STATUS_CHOICES,
display_choices=project_tables.TASK_DISPLAY_CHOICES)
state = tables.Column(project_tables.get_power_state,
filters=(title, filters.replace_underscores),
verbose_name=_("Power State"),
display_choices=project_tables.POWER_DISPLAY_CHOICES)
created = tables.Column("created",
verbose_name=_("Age"),
filters=(filters.parse_isotime,
filters.timesince_sortable),
attrs={'data-type': 'timesince'})
class Meta(object):
name = "instances"
verbose_name = _("Instances")
status_columns = ["status", "task"]
table_actions = (project_tables.DeleteInstance,
AdminInstanceFilterAction)
row_class = AdminUpdateRow
row_actions = (RescueInstance,
project_tables.UnRescueInstance,
project_tables.ConfirmResize,
project_tables.RevertResize,
AdminEditInstance,
AdminConsoleLink,
AdminLogLink,
project_tables.CreateSnapshot,
project_tables.TogglePause,
project_tables.ToggleSuspend,
project_tables.ToggleShelve,
MigrateInstance,
LiveMigrateInstance,
project_tables.SoftRebootInstance,
project_tables.RebootInstance,
project_tables.RebuildInstance,
project_tables.StopInstance,
project_tables.DeleteInstance)
def user_link(datum):
return urls.reverse("horizon:identity:users:detail",
args=(datum.user_id,))
class AdminAuditTable(audit_tables.AuditTable):
user_id = tables.Column('user_id', verbose_name=_('User ID'),
link=user_link)
class Meta(object):
name = 'audit'
verbose_name = _('Instance Action List')
|