问题描述
我正在尝试为Openstack卷编写HOT模板,并且需要具有volume_type作为参数。我还需要支持未提供参数且默认为Cinder默认卷类型的情况。
第一次尝试是将null传递给volume_type,希望它将提供默认的卷类型。但是,无论我通过什么(null,〜,默认值““”),似乎都无法获取默认的卷类型。
type: OS::Cinder::Volume
properties:
name: test
size: 1
volume_type: { if: ["voltype_given",{get_param:[typename]},null] }
定义了“ volume_type”属性后,有什么方法可以获取默认的卷类型?
或者,是否有任何方法可以将“ volume_type”属性本身置于条件后面?我尝试了几种方法,但是没有运气。像这样:
type: OS::Cinder::Volume
properties:
if: ["voltype_given",[ volume_type: {get_param:[typename]} ],""]
name: test
size: 1
错误:TypeError :: resources.kk-test-vol ::“ If”对象不可迭代
解决方法
你能做这样的事吗?
---
parameters:
typename:
type: string
conditions:
use_default_type: {equals: [{get_param: typename},'']}
resources:
MyVolumeWithDefault:
condition: use_default_type
type: OS::Cinder::Volume
properties:
name: test
size: 1
MyVolumeWithExplicit:
condition: {not: use_default_type}
type: OS::Cinder::Volume
properties:
name: test
size: 1
volume_type: {get_param: typename}
# e.g. if you need to refer to the volume from another resource
MyVolumeAttachment:
type: OS::Cinder::VolumeAttachment
properties:
instance_uid: some-instance-uuid
volume_id:
if:
- use_default_type
- get_resource: MyVolumeWithDefault
- get_resource: MyVolumeWithExplicit