---
watcher_services:
  watcher-api:
    container_name: watcher_api
    group: watcher-api
    enabled: true
    image: "{{ watcher_api_image_full }}"
    volumes: "{{ watcher_api_default_volumes + watcher_api_extra_volumes }}"
    dimensions: "{{ watcher_api_dimensions }}"
    healthcheck: "{{ watcher_api_healthcheck }}"
    haproxy:
      watcher_api:
        enabled: "{{ enable_watcher }}"
        mode: "http"
        external: false
        port: "{{ watcher_api_port }}"
        listen_port: "{{ watcher_api_listen_port }}"
        backend_http_extra:
          - "option httpchk GET /"
      watcher_api_external:
        enabled: "{{ enable_watcher }}"
        mode: "http"
        external: true
        external_fqdn: "{{ watcher_external_fqdn }}"
        port: "{{ watcher_api_public_port }}"
        listen_port: "{{ watcher_api_listen_port }}"
        backend_http_extra:
          - "option httpchk GET /"
  watcher-applier:
    container_name: watcher_applier
    group: watcher-applier
    enabled: true
    image: "{{ watcher_applier_image_full }}"
    volumes: "{{ watcher_applier_default_volumes + watcher_applier_extra_volumes }}"
    dimensions: "{{ watcher_applier_dimensions }}"
    healthcheck: "{{ watcher_applier_healthcheck }}"
  watcher-engine:
    container_name: watcher_engine
    group: watcher-engine
    enabled: true
    image: "{{ watcher_engine_image_full }}"
    volumes: "{{ watcher_engine_default_volumes + watcher_engine_extra_volumes }}"
    dimensions: "{{ watcher_engine_dimensions }}"
    healthcheck: "{{ watcher_engine_healthcheck }}"

####################
# Config Validate
####################
watcher_config_validation:
  - generator: "/watcher/etc/watcher/oslo-config-generator/watcher.conf"
    config: "/etc/watcher/watcher.conf"

####################
# Database
####################
watcher_database_name: "watcher"
watcher_database_user: "{% if use_preconfigured_databases | bool and use_common_mariadb_user | bool %}{{ database_user }}{% else %}watcher{% endif %}"
watcher_database_address: "{{ database_address | put_address_in_context('url') }}:{{ database_port }}"

####################
# Database sharding
####################
watcher_database_shard_root_user: "{% if enable_proxysql | bool %}root_shard_{{ watcher_database_shard_id }}{% else %}{{ database_user }}{% endif %}"
watcher_database_shard_id: "{{ mariadb_default_database_shard_id | int }}"
watcher_database_shard:
  users:
    - user: "{{ watcher_database_user }}"
      password: "{{ watcher_database_password }}"
  rules:
    - schema: "{{ watcher_database_name }}"
      shard_id: "{{ watcher_database_shard_id }}"


####################
# Docker
####################
watcher_tag: "{{ openstack_tag }}"

watcher_engine_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ docker_image_name_prefix }}watcher-engine"
watcher_engine_tag: "{{ watcher_tag }}"
watcher_engine_image_full: "{{ watcher_engine_image }}:{{ watcher_engine_tag }}"

watcher_api_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ docker_image_name_prefix }}watcher-api"
watcher_api_tag: "{{ watcher_tag }}"
watcher_api_image_full: "{{ watcher_api_image }}:{{ watcher_api_tag }}"

watcher_applier_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ docker_image_name_prefix }}watcher-applier"
watcher_applier_tag: "{{ watcher_tag }}"
watcher_applier_image_full: "{{ watcher_applier_image }}:{{ watcher_applier_tag }}"

watcher_api_dimensions: "{{ default_container_dimensions }}"
watcher_applier_dimensions: "{{ default_container_dimensions }}"
watcher_engine_dimensions: "{{ default_container_dimensions }}"

watcher_api_enable_healthchecks: "{{ enable_container_healthchecks }}"
watcher_api_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
watcher_api_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
watcher_api_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
watcher_api_healthcheck_test: ["CMD-SHELL", "healthcheck_curl http://{{ api_interface_address | put_address_in_context('url') }}:{{ watcher_api_port }}"]
watcher_api_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
watcher_api_healthcheck:
  interval: "{{ watcher_api_healthcheck_interval }}"
  retries: "{{ watcher_api_healthcheck_retries }}"
  start_period: "{{ watcher_api_healthcheck_start_period }}"
  test: "{% if watcher_api_enable_healthchecks | bool %}{{ watcher_api_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ watcher_api_healthcheck_timeout }}"

watcher_applier_enable_healthchecks: "{{ enable_container_healthchecks }}"
watcher_applier_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
watcher_applier_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
watcher_applier_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
watcher_applier_healthcheck_test: ["CMD-SHELL", "healthcheck_port watcher-applier {{ om_rpc_port }}"]
watcher_applier_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
watcher_applier_healthcheck:
  interval: "{{ watcher_applier_healthcheck_interval }}"
  retries: "{{ watcher_applier_healthcheck_retries }}"
  start_period: "{{ watcher_applier_healthcheck_start_period }}"
  test: "{% if watcher_applier_enable_healthchecks | bool %}{{ watcher_applier_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ watcher_applier_healthcheck_timeout }}"

watcher_engine_enable_healthchecks: "{{ enable_container_healthchecks }}"
watcher_engine_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
watcher_engine_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
watcher_engine_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
watcher_engine_healthcheck_test: ["CMD-SHELL", "healthcheck_port watcher-decision-engine {{ om_rpc_port }}"]
watcher_engine_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
watcher_engine_healthcheck:
  interval: "{{ watcher_engine_healthcheck_interval }}"
  retries: "{{ watcher_engine_healthcheck_retries }}"
  start_period: "{{ watcher_engine_healthcheck_start_period }}"
  test: "{% if watcher_engine_enable_healthchecks | bool %}{{ watcher_engine_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ watcher_engine_healthcheck_timeout }}"

watcher_api_default_volumes:
  - "{{ node_config_directory }}/watcher-api/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "{{ kolla_dev_repos_directory ~ '/watcher:/dev-mode/watcher' if watcher_dev_mode | bool else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ '/dev/shm:/dev/shm' }}"
watcher_applier_default_volumes:
  - "{{ node_config_directory }}/watcher-applier/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "{{ kolla_dev_repos_directory ~ '/watcher:/dev-mode/watcher' if watcher_dev_mode | bool else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ '/dev/shm:/dev/shm' }}"
watcher_engine_default_volumes:
  - "{{ node_config_directory }}/watcher-engine/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "{{ kolla_dev_repos_directory ~ '/watcher:/dev-mode/watcher' if watcher_dev_mode | bool else '' }}"
  - "kolla_logs:/var/log/kolla/"
  - "{{ '/dev/shm:/dev/shm' }}"

watcher_extra_volumes: "{{ default_extra_volumes }}"
watcher_api_extra_volumes: "{{ watcher_extra_volumes }}"
watcher_applier_extra_volumes: "{{ watcher_extra_volumes }}"
watcher_engine_extra_volumes: "{{ watcher_extra_volumes }}"

####################
# OpenStack
####################
watcher_logging_debug: "{{ openstack_logging_debug }}"

watcher_keystone_user: "watcher"

openstack_watcher_auth: "{{ openstack_auth }}"

watcher_api_workers: "{{ openstack_service_workers }}"

####################
# Kolla
####################
watcher_git_repository: "{{ kolla_dev_repos_git }}/{{ project_name }}"
watcher_dev_repos_pull: "{{ kolla_dev_repos_pull }}"
watcher_dev_mode: "{{ kolla_dev_mode }}"
watcher_source_version: "{{ kolla_source_version }}"


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

watcher_enabled_notification_topics: "{{ watcher_notification_topics | selectattr('enabled', 'equalto', true) | list }}"

####################
# Keystone
####################
watcher_ks_services:
  - name: "watcher"
    type: "infra-optim"
    description: "Infrastructure Optimization service"
    endpoints:
      - {'interface': 'internal', 'url': '{{ watcher_internal_endpoint }}'}
      - {'interface': 'public', 'url': '{{ watcher_public_endpoint }}'}

watcher_ks_users:
  - project: "service"
    user: "{{ watcher_keystone_user }}"
    password: "{{ watcher_keystone_password }}"
    role: "admin"
