1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-28 11:36:27 +00:00
rke/hosts/hosts.go

42 lines
990 B
Go
Raw Normal View History

2017-10-29 09:45:21 +00:00
package hosts
import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/client"
)
2017-10-29 09:45:21 +00:00
type Hosts struct {
Hosts []Host `yaml:"hosts"`
}
type Host struct {
2017-11-02 09:27:26 +00:00
IP string `yaml:"ip"`
AdvertiseAddress string `yaml:"advertise_address"`
Role []string `yaml:"role"`
Hostname string `yaml:"hostname"`
User string `yaml:"user"`
DockerSocket string `yaml:"docker_socket"`
DClient *client.Client
2017-10-29 09:45:21 +00:00
}
func DivideHosts(hosts []Host) ([]Host, []Host, []Host) {
etcdHosts := []Host{}
cpHosts := []Host{}
workerHosts := []Host{}
for _, host := range hosts {
for _, role := range host.Role {
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
}