|
|
|
@ -580,19 +580,20 @@ func (h *Host) SetIPHosts(ip string, hosts ...string) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *Host) SetHostIPs(host string, ips ...string) error {
|
|
|
|
|
info := h.ListByHost(host)
|
|
|
|
|
if len(info) == 0 {
|
|
|
|
|
return h.AddHosts(host, ips...)
|
|
|
|
|
} else if len(info) == 1 {
|
|
|
|
|
info[0].ip = ips[0]
|
|
|
|
|
info[0].comment = ""
|
|
|
|
|
return nil
|
|
|
|
|
if len(ips) == 0 {
|
|
|
|
|
return fmt.Errorf("no ip address")
|
|
|
|
|
}
|
|
|
|
|
err := h.RemoveHosts(host)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return h.AddHosts(ips[0], host)
|
|
|
|
|
for _, ip := range ips {
|
|
|
|
|
err := h.AddHosts(ip, host)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (h *Host) addHosts(comment string, ip string, hosts ...string) error {
|
|
|
|
|