Enable "Start Instance" and "Shut Off Instance" buttons

Now that the shutdown and start actions in the nova-api are sane
we'd like to add support for these actions to Horizon.

Fixes Bug: 1190402
Change-Id: I1dffff3850e3fd45e766836600f6c04ebb2f3944
This commit is contained in:
Nicolas Simonds 2013-06-12 16:12:36 -07:00
parent ead648382a
commit 87facce323
2 changed files with 41 additions and 3 deletions

View File

@ -475,6 +475,14 @@ def server_revert_resize(request, instance_id):
novaclient(request).servers.revert_resize(instance_id)
def server_start(request, instance_id):
novaclient(request).servers.start(instance_id)
def server_stop(request, instance_id):
novaclient(request).servers.stop(instance_id)
def tenant_quota_get(request, tenant_id):
return QuotaSet(novaclient(request).quotas.get(tenant_id))

View File

@ -413,6 +413,35 @@ class UpdateRow(tables.Row):
return instance
class StartInstance(tables.BatchAction):
name = "start"
action_present = _("Start")
action_past = _("Started")
data_type_singular = _("Instance")
data_type_plural = _("Instances")
def allowed(self, request, instance):
return instance.status in ("SHUTDOWN", "SHUTOFF", "CRASHED")
def action(self, request, obj_id):
api.nova.server_start(request, obj_id)
class StopInstance(tables.BatchAction):
name = "stop"
action_present = _("Shut Off")
action_past = _("Shut Off")
data_type_singular = _("Instance")
data_type_plural = _("Instances")
classes = ('btn-danger',)
def allowed(self, request, instance):
return get_power_state(instance) in ("RUNNING", "PAUSED", "SUSPENDED")
def action(self, request, obj_id):
api.nova.server_stop(request, obj_id)
def get_ips(instance):
template_name = 'project/instances/_instance_ips.html'
context = {"instance": instance}
@ -514,9 +543,10 @@ class InstancesTable(tables.DataTable):
status_columns = ["status", "task"]
row_class = UpdateRow
table_actions = (LaunchLink, TerminateInstance, InstancesFilterAction)
row_actions = (ConfirmResize, RevertResize, CreateSnapshot,
SimpleAssociateIP, AssociateIP,
row_actions = (StartInstance, ConfirmResize, RevertResize,
CreateSnapshot, SimpleAssociateIP, AssociateIP,
SimpleDisassociateIP, EditInstance,
EditInstanceSecurityGroups, ConsoleLink, LogLink,
TogglePause, ToggleSuspend, ResizeLink,
SoftRebootInstance, RebootInstance, TerminateInstance)
SoftRebootInstance, RebootInstance, StopInstance,
TerminateInstance)