propellor

propellor config for hosts.
git clone git://git.ricketyspace.net/propellor.git
Log | Files | Refs | LICENSE

WIP_adding_dhcp_records_to_libvirt.mdwn (1737B)


      1 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
      2 [[!format bash """
      3 virsh net-update default delete ip-dhcp-host "<host mac='52:54:00:f0:62:01'/>"  --config --live || /bin/true
      4 virsh net-update default add ip-dhcp-host "<host mac='52:54:00:f0:62:01' ip='192.168.122.32'/>" --config --live
      5 """]]
      6 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.
      7 
      8 [[!format haskell """
      9 staticDHCP :: Host -> IPAddr -> Maybe Network.Gateway -> Property UnixLike
     10 staticDHCP h ip gw = property "assign ip to host via dhcp" $ do
     11                 mac <- liftIO $ macAddress
     12                 case mac of
     13                   Nothing -> errorMessage "no interface"
     14                   Just addr -> makeChange $ unlessM (updateIt addr) $
     15                                 errorMessage "failed to update network"
     16   where
     17     updateIt mac = boolSystem "virsh" [ Param "net-update"
     18                                   , Param "default"
     19                                   , Param "add-last"
     20                                   , Param "ip-dhcp-host"
     21                                   , Param $ "<host mac=\""++mac++"\" ip=\""++(ifaceToString ip)++"\"/>"
     22                                   , Param "--config"
     23                                   , Param "--live"]
     24     ifaceToString (IPv6 ipstr) = ipstr
     25     ifaceToString (IPv4 ipstr) = ipstr
     26     macAddress = do
     27       ifaces <- virshGetColumns ["domiflist", hostName h]
     28       case ifaces of
     29         [] -> return Nothing
     30         (i:_) -> return $ Just $ Propellor.Base.last i
     31 """]]