---
mistral_services:
  mistral-api:
    container_name: mistral_api
    group: mistral-api
    enabled: true
    image: "{{ mistral_api_image_full }}"
    volumes: "{{ mistral_api_default_volumes + mistral_api_extra_volumes }}"
    dimensions: "{{ mistral_api_dimensions }}"
    healthcheck: "{{ mistral_api_healthcheck }}"
    haproxy:
      mistral_api:
        enabled: "{{ enable_mistral }}"
        mode: "http"
        external: false
        port: "{{ mistral_api_port }}"
      mistral_api_external:
        enabled: "{{ enable_mistral }}"
        mode: "http"
        external: true
        port: "{{ mistral_api_port }}"
  mistral-engine:
    container_name: mistral_engine
    group: mistral-engine
    enabled: true
    image: "{{ mistral_engine_image_full }}"
    volumes: "{{ mistral_engine_default_volumes + mistral_engine_extra_volumes }}"
    dimensions: "{{ mistral_engine_dimensions }}"
    healthcheck: "{{ mistral_engine_healthcheck }}"
  mistral-event-engine:
    container_name: mistral_event_engine
    group: mistral-event-engine
    enabled: true
    image: "{{ mistral_event_engine_image_full }}"
    volumes: "{{ mistral_event_engine_default_volumes + mistral_event_engine_extra_volumes }}"
    dimensions: "{{ mistral_event_engine_dimensions }}"
    healthcheck: "{{ mistral_event_engine_healthcheck }}"
  mistral-executor:
    container_name: mistral_executor
    group: mistral-executor
    enabled: true
    image: "{{ mistral_executor_image_full }}"
    volumes: "{{ mistral_executor_default_volumes + mistral_executor_extra_volumes }}"
    dimensions: "{{ mistral_executor_dimensions }}"
    healthcheck: "{{ mistral_executor_healthcheck }}"

####################
# Config Validate
####################
mistral_config_validation:
  - generator: "/mistral/tools/config/config-generator.mistral.conf"
    config: "/etc/mistral/mistral.conf"

####################
# Database
####################
mistral_database_name: "mistral"
mistral_database_user: "{% if use_preconfigured_databases | bool and use_common_mariadb_user | bool %}{{ database_user }}{% else %}mistral{% endif %}"
mistral_database_address: "{{ database_address | put_address_in_context('url') }}:{{ database_port }}"

####################
# Database sharding
####################
mistral_database_shard_root_user: "{% if enable_proxysql | bool %}root_shard_{{ mistral_database_shard_id }}{% else %}{{ database_user }}{% endif %}"
mistral_database_shard_id: "{{ mariadb_default_database_shard_id | int }}"
mistral_database_shard:
  users:
    - user: "{{ mistral_database_user }}"
      password: "{{ mistral_database_password }}"
  rules:
    - schema: "{{ mistral_database_name }}"
      shard_id: "{{ mistral_database_shard_id }}"


####################
# Docker
####################
mistral_tag: "{{ openstack_tag }}"

mistral_engine_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/mistral-engine"
mistral_engine_tag: "{{ mistral_tag }}"
mistral_engine_image_full: "{{ mistral_engine_image }}:{{ mistral_engine_tag }}"

mistral_event_engine_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/mistral-event-engine"
mistral_event_engine_tag: "{{ mistral_tag }}"
mistral_event_engine_image_full: "{{ mistral_event_engine_image }}:{{ mistral_event_engine_tag }}"

mistral_executor_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/mistral-executor"
mistral_executor_tag: "{{ mistral_tag }}"
mistral_executor_image_full: "{{ mistral_executor_image }}:{{ mistral_executor_tag }}"

mistral_api_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/mistral-api"
mistral_api_tag: "{{ mistral_tag }}"
mistral_api_image_full: "{{ mistral_api_image }}:{{ mistral_api_tag }}"

mistral_engine_dimensions: "{{ default_container_dimensions }}"
mistral_event_engine_dimensions: "{{ default_container_dimensions }}"
mistral_executor_dimensions: "{{ default_container_dimensions }}"
mistral_api_dimensions: "{{ default_container_dimensions }}"

mistral_api_enable_healthchecks: "{{ enable_container_healthchecks }}"
mistral_api_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
mistral_api_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
mistral_api_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
mistral_api_healthcheck_test: ["CMD-SHELL", "healthcheck_curl http://{{ api_interface_address | put_address_in_context('url') }}:{{ mistral_api_port }}"]
mistral_api_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
mistral_api_healthcheck:
  interval: "{{ mistral_api_healthcheck_interval }}"
  retries: "{{ mistral_api_healthcheck_retries }}"
  start_period: "{{ mistral_api_healthcheck_start_period }}"
  test: "{% if mistral_api_enable_healthchecks | bool %}{{ mistral_api_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ mistral_api_healthcheck_timeout }}"

mistral_engine_enable_healthchecks: "{{ enable_container_healthchecks }}"
mistral_engine_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
mistral_engine_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
mistral_engine_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
mistral_engine_healthcheck_test: ["CMD-SHELL", "healthcheck_port mistral-server {{ om_rpc_port }}"]
mistral_engine_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
mistral_engine_healthcheck:
  interval: "{{ mistral_engine_healthcheck_interval }}"
  retries: "{{ mistral_engine_healthcheck_retries }}"
  start_period: "{{ mistral_engine_healthcheck_start_period }}"
  test: "{% if mistral_engine_enable_healthchecks | bool %}{{ mistral_engine_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ mistral_engine_healthcheck_timeout }}"

mistral_event_engine_enable_healthchecks: "{{ enable_container_healthchecks }}"
mistral_event_engine_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
mistral_event_engine_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
mistral_event_engine_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
mistral_event_engine_healthcheck_test: ["CMD-SHELL", "healthcheck_port mistral-server {{ om_rpc_port }}"]
mistral_event_engine_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
mistral_event_engine_healthcheck:
  interval: "{{ mistral_event_engine_healthcheck_interval }}"
  retries: "{{ mistral_event_engine_healthcheck_retries }}"
  start_period: "{{ mistral_event_engine_healthcheck_start_period }}"
  test: "{% if mistral_event_engine_enable_healthchecks | bool %}{{ mistral_event_engine_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ mistral_event_engine_healthcheck_timeout }}"

mistral_executor_enable_healthchecks: "{{ enable_container_healthchecks }}"
mistral_executor_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
mistral_executor_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
mistral_executor_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
mistral_executor_healthcheck_test: ["CMD-SHELL", "healthcheck_port mistral-server {{ om_rpc_port }}"]
mistral_executor_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
mistral_executor_healthcheck:
  interval: "{{ mistral_executor_healthcheck_interval }}"
  retries: "{{ mistral_executor_healthcheck_retries }}"
  start_period: "{{ mistral_executor_healthcheck_start_period }}"
  test: "{% if mistral_executor_enable_healthchecks | bool %}{{ mistral_executor_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ mistral_executor_healthcheck_timeout }}"

mistral_engine_default_volumes:
  - "{{ node_config_directory }}/mistral-engine/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ kolla_dev_repos_directory ~ '/mistral/mistral:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/mistral' if mistral_dev_mode | bool else '' }}"
mistral_event_engine_default_volumes:
  - "{{ node_config_directory }}/mistral-event-engine/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ kolla_dev_repos_directory ~ '/mistral/mistral:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/mistral' if mistral_dev_mode | bool else '' }}"
mistral_executor_default_volumes:
  - "{{ node_config_directory }}/mistral-executor/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ kolla_dev_repos_directory ~ '/mistral/mistral:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/mistral' if mistral_dev_mode | bool else '' }}"
mistral_api_default_volumes:
  - "{{ node_config_directory }}/mistral-api/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ kolla_dev_repos_directory ~ '/mistral/mistral:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/mistral' if mistral_dev_mode | bool else '' }}"

mistral_extra_volumes: "{{ default_extra_volumes }}"
mistral_engine_extra_volumes: "{{ mistral_extra_volumes }}"
mistral_event_engine_extra_volumes: "{{ mistral_extra_volumes }}"
mistral_executor_extra_volumes: "{{ mistral_extra_volumes }}"
mistral_api_extra_volumes: "{{ mistral_extra_volumes }}"

####################
# OpenStack
####################
mistral_internal_base_endpoint: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ mistral_api_port }}"

mistral_internal_endpoint: "{{ mistral_internal_base_endpoint }}/v2"
mistral_public_endpoint: "{{ public_protocol }}://{{ kolla_external_fqdn | put_address_in_context('url') }}:{{ mistral_api_port }}/v2"

mistral_logging_debug: "{{ openstack_logging_debug }}"

mistral_keystone_user: "mistral"

openstack_mistral_auth: "{{ openstack_auth }}"

mistral_api_workers: "{{ openstack_service_workers }}"

####################
# Kolla
####################
mistral_git_repository: "{{ kolla_dev_repos_git }}/{{ project_name }}"
mistral_dev_repos_pull: "{{ kolla_dev_repos_pull }}"
mistral_dev_mode: "{{ kolla_dev_mode }}"
mistral_source_version: "{{ kolla_source_version }}"


####################
# Notifications
####################
mistral_notification_topics:
  - name: notifications
    enabled: "{{ enable_ceilometer | bool }}"

mistral_enabled_notification_topics: "{{ mistral_notification_topics | selectattr('enabled', 'equalto', true) | list }}"

####################
# Keystone
####################
mistral_ks_services:
  - name: "mistral"
    type: "workflowv2"
    description: "Openstack Workflow"
    endpoints:
      - {'interface': 'internal', 'url': '{{ mistral_internal_endpoint }}'}
      - {'interface': 'public', 'url': '{{ mistral_public_endpoint }}'}

mistral_ks_users:
  - project: "service"
    user: "{{ mistral_keystone_user }}"
    password: "{{ mistral_keystone_password }}"
    role: "admin"
