Add Server Reboot/Soft Reboot actions

Change-Id: Id71ef311cd8c515af0f1052f3793bf4a95a14c2c
This commit is contained in:
Zhenguo Niu 2017-05-11 16:32:25 +08:00
parent b05a0bc9fb
commit 60c1be6150
2 changed files with 81 additions and 2 deletions

View File

@ -102,6 +102,20 @@ def server_stop(request, server_id):
return server_manager.set_power_state(server_id, 'off')
def server_reboot(request, server_id, soft_reboot=False):
"""Reboot a server.
:param request: HTTP request.
:param server_id: The uuid of the server.
"""
server_manager = moganclient(request).server
if soft_reboot:
target = 'soft_reboot'
else:
target = 'reboot'
return server_manager.set_power_state(server_id, target)
def keypair_list(request):
"""Retrieve a list of keypairs.

View File

@ -143,6 +143,70 @@ class StopServer(tables.BatchAction):
mogan.server_stop(request, obj_id)
class RebootServer(tables.BatchAction):
name = "reboot"
classes = ('btn-reboot',)
help_text = _("Restarted servers will lose any data"
" not saved in persistent storage.")
action_type = "danger"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Hard Reboot Server",
u"Hard Reboot Servers",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Hard Rebooted Server",
u"Hard Rebooted Servers",
count
)
def allowed(self, request, server=None):
if server is not None:
return ((server.status.lower() == 'active'
or server.status.lower() == 'stopped')
and not (server.status.lower() == 'deleting'))
else:
return True
def action(self, request, obj_id):
mogan.server_reboot(request, obj_id, soft_reboot=False)
class SoftRebootServer(RebootServer):
name = "soft_reboot"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Soft Reboot Server",
u"Soft Reboot Servers",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Soft Rebooted Server",
u"Soft Rebooted Servers",
count
)
def action(self, request, obj_id):
mogan.server_reboot(request, obj_id, soft_reboot=True)
def allowed(self, request, server=None):
if server is not None:
return server.status.lower() == 'active'
else:
return True
class UpdateRow(tables.Row):
ajax = True
@ -254,6 +318,7 @@ class ServersTable(tables.DataTable):
verbose_name = _("Servers")
status_columns = ["status"]
row_class = UpdateRow
table_actions_menu = (StartServer, StopServer)
table_actions_menu = (StartServer, StopServer, SoftRebootServer)
table_actions = (LaunchLink, DeleteServer, ServersFilterAction)
row_actions = (StartServer, StopServer, DeleteServer,)
row_actions = (StartServer, StopServer, SoftRebootServer,
RebootServer, DeleteServer)