diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py index c8c466a8..8ddc6c8a 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -1844,6 +1844,32 @@ class ShellTestUserPass(ShellBase): resp = self.shell('snapshot-delete teststack/1 2') self.assertEqual("", resp) + @httpretty.activate + def test_stack_restore(self): + self.register_keystone_auth_fixture() + + stack_dict = {"stack": { + "id": "1", + "stack_name": "teststack", + "stack_status": 'CREATE_COMPLETE', + "creation_time": "2012-10-25T01:58:47Z" + }} + + resp = fakes.FakeHTTPResponse( + 204, + 'No Content', + {}, + None) + http.HTTPClient.json_request( + 'GET', '/stacks/teststack/1').AndReturn((resp, stack_dict)) + http.HTTPClient.json_request( + 'POST', + '/stacks/teststack/1/snapshots/2/restore').AndReturn((resp, {})) + + self.m.ReplayAll() + resp = self.shell('stack-restore teststack/1 2') + self.assertEqual("", resp) + @httpretty.activate def test_snapshot_list(self): self.register_keystone_auth_fixture() diff --git a/heatclient/tests/test_stacks.py b/heatclient/tests/test_stacks.py index 18dcec13..0d7b0c3a 100644 --- a/heatclient/tests/test_stacks.py +++ b/heatclient/tests/test_stacks.py @@ -125,6 +125,13 @@ class StackOperationsTest(testtools.TestCase): manager.snapshot_delete.assert_called_once_with( 'the_stack/abcd1234', 'snap1234') + def test_restore(self): + manager = MagicMock() + stack = mock_stack(manager, 'the_stack', 'abcd1234') + stack.restore('snap1234') + manager.restore.assert_called_once_with( + 'the_stack/abcd1234', 'snap1234') + def test_snapshot_list(self): manager = MagicMock() stack = mock_stack(manager, 'the_stack', 'abcd1234') diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 28b0d77b..ffeca26b 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -943,6 +943,19 @@ def do_snapshot_delete(hc, args): raise exc.CommandError('Stack or snapshot not found') +@utils.arg('id', metavar='', + help='Name or ID of the stack containing the snapshot.') +@utils.arg('snapshot', metavar='', + help='The ID of the snapshot to restore.') +def do_stack_restore(hc, args): + '''Restore a snapshot of a stack.''' + fields = {'stack_id': args.id, 'snapshot_id': args.snapshot} + try: + hc.stacks.restore(**fields) + except exc.HTTPNotFound: + raise exc.CommandError('Stack or snapshot not found') + + @utils.arg('id', metavar='', help='Name or ID of the stack containing the snapshots.') def do_snapshot_list(hc, args): diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py index 1f955b89..0524af89 100644 --- a/heatclient/v1/stacks.py +++ b/heatclient/v1/stacks.py @@ -47,6 +47,9 @@ class Stack(base.Resource): def snapshot_delete(self, snapshot_id): return self.manager.snapshot_delete(self.identifier, snapshot_id) + def restore(self, snapshot_id): + return self.manager.restore(self.identifier, snapshot_id) + def snapshot_list(self): return self.manager.snapshot_list(self.identifier) @@ -176,6 +179,14 @@ class StackManager(base.BaseManager): '/stacks/%s/snapshots/%s' % (stack.identifier, snapshot_id)) return body + def restore(self, stack_id, snapshot_id): + stack = self.get(stack_id) + resp, body = self.client.json_request( + 'POST', + '/stacks/%s/snapshots/%s/restore' % (stack.identifier, + snapshot_id)) + return body + def snapshot_list(self, stack_id): stack = self.get(stack_id) resp, body = self.client.json_request(