{%- set resourceName = kolla_kubernetes.cli.args.resource_name %}

{%- if storage_provider == "host" %}
  {# Host storage provider uses storage on the local filesystem #}
  {%- if kolla_kubernetes.cli.args.action == "create" %}
    sudo mkdir -p /var/lib/kolla/volumes/{{ resourceName }}
  {%- elif kolla_kubernetes.cli.args.action == "delete" %}
    sudo rm -rf /var/lib/kolla/volumes/{{ resourceName }}
  {%- else %}
    {{ raise('Unknown action') }}
  {%- endif %}

{%- elif storage_provider == "ceph" %}
  {%- if kolla_kubernetes.cli.args.action == "create" %}
  ssh {{ storage_ceph.ssh_user -}} @ {{- storage_ceph.monitors[0] }} rbd create {{ storage_ceph.pool -}}/{{- resourceName }} --size "{{ kolla_kubernetes.template.vars.size_in_gb | int * 1024 }}" --image-feature layering
  {%- elif kolla_kubernetes.cli.args.action == "delete" %}
  ssh {{ storage_ceph.ssh_user -}} @ {{- storage_ceph.monitors[0] }} rbd rm {{ storage_ceph.pool -}}/{{- resourceName }}
  {%- else %}
    {{ raise('Unknown action') }}
  {%- endif %}

{%- elif storage_provider == "gce" %}
  {%- set type = 'pd-standard' %}
  {%- if kolla_kubernetes.cli.args.action == "create" %}
  gcloud compute disks create "{{ resourceName }}" --OAsize "{{ kolla_kubernetes.template.vars.size_in_gb }}" --type "{{ type }}"
  {%- elif kolla_kubernetes.cli.args.action == "delete" %}
  gcloud compute disks delete "{{ resourceName }}" -q
  {%- else %}
    {{ raise('Unknown action') }}
  {%- endif %}

{%- elif storage_provider == "aws" %}
  echo "# NO-OP for AWS, which supports Experimental Persistent Volume Provisioning"
  echo "# https://github.com/kubernetes/kubernetes/blob/release-1.2/examples/experimental/persistent-volume-provisioning/README.md"

{%- else %}
  {{ raise('Unknown storage_provider: check kolla-kubernetes.yml:storage_provider') }}

{%- endif %}
