diff --git a/openstack/orchestration/v1/_proxy.py b/openstack/orchestration/v1/_proxy.py index fec0a5a0..7db0bb6d 100644 --- a/openstack/orchestration/v1/_proxy.py +++ b/openstack/orchestration/v1/_proxy.py @@ -18,9 +18,13 @@ from openstack import proxy class Proxy(proxy.BaseProxy): - def create_stack(self, **attrs): + def create_stack(self, preview=False, **attrs): """Create a new stack from attributes + :param bool perview: When ``True``, returns + :class:`~openstack.orchestration.v1.stack.StackPreview` objects, + otherwise :class:`~openstack.orchestration.v1.stack.Stack`. + *Default: ``False``* :param dict attrs: Keyword arguments which will be used to create a :class:`~openstack.orchestration.v1.stack.Stack`, comprised of the properties on the Stack class. @@ -28,7 +32,8 @@ class Proxy(proxy.BaseProxy): :returns: The results of stack creation :rtype: :class:`~openstack.orchestration.v1.stack.Stack` """ - return self._create(_stack.Stack, **attrs) + stk = _stack.StackPreview if preview else _stack.Stack + return self._create(stk, **attrs) def find_stack(self, name_or_id, ignore_missing=True): """Find a single stack diff --git a/openstack/orchestration/v1/stack.py b/openstack/orchestration/v1/stack.py index c108a726..211852c6 100644 --- a/openstack/orchestration/v1/stack.py +++ b/openstack/orchestration/v1/stack.py @@ -107,3 +107,13 @@ class Stack(resource.Resource): raise exceptions.ResourceNotFound( "No stack found for %s" % name_or_id) return stk + + +class StackPreview(Stack): + base_path = '/stacks/preview' + + allow_create = True + allow_list = False + allow_retrieve = False + allow_update = False + allow_delete = False diff --git a/openstack/tests/unit/orchestration/v1/test_proxy.py b/openstack/tests/unit/orchestration/v1/test_proxy.py index 10cfb06f..a55cf0c3 100644 --- a/openstack/tests/unit/orchestration/v1/test_proxy.py +++ b/openstack/tests/unit/orchestration/v1/test_proxy.py @@ -28,6 +28,11 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase): def test_stack_create_attrs(self): self.verify_create(self.proxy.create_stack, stack.Stack) + def test_stack_preview_attrs(self): + method_kwargs = {"preview": True, "x": 1, "y": 2, "z": 3} + self.verify_create(self.proxy.create_stack, stack.StackPreview, + method_kwargs=method_kwargs) + def test_stack_find(self): self.verify_find(self.proxy.find_stack, stack.Stack) diff --git a/openstack/tests/unit/orchestration/v1/test_stack.py b/openstack/tests/unit/orchestration/v1/test_stack.py index b617bf84..e8332ac8 100644 --- a/openstack/tests/unit/orchestration/v1/test_stack.py +++ b/openstack/tests/unit/orchestration/v1/test_stack.py @@ -103,6 +103,25 @@ class TestStack(testtools.TestCase): self.assertEqual(FAKE_ID, sot.id) self.assertEqual(FAKE_NAME, sot.name) + def test_preview(self): + resp = mock.Mock() + resp.json = mock.Mock(return_value=FAKE_CREATE_RESPONSE) + sess = mock.Mock() + sess.post = mock.Mock(return_value=resp) + attrs = FAKE.copy() + sot = stack.StackPreview(attrs) + + sot.create(sess) + + url = '/stacks/preview' + body = sot._attrs.copy() + body.pop('id', None) + body.pop('name', None) + sess.post.assert_called_with(url, endpoint_filter=sot.service, + json=body) + self.assertEqual(FAKE_ID, sot.id) + self.assertEqual(FAKE_NAME, sot.name) + def test_update(self): # heat responds to update request with an 202 status code resp_update = mock.Mock()