Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for whole config as a yaml #1

Open
wants to merge 1 commit into
base: pass-missing-options-to-pool
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

twemproxy::yaml_config:
default:
listen: 127.0.0.1:22122
hash: md5
distribution: ketama
timeout: 400
backlog: 1024
redis: false
server_connections: 1
auto_eject_hosts: false
server_retry_timeout: 30000
server_failure_limit: 2
servers:
- 127.0.0.1:11211
22 changes: 22 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
version: 5

defaults:
datadir: 'data'
data_hash: 'yaml_data'

hierarchy:
- name: 'Full Version'
path: '%{facts.os.name}-%{facts.os.release.full}.yaml'

- name: 'Major Version'
path: '%{facts.os.name}-%{facts.os.release.major}.yaml'

- name: 'Distribution Name'
path: '%{facts.os.name}.yaml'

- name: 'Operating System Family'
path: '%{facts.os.family}-family.yaml'

- name: 'common'
path: 'common.yaml'
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
$client_port = $twemproxy::params::client_port,
$client_weight = $twemproxy::params::client_weight,
$clients_array = undef,
$yaml_config = undef,
) inherits twemproxy::params {

anchor { 'twemproxy::start': } ->
Expand All @@ -64,6 +65,7 @@
client_port => $client_port,
client_weight => $client_weight,
clients_array => $clients_array,
yaml_config => $yaml_config,
} ->

class { 'twemproxy::service': } ->
Expand Down
68 changes: 40 additions & 28 deletions manifests/pool.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,49 @@
$clients_array = undef,
$client_port = $twemproxy::params::client_port,
$client_weight = $twemproxy::params::client_weight,
$yaml_config = undef,
) {

if !$client_address and !$clients_array {
fail('You must set at least one of client_address or clients_array parameter.')
}
if !$yaml_config {
if !$client_address and !$clients_array {
fail('You must set at least one of client_address or clients_array parameter.')
}

twemproxy::listen { $name:
order => $order,
listen_address => $listen_address,
listen_port => $listen_port,
connections => $connections,
hash => $hash,
hash_tag => $hash_tag,
distribution => $distribution,
timeout => $timeout,
backlog => $backlog,
preconnect => $preconnect,
redis => $redis,
redis_auth => $redis_auth,
redis_db => $redis_db,
server_connections => $server_connections,
auto_eject_hosts => $auto_eject_hosts,
server_retry_timeout => $server_retry_timeout,
server_failure_limit => $server_failure_limit,
}
twemproxy::listen { $name:
order => $order,
listen_address => $listen_address,
listen_port => $listen_port,
connections => $connections,
hash => $hash,
hash_tag => $hash_tag,
distribution => $distribution,
timeout => $timeout,
backlog => $backlog,
preconnect => $preconnect,
redis => $redis,
redis_auth => $redis_auth,
redis_db => $redis_db,
server_connections => $server_connections,
auto_eject_hosts => $auto_eject_hosts,
server_retry_timeout => $server_retry_timeout,
server_failure_limit => $server_failure_limit,
}

twemproxy::member { $name:
order => $order,
client_address => $client_address,
client_port => $client_port,
client_weight => $client_weight,
clients_array => $clients_array,
twemproxy::member { $name:
order => $order,
client_address => $client_address,
client_port => $client_port,
client_weight => $client_weight,
clients_array => $clients_array,
}
}
else {
file {'/etc/nutcracker.yml':
ensure => present,
content => template("${module_name}/pure_hash.yml.erb"),
owner => 'root',
group => 'root',
mode => '0644',
}
}
}
2 changes: 2 additions & 0 deletions templates/pure_hash.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Twemproxy/Nutcracker configuration managed by Puppet ###
#<%= @yaml_config.to_yaml() %>