discover

package module
v0.0.0-...-21b26b7 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2017 License: MPL-2.0 Imports: 10 Imported by: 0

README

Go Discover Nodes for Cloud Providers Build Status GoDoc

go-discover is a Go (golang) library and command line tool to discover ip addresses of nodes in cloud environments based on meta information like tags provided by the environment.

The configuration for the providers is provided as a list of key=val key=val ... tuples where the values can be URL encoded. The provider is determined through the provider key. Effectively, only spaces have to be encoded with a + and on the command line you have to observe quoting rules with your shell.

Supported Providers

The following cloud providers have implementations in the go-discover/provider sub packages. Additional providers can be added through the Register function.

Config Example
# Amazon AWS
provider=aws region=eu-west-1 tag_key=consul tag_value=... access_key_id=... secret_access_key=...

# Google Cloud
provider=gce project_name=... zone_pattern=eu-west-* tag_value=consul credentials_file=...

# Microsoft Azure
provider=azure tag_name=consul tag_value=... tenant_id=... client_id=... subscription_id=... secret_access_key=...

# SoftLayer
provider=softlayer datacenter=dal06 tag_value=consul username=... api_key=...

Command Line Tool Usage

Install the command line tool with:

go get -u github.com/hashicorp/go-discover/cmd/discover

Then run it with:

$ discover addrs provider=aws region=eu-west-1 ...

Library Usage

Install the library with:

go get -u github.com/hashicorp/go-discover

You can then either support discovery for all available providers or only for some of them.

// support discovery for all supported providers
d := discover.Discover{}

// support discovery for AWS and GCE only
d := discover.Discover{
	Providers : map[string]discover.Provider{
		"aws": discover.Providers["aws"],
		"gce": discover.Providers["gce"],
	}
}

// use ioutil.Discard for no log output
l := log.New(os.Stderr, "", log.LstdFlags)

cfg := "provider=aws region=eu-west-1 ..."
addrs, err := d.Addrs(cfg, l)

For complete API documentation, see GoDoc. The configuration for the supported providers is documented in the providers sub-package.

Documentation

Overview

Package discover provides functions to get metadata for different cloud environments.

Index

Constants

This section is empty.

Variables

View Source
var Providers = map[string]Provider{
	"aws":       &aws.Provider{},
	"azure":     &azure.Provider{},
	"gce":       &gce.Provider{},
	"softlayer": &softlayer.Provider{},
}

Providers contains all available providers.

Functions

This section is empty.

Types

type Config

type Config map[string]string

Config stores key/value pairs for the discovery functions to use.

func Parse

func Parse(s string) (Config, error)

Parse parses a "key=val key=val ..." string into a config map. Values are URL escaped.

func (Config) String

func (c Config) String() string

String formats a config map into the "key=val key=val ..." understood by Parse. The order of the keys is stable.

type Discover

type Discover struct {
	// Providers is the list of address lookup providers.
	// If nil, the default list of providers is used.
	Providers map[string]Provider
	// contains filtered or unexported fields
}

Discover looks up metadata in different cloud environments.

func (*Discover) Addrs

func (d *Discover) Addrs(cfg string, l *log.Logger) ([]string, error)

Addrs discovers ip addresses of nodes that match the given filter criteria. The config string must have the format 'provider=xxx key=val key=val ...' where the keys and values are provider specific. The values are URL encoded.

func (*Discover) Help

func (d *Discover) Help() string

Help describes the format of the configuration string for address discovery and the various provider specific options.

func (*Discover) Names

func (d *Discover) Names() []string

Names returns the names of the configured providers.

type Provider

type Provider interface {
	// Addrs looks up addresses in the cloud environment according to the
	// configuration provided in args.
	Addrs(args map[string]string, l *log.Logger) ([]string, error)

	// Help provides the configuration help for the command line client.
	Help() string
}

Provider has lookup functions for meta data in a cloud environment.

Directories

Path Synopsis
cmd
discover
discover provides node discovery on the command line.
discover provides node discovery on the command line.
provider
aws
Package aws provides node discovery for Amazon AWS.
Package aws provides node discovery for Amazon AWS.
azure
Package azure provides node discovery for Microsoft Azure.
Package azure provides node discovery for Microsoft Azure.
gce
Package gce provides node discovery for Google Cloud.
Package gce provides node discovery for Google Cloud.
softlayer
Package softlayer provides node discovery for Softlayer.
Package softlayer provides node discovery for Softlayer.

Jump to

Keyboard shortcuts

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