| 291 | |
| 292 | |
| 293 | Try<Nothing> machine(const MachineID& id) |
| 294 | { |
| 295 | // Verify that the machine has at least one non-empty field value. |
| 296 | if (id.hostname().empty() && id.ip().empty()) { |
| 297 | return Error("Both 'hostname' and 'ip' for a machine are empty"); |
| 298 | } |
| 299 | |
| 300 | // Validate the IP field. |
| 301 | if (!id.ip().empty()) { |
| 302 | Try<net::IP> ip = net::IP::parse(id.ip(), AF_INET); |
| 303 | if (ip.isError()) { |
| 304 | return Error(ip.error()); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | return Nothing(); |
| 309 | } |
| 310 | |
| 311 | } // namespace validation { |
| 312 | } // namespace maintenance { |