aboutsummaryrefslogtreecommitdiff
path: root/src/connection/local.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-02-16 18:39:13 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-02-16 18:39:13 -0700
commitb981a5e783d491de1aad59abb5db8469b73c1080 (patch)
treeca792a586eb97e89e77c304cd7c9a92df6be7920 /src/connection/local.lisp
parentce5ab88ba012ae95c3916246d07e5de495a9edc0 (diff)
downloadconsfigurator-b981a5e783d491de1aad59abb5db8469b73c1080.tar.gz
move code into an src/ subdir
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection/local.lisp')
-rw-r--r--src/connection/local.lisp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/connection/local.lisp b/src/connection/local.lisp
new file mode 100644
index 0000000..e219fea
--- /dev/null
+++ b/src/connection/local.lisp
@@ -0,0 +1,42 @@
+(in-package :consfigurator.connection.local)
+
+(defmethod connect-and-apply ((type (eql :local)) host &key)
+ (apply-properties (make-instance 'local-connection) host))
+
+(defclass local-connection (lisp-connection)
+ ()
+ (:documentation "The root deployment: applying properties to the machine the
+root Lisp is running on, as the root Lisp's uid."))
+
+(defmethod connection-run ((connection local-connection)
+ shell-cmd
+ &optional
+ input)
+ ;; assumes a POSIX shell (otherwise we could wrap in 'sh -c')
+ (multiple-value-bind (output _ exit-code)
+ (uiop:run-program shell-cmd
+ :force-shell t
+ :input (and input
+ (make-string-input-stream input))
+ :output :string
+ :error-output :output)
+ (declare (ignore _))
+ (values output exit-code)))
+
+(defmethod connection-readfile ((connection local-connection) path)
+ (uiop:read-file-string path))
+
+(defmethod connection-writefile ((connection local-connection) path contents)
+ (with-open-file (stream path :direction :output :if-exists :supersede)
+ (write-string contents stream)))
+
+(defmethod connection-upload ((connection local-connection) from to)
+ (uiop:copy-file from to))
+
+;; set the root Lisp's connection context now we've defined its value -- other
+;; implementations of ESTABLISH-CONNECTION will rely on this when they call
+;; RUN, READFILE etc.
+(eval-when (:load-toplevel :execute)
+ (unless consfigurator.core::*connection*
+ (setq consfigurator.core::*connection*
+ (make-instance 'local-connection))))