2024-03-05 00:01:19 +01:00
|
|
|
(local nl (require :anoia.nl))
|
2023-03-01 18:55:52 +01:00
|
|
|
|
|
|
|
; (local { : view} (require :fennel))
|
|
|
|
|
2024-03-05 00:03:42 +01:00
|
|
|
(local { : assoc } (require :anoia))
|
2023-03-01 18:55:52 +01:00
|
|
|
|
|
|
|
(fn parse-args [args]
|
|
|
|
(match args
|
|
|
|
["-v" & rest] (assoc (parse-args rest) :verbose true)
|
|
|
|
["-t" timeout & rest] (assoc (parse-args rest) :timeout (tonumber timeout))
|
|
|
|
[linkname "up"] {:link linkname :expecting "up"}
|
|
|
|
[linkname "running"] {:link linkname :expecting "running"}
|
|
|
|
[linkname "present"] {:link linkname :expecting "present"}
|
|
|
|
[linkname nil] {:link linkname :expecting "present"}
|
|
|
|
_ nil))
|
|
|
|
|
|
|
|
(local parameters
|
|
|
|
(or
|
|
|
|
(parse-args arg)
|
|
|
|
(assert false (.. "Usage: " (. arg 0) " [-v] ifname [present|up|running]"))))
|
|
|
|
|
2024-03-05 00:01:19 +01:00
|
|
|
(fn run-event [v]
|
|
|
|
(let [got
|
|
|
|
(match v
|
|
|
|
;; - up: Reflects the administrative state of the interface (IFF_UP)
|
|
|
|
;; - running: Reflects the operational state (IFF_RUNNING).
|
|
|
|
{:event "newlink" :name parameters.link :up :yes :running :yes}
|
|
|
|
{:present true :up true :running true}
|
2023-03-01 18:55:52 +01:00
|
|
|
|
2024-03-05 00:01:19 +01:00
|
|
|
{:event "newlink" :name parameters.link :up :yes}
|
|
|
|
{:present :true :up true}
|
2023-03-01 18:55:52 +01:00
|
|
|
|
2024-03-05 00:01:19 +01:00
|
|
|
{:event "newlink" :name parameters.link}
|
|
|
|
{:present true }
|
2023-03-01 18:55:52 +01:00
|
|
|
|
2024-03-05 00:01:19 +01:00
|
|
|
_
|
|
|
|
{})]
|
|
|
|
(when (. got parameters.expecting)
|
|
|
|
(os.exit 0))))
|
2023-03-01 18:55:52 +01:00
|
|
|
|
|
|
|
(when parameters.verbose
|
|
|
|
(print (.. (. arg 0) ": waiting for "
|
|
|
|
parameters.link " to be " parameters.expecting)))
|
|
|
|
|
2024-03-05 00:01:19 +01:00
|
|
|
(each [event (nl.events {:link true})]
|
|
|
|
(run-event event))
|