func getPeerName(deps service.ServiceDependencies, flags *service.ServiceFlags) (string, error) { members, err := flags.GetClusterMembers(deps.Logger) if err != nil { return "", maskAny(err) } for _, member := range members { if member.ClusterIP == flags.Network.ClusterIP { name, err := util.WeaveNameFromMachineID(member.MachineID) if err != nil { return "", maskAny(err) } return name, nil } } return "", nil }
// SetupDefaults fills given flags with default value func (flags *ServiceFlags) SetupDefaults(log *logging.Logger) error { if flags.Docker.PrivateRegistryUrl == "" { url, err := ioutil.ReadFile(privateRegistryUrlPath) if err != nil && !os.IsNotExist(err) { return maskAny(err) } else if err == nil { flags.Docker.PrivateRegistryUrl = string(url) } } if flags.Fleet.Metadata == "" { raw, err := ioutil.ReadFile(fleetMetadataPath) if err != nil && !os.IsNotExist(err) { return maskAny(err) } else if err == nil { lines := trimLines(strings.Split(string(raw), "\n")) flags.Fleet.Metadata = strings.Join(lines, ",") } } if flags.Etcd.ClusterState == "" { raw, err := ioutil.ReadFile(etcdClusterStatePath) if err != nil && !os.IsNotExist(err) { return maskAny(err) } else if err == nil { lines := trimLines(strings.Split(string(raw), "\n")) flags.Etcd.ClusterState = strings.TrimSpace(strings.Join(lines, " ")) } } if flags.Network.PrivateClusterDevice == "" { flags.Network.PrivateClusterDevice = "eth1" } if flags.GluonImage == "" { content, err := ioutil.ReadFile(gluonImagePath) if err != nil && !os.IsNotExist(err) { return maskAny(err) } else if err == nil { flags.GluonImage = strings.TrimSpace(string(content)) } } if flags.Weave.Seed == "" { seed, err := ioutil.ReadFile(weaveSeedPath) if err != nil && !os.IsNotExist(err) { return maskAny(err) } else if err == nil { flags.Weave.Seed = string(seed) } else { members, err := flags.GetClusterMembers(log) if err != nil { return maskAny(err) } var seeds []string for _, m := range members { if !m.EtcdProxy { name, err := util.WeaveNameFromMachineID(m.MachineID) if err != nil { return maskAny(err) } seeds = append(seeds, name) } } flags.Weave.Seed = strings.Join(seeds, ",") } } return nil }