From 3685369de57bddd242e28fd3cc3603704ebd156d Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Sat, 31 May 2025 16:53:00 +0100 Subject: [PATCH] Fix inventory --- ordo/inventory.scm | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/ordo/inventory.scm b/ordo/inventory.scm index c89f5ec..11123e4 100644 --- a/ordo/inventory.scm +++ b/ordo/inventory.scm @@ -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 (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))))