first commit
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..0597505
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,6 @@
+etcd formula
+=========================================
+
+0.1 (2015-08-22)
+
+- Initial formula setup
diff --git a/INTEGRATION.rst b/INTEGRATION.rst
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/INTEGRATION.rst
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0b835f6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,13 @@
+Copyright (c) 2014-2016 tcp cloud a.s.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..fa15e0f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,66 @@
+DESTDIR=/
+SALTENVDIR=/usr/share/salt-formulas/env
+RECLASSDIR=/usr/share/salt-formulas/reclass
+FORMULANAME=$(shell grep name: metadata.yml|head -1|cut -d : -f 2|grep -Eo '[a-z0-9\-\_]*')
+
+MAKE_PID := $(shell echo $$PPID)
+JOB_FLAG := $(filter -j%, $(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))
+
+ifneq ($(subst -j,,$(JOB_FLAG)),)
+JOBS := $(subst -j,,$(JOB_FLAG))
+else
+JOBS := 1
+endif
+
+KITCHEN_LOCAL_YAML?=.kitchen.yml
+KITCHEN_OPTS?="--concurrency=$(JOBS)"
+KITCHEN_OPTS_CREATE?=""
+KITCHEN_OPTS_CONVERGE?=""
+KITCHEN_OPTS_VERIFY?=""
+KITCHEN_OPTS_TEST?=""
+
+all:
+ @echo "make install - Install into DESTDIR"
+ @echo "make test - Run tests"
+ @echo "make kitchen - Run Kitchen CI tests (create, converge, verify)"
+ @echo "make clean - Cleanup after tests run"
+
+install:
+ # Formula
+ [ -d $(DESTDIR)/$(SALTENVDIR) ] || mkdir -p $(DESTDIR)/$(SALTENVDIR)
+ cp -a $(FORMULANAME) $(DESTDIR)/$(SALTENVDIR)/
+ [ ! -d _modules ] || cp -a _modules $(DESTDIR)/$(SALTENVDIR)/
+ [ ! -d _states ] || cp -a _states $(DESTDIR)/$(SALTENVDIR)/ || true
+ # Metadata
+ [ -d $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME) ] || mkdir -p $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
+ cp -a metadata/service/* $(DESTDIR)/$(RECLASSDIR)/service/$(FORMULANAME)
+
+test:
+ [ ! -d tests ] || (cd tests; ./run_tests.sh)
+
+kitchen: kitchen-create kitchen-converge kitchen-verify kitchen-list
+
+kitchen-create:
+ kitchen create ${KITCHEN_OPTS} ${KITCHEN_OPTS_CREATE}
+ [ "$(shell echo $(KITCHEN_LOCAL_YAML)|grep -Eo docker)" = "docker" ] || sleep 120
+
+kitchen-converge:
+ kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE} &&\
+ kitchen converge ${KITCHEN_OPTS} ${KITCHEN_OPTS_CONVERGE}
+
+kitchen-verify:
+ [ ! -d tests/integration ] || kitchen verify -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
+ [ -d tests/integration ] || kitchen verify ${KITCHEN_OPTS} ${KITCHEN_OPTS_VERIFY}
+
+kitchen-test:
+ [ ! -d tests/integration ] || kitchen test -t tests/integration ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
+ [ -d tests/integration ] || kitchen test ${KITCHEN_OPTS} ${KITCHEN_OPTS_TEST}
+
+kitchen-list:
+ kitchen list
+
+clean:
+ [ ! -x "$(shell which kitchen)" ] || kitchen destroy
+ [ ! -d .kitchen ] || rm -rf .kitchen
+ [ ! -d tests/build ] || rm -rf tests/build
+ [ ! -d build ] || rm -rf build
diff --git a/README.rst b/README.rst
index b46f41f..1760c3e 100644
--- a/README.rst
+++ b/README.rst
@@ -56,7 +56,7 @@
enabled: true
bind:
host: 10.0.175.101
- proxy: on
+ proxy: true
members:
- host: 10.0.175.101
name: etcd01
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..49d5957
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..f6b81ee
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+salt-formula-etcd (0.1) trusty; urgency=medium
+
+ * Initial release
+
+ -- tcpcloud <cloud@tcpcloud.eu> Thu, 13 Aug 2015 23:23:41 +0200
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..ec63514
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+9
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..d7501d3
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,15 @@
+Source: salt-formula-etcd
+Maintainer: tcpcloud <cloud@tcpcloud.eu>
+Section: admin
+Priority: optional
+Build-Depends: debhelper (>= 9), salt-master, python, python-yaml
+Standards-Version: 3.9.6
+Homepage: http://www.tcpcloud.eu
+Vcs-Browser: https://github.com/tcpcloud/salt-formula-etcd
+Vcs-Git: https://github.com/tcpcloud/salt-formula-etcd.git
+
+Package: salt-formula-etcd
+Architecture: all
+Depends: ${misc:Depends}, salt-master, reclass
+Description: etcd salt formula
+ Install and configure etcd system.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..3d9f5a8
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,15 @@
+Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+Upstream-Name: salt-formula-etcd
+Upstream-Contact:
+Source: https://github.com/tcpcloud/salt-formula-etcd
+
+Files: *
+Copyright: 2014-2015 tcp cloud a.s.
+License: Apache-2.0
+ Copyright (C) 2014-2015 tcp cloud a.s.
+ .
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ .
+ On a Debian system you can find a copy of this license in
+ /usr/share/common-licenses/Apache-2.0.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..d585829
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+README.rst
+CHANGELOG.rst
+VERSION
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..abde6ef
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,5 @@
+#!/usr/bin/make -f
+
+%:
+ dh $@
+
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..89ae9db
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/doc/source/conf.py b/doc/source/conf.py
new file mode 100644
index 0000000..93b8d99
--- /dev/null
+++ b/doc/source/conf.py
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import sys
+
+sys.path.insert(0, os.path.abspath('../..'))
+# -- General configuration ----------------------------------------------------
+
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = [
+ 'sphinx.ext.autodoc',
+]
+
+# autodoc generation is a bit aggressive and a nuisance when doing heavy
+# text edit cycles.
+# execute "export SPHINX_DEBUG=1" in your terminal to disable
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'salt-formula-etcd'
+copyright = u'2016, tcp cloud a.s.'
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+add_module_names = True
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# -- Options for HTML output --------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. Major themes that come with
+# Sphinx are currently 'default' and 'sphinxdoc'.
+# html_theme_path = ["."]
+# html_theme = '_theme'
+# html_static_path = ['static']
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = '%sdoc' % project
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass
+# [howto/manual]).
+latex_documents = [
+ ('index',
+ '%s.tex' % project,
+ u'%s Documentation' % project,
+ u'OpenStack Foundation', 'manual'),
+]
+
+# Example configuration for intersphinx: refer to the Python standard library.
+# intersphinx_mapping = {'http://docs.python.org/': None}
diff --git a/doc/source/index.rst b/doc/source/index.rst
new file mode 100644
index 0000000..a6210d3
--- /dev/null
+++ b/doc/source/index.rst
@@ -0,0 +1 @@
+.. include:: ../../README.rst
diff --git a/etcd/files/default b/etcd/files/default
new file mode 100644
index 0000000..a946dcc
--- /dev/null
+++ b/etcd/files/default
@@ -0,0 +1,270 @@
+{%- from "etcd/map.jinja" import server with context %}
+## etcd(1) daemon options
+## See "/usr/share/doc/etcd/Documentation/configuration.md.gz".
+
+{%- if {{ server.get('proxy', 'false') }} %}
+
+### Proxy Flags
+
+##### -proxy
+## Proxy mode setting ("off", "readonly" or "on").
+## default: "off"
+ETCD_PROXY="on"
+
+ETCD_INITIAL_CLUSTER="{% for member in server.members %}{{ member.name }}={%- if server.bind.host == '127.0.0.1' %}http://127.0.0.1:2380{% else %}http://{{ member.host }}:2380{% if not loop.last %},{% endif %}{% endif %}{% endfor %}"
+
+##### -proxy-failure-wait
+## Time (in milliseconds) an endpoint will be held in a failed state before being
+## reconsidered for proxied requests.
+## default: 5000
+# ETCD_PROXY_FAILURE_WAIT="5000"
+
+##### -proxy-refresh-interval
+## Time (in milliseconds) of the endpoints refresh interval.
+## default: 30000
+# ETCD_PROXY_REFRESH_INTERVAL="30000"
+
+##### -proxy-dial-timeout
+## Time (in milliseconds) for a dial to timeout or 0 to disable the timeout
+## default: 1000
+# ETCD_PROXY_DIAL_TIMEOUT="1000"
+
+##### -proxy-write-timeout
+## Time (in milliseconds) for a write to timeout or 0 to disable the timeout.
+## default: 5000
+# ETCD_PROXY_WRITE_TIMEOUT="5000"
+
+##### -proxy-read-timeout
+## Time (in milliseconds) for a read to timeout or 0 to disable the timeout.
+## Don't change this value if you use watches because they are using long polling requests.
+## default: 0
+# ETCD_PROXY_READ_TIMEOUT="0"
+
+
+{%- else %}
+### Member Flags
+
+##### -name
+## Human-readable name for this member.
+## default: host name returned by `hostname`.
+## This value is referenced as this node's own entries listed in the `-initial-cluster`
+## flag (Ex: `default=http://localhost:2380` or `default=http://localhost:2380,default=http://localhost:7001`).
+## This needs to match the key used in the flag if you're using [static boostrapping](clustering.md#static).
+# ETCD_NAME="hostname"
+ETCD_NAME="{{ pillar.linux.system.name }}"
+
+##### -data-dir
+## Path to the data directory.
+# ETCD_DATA_DIR="/var/lib/etcd/default"
+ETCD_DATA_DIR="/var/lib/etcd/default"
+
+##### -wal-dir
+## Path to the dedicated wal directory. If this flag is set, etcd will write the
+## WAL files to the walDir rather than the dataDir. This allows a dedicated disk
+## to be used, and helps avoid io competition between logging and other IO operations.
+## default: ""
+# ETCD_WAL_DIR
+
+##### -snapshot-count
+## Number of committed transactions to trigger a snapshot to disk.
+## default: "10000"
+# ETCD_SNAPSHOT_COUNT="10000"
+
+##### -heartbeat-interval
+## Time (in milliseconds) of a heartbeat interval.
+## default: "100"
+# ETCD_HEARTBEAT_INTERVAL="100"
+
+##### -election-timeout
+## Time (in milliseconds) for an election to timeout.
+## See /usr/share/doc/etcd/Documentation/tuning.md
+## default: "1000"
+# ETCD_ELECTION_TIMEOUT="1000"
+
+##### -listen-peer-urls
+## List of URLs to listen on for peer traffic. This flag tells the etcd to accept
+## incoming requests from its peers on the specified scheme://IP:port combinations.
+## Scheme can be either http or https. If 0.0.0.0 is specified as the IP, etcd
+## listens to the given port on all interfaces. If an IP address is given as
+## well as a port, etcd will listen on the given port and interface.
+## Multiple URLs may be used to specify a number of addresses and ports to listen on.
+## The etcd will respond to requests from any of the listed addresses and ports.
+## example: "http://10.0.0.1:2380"
+## invalid example: "http://example.com:2380" (domain name is invalid for binding)
+## default: "http://localhost:2380,http://localhost:7001"
+# ETCD_LISTEN_PEER_URLS="http://localhost:2380,http://localhost:7001"
+ETCD_LISTEN_PEER_URLS="http://{{ server.host }}:2380"
+
+##### -listen-client-urls
+## List of URLs to listen on for client traffic. This flag tells the etcd to accept
+## incoming requests from the clients on the specified scheme://IP:port combinations.
+## Scheme can be either http or https. If 0.0.0.0 is specified as the IP, etcd
+## listens to the given port on all interfaces. If an IP address is given as
+## well as a port, etcd will listen on the given port and interface.
+## Multiple URLs may be used to specify a number of addresses and ports to listen on.
+## The etcd will respond to requests from any of the listed addresses and ports.
+## (ADVERTISE_CLIENT_URLS is required when LISTEN_CLIENT_URLS is set explicitly).
+## example: "http://10.0.0.1:2379"
+## invalid example: "http://example.com:2379" (domain name is invalid for binding)
+## default: "http://localhost:2379,http://localhost:4001"
+# ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://localhost:4001"
+ETCD_LISTEN_CLIENT_URLS="{%- if server.bind.host != '127.0.0.1' %}http://{{ server.bind.host }}:4001,{% endif %}http://127.0.0.1:4001"
+##### -max-snapshots
+## Maximum number of snapshot files to retain (0 is unlimited)
+## default: 5
+# ETCD_MAX_SNAPSHOTS="5"
+
+##### -max-wals
+## Maximum number of wal files to retain (0 is unlimited)
+## default: 5
+# ETCD_MAX_WALS="5"
+
+##### -cors
+## Comma-separated whitelist of origins for CORS (cross-origin resource sharing).
+## default: none
+# ETCD_CORS
+
+### Clustering Flags
+## For an explanation of the various ways to do cluster setup, see:
+## /usr/share/doc/etcd/Documentation/clustering.md.gz
+##
+## The command line parameters starting with -initial-cluster will be
+## ignored on subsequent runs of etcd as they are used only during initial
+## bootstrap process.
+
+##### -initial-advertise-peer-urls
+## List of this member's peer URLs to advertise to the rest of the cluster.
+## These addresses are used for communicating etcd data around the cluster.
+## At least one must be routable to all cluster members.
+## These URLs can contain domain names.
+## example: "http://example.com:2380, http://10.0.0.1:2380"
+## default: "http://localhost:2380,http://localhost:7001"
+# ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380,http://localhost:7001"
+ETCD_INITIAL_ADVERTISE_PEER_URLS="http://{{ server.bind.host }}:2380"
+
+##### -initial-cluster
+## initial cluster configuration for bootstrapping.
+## The key is the value of the `-name` flag for each node provided.
+## The default uses `default` for the key because this is the default for the `-name` flag.
+## default: "default=http://localhost:2380,default=http://localhost:7001"
+# ETCD_INITIAL_CLUSTER="default=http://localhost:2380,default=http://localhost:7001"
+ETCD_INITIAL_CLUSTER="{% for member in server.members %}{{ member.name }}={%- if server.bind.host == '127.0.0.1' %}http://127.0.0.1:2380{% else %}http://{{ member.host }}:2380{% if not loop.last %},{% endif %}{% endif %}{% endfor %}"
+##### -initial-cluster-state
+## Initial cluster state ("new" or "existing"). Set to `new` for all members
+## present during initial static or DNS bootstrapping. If this option is set to
+## `existing`, etcd will attempt to join the existing cluster. If the wrong
+## value is set, etcd will attempt to start but fail safely.
+## default: "new"
+# ETCD_INITIAL_CLUSTER_STATE="existing"
+ETCD_INITIAL_CLUSTER_STATE="new"
+
+##### -initial-cluster-token
+## Initial cluster token for the etcd cluster during bootstrap.
+## If you are spinning up multiple clusters (or creating and destroying a
+## single cluster) with same configuration for testing purpose, it is highly
+## recommended that you specify a unique initial-cluster-token for the
+## different clusters.
+## default: "etcd-cluster"
+# ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
+ETCD_INITIAL_CLUSTER_TOKEN="{{ server.token }}"
+
+##### -advertise-client-urls
+## List of this member's client URLs to advertise to the rest of the cluster.
+## These URLs can contain domain names.
+## example: "http://example.com:2379, http://10.0.0.1:2379"
+## Be careful if you are advertising URLs such as http://localhost:2379 from a
+## cluster member and are using the proxy feature of etcd. This will cause loops,
+## because the proxy will be forwarding requests to itself until its resources
+## (memory, file descriptors) are eventually depleted.
+## default: "http://localhost:2379,http://localhost:4001"
+# ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379,http://localhost:4001"
+ETCD_ADVERTISE_CLIENT_URLS="http://{{ server.bind.host }}:4001"
+
+##### -discovery
+## Discovery URL used to bootstrap the cluster.
+## default: none
+# ETCD_DISCOVERY
+
+##### -discovery-srv
+## DNS srv domain used to bootstrap the cluster.
+## default: none
+# ETCD_DISCOVERY_SRV
+
+##### -discovery-fallback
+## Expected behavior ("exit" or "proxy") when discovery services fails.
+## default: "proxy"
+# ETCD_DISCOVERY_FALLBACK="proxy"
+
+##### -discovery-proxy
+## HTTP proxy to use for traffic to discovery service.
+## default: none
+# ETCD_DISCOVERY_PROXY
+
+### Security Flags
+
+##### -ca-file [DEPRECATED]
+## Path to the client server TLS CA file.
+## default: none
+# ETCD_CA_FILE=""
+
+##### -cert-file
+## Path to the client server TLS cert file.
+## default: none
+# ETCD_CERT_FILE=""
+
+##### -key-file
+## Path to the client server TLS key file.
+## default: none
+# ETCD_KEY_FILE=""
+
+##### -client-cert-auth
+## Enable client cert authentication.
+## default: false
+# ETCD_CLIENT_CERT_AUTH
+
+##### -trusted-ca-file
+## Path to the client server TLS trusted CA key file.
+## default: none
+# ETCD_TRUSTED_CA_FILE
+
+##### -peer-ca-file [DEPRECATED]
+## Path to the peer server TLS CA file. `-peer-ca-file ca.crt` could be replaced
+## by `-peer-trusted-ca-file ca.crt -peer-client-cert-auth` and etcd will perform the same.
+## default: none
+# ETCD_PEER_CA_FILE
+
+##### -peer-cert-file
+## Path to the peer server TLS cert file.
+## default: none
+# ETCD_PEER_CERT_FILE
+
+##### -peer-key-file
+## Path to the peer server TLS key file.
+## default: none
+# ETCD_PEER_KEY_FILE
+
+##### -peer-client-cert-auth
+## Enable peer client cert authentication.
+## default: false
+# ETCD_PEER_CLIENT_CERT_AUTH
+
+##### -peer-trusted-ca-file
+## Path to the peer server TLS trusted CA file.
+## default: none
+# ETCD_PEER_TRUSTED_CA_FILE
+
+### Logging Flags
+##### -debug
+## Drop the default log level to DEBUG for all subpackages.
+## default: false (INFO for all packages)
+# ETCD_DEBUG
+
+##### -log-package-levels
+## Set individual etcd subpackages to specific log levels.
+## An example being `etcdserver=WARNING,security=DEBUG`
+## default: none (INFO for all packages)
+# ETCD_LOG_PACKAGE_LEVELS
+
+
+#### Daemon parameters:
+# DAEMON_ARGS=""
diff --git a/etcd/init.sls b/etcd/init.sls
new file mode 100644
index 0000000..cddcbaa
--- /dev/null
+++ b/etcd/init.sls
@@ -0,0 +1,6 @@
+{%- if pillar.etcd is defined %}
+include:
+{%- if pillar.etcd.server is defined %}
+- etcd.server
+{%- endif %}
+{%- endif %}
diff --git a/etcd/map.jinja b/etcd/map.jinja
new file mode 100644
index 0000000..68ff80e
--- /dev/null
+++ b/etcd/map.jinja
@@ -0,0 +1,10 @@
+{% set etcd = salt['grains.filter_by']({
+ 'Debian': {
+ 'pkgs': ['etcd', 'python-etcd'],
+ 'services': ['etcd']
+ },
+ 'RedHat': {
+ 'pkgs': [],
+ 'services': []
+ },
+}, merge=salt['pillar.get']('etcd')) %}
diff --git a/etcd/meta/sensu.yml b/etcd/meta/sensu.yml
new file mode 100644
index 0000000..26e9a64
--- /dev/null
+++ b/etcd/meta/sensu.yml
@@ -0,0 +1,8 @@
+# Sample check
+check:
+ local_etcd_proc:
+ command: "PATH=$PATH:/usr/lib64/nagios/plugins:/usr/lib/nagios/plugins check_procs -C etcd -u etcd -c 1:1"
+ interval: 60
+ occurrences: 1
+ subscribers:
+ - local-etcd-server
diff --git a/etcd/meta/sphinx.yml b/etcd/meta/sphinx.yml
new file mode 100644
index 0000000..b9f1250
--- /dev/null
+++ b/etcd/meta/sphinx.yml
@@ -0,0 +1,12 @@
+{%- from "etcd/map.jinja" import server with context %}
+# Fill in documentation details
+doc:
+ name: etcd
+ description: Some service info
+ role:
+ server:
+ name: server
+ param:
+ some_param:
+ name: "Some name"
+ value: "some value"
diff --git a/etcd/server.sls b/etcd/server.sls
new file mode 100644
index 0000000..848affb
--- /dev/null
+++ b/etcd/server.sls
@@ -0,0 +1,22 @@
+{%- from "etcd/map.jinja" import server with context %}
+{%- if server.enabled %}
+
+etcd_packages:
+ pkg.installed:
+ - names: {{ server.pkgs }}
+
+/etc/default/etcd:
+ file.managed:
+ - source: salt://etcd/files/default
+ - template: jinja
+ - require:
+ - pkg: etcd_packages
+
+etcd_service:
+ service.running:
+ - name: etcd
+ - enable: True
+ - watch:
+ - file: /etc/default/etcd
+
+{%- endif %}
diff --git a/metadata.yml b/metadata.yml
new file mode 100644
index 0000000..43c307e
--- /dev/null
+++ b/metadata.yml
@@ -0,0 +1,3 @@
+name: "etcd"
+version: "0.1"
+source: "https://github.com/tcpcloud/salt-formula-etcd"
diff --git a/metadata/service/server/cluster.yml b/metadata/service/server/cluster.yml
new file mode 100644
index 0000000..c42e8eb
--- /dev/null
+++ b/metadata/service/server/cluster.yml
@@ -0,0 +1,21 @@
+applications:
+- etcd
+classes:
+- service.etcd.support
+parameters:
+ etcd:
+ server:
+ enabled: true
+ bind:
+ host: ${_param:host_address}
+ token: ${_param:etcd_initial_token}
+ members:
+ - host: ${_param:cluster_node01_address}
+ name: ${_param:cluster_node01_hostname}
+ port: ${_param:cluster_node01_port}
+ - host: ${_param:cluster_node02_address}
+ name: ${_param:cluster_node02_hostname}
+ port: ${_param:cluster_node02_port}
+ - host: ${_param:cluster_node03_address}
+ name: ${_param:cluster_node03_hostname}
+ port: ${_param:cluster_node03_port}
diff --git a/metadata/service/server/proxy.yml b/metadata/service/server/proxy.yml
new file mode 100644
index 0000000..4de7a90
--- /dev/null
+++ b/metadata/service/server/proxy.yml
@@ -0,0 +1,18 @@
+applications:
+- etcd
+classes:
+- service.etcd.support
+parameters:
+ etcd:
+ server:
+ enabled: true
+ bind:
+ host: ${_param:host_address}
+ proxy: true
+ members:
+ - host: ${_param:cluster_node01_address}
+ name: ${_param:cluster_node01_hostname}
+ - host: ${_param:cluster_node02_address}
+ name: ${_param:cluster_node02_hostname}
+ - host: ${_param:cluster_node03_address}
+ name: ${_param:cluster_node03_hostname}
\ No newline at end of file
diff --git a/metadata/service/server/single.yml b/metadata/service/server/single.yml
new file mode 100644
index 0000000..0af0ec7
--- /dev/null
+++ b/metadata/service/server/single.yml
@@ -0,0 +1,15 @@
+applications:
+- etcd
+classes:
+- service.etcd.support
+parameters:
+ etcd:
+ server:
+ enabled: true
+ bind:
+ host: ${_param:host_address}
+ token: ${_param:etcd_initial_token}
+ members:
+ - host: ${_param:node_address}
+ name: ${_param:node_hostname}
+ port: ${_param:node_port}
\ No newline at end of file
diff --git a/metadata/service/support.yml b/metadata/service/support.yml
new file mode 100644
index 0000000..fbd7745
--- /dev/null
+++ b/metadata/service/support.yml
@@ -0,0 +1,11 @@
+parameters:
+ etcd:
+ _support:
+ collectd:
+ enabled: false
+ heka:
+ enabled: false
+ sensu:
+ enabled: false
+ sphinx:
+ enabled: true
diff --git a/tests/pillar/cluster.sls b/tests/pillar/cluster.sls
new file mode 100644
index 0000000..730b768
--- /dev/null
+++ b/tests/pillar/cluster.sls
@@ -0,0 +1,16 @@
+etcd:
+ server:
+ enabled: true
+ bind:
+ host: 10.0.175.101
+ token: $(uuidgen)
+ members:
+ - host: 10.0.175.101
+ name: etcd01
+ port: 4001
+ - host: 10.0.175.102
+ name: etcd02
+ port: 4001
+ - host: 10.0.175.103
+ name: etcd03
+ port: 4001
\ No newline at end of file
diff --git a/tests/pillar/proxy.sls b/tests/pillar/proxy.sls
new file mode 100644
index 0000000..b440098
--- /dev/null
+++ b/tests/pillar/proxy.sls
@@ -0,0 +1,13 @@
+etcd:
+ server:
+ enabled: true
+ bind:
+ host: 10.0.175.101
+ proxy: true
+ members:
+ - host: 10.0.175.101
+ name: etcd01
+ - host: 10.0.175.102
+ name: etcd02
+ - host: 10.0.175.103
+ name: etcd03
\ No newline at end of file
diff --git a/tests/pillar/single.sls b/tests/pillar/single.sls
new file mode 100644
index 0000000..cf2e30d
--- /dev/null
+++ b/tests/pillar/single.sls
@@ -0,0 +1,10 @@
+etcd:
+ server:
+ enabled: true
+ bind:
+ host: 10.0.175.101
+ token: $(uuidgen)
+ members:
+ - host: 10.0.175.101
+ name: etcd01
+ port: 4001
\ No newline at end of file
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755
index 0000000..3f42101
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,162 @@
+#!/usr/bin/env bash
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+METADATA=${CURDIR}/../metadata.yml
+FORMULA_NAME=$(cat $METADATA | python -c "import sys,yaml; print yaml.load(sys.stdin)['name']")
+
+## Overrideable parameters
+PILLARDIR=${PILLARDIR:-${CURDIR}/pillar}
+BUILDDIR=${BUILDDIR:-${CURDIR}/build}
+VENV_DIR=${VENV_DIR:-${BUILDDIR}/virtualenv}
+DEPSDIR=${BUILDDIR}/deps
+
+SALT_FILE_DIR=${SALT_FILE_DIR:-${BUILDDIR}/file_root}
+SALT_PILLAR_DIR=${SALT_PILLAR_DIR:-${BUILDDIR}/pillar_root}
+SALT_CONFIG_DIR=${SALT_CONFIG_DIR:-${BUILDDIR}/salt}
+SALT_CACHE_DIR=${SALT_CACHE_DIR:-${SALT_CONFIG_DIR}/cache}
+
+SALT_OPTS="${SALT_OPTS} --retcode-passthrough --local -c ${SALT_CONFIG_DIR}"
+
+if [ "x${SALT_VERSION}" != "x" ]; then
+ PIP_SALT_VERSION="==${SALT_VERSION}"
+fi
+
+## Functions
+log_info() {
+ echo "[INFO] $*"
+}
+
+log_err() {
+ echo "[ERROR] $*" >&2
+}
+
+setup_virtualenv() {
+ log_info "Setting up Python virtualenv"
+ virtualenv $VENV_DIR
+ source ${VENV_DIR}/bin/activate
+ pip install salt${PIP_SALT_VERSION}
+}
+
+setup_pillar() {
+ [ ! -d ${SALT_PILLAR_DIR} ] && mkdir -p ${SALT_PILLAR_DIR}
+ echo "base:" > ${SALT_PILLAR_DIR}/top.sls
+ for pillar in ${PILLARDIR}/*; do
+ state_name=$(basename ${pillar%.sls})
+ echo -e " ${state_name}:\n - ${state_name}" >> ${SALT_PILLAR_DIR}/top.sls
+ done
+}
+
+setup_salt() {
+ [ ! -d ${SALT_FILE_DIR} ] && mkdir -p ${SALT_FILE_DIR}
+ [ ! -d ${SALT_CONFIG_DIR} ] && mkdir -p ${SALT_CONFIG_DIR}
+ [ ! -d ${SALT_CACHE_DIR} ] && mkdir -p ${SALT_CACHE_DIR}
+
+ echo "base:" > ${SALT_FILE_DIR}/top.sls
+ for pillar in ${PILLARDIR}/*.sls; do
+ state_name=$(basename ${pillar%.sls})
+ echo -e " ${state_name}:\n - ${FORMULA_NAME}" >> ${SALT_FILE_DIR}/top.sls
+ done
+
+ cat << EOF > ${SALT_CONFIG_DIR}/minion
+file_client: local
+cachedir: ${SALT_CACHE_DIR}
+verify_env: False
+
+file_roots:
+ base:
+ - ${SALT_FILE_DIR}
+ - ${CURDIR}/..
+ - /usr/share/salt-formulas/env
+
+pillar_roots:
+ base:
+ - ${SALT_PILLAR_DIR}
+ - ${PILLARDIR}
+EOF
+}
+
+fetch_dependency() {
+ dep_name="$(echo $1|cut -d : -f 1)"
+ dep_source="$(echo $1|cut -d : -f 2-)"
+ dep_root="${DEPSDIR}/$(basename $dep_source .git)"
+ dep_metadata="${dep_root}/metadata.yml"
+
+ [ -d /usr/share/salt-formulas/env/${dep_name} ] && log_info "Dependency $dep_name already present in system-wide salt env" && return 0
+ [ -d $dep_root ] && log_info "Dependency $dep_name already fetched" && return 0
+
+ log_info "Fetching dependency $dep_name"
+ [ ! -d ${DEPSDIR} ] && mkdir -p ${DEPSDIR}
+ git clone $dep_source ${DEPSDIR}/$(basename $dep_source .git)
+ ln -s ${dep_root}/${dep_name} ${SALT_FILE_DIR}/${dep_name}
+
+ METADATA="${dep_metadata}" install_dependencies
+}
+
+install_dependencies() {
+ grep -E "^dependencies:" ${METADATA} >/dev/null || return 0
+ (python - | while read dep; do fetch_dependency "$dep"; done) << EOF
+import sys,yaml
+for dep in yaml.load(open('${METADATA}', 'ro'))['dependencies']:
+ print '%s:%s' % (dep["name"], dep["source"])
+EOF
+}
+
+clean() {
+ log_info "Cleaning up ${BUILDDIR}"
+ [ -d ${BUILDDIR} ] && rm -rf ${BUILDDIR} || exit 0
+}
+
+salt_run() {
+ [ -e ${VEN_DIR}/bin/activate ] && source ${VENV_DIR}/bin/activate
+ salt-call ${SALT_OPTS} $*
+}
+
+prepare() {
+ [ -d ${BUILDDIR} ] && mkdir -p ${BUILDDIR}
+
+ which salt-call || setup_virtualenv
+ setup_pillar
+ setup_salt
+ install_dependencies
+}
+
+run() {
+ for pillar in ${PILLARDIR}/*.sls; do
+ state_name=$(basename ${pillar%.sls})
+ salt_run --id=${state_name} state.show_sls ${FORMULA_NAME} || (log_err "Execution of ${FORMULA_NAME}.${state_name} failed"; exit 1)
+ done
+}
+
+_atexit() {
+ RETVAL=$?
+ trap true INT TERM EXIT
+
+ if [ $RETVAL -ne 0 ]; then
+ log_err "Execution failed"
+ else
+ log_info "Execution successful"
+ fi
+ return $RETVAL
+}
+
+## Main
+trap _atexit INT TERM EXIT
+
+case $1 in
+ clean)
+ clean
+ ;;
+ prepare)
+ prepare
+ ;;
+ run)
+ run
+ ;;
+ *)
+ prepare
+ run
+ ;;
+esac