Add support for suspend/resume actions

Adds support for action-suspend and action-resume

blueprint stack-suspend-resume

Change-Id: If82e6b19756d3eae8a379141ae1f25565895e262
This commit is contained in:
Steven Hardy
2013-06-13 17:59:32 +01:00
parent 7774ac3217
commit 0a23b8bd55
3 changed files with 77 additions and 0 deletions

50
heatclient/v1/actions.py Normal file
View File

@@ -0,0 +1,50 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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 heatclient.common import base
from heatclient.v1 import stacks
DEFAULT_PAGE_SIZE = 20
class Action(base.Resource):
def __repr__(self):
return "<Action %s>" % self._info
def update(self, **fields):
self.manager.update(self, **fields)
def delete(self):
return self.manager.delete(self)
def data(self, **kwargs):
return self.manager.data(self, **kwargs)
class ActionManager(stacks.StackChildManager):
resource_class = Action
def suspend(self, stack_id):
"""Suspend a stack."""
body = {'suspend': None}
resp, body = self.api.json_request('POST',
'/stacks/%s/actions' % stack_id,
body=body)
def resume(self, stack_id):
"""Resume a stack."""
body = {'resume': None}
resp, body = self.api.json_request('POST',
'/stacks/%s/actions' % stack_id,
body=body)

View File

@@ -14,6 +14,7 @@
# under the License.
from heatclient.common import http
from heatclient.v1 import actions
from heatclient.v1 import events
from heatclient.v1 import resources
from heatclient.v1 import stacks
@@ -35,3 +36,4 @@ class Client(http.HTTPClient):
self.stacks = stacks.StackManager(self)
self.resources = resources.ResourceManager(self)
self.events = events.EventManager(self)
self.actions = actions.ActionManager(self)

View File

@@ -166,6 +166,31 @@ def do_stack_delete(hc, args):
do_stack_list(hc)
@utils.arg('id', metavar='<NAME or ID>',
help='Name or ID of stack to suspend.')
def do_action_suspend(hc, args):
'''Suspend the stack.'''
fields = {'stack_id': args.id}
try:
hc.actions.suspend(**fields)
except exc.HTTPNotFound:
raise exc.CommandError('Stack not found: %s' % args.id)
else:
do_stack_list(hc)
@utils.arg('id', metavar='<NAME or ID>', help='Name or ID of stack to resume.')
def do_action_resume(hc, args):
'''Resume the stack.'''
fields = {'stack_id': args.id}
try:
hc.actions.resume(**fields)
except exc.HTTPNotFound:
raise exc.CommandError('Stack not found: %s' % args.id)
else:
do_stack_list(hc)
@utils.arg('id', metavar='<NAME or ID>',
help='Name or ID of stack to describe.')
def do_describe(hc, args):