summaryrefslogtreecommitdiff
path: root/src/Propellor
diff options
context:
space:
mode:
authorSean Whitton2018-11-10 12:22:04 -0700
committerSean Whitton2018-11-10 15:54:32 -0700
commit161de767e430861e8c79133cc79b174a8674e494 (patch)
treebe49da41bf04dd8366533c7414ae6b389b49bc0d /src/Propellor
parent8d5a901ee6fb14eb199c0360408eda9c9f15617c (diff)
Libvirt.defaultNetworkAutostarted additionally starts the network
Diffstat (limited to 'src/Propellor')
-rw-r--r--src/Propellor/Property/Libvirt.hs25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/Propellor/Property/Libvirt.hs b/src/Propellor/Property/Libvirt.hs
index 6119ebc8..c5dda41b 100644
--- a/src/Propellor/Property/Libvirt.hs
+++ b/src/Propellor/Property/Libvirt.hs
@@ -7,6 +7,7 @@ module Propellor.Property.Libvirt (
DiskImageType(..),
installed,
defaultNetworkAutostarted,
+ defaultNetworkStarted,
defined,
) where
@@ -36,16 +37,32 @@ data DiskImageType = Raw -- | QCow2
installed :: Property DebianLike
installed = Apt.installed ["libvirt-clients", "virtinst"]
--- | Ensure that the default libvirt network is set to autostart.
+-- | Ensure that the default libvirt network is set to autostart, and start it.
--
-- On Debian, it is not started by default after installation of libvirt.
defaultNetworkAutostarted :: Property DebianLike
-defaultNetworkAutostarted = check (not <$> doesFileExist autostartFile)
- (cmdProperty "virsh" ["net-autostart", "default"])
+defaultNetworkAutostarted = autostarted
`requires` installed
+ `before` defaultNetworkStarted
where
+ autostarted = check (not <$> doesFileExist autostartFile) $
+ cmdProperty "virsh" ["net-autostart", "default"]
autostartFile = "/etc/libvirt/qemu/networks/autostart/default.xml"
+-- | Ensure that the default libvirt network is started.
+defaultNetworkStarted :: Property DebianLike
+defaultNetworkStarted = go `requires` installed
+ where
+ go :: Property UnixLike
+ go = property "start libvirt's default network" $ do
+ runningNetworks <- liftIO $ virshGetColumns ["net-list"]
+ if ["default"] `elem` (take 1 <$> runningNetworks)
+ then noChange
+ else makeChange $ unlessM startIt $
+ errorMessage "failed to start default network"
+ startIt = boolSystem "virsh" [Param "net-start", Param "default"]
+
+
-- | Builds a disk image with the properties of the given Host, installs a
-- libvirt configuration file to boot the image, and if it is set to autostart,
-- start the VM.
@@ -61,8 +78,6 @@ defaultNetworkAutostarted = check (not <$> doesFileExist autostartFile)
-- > mybox = host "mybox.example.com" $ props
-- > & osDebian (Stable "stretch") X86_64
-- > & Libvirt.defaultNetworkAutostarted
--- > `onChange` (cmdProperty "virsh" ["net-start", "default"]
--- > `assume` MadeChange)
-- > & Libvirt.defined Libvirt.Raw
-- > (Libvirt.MiBMemory 2048) (Libvirt.NumVCPUs 2)
-- > Libvirt.NoAutoStart subbox