node

package
v0.0.0-...-b1baf6d Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2016 License: Apache-2.0 Imports: 14 Imported by: 2

README

Node

Manage hosts from the d2k8 cli.

Create a node

Create a node to be managed by d2k8 and installs docker on it.

d2k8 node create name -ip ip -cert docker_cert_path -tags staging,database

Argument Meaning
name name of the node to be identified in elora cli commands
url url to connect to the node
cert path to docker node certificates
tags list of tags associated to this node

Configure a docker client to connect to a node

Retrieve Docker environment variables to allow docker client configuration by executing $(d2k8 node env name).

d2k8 node env name

Argument Meaning
name name of the node to be retrieved

Inspect a node

Retrieve node information.

d2k8 node inspect name

Argument Meaning
name name of the node to be retrieved

List nodes

Retrive all nodes information.

d2k8 node list

Update a node

Update a node managed by d2k8.

d2k8 node update name -ip ip -cert docker_cert_path -tags staging,database

Argument Meaning
name name of the node to be updated
url new url of the node (optional)
cert new path to docker node certificates (optional)
tags new list of tags associated to this node (optional)

Delete a node

Remove a node from d2k8. Containers created in this node are also deleted.

d2k8 node remove name

Argument Meaning
name name of the node to be deleted

Integration with Docker-Machine

Docker-Machine is a beuatiful Docker project to create virtual machines where docker is automatically configured. At d2k8 we don't want to re-implement all this functionality, but allow for easier integration of Docker-Machine users instead. This is achieved by allowing d2k8 node create flags to be passed via environment variables. In particular, the value of -url is taken from DOCKER_HOST and the value of -cert is taken from DOCKER_CERT_PATH if they are not specified in the node create command.

For example, to create a virtualbox node and register it into d2k8 you can do like this:

docker-machine create --driver virtualbox test
$(docker-machine env test)
d2k8 node create test

And the node test will be ready to deploy stacks from d2k8. A full list of Docker-Machine supported providers and its configuration options is available here.

Documentation

Index

Constants

View Source
const (
	FILL_SIZE = 30
)

Variables

View Source
var Commands = cli.Command{
	Name:  "node",
	Usage: "manage d2k8 nodes",
	Subcommands: []cli.Command{
		{
			Name:  "create",
			Usage: "create a node",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:   "url",
					Usage:  "Specify the url of the node",
					EnvVar: "DOCKER_HOST",
				},
				cli.StringFlag{
					Name:   "cert",
					Usage:  "Specify the docker certificate path",
					EnvVar: "DOCKER_CERT_PATH",
				},
				cli.StringFlag{
					Name:  "key, k",
					Usage: "Specify the SSH certificate path",
				},
				cli.StringFlag{
					Name:  "cluster, c",
					Usage: "Specify the node cluster",
				},
				cli.StringFlag{
					Name:  "tags, t",
					Usage: "Specify the node tags separated by commas",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) != 1 {
					log.Fatal("'create' command only needs the name of the node to be created as a positional argument")
				}
				if c.String("url") == "" {
					log.Fatal("flag 'url' is mandatory, or set the variable 'DOCKER_HOST'")
				}
				if !filepath.IsAbs(c.String("cert")) {
					log.Fatal("'cert' must be an absolute path")
				}
				key := c.String("key")
				if key == "" {
					if strings.Contains(c.String("cert"), "/.docker/machine/machines/") {
						key = filepath.Join(c.String("cert"), "id_rsa")
					} else {
						log.Fatal("flag 'key' is mandatory, or set the variable 'DOCKER_CERT_PATH' of a machine created with docker-machine")
					}
				}
				if !filepath.IsAbs(key) {
					log.Fatal("'key' must be an absolute path")
				}
				cluster := c.String("cluster")
				if cluster == "" {
					cluster = "default"
				}
				tags := strings.Split(c.String("tags"), ",")
				err := CreateCmd(c.Args().First(), c.String("url"), c.String("cert"), key, cluster, tags)
				if err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:  "env",
			Usage: "show docker env variables. Configure the docker client to connect to this node by executing '$(elora node env test)'.",
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "unset, u",
					Usage: "show unset commands",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) != 1 {
					log.Fatal("'env' command only needs the name of the node to retrieve as a postional argument")
				}
				err := EnvCmd(c.Args().First(), c.Bool("unset"))
				if err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:      "inspect",
			ShortName: "get",
			Usage:     "get the information of a node",
			Action: func(c *cli.Context) {
				if len(c.Args()) != 1 {
					log.Fatal("'inspect' command only needs the name of the node to retrieve as a postional argument")
				}
				err := InspectCmd(c.Args().First())
				if err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:      "list",
			ShortName: "ls",
			Usage:     "list the d2k8 current nodes",
			Action: func(c *cli.Context) {
				err := ListCmd()
				if err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:      "update",
			ShortName: "up",
			Usage:     "update a node",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "url",
					Usage: "Specify the url of the node",
				},
				cli.StringFlag{
					Name:  "cert, c",
					Usage: "Specify the docker certificate path",
				},
				cli.StringFlag{
					Name:  "key, k",
					Usage: "Specify the SSH certificate path",
				},
				cli.StringFlag{
					Name:  "tags, t",
					Usage: "Specify the host tags separated by commas",
				},
			},
			Action: func(c *cli.Context) {
				if len(c.Args()) != 1 {
					log.Fatal("'update' command only needs the name of the node to be updated as a positional argument")
				}
				key := c.String("key")
				if key == "" {
					if strings.Contains(c.String("cert"), "/.docker/machine/machines/") {
						key = filepath.Join(c.String("cert"), "id_rsa")
					}
				}
				if !filepath.IsAbs(key) {
					log.Fatal("'key' must be an absolute path")
				}
				tags := strings.Split(c.String("tags"), ",")
				err := UpdateCmd(c.Args().First(), c.String("url"), c.String("cert"), key, tags)
				if err != nil {
					log.Fatal(err)
				}
			},
		},
		{
			Name:      "remove",
			ShortName: "rm",
			Usage:     "remove a node",
			Action: func(c *cli.Context) {
				if len(c.Args()) != 1 {
					log.Fatal("'remove' command only needs the name of the node to be removed as a positional argument")
				}
				err := RemoveCmd(c.Args().First())
				if err != nil {
					log.Fatal(err)
				}
			},
		},
	},
}

Functions

func CompleteUrl

func CompleteUrl(url string) string

func CreateCmd

func CreateCmd(name string, url string, cert string, key string, clusterName string, tags []string) error

func Delete

func Delete(name string) error

func EnvCmd

func EnvCmd(name string, unset bool) error

func Exists

func Exists(name string) bool

func FileFolder

func FileFolder() string

func FilePath

func FilePath(name string) string

func GetIp

func GetIp(url string) string

func InspectCmd

func InspectCmd(name string) error

func List

func List() ([]string, error)

func ListCmd

func ListCmd() error

func RemoveCmd

func RemoveCmd(name string) error

func UpdateCmd

func UpdateCmd(name string, url string, cert string, key string, tags []string) error

func Write

func Write(node Node) error

Types

type Node

type Node struct {
	Name    string
	Url     string
	Cert    string
	Key     string
	Cluster string
	Tags    []string
}

func Read

func Read(name string) (Node, error)

func (*Node) Client

func (n *Node) Client() (client.Client, error)

func (*Node) Execute

func (n *Node) Execute(command string) (string, error)

func (*Node) RemoveContainers

func (n *Node) RemoveContainers() error

Jump to

Keyboard shortcuts

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