diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-28 11:34:13 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-29 08:43:35 -0700 |
commit | 451b63e0481090813d060d231a0fee30c125eb30 (patch) | |
tree | 32105a55a58430a73f807347925bc5df9914c497 /src | |
parent | d551549936347ec06656f3e9063a32cac1ad327e (diff) | |
download | consfigurator-451b63e0481090813d060d231a0fee30c125eb30.tar.gz |
ensure implicitly defined hosts have a hostname & add HOSTNAME:IS
Previously, the hosts representing chroots defined inline using dotted propapp
notation did not have any hostname in their hostattrs, but many properties
assume that every HOST object has a hostname. HOSTNAME:IS can be used to
override the default value we provide in MAKE-CHILD-HOST.
This approach avoids adding a hostname parameter to properties like
CHROOT:OS-BOOTSTRAPPED, which would be less convenient because many chroots do
not need a hostname different from their parent's.
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r-- | src/host.lisp | 11 | ||||
-rw-r--r-- | src/package.lisp | 3 | ||||
-rw-r--r-- | src/property/hostname.lisp | 10 |
3 files changed, 18 insertions, 6 deletions
diff --git a/src/host.lisp b/src/host.lisp index 35336da..acda791 100644 --- a/src/host.lisp +++ b/src/host.lisp @@ -98,10 +98,13 @@ values higher up the call stack.")) (defun make-child-host (&key hostattrs propspec) "Make a host object to represent a chroot, container or the like. Called by properties which set up such subhosts, like CHROOT:OS-BOOTSTRAPPED." - (make-instance - 'unpreprocessed-host - :propspec propspec - :hostattrs (list* :parent-hostattrs (hostattrs *host*) hostattrs))) + (let ((hostattrs* + (list* :parent-hostattrs (hostattrs *host*) (copy-list hostattrs)))) + (unless (getf hostattrs :hostname) + (push (car (getf (hostattrs *host*) :hostname)) + (getf hostattrs* :hostname))) + (make-instance 'unpreprocessed-host + :propspec propspec :hostattrs hostattrs*))) (define-print-object-for-structlike host) diff --git a/src/package.lisp b/src/package.lisp index 8e30df7..f865159 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -541,7 +541,8 @@ (:local-nicknames (#:cmd #:consfigurator.property.cmd) (#:container #:consfigurator.property.container) (#:file #:consfigurator.property.file)) - (:export #:configured + (:export #:is + #:configured #:mailname-configured #:search-configured)) diff --git a/src/property/hostname.lisp b/src/property/hostname.lisp index 3930b96..5a93431 100644 --- a/src/property/hostname.lisp +++ b/src/property/hostname.lisp @@ -21,8 +21,15 @@ (defun domain (hostname) (subseq hostname (min (length hostname) (1+ (position #\. hostname))))) +(defprop is :posix (hostname) + "Specify that the hostname of this host is HOSTNAME. +Useful for hosts implicitly defined inline using dotted propapp notation. +Unlikely to be useful for hosts defined using DEFHOST." + (:hostattrs (push-hostattrs :hostname hostname))) + (defpropspec configured :posix - (&optional (hostname (get-hostname)) (domain (domain hostname)) + (&optional (hostname (get-hostname) hostname-supplied-p) + (domain (domain hostname)) &aux (short (car (split-string hostname :separator ".")))) "Set the hostname in the standard Debian way. When HOSTNAME is an FQDN, DOMAIN is the domain part of the hostname, @@ -30,6 +37,7 @@ defaulting to everything after the first dot. (For some hosts, the domain should rather be the whole hostname.)" (:desc "Hostname configured") `(seqprops + ,@(and hostname-supplied-p `((is ,hostname))) (on-change (file:has-content "/etc/hostname" ,short) (container:when-contained (:hostname) (cmd:single ,(strcat "hostname " short)))) |