mirror of
https://opendev.org/openstack/python-heatclient.git
synced 2026-01-16 23:00:35 +00:00
OSC plugin for stack snapshot create
This change implements "openstack stack snapshot create" command Based from the existing heat commands: heat stack-snapshot Blueprint: heat-support-python-openstackclient Change-Id: I0a4dc70d9f0dd82129d5839acecf5c1822fc147c
This commit is contained in:
parent
7ee16eed9f
commit
89deaa3c3c
3 changed files with 87 additions and 1 deletions
|
|
@ -18,6 +18,7 @@ import six
|
|||
|
||||
from cliff import command
|
||||
from cliff import lister
|
||||
from cliff import show
|
||||
from openstackclient.common import exceptions as exc
|
||||
from openstackclient.common import utils
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ from openstackclient.i18n import _
|
|||
|
||||
|
||||
class ListSnapshot(lister.Lister):
|
||||
"""List stack snapshots"""
|
||||
"""List stack snapshots."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".ListSnapshot")
|
||||
|
||||
|
|
@ -134,3 +135,44 @@ class RestoreSnapshot(command.Command):
|
|||
'snapshot %(snapshot)s not found.') %
|
||||
{'stack': parsed_args.stack,
|
||||
'snapshot': parsed_args.snapshot})
|
||||
|
||||
|
||||
class CreateSnapshot(show.ShowOne):
|
||||
"""Create stack snapshot."""
|
||||
|
||||
log = logging.getLogger(__name__ + ".CreateSnapshot")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateSnapshot, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'stack',
|
||||
metavar='<stack>',
|
||||
help=_('Name or ID of stack')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help=_('Name of snapshot')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug('take_action(%s)' % parsed_args)
|
||||
heat_client = self.app.client_manager.orchestration
|
||||
|
||||
try:
|
||||
data = heat_client.stacks.snapshot(parsed_args.stack,
|
||||
parsed_args.name)
|
||||
except heat_exc.HTTPNotFound:
|
||||
raise exc.CommandError(_('Stack not found: %s')
|
||||
% parsed_args.stack)
|
||||
|
||||
columns = [
|
||||
'ID',
|
||||
'name',
|
||||
'status',
|
||||
'status_reason',
|
||||
'data',
|
||||
'creation_time'
|
||||
]
|
||||
return (columns, utils.get_dict_properties(data, columns))
|
||||
|
|
|
|||
|
|
@ -102,3 +102,46 @@ class TestRestoreSnapshot(TestStack):
|
|||
parsed_args)
|
||||
self.assertEqual('Stack my_stack or snapshot my_snapshot not found.',
|
||||
str(error))
|
||||
|
||||
|
||||
class TestSnapshotCreate(TestStack):
|
||||
get_response = {
|
||||
"status": "IN_PROGRESS",
|
||||
"name": "test_snapshot",
|
||||
"status_reason": None,
|
||||
"creation_time": "2015-11-09T04:35:38.534130",
|
||||
"data": None,
|
||||
"id": "108604fe-6d13-41b7-aa3a-79b6cf60c4ff"
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
super(TestSnapshotCreate, self).setUp()
|
||||
self.cmd = snapshot.CreateSnapshot(self.app, None)
|
||||
|
||||
def test_snapshot_create(self):
|
||||
arglist = ['my_stack', '--name', 'test_snapshot']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.stack_client.snapshot = mock.Mock(
|
||||
return_value=self.get_response)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.stack_client.snapshot.assert_called_with(
|
||||
'my_stack', 'test_snapshot')
|
||||
|
||||
def test_snapshot_create_no_name(self):
|
||||
arglist = ['my_stack']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.stack_client.snapshot = mock.Mock(
|
||||
return_value=self.get_response)
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.stack_client.snapshot.assert_called_with(
|
||||
'my_stack', None)
|
||||
|
||||
def test_snapshot_create_error(self):
|
||||
arglist = ['my_stack', '--name', 'test_snapshot']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.stack_client.snapshot = mock.Mock(
|
||||
side_effect=heat_exc.HTTPNotFound)
|
||||
self.assertRaises(
|
||||
exc.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ openstack.orchestration.v1 =
|
|||
stack_resource_signal = heatclient.osc.v1.resources:ResourceSignal
|
||||
stack_resume = heatclient.osc.v1.stack:ResumeStack
|
||||
stack_show = heatclient.osc.v1.stack:ShowStack
|
||||
stack_snapshot_create = heatclient.osc.v1.snapshot:CreateSnapshot
|
||||
stack_snapshot_list = heatclient.osc.v1.snapshot:ListSnapshot
|
||||
stack_snapshot_restore = heatclient.osc.v1.snapshot:RestoreSnapshot
|
||||
stack_snapshot_show = heatclient.osc.v1.snapshot:ShowSnapshot
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue