aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-08-27 14:32:16 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-08-31 15:30:50 -0700
commitab469268b42d8fc8b0a180990be40e925a65935a (patch)
tree3b18ccc1fc99dfeded420634b4e529e1203881e1
parent7e72e55e996b29ba775e6695ee1f85ce637dc90a (diff)
downloadconsfigurator-ab469268b42d8fc8b0a180990be40e925a65935a.tar.gz
rework PUSHNEW-HOSTATTRS to use EQUAL not EQL & add PUSHNEW-HOSTATTR
Previously, PUSHNEW-HOSTATTRS always used EQL to determine whether a hostattr was already pushed, which would give the wrong answer for many common cases. Now default to using EQUAL, and provide a way for the caller to specify the test function. PUSHNEW-HOSTATTRS now takes a list of hostattrs as a single parameter, rather than using &REST, in order to make room for the new :TEST keyword parameter. To mitigate the inconvenience of no longer using &REST, add PUSHNEW-HOSTATTR. Also fix some parameter and function names in docstrings. Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/package.lisp1
-rw-r--r--src/property.lisp19
-rw-r--r--src/property/apt.lisp4
-rw-r--r--src/property/network.lisp10
4 files changed, 20 insertions, 14 deletions
diff --git a/src/package.lisp b/src/package.lisp
index 2cbff57..6c4e81b 100644
--- a/src/package.lisp
+++ b/src/package.lisp
@@ -181,6 +181,7 @@
#:get-parent-hostattrs
#:get-parent-hostattrs-car
#:push-hostattrs
+ #:pushnew-hostattr
#:pushnew-hostattrs
#:get-hostname
#:get-short-hostname
diff --git a/src/property.lisp b/src/property.lisp
index 9e517f2..ac66c38 100644
--- a/src/property.lisp
+++ b/src/property.lisp
@@ -512,19 +512,24 @@ Called by property :HOSTATTRS subroutines."
(setf (getf (slot-value *host* 'hostattrs) k)
(append vs (get-hostattrs k))))
-(defun pushnew-hostattrs (k &rest vs)
- "Push new static informational attributes VS of type KEY.
-
-Called by property :HOSTATTRS subroutines."
+(defun pushnew-hostattr (k v &key (test #'equal))
+ "Push new static informational attribute V of type K.
+TEST is passed on to PUSHNEW. Called by property :HOSTATTRS subroutines."
+ (pushnew-hostattrs k (list v) :test test))
+
+(defun pushnew-hostattrs (k vs &key (test #'equal))
+ "Push new static informational attributes VS of type K.
+VS is a list of items. TEST is passed on to PUSHNEW. Called by property
+:HOSTATTRS subroutines."
(dolist (v (reverse vs))
- (pushnew v (getf (slot-value *host* 'hostattrs) k))))
+ (pushnew v (getf (slot-value *host* 'hostattrs) k) :test test)))
(defun require-data (iden1 iden2)
- "Wrapper around PUSH-HOSTATTRS to indicate that a piece of prerequisite data
+ "Wrapper around PUSHNEW-HOSTATTR to indicate that a piece of prerequisite data
is needed to deploy a property.
Called by property :HOSTATTRS subroutines."
- (pushnew-hostattrs :data (cons iden1 iden2)))
+ (pushnew-hostattr :data (cons iden1 iden2)))
(defun get-hostname (&optional (host *host*))
"Get the hostname of HOST, defaulting to the host to which properties are
diff --git a/src/property/apt.lisp b/src/property/apt.lisp
index cd0e938..2197148 100644
--- a/src/property/apt.lisp
+++ b/src/property/apt.lisp
@@ -163,7 +163,7 @@ only upgrade Debian stable."
(defprop mirror :posix (uri)
(:desc #?"${uri} apt mirror selected")
(:hostattrs
- (pushnew-hostattrs :apt.mirror uri)))
+ (pushnew-hostattr :apt.mirror uri)))
(defpropspec uses-parent-mirrors :posix ()
(:desc #?"Uses parent's apt mirror(s), if any")
@@ -175,7 +175,7 @@ only upgrade Debian stable."
(defprop proxy :posix (uri)
(:desc #?"${uri} apt proxy selected")
(:hostattrs
- (pushnew-hostattrs :apt.proxy uri))
+ (pushnew-hostattr :apt.proxy uri))
(:apply
(file:has-content "/etc/apt/apt.conf.d/20proxy"
(format nil "Acquire::HTTP::Proxy \"~A\";~%" uri))))
diff --git a/src/property/network.lisp b/src/property/network.lisp
index 0a59428..4ac849a 100644
--- a/src/property/network.lisp
+++ b/src/property/network.lisp
@@ -23,9 +23,9 @@
server might have aliases like imap.example.org and smtp.example.org, even
though its hostname is neither 'imap' nor 'smtp'."
(:desc (format nil "Has alias~1{~#[es~;~;es~]~} ~:*~{~A~^, ~}" aliases))
- (:hostattrs (apply #'pushnew-hostattrs
- :aliases (delete (get-hostname) (flatten aliases)
- :test #'string=))))
+ (:hostattrs
+ (pushnew-hostattrs
+ :aliases (delete (get-hostname) (flatten aliases) :test #'string=))))
(defprop ipv4 :posix (&rest addresses)
"Record the host's public Internet IPv4 addresses.
@@ -35,7 +35,7 @@ similar property which pushes hostattrs identified by a non-keyword
symbol (unless your consfig deals only in hosts without public IP addresses,
in which case you can use this property)."
(:desc (format nil "Has public IPv4 ~{~A~^, ~}" addresses))
- (:hostattrs (apply #'pushnew-hostattrs :ipv4 (flatten addresses))))
+ (:hostattrs (pushnew-hostattrs :ipv4 (flatten addresses))))
(defprop ipv6 :posix (&rest addresses)
"Record the host's public Internet IPv6 addresses.
@@ -45,7 +45,7 @@ similar property which pushes hostattrs identified by a non-keyword
symbol (unless your consfig deals only in hosts without public IP addresses,
in which case you can use this property)."
(:desc (format nil "Has public IPv6 ~{~A~^, ~}" addresses))
- (:hostattrs (apply #'pushnew-hostattrs :ipv6 (flatten addresses))))
+ (:hostattrs (pushnew-hostattrs :ipv6 (flatten addresses))))
(defproplist clean-/etc/network/interfaces :posix ()
"Empty /etc/network/interfaces in preparation for configuring interfaces using