Add support for facts.
This commit is contained in:
parent
5376ce9f19
commit
7f507c8e6d
4 changed files with 64 additions and 10 deletions
|
@ -2,6 +2,7 @@
|
|||
#:use-module (ice-9 exceptions)
|
||||
#:use-module (logging logger)
|
||||
#:use-module (ordo connection)
|
||||
#:use-module (ordo facts)
|
||||
#:use-module (srfi srfi-1) ; list utils
|
||||
#:use-module (srfi srfi-9) ; records
|
||||
#:use-module (srfi srfi-26) ; cut
|
||||
|
@ -27,6 +28,7 @@
|
|||
playbook-plays
|
||||
run-playbook
|
||||
$
|
||||
$$
|
||||
register-play-var
|
||||
register-playbook-var))
|
||||
|
||||
|
@ -67,6 +69,10 @@ variable (in that order). Raise an exception if the variable is not found."
|
|||
v)))))
|
||||
(lookup-var var-name (list +play-vars+ +playbook-vars+)))
|
||||
|
||||
(define ($$ . keys)
|
||||
"Look up nested keys in gathered facts."
|
||||
(apply get-fact (hash-table-ref +play-vars+ #:ordo-facts) keys))
|
||||
|
||||
(define +triggers+ #f)
|
||||
|
||||
(define (add-triggers triggers)
|
||||
|
@ -106,18 +112,19 @@ variable (in that order). Raise an exception if the variable is not found."
|
|||
(make-handler name action))
|
||||
|
||||
(define-record-type <play>
|
||||
(make-play name connection vars tasks handlers)
|
||||
(make-play name connection vars gather-facts tasks handlers)
|
||||
play?
|
||||
(name play-name)
|
||||
(connection play-connection)
|
||||
(vars play-vars)
|
||||
(tasks play-tasks)
|
||||
(handlers play-handlers))
|
||||
(handlers play-handlers)
|
||||
(gather-facts play-gather-facts))
|
||||
|
||||
(define* (play name #:key connection (vars '()) . more)
|
||||
(define* (play name #:key connection (vars '()) (gather-facts #t) . more)
|
||||
(let ((tasks (filter task? more))
|
||||
(handlers (filter handler? more)))
|
||||
(make-play name connection vars tasks handlers)))
|
||||
(make-play name connection vars gather-facts tasks handlers)))
|
||||
|
||||
(define (run-play p)
|
||||
(log-msg 'NOTICE "Running play " (play-name p))
|
||||
|
@ -126,6 +133,8 @@ variable (in that order). Raise an exception if the variable is not found."
|
|||
(set! +play-vars+ (alist->hash-table (play-vars p) equal?))
|
||||
(init-connection! (play-connection p)))
|
||||
(lambda ()
|
||||
(when (play-gather-facts p)
|
||||
(hash-table-set! +play-vars+ #:ordo-facts (gather-facts (play-connection p))))
|
||||
(for-each (cut run-task <> (play-connection p)) (play-tasks p))
|
||||
(for-each (lambda (h)
|
||||
(when (member (handler-name h) +triggers+)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue