---
- name: Restart cinder-api container
  vars:
    service_name: "cinder-api"
    service: "{{ cinder_services[service_name] }}"
  become: true
  kolla_docker:
    action: "recreate_or_restart_container"
    common_options: "{{ docker_common_options }}"
    name: "{{ service.container_name }}"
    image: "{{ service.image }}"
    volumes: "{{ service.volumes | reject('equalto', '') | list }}"
    dimensions: "{{ service.dimensions }}"
    healthcheck: "{{ service.healthcheck | default(omit) }}"
  when:
    - kolla_action != "config"

- name: Restart cinder-scheduler container
  vars:
    service_name: "cinder-scheduler"
    service: "{{ cinder_services[service_name] }}"
  become: true
  kolla_docker:
    action: "recreate_or_restart_container"
    common_options: "{{ docker_common_options }}"
    name: "{{ service.container_name }}"
    image: "{{ service.image }}"
    volumes: "{{ service.volumes | reject('equalto', '') | list }}"
    dimensions: "{{ service.dimensions }}"
    healthcheck: "{{ service.healthcheck | default(omit) }}"
  when:
    - kolla_action != "config"

- name: Restart cinder-volume container
  vars:
    service_name: "cinder-volume"
    service: "{{ cinder_services[service_name] }}"
  become: true
  kolla_docker:
    action: "recreate_or_restart_container"
    common_options: "{{ docker_common_options }}"
    name: "{{ service.container_name }}"
    image: "{{ service.image }}"
    privileged: "{{ service.privileged | default(False) }}"
    ipc_mode: "{{ service.ipc_mode | default('') }}"
    tmpfs: "{{ service.tmpfs | default(omit) }}"
    volumes: "{{ service.volumes | reject('equalto', '') | list }}"
    dimensions: "{{ service.dimensions }}"
    healthcheck: "{{ service.healthcheck | default(omit) }}"
  when:
    - kolla_action != "config"

- name: Restart cinder-backup container
  vars:
    service_name: "cinder-backup"
    service: "{{ cinder_services[service_name] }}"
  become: true
  kolla_docker:
    action: "recreate_or_restart_container"
    common_options: "{{ docker_common_options }}"
    name: "{{ service.container_name }}"
    image: "{{ service.image }}"
    privileged: "{{ service.privileged | default(False) }}"
    volumes: "{{ service.volumes | reject('equalto', '') | list }}"
    dimensions: "{{ service.dimensions }}"
    healthcheck: "{{ service.healthcheck | default(omit) }}"
  when:
    - kolla_action != "config"

# NOTE(mgoddard): After upgrading cinder, services will have an RPC version cap
# in place.  We need to restart all services in order to allow them to use the
# latest RPC version. Ideally, there would be a way to check whether all cinder
# services are using the latest version, but currently there is not. Instead,
# wait a short time for all cinder services to update the version of their
# service in the database.  This seems to take around 10 seconds, but the
# default is 30 to allow room for slowness.

- name: Wait for cinder services to update service versions
  pause:
    seconds: "{{ cinder_rpc_version_startup_delay }}"
  run_once: true
  when:
    - kolla_action == 'upgrade'
  listen:
    - Restart cinder-api container
    - Restart cinder-scheduler container
    - Restart cinder-volume container
    - Restart cinder-backup container
