Fix inventory

This commit is contained in:
Ray Miller 2025-05-31 16:53:00 +01:00
parent f6ef09f91d
commit 3685369de5
Signed by: ray
GPG key ID: 043F786C4CD681B8

View file

@ -2,8 +2,8 @@
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
;; #:use-module ((ordo connection) #:select (local-connection)) TODO: implement connections
#:export (make-host
#:use-module ((ordo connection) #:select (local-connection))
#:export (host
host?
host-name
host-connection
@ -11,8 +11,6 @@
add-host!
resolve-hosts))
(define *inventory* '())
(define-record-type <host>
(make-host name connection tags)
host?
@ -20,9 +18,8 @@
(connection host-connection)
(tags host-tags))
(define (add-host! name connection . tags)
(set! *inventory* (cons (make-host name connection tags)
*inventory*)))
(define (host name connection . tags)
(make-host name connection tags))
(define (tagged-every? wanted-tags)
(lambda (h)
@ -36,13 +33,12 @@
(lambda (h)
(string=? (host-name h) hostname)))
(define resolve-hosts
(match-lambda
("localhost" (list (or (find (named? "localhost") *inventory*)
;;(make-host "localhost" (local-connection) '()) ;; TODO: needs connections
)))
((? string? hostname) (filter (named? hostname) *inventory*))
('all *inventory*)
(('tagged tag) (filter (tagged-every? (list tag)) *inventory*))
(('tagged/every tag . tags) (filter (tagged-every? (cons tag tags)) *inventory*))
(('tagged/any tag . tags) (filter (tagged-any? (cons tag tags)) *inventory*))))
(define (resolve-hosts inventory expr)
(match expr
("localhost" (list (or (find (named? "localhost") inventory)
(make-host "localhost" (local-connection) '()))))
((? string? hostname) (filter (named? hostname) inventory))
('all inventory)
(('tagged tag) (filter (tagged-every? (list tag)) inventory))
(('tagged/every tag . tags) (filter (tagged-every? (cons tag tags)) inventory))
(('tagged/any tag . tags) (filter (tagged-any? (cons tag tags)) inventory))))