summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/Libvirt.hs
diff options
context:
space:
mode:
authorSean Whitton2018-11-10 11:34:10 -0700
committerSean Whitton2018-11-10 15:54:32 -0700
commit8d5a901ee6fb14eb199c0360408eda9c9f15617c (patch)
tree3d28993f092f72284b669d68683d6275f1f7f005 /src/Propellor/Property/Libvirt.hs
parent7ea7e745e5b7c0f2965b6311e2f20874f58fffc1 (diff)
rewrite code to start the VM to not use a shell script
Diffstat (limited to 'src/Propellor/Property/Libvirt.hs')
-rw-r--r--src/Propellor/Property/Libvirt.hs16
1 files changed, 11 insertions, 5 deletions
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