diff --git a/doc/source/template_guide/hot_spec.rst b/doc/source/template_guide/hot_spec.rst index 59ef937db..e5ea8e2ba 100644 --- a/doc/source/template_guide/hot_spec.rst +++ b/doc/source/template_guide/hot_spec.rst @@ -438,11 +438,14 @@ For example: Pseudo Parameters ----------------- -In addition to parameters defined by a template author, Heat also creates two -parameters for every stack that allow referential access to the stack's name -and identifier. These parameters are named ``OS::stack_name`` for the stack -name and ``OS::stack_id`` for the stack identifier. These values are accessible -via the `get_param`_ intrinsic function just like user-defined parameters. +In addition to parameters defined by a template author, Heat also +creates three parameters for every stack that allow referential access +to the stack's name, stack's identifier and project's +identifier. These parameters are named ``OS::stack_name`` for the +stack name, ``OS::stack_id`` for the stack identifier and +``OS::project_id`` for the project identifier. These values are +accessible via the `get_param`_ intrinsic function just like +user-defined parameters. .. _hot_spec_resources: diff --git a/heat/engine/hot/parameters.py b/heat/engine/hot/parameters.py index 913b823fd..7aae32f37 100644 --- a/heat/engine/hot/parameters.py +++ b/heat/engine/hot/parameters.py @@ -111,9 +111,9 @@ class HOTParamSchema(parameters.Schema): class HOTParameters(parameters.Parameters): PSEUDO_PARAMETERS = ( - PARAM_STACK_ID, PARAM_STACK_NAME, PARAM_REGION + PARAM_STACK_ID, PARAM_STACK_NAME, PARAM_REGION, PARAM_PROJECT_ID ) = ( - 'OS::stack_id', 'OS::stack_name', 'OS::region' + 'OS::stack_id', 'OS::stack_name', 'OS::region', 'OS::project_id' ) def set_stack_id(self, stack_identifier): @@ -129,11 +129,16 @@ class HOTParameters(parameters.Parameters): def _pseudo_parameters(self, stack_identifier): stack_id = getattr(stack_identifier, 'stack_id', '') stack_name = getattr(stack_identifier, 'stack_name', '') + tenant = getattr(stack_identifier, 'tenant', '') yield parameters.Parameter( self.PARAM_STACK_ID, parameters.Schema(parameters.Schema.STRING, _('Stack ID'), default=str(stack_id))) + yield parameters.Parameter( + self.PARAM_PROJECT_ID, + parameters.Schema(parameters.Schema.STRING, _('Project ID'), + default=str(tenant))) if stack_name: yield parameters.Parameter( self.PARAM_STACK_NAME, diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 609e3cbb1..19f0618fc 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -1129,6 +1129,12 @@ class StackParametersTest(common.HeatTestCase): snippet={'properties': {'prop1': {'get_param': 'OS::stack_name'}}}, expected={'properties': {'prop1': 'test'}})), + ('pseudo_project_id', + dict(params={}, + snippet={'properties': {'prop1': {'get_param': + 'OS::project_id'}}}, + expected={'properties': + {'prop1': '9913ef0a-b8be-4b33-b574-9061441bd373'}})), ] @@ -1160,7 +1166,8 @@ class StackParametersTest(common.HeatTestCase): tmpl = parser.Template(self.props_template) env = environment.Environment(self.params) stack = parser.Stack(utils.dummy_context(), 'test', tmpl, env, - stack_id='1ba8c334-2297-4312-8c7c-43763a988ced') + stack_id='1ba8c334-2297-4312-8c7c-43763a988ced', + tenant_id='9913ef0a-b8be-4b33-b574-9061441bd373') self.assertEqual(self.expected, function.resolve(tmpl.parse(stack, self.snippet)))