heat_template_version: rocky

description: >
  Gnocchi service configured with Puppet

parameters:
  ServiceData:
    default: {}
    description: Dictionary packing service data
    type: json
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry.  This
                 mapping overrides those in ServiceNetMapDefaults.
    type: json
  DefaultPasswords:
    default: {}
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json
  GnocchiIndexerBackend:
    default: 'mysql'
    description: The short name of the Gnocchi indexer backend to use.
    type: string
  NumberOfStorageSacks:
    default: 128
    description: Number of storage sacks to create.
    type: number
  GnocchiPassword:
    description: The password for the gnocchi service and db account.
    type: string
    hidden: true
  GnocchiRbdPoolName:
    default: metrics
    type: string
  CephClusterName:
    type: string
    default: ceph
    description: The Ceph cluster name.
    constraints:
    - allowed_pattern: "[a-zA-Z0-9]+"
      description: >
        The Ceph cluster name must be at least 1 character and contain only
        letters and numbers.
  CephClientUserName:
    default: openstack
    type: string
  RedisPassword:
    description: The password for the redis service account.
    type: string
    hidden: true
  Debug:
    type: boolean
    default: false
    description: Set to True to enable debugging on all services.
  GnocchiDebug:
    default: ''
    description: Set to True to enable debugging Gnocchi services.
    type: string
    constraints:
      - allowed_values: [ '', 'true', 'True', 'TRUE', 'false', 'False', 'FALSE']
  EnableSQLAlchemyCollectd:
    type: boolean
    description: >
        Set to true to enable the SQLAlchemy-collectd server plugin
    default: false
  GnocchiStorageSwiftEndpointType:
    default: 'internalURL'
    description: Set to modify which endpoint type is gnocchi accessing swift
                 from.
    type: string
  GnocchiStorageS3Endpoint:
    default: ''
    description: The endpoint url for S3 storage.
    type: string
  GnocchiStorageS3RegionName:
    default: ''
    description: S3 Region name.
    type: string
  GnocchiStorageS3AccessKeyId:
    default: ''
    description: S3 storage access key Id.
    type: string
  GnocchiStorageS3AccessSecret:
    default: ''
    description: S3 storage access key secret.
    type: string
    hidden: true
  GnocchiStorageS3BucketPrefix:
    default: ''
    description: S3 storage bucket prefix.
    type: string
  GnocchiFileBasePath:
    default: '/var/lib/gnocchi'
    description: Path to use when file driver is used. This could be NFS or a
      flat file.
    type: string

conditions:
  service_debug_unset: {equals : [{get_param: GnocchiDebug}, '']}
  enable_sqlalchemy_collectd: {equals : [{get_param: EnableSQLAlchemyCollectd}, true]}

outputs:
  aux_parameters:
    description: Additional parameters referenced outside the base file
    value:
      gnocchi_indexer_backend: {get_param: GnocchiIndexerBackend}
  role_data:
    description: Shared role data for the Heat services.
    value:
      service_name: gnocchi_base
      config_settings:
        #Gnocchi engine
        gnocchi_redis_password: {get_param: RedisPassword}
        gnocchi::logging::debug:
          if:
          - service_debug_unset
          - {get_param: Debug }
          - {get_param: GnocchiDebug }
        gnocchi::db::database_connection:
          make_url:
            scheme: {get_param: [EndpointMap, MysqlInternal, protocol]}
            username: gnocchi
            password: {get_param: GnocchiPassword}
            host: {get_param: [EndpointMap, MysqlInternal, host]}
            path: /gnocchi
            query:
                if:
                  - enable_sqlalchemy_collectd
                  -
                      read_default_file: /etc/my.cnf.d/tripleo.cnf
                      read_default_group: tripleo
                      plugin: collectd
                      collectd_program_name: gnochhi
                      collectd_host: localhost
                  -
                      read_default_file: /etc/my.cnf.d/tripleo.cnf
                      read_default_group: tripleo


        gnocchi::db::sync::extra_opts:
          str_replace:
            template: " --sacks-number NUM_SACKS"
            params:
              NUM_SACKS: {get_param: NumberOfStorageSacks}
        gnocchi::storage::file::file_basepath: {get_param: GnocchiFileBasePath}
        gnocchi::storage::swift::swift_user: 'service:gnocchi'
        gnocchi::storage::swift::swift_auth_version: 3
        gnocchi::storage::swift::swift_key: {get_param: GnocchiPassword}
        gnocchi::storage::swift::swift_authurl: {get_param: [EndpointMap, KeystoneV3Internal, uri]}
        gnocchi::storage::swift::swift_endpoint_type: {get_param: GnocchiStorageSwiftEndpointType}
        gnocchi::storage::ceph::ceph_pool: {get_param: GnocchiRbdPoolName}
        gnocchi::storage::ceph::ceph_username: {get_param: CephClientUserName}
        gnocchi::storage::ceph::ceph_conffile:
          list_join:
          - ''
          - - '/etc/ceph/'
            - {get_param: CephClusterName}
            - '.conf'
        gnocchi::storage::ceph::ceph_keyring:
          list_join:
          - ''
          - - '/etc/ceph/'
            - {get_param: CephClusterName}
            - '.client.'
            - {get_param: CephClientUserName}
            - '.keyring'
        gnocchi::storage::s3::s3_endpoint_url: {get_param: GnocchiStorageS3Endpoint}
        gnocchi::storage::s3::s3_region_name: {get_param: GnocchiStorageS3RegionName}
        gnocchi::storage::s3::s3_access_key_id: {get_param: GnocchiStorageS3AccessKeyId}
        gnocchi::storage::s3::s3_secret_access_key: {get_param: GnocchiStorageS3AccessSecret}
        gnocchi::storage::s3::s3_bucket_prefix: {get_param: GnocchiStorageS3BucketPrefix}
        #Gnocchi statsd
        gnocchi::statsd::resource_id: '0a8b55df-f90f-491c-8cb9-7cdecec6fc26'
        gnocchi::statsd::user_id: '27c0d3f8-e7ee-42f0-8317-72237d1c5ae3'
        gnocchi::statsd::project_id: '6c38cd8d-099a-4cb2-aecf-17be688e8616'
        gnocchi::statsd::flush_delay: 10
        gnocchi::statsd::archive_policy_name: 'low'
