Skip to content

Commit

Permalink
Enable "Start Instance" and "Shut Off Instance" buttons
Browse files Browse the repository at this point in the history
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
  • Loading branch information
0xDEC0DE committed Jun 12, 2013
1 parent ead6483 commit 87facce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
8 changes: 8 additions & 0 deletions openstack_dashboard/api/nova.py
Expand Up @@ -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))

Expand Down
36 changes: 33 additions & 3 deletions openstack_dashboard/dashboards/project/instances/tables.py
Expand Up @@ -413,6 +413,35 @@ def get_data(self, request, instance_id):
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}
Expand Down Expand Up @@ -514,9 +543,10 @@ class Meta:
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)

0 comments on commit 87facce

Please sign in to comment.