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