有或没有 volume_type 的煤渣体积热模板

HOT template for cinder volume with or without volume_type

我正在尝试为 Openstack 卷编写 HOT 模板,并且需要将 volume_type 作为参数。我还需要支持不给参数的情况,默认为Cinder默认卷类型

第一次尝试是将 null 传递给 volume_type ,希望它能给出默认的卷类型。但是无论我传递什么 (null, ~, default, "" ) ,似乎都无法获得默认卷类型。

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

错误:类型错误::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