initial commit
This commit is contained in:
46
pkg/validators/validators.go
Normal file
46
pkg/validators/validators.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// CheckBridge returns nil if the bridge exists on the host.
|
||||
func CheckBridge(name string) error {
|
||||
if name == "" {
|
||||
return fmt.Errorf("bridge name required")
|
||||
}
|
||||
if err := exec.Command("bash", "-lc", fmt.Sprintf("ip link show %s", name)).Run(); err != nil {
|
||||
return fmt.Errorf("bridge %s not found", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckBridgeSet validates all bridges in NIC specs.
|
||||
func CheckBridgeSet(nics []libvirt.NICSpec) error {
|
||||
for _, nic := range nics {
|
||||
if err := CheckBridge(nic.Bridge); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckBridgeSetCT validates bridges for LXC NICs.
|
||||
func CheckBridgeSetCT(nics []lxc.NICSpec) error {
|
||||
for _, nic := range nics {
|
||||
if err := CheckBridge(nic.Bridge); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckStoragePool is a stub; implement LVM/ZFS/dir verification as needed.
|
||||
func CheckStoragePool(name string) error {
|
||||
if name == "" {
|
||||
return fmt.Errorf("storage pool name required")
|
||||
}
|
||||
// TODO: query configured pools
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user