---
gnocchi_services:
  gnocchi-api:
    container_name: gnocchi_api
    group: gnocchi-api
    enabled: true
    image: "{{ gnocchi_api_image_full }}"
    volumes: "{{ gnocchi_api_default_volumes + gnocchi_api_extra_volumes }}"
    dimensions: "{{ gnocchi_api_dimensions }}"
    healthcheck: "{{ gnocchi_api_healthcheck }}"
    haproxy:
      gnocchi_api:
        enabled: "{{ enable_gnocchi }}"
        mode: "http"
        external: false
        port: "{{ gnocchi_api_port }}"
        listen_port: "{{ gnocchi_api_listen_port }}"
      gnocchi_api_external:
        enabled: "{{ enable_gnocchi }}"
        mode: "http"
        external: true
        external_fqdn: "{{ gnocchi_external_fqdn }}"
        port: "{{ gnocchi_api_public_port }}"
        listen_port: "{{ gnocchi_api_listen_port }}"
  gnocchi-metricd:
    container_name: gnocchi_metricd
    group: gnocchi-metricd
    enabled: true
    image: "{{ gnocchi_metricd_image_full }}"
    volumes: "{{ gnocchi_metricd_default_volumes + gnocchi_metricd_extra_volumes }}"
    dimensions: "{{ gnocchi_metricd_dimensions }}"
    healthcheck: "{{ gnocchi_metricd_healthcheck }}"
  gnocchi-statsd:
    container_name: gnocchi_statsd
    group: gnocchi-statsd
    enabled: "{{ enable_gnocchi_statsd | bool }}"
    image: "{{ gnocchi_statsd_image_full }}"
    volumes: "{{ gnocchi_statsd_default_volumes + gnocchi_statsd_extra_volumes }}"
    dimensions: "{{ gnocchi_statsd_dimensions }}"
    healthcheck: "{{ gnocchi_statsd_healthcheck }}"

####################
# Config Validate
####################
gnocchi_config_validation:
  - generator: "/gnocchi/gnocchi/gnocchi-config-generator.conf"
    config: "/etc/gnocchi/gnocchi.conf"

####################
# Swift
####################
swift_keystone_user: "swift"
swift_admin_tenant_name: "admin"


####################
# Database
####################
gnocchi_database_name: "gnocchi"
gnocchi_database_user: "{% if use_preconfigured_databases | bool and use_common_mariadb_user | bool %}{{ database_user }}{% else %}gnocchi{% endif %}"
gnocchi_database_address: "{{ database_address | put_address_in_context('url') }}:{{ database_port }}"

####################
# Database sharding
####################
gnocchi_database_shard_root_user: "{% if enable_proxysql | bool %}root_shard_{{ gnocchi_database_shard_id }}{% else %}{{ database_user }}{% endif %}"
gnocchi_database_shard_id: "{{ mariadb_default_database_shard_id | int }}"
gnocchi_database_shard:
  users:
    - user: "{{ gnocchi_database_user }}"
      password: "{{ gnocchi_database_password }}"
  rules:
    - schema: "{{ gnocchi_database_name }}"
      shard_id: "{{ gnocchi_database_shard_id }}"


####################
# Docker
####################
gnocchi_tag: "{{ openstack_tag }}"

gnocchi_api_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/gnocchi-api"
gnocchi_api_tag: "{{ gnocchi_tag }}"
gnocchi_api_image_full: "{{ gnocchi_api_image }}:{{ gnocchi_api_tag }}"

gnocchi_statsd_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/gnocchi-statsd"
gnocchi_statsd_tag: "{{ gnocchi_tag }}"
gnocchi_statsd_image_full: "{{ gnocchi_statsd_image }}:{{ gnocchi_statsd_tag }}"

gnocchi_metricd_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/gnocchi-metricd"
gnocchi_metricd_tag: "{{ gnocchi_tag }}"
gnocchi_metricd_image_full: "{{ gnocchi_metricd_image }}:{{ gnocchi_metricd_tag }}"

gnocchi_api_dimensions: "{{ default_container_dimensions }}"
gnocchi_metricd_dimensions: "{{ default_container_dimensions }}"
gnocchi_statsd_dimensions: "{{ default_container_dimensions }}"

gnocchi_api_enable_healthchecks: "{{ enable_container_healthchecks }}"
gnocchi_api_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
gnocchi_api_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
gnocchi_api_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
gnocchi_api_healthcheck_test: ["CMD-SHELL", "healthcheck_curl http://{{ api_interface_address | put_address_in_context('url') }}:{{ gnocchi_api_listen_port }}"]
gnocchi_api_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
gnocchi_api_healthcheck:
  interval: "{{ gnocchi_api_healthcheck_interval }}"
  retries: "{{ gnocchi_api_healthcheck_retries }}"
  start_period: "{{ gnocchi_api_healthcheck_start_period }}"
  test: "{% if gnocchi_api_enable_healthchecks | bool %}{{ gnocchi_api_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ gnocchi_api_healthcheck_timeout }}"

gnocchi_metricd_enable_healthchecks: "{{ enable_container_healthchecks }}"
gnocchi_metricd_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
gnocchi_metricd_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
gnocchi_metricd_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
gnocchi_metricd_healthcheck_test: ["CMD-SHELL", "healthcheck_port gnocchi-metricd {{ database_port }}"]
gnocchi_metricd_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
gnocchi_metricd_healthcheck:
  interval: "{{ gnocchi_metricd_healthcheck_interval }}"
  retries: "{{ gnocchi_metricd_healthcheck_retries }}"
  start_period: "{{ gnocchi_metricd_healthcheck_start_period }}"
  test: "{% if gnocchi_metricd_enable_healthchecks | bool %}{{ gnocchi_metricd_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ gnocchi_metricd_healthcheck_timeout }}"

gnocchi_statsd_enable_healthchecks: "{{ enable_container_healthchecks }}"
gnocchi_statsd_healthcheck_interval: "{{ default_container_healthcheck_interval }}"
gnocchi_statsd_healthcheck_retries: "{{ default_container_healthcheck_retries }}"
gnocchi_statsd_healthcheck_start_period: "{{ default_container_healthcheck_start_period }}"
gnocchi_statsd_healthcheck_test: ["CMD-SHELL", "healthcheck_port gnocchi-statsd {{ database_port }}"]
gnocchi_statsd_healthcheck_timeout: "{{ default_container_healthcheck_timeout }}"
gnocchi_statsd_healthcheck:
  interval: "{{ gnocchi_statsd_healthcheck_interval }}"
  retries: "{{ gnocchi_statsd_healthcheck_retries }}"
  start_period: "{{ gnocchi_statsd_healthcheck_start_period }}"
  test: "{% if gnocchi_statsd_enable_healthchecks | bool %}{{ gnocchi_statsd_healthcheck_test }}{% else %}NONE{% endif %}"
  timeout: "{{ gnocchi_statsd_healthcheck_timeout }}"

gnocchi_api_default_volumes:
  - "{{ node_config_directory }}/gnocchi-api/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "{{ gnocchi_metric_datadir_volume }}:/var/lib/gnocchi/"
  - "kolla_logs:/var/log/kolla/"

gnocchi_metricd_default_volumes:
  - "{{ node_config_directory }}/gnocchi-metricd/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "{{ gnocchi_metric_datadir_volume }}:/var/lib/gnocchi/"
  - "kolla_logs:/var/log/kolla/"

gnocchi_statsd_default_volumes:
  - "{{ node_config_directory }}/gnocchi-statsd/:{{ container_config_directory }}/:ro"
  - "/etc/localtime:/etc/localtime:ro"
  - "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
  - "{{ gnocchi_metric_datadir_volume }}:/var/lib/gnocchi/"
  - "kolla_logs:/var/log/kolla/"

gnocchi_extra_volumes: "{{ default_extra_volumes }}"
gnocchi_api_extra_volumes: "{{ gnocchi_extra_volumes }}"
gnocchi_metricd_extra_volumes: "{{ gnocchi_extra_volumes }}"
gnocchi_statsd_extra_volumes: "{{ gnocchi_extra_volumes }}"

####################
# OpenStack
####################
gnocchi_internal_endpoint: "{{ gnocchi_internal_fqdn | kolla_url(internal_protocol, gnocchi_api_port) }}"
gnocchi_public_endpoint: "{{ gnocchi_external_fqdn | kolla_url(public_protocol, gnocchi_api_public_port) }}"

gnocchi_logging_debug: "{{ openstack_logging_debug }}"

gnocchi_metricd_workers: "{{ openstack_service_workers }}"

gnocchi_keystone_user: "gnocchi"

openstack_gnocchi_auth: "{{ openstack_auth }}"

gnocchi_api_workers: "{{ openstack_service_workers }}"

####################
# Keystone
####################
gnocchi_ks_services:
  - name: "gnocchi"
    type: "metric"
    description: "OpenStack Metric Service"
    endpoints:
      - {'interface': 'internal', 'url': '{{ gnocchi_internal_endpoint }}'}
      - {'interface': 'public', 'url': '{{ gnocchi_public_endpoint }}'}

gnocchi_ks_users:
  - project: "service"
    user: "{{ gnocchi_keystone_user }}"
    password: "{{ gnocchi_keystone_password }}"
    role: "admin"

gnocchi_ceph_cluster: "ceph"
