UpdateDNSMasqStatic rebuilds the DNSMasq static allocations.
(s *state.State, networkName string)
| 423 | |
| 424 | // UpdateDNSMasqStatic rebuilds the DNSMasq static allocations. |
| 425 | func UpdateDNSMasqStatic(s *state.State, networkName string) error { |
| 426 | // We don't want to race with ourselves here. |
| 427 | dnsmasq.ConfigMutex.Lock() |
| 428 | defer dnsmasq.ConfigMutex.Unlock() |
| 429 | |
| 430 | // Get all the networks. |
| 431 | var networks []string |
| 432 | if networkName == "" { |
| 433 | var err error |
| 434 | |
| 435 | err = s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error { |
| 436 | // Pass api.ProjectDefaultName here, as currently dnsmasq (bridged) networks do not support projects. |
| 437 | networks, err = tx.GetNetworks(ctx, api.ProjectDefaultName) |
| 438 | |
| 439 | return err |
| 440 | }) |
| 441 | if err != nil { |
| 442 | return err |
| 443 | } |
| 444 | } else { |
| 445 | networks = []string{networkName} |
| 446 | } |
| 447 | |
| 448 | // Get all the instances. |
| 449 | insts, err := instance.LoadNodeAll(s, instancetype.Any) |
| 450 | if err != nil { |
| 451 | return err |
| 452 | } |
| 453 | |
| 454 | // Build a list of dhcp host entries. |
| 455 | entries := map[string][][]string{} |
| 456 | for _, inst := range insts { |
| 457 | // Go through all its devices (including profiles). |
| 458 | for deviceName, d := range inst.ExpandedDevices() { |
| 459 | // Skip uninteresting entries. |
| 460 | if d["type"] != "nic" { |
| 461 | continue |
| 462 | } |
| 463 | |
| 464 | nicType, err := nictype.NICType(s, inst.Project().Name, d) |
| 465 | if err != nil || nicType != "bridged" { |
| 466 | continue |
| 467 | } |
| 468 | |
| 469 | // Temporarily populate parent from network setting if used. |
| 470 | if d["network"] != "" { |
| 471 | d["parent"] = d["network"] |
| 472 | } |
| 473 | |
| 474 | // Skip devices not connected to managed networks. |
| 475 | if !slices.Contains(networks, d["parent"]) { |
| 476 | continue |
| 477 | } |
| 478 | |
| 479 | // Fill in the hwaddr from volatile. |
| 480 | d, err = inst.FillNetworkDevice(deviceName, d) |
| 481 | if err != nil { |
| 482 | continue |
no test coverage detected
searching dependent graphs…