From 229d439829bcb398a9a2414678e474cf1f3ccd1a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 10 Nov 2018 12:37:12 -0700 Subject: define the VM without using a shell script --- src/Propellor/Property/Libvirt.hs | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/Propellor/Property/Libvirt.hs') diff --git a/src/Propellor/Property/Libvirt.hs b/src/Propellor/Property/Libvirt.hs index c5dda41b..05ce074a 100644 --- a/src/Propellor/Property/Libvirt.hs +++ b/src/Propellor/Property/Libvirt.hs @@ -120,19 +120,26 @@ defined imageType (MiBMemory mem) (NumVCPUs cpus) auto h = return MadeChange xmlDefined :: Property UnixLike xmlDefined = check (not <$> doesFileExist conf) $ - scriptProperty - [ "virt-install -n " ++ hostName h - ++ osVariantArg - ++ " --memory=" ++ show mem - ++ " --vcpus=" ++ show cpus - ++ " --disk path=" ++ imageLoc + property "define the libvirt VM" $ + withTmpFile (hostName h) $ \t fh -> do + xml <- liftIO $ readProcess "virt-install" $ + [ "-n", hostName h + , osVariantArg + , "--memory=" ++ show mem + , "--vcpus=" ++ show cpus + , "--disk" + , "path=" ++ imageLoc ++ ",device=disk,bus=virtio" - ++ autoStartArg - ++ " --print-xml" - ++ " >" ++ confTmp - , "virsh define " ++ confTmp - , "rm " ++ confTmp - ] + , autoStartArg + , "--print-xml" + ] + liftIO $ hPutStrLn fh xml + liftIO $ hClose fh + makeChange $ unlessM (defineIt t) $ + errorMessage "failed to define VM" + where + defineIt t = boolSystem "virsh" [Param "define", Param t] + started :: Property UnixLike started = case auto of AutoStart -> property "start the VM" $ do @@ -154,11 +161,10 @@ defined imageType (MiBMemory mem) (NumVCPUs cpus) auto h = "/var/lib/libvirt/images" hostName h <.> case imageType of Raw -> "img" conf = "/etc/libvirt/qemu" hostName h <.> "xml" - confTmp = conf <.> "tmp" - osVariantArg = maybe "" (" --os-variant=" ++) $ osVariant h + osVariantArg = maybe "" ("--os-variant=" ++) $ osVariant h autoStartArg = case auto of - AutoStart -> " --autostart" + AutoStart -> "--autostart" NoAutoStart -> "" -- ==== utility functions ==== -- cgit v1.2.3