class iaas::profile::glance (
  $password = undef,
  $public_interface = hiera('iaas::public_interface', undef),
  $admin_interface = hiera('iaas::admin_interface', undef),

##verbose, debug
  $verbose = hiera('iaas::verbose', undef),
  $debug = hiera('iaas::debug', undef),

  $region = hiera('iaas::region', undef),

#VIP1
  $endpoint_main = hiera('iaas::main_address', undef),
#VIP2
  $endpoint_admin = hiera('iaas::admin_address', undef),

##rhosts
#  $endpoint = hiera('iaas::role::endpoint::main_address', undef),
  $rhosts = hiera('iaas::profile::rabbitmq::rhosts', undef),
  $rabbitmq_user = hiera('iaas::profile::rabbitmq::user', undef),
  $rabbitmq_password = hiera('iaas::profile::rabbitmq::password', undef),
) {

  include iaas::resources::connectors

  if $endpoint_admin == '' {
    $real_endpoint_admin = $endpoint_main
  }else{
    $real_endpoint_admin = $endpoint_admin
  }

  class { 'ceph::profile::client': } ->
  class { 'ceph::keys': } ->

  class { '::glance::api':
##verbose, debug
    verbose => $verbose,
    debug => $debug,
##Identity_uri - planed to be implemented in Kilo
#    identity_uri => "http://${real_endpoint_admin}:35357",
    bind_host => $::facts["ipaddress_${admin_interface}"],
    auth_host => $real_endpoint_admin,
    keystone_password => $password,
    auth_uri => "http://${endpoint_main}:5000/v2.0",
    keystone_tenant => 'services',
    keystone_user => 'glance',
    auth_url => "http://${endpoint_main}:5000/v2.0",
    database_connection => $iaas::resources::connectors::glance,
##registry_host
    registry_host => $real_endpoint_admin,
    mysql_module => '2.3',
    database_idle_timeout => 3600,
    os_region_name => $region,
    known_stores => ['glance.store.filesystem.Store', 'glance.store.http.Store', 'glance.store.rbd.Store', 'glance.store.cinder.Store'],
#    known_stores => ['glance.store.filesystem.Store', 'glance.store.http.Store', 'glance.store.rbd.Store', 'glance.store.cinder.Store'], 
#  'glance.store.sheepdog.Store', 'glance.store.vmware_datastore.Store', 'glance.store.s3.Store', 'glance.store.swift.Store'
    show_image_direct_url => true,
##For GPFS
#    show_multiple_locations => true,
    pipeline => 'keystone',
  }

##Identity_uri - workaround in juno
  glance_api_config { 'keystone_authtoken/identity_uri' :
    value => "http://${real_endpoint_admin}:35357",
  }

  class { '::glance::backend::rbd':
    rbd_store_user => 'glance',
    rbd_store_ceph_conf => '/etc/ceph/ceph.conf',
    rbd_store_pool => 'images',
  }

  class { '::glance::registry':
    verbose => $verbose,
    debug => $debug,
##Identity_uri - planed to be implemented
#    identity_uri => "http://${real_endpoint_admin}:35357",
    keystone_password => $password,
    database_connection => $iaas::resources::connectors::glance,
    auth_host => $real_endpoint_admin,
    auth_uri => "http://${endpoint_main}:5000/v2.0",
    keystone_tenant => 'services',
    keystone_user => 'glance',
    mysql_module => '2.3',
    database_idle_timeout => 3600,
    bind_host => $::facts["ipaddress_${admin_interface}"],
  }

##Identity_uri - workaround in juno
  glance_registry_config { 'keystone_authtoken/identity_uri' :
    value => "http://${real_endpoint_admin}:35357",
  }

  class { '::glance::notify::rabbitmq':
    rabbit_userid => $rabbitmq_user,
    rabbit_password => $rabbitmq_password,
##rabbit_hosts - uncomment as needed
#    rabbit_host => $endpoint,
    rabbit_hosts => $rhosts,
  }

##Leave commented if DB is not controller
#  iaas::resources::database { 'glance': }

  class  { '::glance::keystone::auth':
    password => $password,
    public_address => $endpoint_main,
    admin_address => $real_endpoint_admin,
    internal_address => $real_endpoint_admin,
    region => $region,
  }

}