updateState updates the state of an IP for a vserver based on the state of that IP's services.
(ip seesaw.IP)
| 1161 | // updateState updates the state of an IP for a vserver based on the state of |
| 1162 | // that IP's services. |
| 1163 | func (v *vserver) updateState(ip seesaw.IP) { |
| 1164 | // A vserver anycast IP is healthy if *all* services for that IP are healthy. |
| 1165 | // A vserver unicast IP is healthy if *any* services for that IP are healthy. |
| 1166 | var healthy bool |
| 1167 | for _, s := range v.services { |
| 1168 | if !s.ip.Equal(ip) { |
| 1169 | continue |
| 1170 | } |
| 1171 | healthy = s.healthy |
| 1172 | if !healthy && seesaw.IsAnycast(ip.IP()) { |
| 1173 | break |
| 1174 | } |
| 1175 | if healthy && !seesaw.IsAnycast(ip.IP()) { |
| 1176 | break |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | if v.active[ip] == healthy { |
| 1181 | v.updateServices(ip) |
| 1182 | return |
| 1183 | } |
| 1184 | switch { |
| 1185 | case !healthy && v.active[ip]: |
| 1186 | v.down(ip) |
| 1187 | case healthy && !v.active[ip]: |
| 1188 | v.up(ip) |
| 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | // updateServices brings the services for a vserver up or down based on the |
| 1193 | // state of the vserver and the health of each service. |