aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-05-26 18:09:51 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-05-26 18:11:16 -0700
commitb257978c5f2767527931a62591ba65a3b4337965 (patch)
tree94430a36941d709da4644901a75fd8ab9146ada0
parent5d488aa831100ff04d8c81f413313f4281f43cfb (diff)
downloadconsfigurator-b257978c5f2767527931a62591ba65a3b4337965.tar.gz
add LIBVIRT:{INSTALLED,DEFAULT-NETWORK-{AUTO,}STARTED}
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--consfigurator.asd1
-rw-r--r--debian/copyright4
-rw-r--r--src/package.lisp9
-rw-r--r--src/property/libvirt.lisp59
4 files changed, 71 insertions, 2 deletions
diff --git a/consfigurator.asd b/consfigurator.asd
index 2a8e6a0..a586cf9 100644
--- a/consfigurator.asd
+++ b/consfigurator.asd
@@ -50,6 +50,7 @@
(:file "src/property/grub")
(:file "src/property/u-boot")
(:file "src/property/hostname")
+ (:file "src/property/libvirt")
(:file "src/connection/shell-wrap")
(:file "src/connection/fork")
(:file "src/connection/rehome")
diff --git a/debian/copyright b/debian/copyright
index 0351f31..e5ee99f 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,8 +1,8 @@
Consfigurator
Lisp declarative configuration management system
-Copyright (C)2015, 2020-2021 Sean Whitton
-Copyright (C)2021 David Bremner
+Copyright (C)2015, 2018, 2020-2021 Sean Whitton
+Copyright (C)2021 David Bremner
This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/src/package.lisp b/src/package.lisp
index ca6605f..9658041 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -544,6 +544,15 @@
#:mailname-configured
#:search-configured))
+(defpackage :consfigurator.property.libvirt
+ (:use #:cl #:consfigurator)
+ (:local-nicknames (#:os #:consfigurator.property.os)
+ (#:file #:consfigurator.property.file)
+ (#:apt #:consfigurator.property.apt))
+ (:export #:installed
+ #:default-network-started
+ #:default-network-autostarted))
+
(defpackage :consfigurator.connection.local
(:use #:cl #:consfigurator #:alexandria)
(:export #:local-connection))
diff --git a/src/property/libvirt.lisp b/src/property/libvirt.lisp
new file mode 100644
index 0000000..5c3c2b6
--- /dev/null
+++ b/src/property/libvirt.lisp
@@ -0,0 +1,59 @@
+;;; Consfigurator -- Lisp declarative configuration management system
+
+;;; Copyright (C) 2018, 2021 Sean Whitton <spwhitton@spwhitton.name>
+
+;;; This file is free software; you can redistribute it and/or modify
+;;; it under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3, or (at your option)
+;;; any later version.
+
+;;; This file is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+
+;;; You should have received a copy of the GNU General Public License
+;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+(in-package :consfigurator.property.libvirt)
+(named-readtables:in-readtable :consfigurator)
+
+(defproplist installed :posix ()
+ "Install basic libvirt components."
+ (:desc "libvirt installed")
+ (os:etypecase
+ (debianlike (apt:installed "libvirt-clients" "virtinst"
+ "libvirt-daemon" "libvirt-daemon-system"))))
+
+(defprop %default-network-started :posix ()
+ (:check
+ (member "default" (mapcar #'car (virsh-get-columns "net-list"))
+ :test #'string=))
+ (:apply
+ (mrun "virsh" "net-start" "default")))
+
+(defprop %default-network-autostarted :posix ()
+ (:check
+ (remote-exists-p "/etc/libvirt/qemu/networks/autostart/default.xml"))
+ (:apply
+ (mrun "virsh" "net-autostart" "default")))
+
+(defproplist default-network-started :posix ()
+ "Ensure that the default libvirt network is started."
+ (:desc "libvirt's default network started")
+ (installed)
+ (%default-network-started))
+
+(defproplist default-network-autostarted :posix ()
+ "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."
+ (installed)
+ (%default-network-autostarted)
+ (%default-network-started))
+
+(defun virsh-get-columns (&rest arguments)
+ "Run a virsh command that is expected to yield tabular output, with the given
+list of ARGUMENTS, and return the rows."
+ (mapcar (lambda (row)
+ (delete "" (split-string row) :test #'string=))
+ (cddr (nbutlast (runlines "virsh" arguments)))))