From 30c1e57ea90ca2e8cd607fc1ad9b78bc7bf6dee1 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 8 Jun 2019 14:27:07 +0000 Subject: --- doc/forum/WIP_adding_dhcp_records_to_libvirt.mdwn | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/forum/WIP_adding_dhcp_records_to_libvirt.mdwn (limited to 'doc') diff --git a/doc/forum/WIP_adding_dhcp_records_to_libvirt.mdwn b/doc/forum/WIP_adding_dhcp_records_to_libvirt.mdwn new file mode 100644 index 00000000..118f01ab --- /dev/null +++ b/doc/forum/WIP_adding_dhcp_records_to_libvirt.mdwn @@ -0,0 +1,31 @@ +I'm working on adding static (predictable) dhcp records to libvirt guests (code at the end). It seems like I might need to either do the equivalent of +[[!format bash """ +virsh net-update default delete ip-dhcp-host "" --config --live || /bin/true +virsh net-update default add ip-dhcp-host "" --config --live +"""]] +or parse the xml output of "virsh net-dumpxml". Is there some simple lightweight xml parsing option? Last time I tried something like this was a decade ago using HXT.Arrow, which didn't really end well. + +[[!format haskell """ +staticDHCP :: Host -> IPAddr -> Maybe Network.Gateway -> Property UnixLike +staticDHCP h ip gw = property "assign ip to host via dhcp" $ do + mac <- liftIO $ macAddress + case mac of + Nothing -> errorMessage "no interface" + Just addr -> makeChange $ unlessM (updateIt addr) $ + errorMessage "failed to update network" + where + updateIt mac = boolSystem "virsh" [ Param "net-update" + , Param "default" + , Param "add-last" + , Param "ip-dhcp-host" + , Param $ "" + , Param "--config" + , Param "--live"] + ifaceToString (IPv6 ipstr) = ipstr + ifaceToString (IPv4 ipstr) = ipstr + macAddress = do + ifaces <- virshGetColumns ["domiflist", hostName h] + case ifaces of + [] -> return Nothing + (i:_) -> return $ Just $ Propellor.Base.last i +"""]] -- cgit v1.2.3