2017-10-29 09:45:21 +00:00
|
|
|
package hosts
|
|
|
|
|
2017-10-30 06:31:06 +00:00
|
|
|
import (
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
)
|
2017-10-29 09:45:21 +00:00
|
|
|
|
|
|
|
type Hosts struct {
|
|
|
|
Hosts []Host `yaml:"hosts"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Host struct {
|
|
|
|
IP string `yaml:"ip"`
|
|
|
|
Role []string `yaml:"role"`
|
|
|
|
Hostname string `yaml:"hostname"`
|
|
|
|
User string `yaml:"user"`
|
|
|
|
DockerSocket string `yaml:"docker_socket"`
|
|
|
|
DClient *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func DivideHosts(hosts []Host) ([]Host, []Host, []Host) {
|
|
|
|
etcdHosts := []Host{}
|
|
|
|
cpHosts := []Host{}
|
|
|
|
workerHosts := []Host{}
|
|
|
|
for _, host := range hosts {
|
|
|
|
for _, role := range host.Role {
|
2017-10-30 06:31:06 +00:00
|
|
|
logrus.Debugf("Host: " + host.Hostname + " has role: " + role)
|
2017-10-29 09:45:21 +00:00
|
|
|
if role == "etcd" {
|
|
|
|
etcdHosts = append(etcdHosts, host)
|
|
|
|
}
|
|
|
|
if role == "controlplane" {
|
|
|
|
cpHosts = append(cpHosts, host)
|
|
|
|
}
|
|
|
|
if role == "worker" {
|
|
|
|
workerHosts = append(workerHosts, host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return etcdHosts, cpHosts, workerHosts
|
|
|
|
}
|