Add "Suspend" and "Resume" actions to Stacks table

This patch set adds "Suspend Stack" and "Resume Stack" buttons
to Stacks table to provide user with a possibility to suspend
and resume stack, like it is already implemented in CLI.

Partially implements blueprint: heat-ui-improvement

Change-Id: I6ea8cb7f342fdd8fcfd124012aefc66d9d898410
This commit is contained in:
Tatiana Ovchinnikova 2015-01-23 15:18:24 +03:00
parent 78fc7e6ea6
commit b2c07ad64e
4 changed files with 86 additions and 2 deletions

View File

@ -130,6 +130,14 @@ def action_check(request, stack_id):
return heatclient(request).actions.check(stack_id)
def action_suspend(request, stack_id):
return heatclient(request).actions.suspend(stack_id)
def action_resume(request, stack_id):
return heatclient(request).actions.resume(stack_id)
def resource_types_list(request):
return heatclient(request).resource_types.list()

View File

@ -15,6 +15,8 @@
"cloudformation:DescribeStackResources": "rule:deny_stack_user",
"cloudformation:ListStackResources": "rule:deny_stack_user",
"cloudformation:CheckStack": "rule:deny_stack_user",
"cloudformation:SuspendStack": "rule:deny_stack_user",
"cloudformation:ResumeStack": "rule:deny_stack_user",
"cloudwatch:DeleteAlarms": "rule:deny_stack_user",
"cloudwatch:DescribeAlarmHistory": "rule:deny_stack_user",

View File

@ -61,6 +61,56 @@ class CheckStack(tables.BatchAction):
api.heat.action_check(request, stack_id)
class SuspendStack(tables.BatchAction):
name = "suspend"
verbose_name = _("Suspend Stack")
policy_rules = (("orchestration", "cloudformation:SuspendStack"),)
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Suspend Stack",
u"Suspend Stacks",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Suspended Stack",
u"Suspended Stacks",
count
)
def action(self, request, stack_id):
api.heat.action_suspend(request, stack_id)
class ResumeStack(tables.BatchAction):
name = "resume"
verbose_name = _("Resume Stack")
policy_rules = (("orchestration", "cloudformation:ResumeStack"),)
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Resume Stack",
u"Resume Stacks",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Resumed Stack",
u"Resumed Stacks",
count
)
def action(self, request, stack_id):
api.heat.action_resume(request, stack_id)
class ChangeStackTemplate(tables.LinkAction):
name = "edit"
verbose_name = _("Change Stack Template")
@ -152,8 +202,16 @@ class StacksTable(tables.DataTable):
pagination_param = 'stack_marker'
status_columns = ["status", ]
row_class = StacksUpdateRow
table_actions = (LaunchStack, CheckStack, DeleteStack,)
row_actions = (CheckStack, ChangeStackTemplate, DeleteStack,)
table_actions = (LaunchStack,
CheckStack,
SuspendStack,
ResumeStack,
DeleteStack,)
row_actions = (CheckStack,
SuspendStack,
ResumeStack,
ChangeStackTemplate,
DeleteStack,)
def get_resource_url(obj):

View File

@ -679,6 +679,22 @@ class StackTests(test.TestCase):
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_suspend_stack(self):
stack = self.stacks.first()
form_data = {"action": "stacks__suspend__%s" % stack.id}
res = self.client.post(INDEX_URL, form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
def test_resume_stack(self):
stack = self.stacks.first()
form_data = {"action": "stacks__resume__%s" % stack.id}
res = self.client.post(INDEX_URL, form_data)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
class TemplateFormTests(test.TestCase):