Added pseudo param OS::project_id

project id can be used to identify or tag which project the resources
belong to. The project id can be found in cfn pseudo param AWS::StackId, but when we
switch to hot, OS::stack_id is a pure stack id, no project info in it. So
we add OS::project_id to meet the similar scenario requirements.

Change-Id: I3db9db7c59cfa0ff3005a97cd0cb7962928598ab
This commit is contained in:
JUNJIE NAN 2014-12-05 22:43:41 +08:00
parent 1bc2e6c35c
commit 7fbdb1260a
3 changed files with 23 additions and 8 deletions

View File

@ -438,11 +438,14 @@ For example:
Pseudo Parameters Pseudo Parameters
----------------- -----------------
In addition to parameters defined by a template author, Heat also creates two In addition to parameters defined by a template author, Heat also
parameters for every stack that allow referential access to the stack's name creates three parameters for every stack that allow referential access
and identifier. These parameters are named ``OS::stack_name`` for the stack to the stack's name, stack's identifier and project's
name and ``OS::stack_id`` for the stack identifier. These values are accessible identifier. These parameters are named ``OS::stack_name`` for the
via the `get_param`_ intrinsic function just like user-defined parameters. 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: .. _hot_spec_resources:

View File

@ -111,9 +111,9 @@ class HOTParamSchema(parameters.Schema):
class HOTParameters(parameters.Parameters): class HOTParameters(parameters.Parameters):
PSEUDO_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): def set_stack_id(self, stack_identifier):
@ -129,11 +129,16 @@ class HOTParameters(parameters.Parameters):
def _pseudo_parameters(self, stack_identifier): def _pseudo_parameters(self, stack_identifier):
stack_id = getattr(stack_identifier, 'stack_id', '') stack_id = getattr(stack_identifier, 'stack_id', '')
stack_name = getattr(stack_identifier, 'stack_name', '') stack_name = getattr(stack_identifier, 'stack_name', '')
tenant = getattr(stack_identifier, 'tenant', '')
yield parameters.Parameter( yield parameters.Parameter(
self.PARAM_STACK_ID, self.PARAM_STACK_ID,
parameters.Schema(parameters.Schema.STRING, _('Stack ID'), parameters.Schema(parameters.Schema.STRING, _('Stack ID'),
default=str(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: if stack_name:
yield parameters.Parameter( yield parameters.Parameter(
self.PARAM_STACK_NAME, self.PARAM_STACK_NAME,

View File

@ -1129,6 +1129,12 @@ class StackParametersTest(common.HeatTestCase):
snippet={'properties': {'prop1': {'get_param': snippet={'properties': {'prop1': {'get_param':
'OS::stack_name'}}}, 'OS::stack_name'}}},
expected={'properties': {'prop1': 'test'}})), 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) tmpl = parser.Template(self.props_template)
env = environment.Environment(self.params) env = environment.Environment(self.params)
stack = parser.Stack(utils.dummy_context(), 'test', tmpl, env, 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, self.assertEqual(self.expected,
function.resolve(tmpl.parse(stack, self.snippet))) function.resolve(tmpl.parse(stack, self.snippet)))