etcd

package
v0.0.0-...-9aee857 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package etcd is a library for performing common Etcd tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateClient

func CreateClient(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

CreateClient creates a new Etcd client and prepares it for work.

Params:

  • url (string): A server to connect to.
  • retries (int): Number of times to retry a connection to the server
  • retrySleep (time.Duration): How long to sleep between retries

Returns:

This puts an *etcd.Client into the context.

func FindSSHUser

func FindSSHUser(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

FindSSHUser finds an SSH user by public key.

Some parts of the system require that we know not only the SSH key, but also the name of the user. That information is stored in etcd.

Params:

  • client (EtcdGetter)
  • fingerprint (string): The fingerprint of the SSH key.

Returns: - username (string)

func Get

func Get(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

Get performs an etcd Get operation.

Params:

  • client (EtcdGetter): Etcd client
  • path (string): The path/key to fetch

Returns:

  • This puts an `etcd.Response` into the context, and returns an error if the client could not connect.

func IsRunning

func IsRunning(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

IsRunning checks to see if etcd is running.

It will test `count` times before giving up.

Params:

  • client (EtcdGetter)
  • count (int): Number of times to try before giving up.

Returns:

boolean true if etcd is listening.

func MakeDir

func MakeDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

MakeDir makes a directory in Etcd.

Params:

  • client (EtcdDirCreator): Etcd client
  • path (string): The name of the directory to create.
  • ttl (uint64): Time to live.

Returns:

*etcd.Response

func Set

func Set(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

Set sets a value in etcd.

Params:

  • key (string): The key
  • value (string): The value
  • ttl (uint64): Time to live
  • client (EtcdGetter): Client, usually an *etcd.Client.

Returns:

  • *etcd.Result

func StoreHostKeys

func StoreHostKeys(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

StoreHostKeys stores SSH hostkeys locally.

First it tries to fetch them from etcd. If the keys are not present there, it generates new ones and then puts them into etcd.

Params:

  • client(EtcdGetterSetter)
  • ciphers([]string): A list of ciphers to generate. Defaults are dsa, ecdsa, ed25519 and rsa.
  • basepath (string): Base path in etcd (ETCD_PATH).

Returns:

func UpdateHostPort

func UpdateHostPort(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

UpdateHostPort intermittently notifies etcd of the builder's address.

If `port` is specified, this will notify etcd at 10 second intervals that the builder is listening at $HOST:$PORT, setting the TTL to 20 seconds.

This will notify etcd as long as the local sshd is running.

Params:

  • base (string): The base path to write the data: $base/host and $base/port.
  • host (string): The hostname
  • port (string): The port
  • client (Setter): The client to use to write the data to etcd.
  • sshPid (int): The PID for SSHD. If SSHD dies, this stops notifying.

func Watch

func Watch(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

Watch watches a given path, and executes a git check-repos for each event.

It starts the watcher and then returns. The watcher runs on its own goroutine. To stop the watching, send the returned channel a bool.

Params: - client (Watcher): An Etcd client. - path (string): The path to watch

Returns:

  • chan bool: Send this a message to stop the watcher.

Types

type DirCreator

type DirCreator interface {
	CreateDir(string, uint64) (*etcd.Response, error)
}

DirCreator describes etcd's CreateDir behavior.

Usually you will want to use go-etcd/etcd.Client to satisfy this.

type Getter

type Getter interface {
	Get(string, bool, bool) (*etcd.Response, error)
}

Getter describes the Get behavior of an Etcd client.

Usually you will want to use go-etcd/etcd.Client to satisfy this.

We use an interface because it is more testable.

type GetterSetter

type GetterSetter interface {
	Getter
	Setter
}

GetterSetter performs get and set operations.

type Setter

type Setter interface {
	Set(string, string, uint64) (*etcd.Response, error)
}

Setter sets a value in Etcd.

type Watcher

type Watcher interface {
	Watch(string, uint64, bool, chan *etcd.Response, chan bool) (*etcd.Response, error)
}

Watcher watches an etcd entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL