From 8d5a901ee6fb14eb199c0360408eda9c9f15617c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 10 Nov 2018 11:34:10 -0700 Subject: rewrite code to start the VM to not use a shell script --- src/Propellor/Property/Libvirt.hs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Libvirt.hs b/src/Propellor/Property/Libvirt.hs index 9f3f96a4..6119ebc8 100644 --- a/src/Propellor/Property/Libvirt.hs +++ b/src/Propellor/Property/Libvirt.hs @@ -120,12 +120,18 @@ defined imageType (MiBMemory mem) (NumVCPUs cpus) auto h = ] started :: Property UnixLike started = case auto of - AutoStart -> scriptProperty - [ "virsh list | grep -q \"" - ++ hostName h ++ " .*running\" && exit 0" - , "virsh start " ++ hostName h - ] `assume` NoChange + AutoStart -> property "start the VM" $ do + runningVMs <- liftIO $ virshGetColumns ["list"] + -- From the point of view of `virsh start`, the "State" + -- column in the output of `virsh list` is not relevant. + -- So long as the VM is listed, it's considered started. + if [hostName h] `elem` (take 1 . drop 1 <$> runningVMs) + then noChange + else makeChange $ unlessM startIt $ + errorMessage "failed to start VM" NoAutoStart -> doNothing + where + startIt = boolSystem "virsh" [Param "start", Param $ hostName h] image = case imageType of Raw -> RawDiskImage imageLoc -- cgit v1.2.3