HOT template for cinder volume with or without volume_type

494 views Asked by At

I am trying to write a HOT template for Openstack volume, and need to have the volume_type as a parameter. I also need to support a case when the parameter is not given, and default to the Cinder default volume type.

First attempt was to pass null to the volume_type , hoping it would give the default volume type. However no matter what I pass (null, ~, default, "" ) , seems there is no way to get the default volume type.

type: OS::Cinder::Volume
properties:
  name: test
  size: 1
  volume_type: { if: ["voltype_given" , {get_param:[typename]} , null] }

Is there any way to get the default volume type , when you have the "volume_type" property defined?

Alternatively, is there any way to have the "volume_type" property itself behind a conditional? I tried several ways, but no luck. Something like:

type: OS::Cinder::Volume
properties:
  if: ["voltype_given" , [ volume_type: {get_param:[typename]} ] , ""]
  name: test
  size: 1

ERROR: TypeError: : resources.kk-test-vol: : 'If' object is not iterable

1

There are 1 answers

0
larsks On BEST ANSWER

Could you do something like this?

---
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